18
18
"launchpad.net/juju-core/juju/osenv"
19
19
"launchpad.net/juju-core/schema"
20
20
"launchpad.net/juju-core/testing"
21
"launchpad.net/juju-core/testing/testbase"
22
21
"launchpad.net/juju-core/version"
29
28
type ConfigSuite struct {
29
testing.FakeJujuHomeSuite
34
33
var _ = gc.Suite(&ConfigSuite{})
36
35
func (s *ConfigSuite) SetUpTest(c *gc.C) {
37
s.LoggingSuite.SetUpTest(c)
36
s.FakeJujuHomeSuite.SetUpTest(c)
38
37
// Make sure that the defaults are used, which
39
38
// is <root>=WARNING
40
39
loggo.ResetLoggers()
140
140
"authorized-keys-path": "~/.ssh/authorized_keys2",
143
about: "LXC clone values",
144
useDefaults: config.UseDefaults,
145
attrs: testing.Attrs{
148
"default-series": "precise",
150
"lxc-clone-aufs": true,
153
about: "Deprecated lxc-use-clone used",
154
useDefaults: config.UseDefaults,
155
attrs: testing.Attrs{
158
"lxc-use-clone": true,
161
about: "Deprecated lxc-use-clone ignored",
162
useDefaults: config.UseDefaults,
163
attrs: testing.Attrs{
166
"lxc-use-clone": false,
143
170
about: "CA cert & key from path",
144
171
useDefaults: config.UseDefaults,
145
172
attrs: testing.Attrs{
696
723
name, data string
699
func (*ConfigSuite) TestConfig(c *gc.C) {
726
func (s *ConfigSuite) TestConfig(c *gc.C) {
700
727
files := []testing.TestFile{
701
728
{".ssh/id_dsa.pub", "dsa"},
702
729
{".ssh/id_rsa.pub", "rsa\n"},
711
738
{"othercert.pem", caCert3},
712
739
{"otherkey.pem", caKey3},
714
h := testing.MakeFakeHomeWithFiles(c, files)
741
s.FakeHomeSuite.Home.AddFiles(c, files...)
716
742
for i, test := range configTests {
717
743
c.Logf("test %d. %s", i, test.about)
744
test.check(c, s.FakeHomeSuite.Home)
744
func (*ConfigSuite) TestConfigNoCertFiles(c *gc.C) {
745
h := testing.MakeEmptyFakeHome(c)
770
func (s *ConfigSuite) TestConfigNoCertFiles(c *gc.C) {
747
771
for i, test := range noCertFilesTests {
748
772
c.Logf("test %d. %s", i, test.about)
773
test.check(c, s.FakeHomeSuite.Home)
806
func (*ConfigSuite) TestConfigEmptyCertFiles(c *gc.C) {
830
func (s *ConfigSuite) TestConfigEmptyCertFiles(c *gc.C) {
807
831
files := []testing.TestFile{
808
832
{".juju/my-name-cert.pem", ""},
809
833
{".juju/my-name-private-key.pem", ""},
811
h := testing.MakeFakeHomeWithFiles(c, files)
835
s.FakeHomeSuite.Home.AddFiles(c, files...)
814
837
for i, test := range emptyCertFilesTests {
815
838
c.Logf("test %d. %s", i, test.about)
839
test.check(c, s.FakeHomeSuite.Home)
981
1004
c.Assert(oldURLAttrPresent, jc.IsFalse)
982
1005
c.Assert(oldToolsURL, gc.Equals, "")
1008
useLxcClone, useLxcClonePresent := cfg.LXCUseClone()
1009
oldUseClone, oldUseClonePresent := cfg.AllAttrs()["lxc-use-clone"]
1010
if v, ok := test.attrs["lxc-clone"]; ok {
1011
c.Assert(useLxcClone, gc.Equals, v)
1012
c.Assert(useLxcClonePresent, jc.IsTrue)
1014
if oldUseClonePresent {
1015
c.Assert(useLxcClonePresent, jc.IsTrue)
1016
c.Assert(useLxcClone, gc.Equals, oldUseClone)
1018
c.Assert(useLxcClonePresent, jc.IsFalse)
1019
c.Assert(useLxcClone, gc.Equals, false)
1022
useLxcCloneAufs, ok := cfg.LXCUseCloneAUFS()
1023
if v, ok := test.attrs["lxc-clone-aufs"]; ok {
1024
c.Assert(useLxcCloneAufs, gc.Equals, v)
1026
c.Assert(useLxcCloneAufs, gc.Equals, false)
986
1030
func (test configTest) assertDuration(c *gc.C, name string, actual time.Duration, defaultInSeconds int) {
1028
1072
attrs["tools-url"] = ""
1029
1073
attrs["image-stream"] = ""
1030
1074
attrs["proxy-ssh"] = false
1031
attrs["lxc-use-clone"] = false
1075
attrs["lxc-clone-aufs"] = false
1033
1077
// Default firewall mode is instance
1034
1078
attrs["firewall-mode"] = string(config.FwInstance)
1112
1156
new: testing.Attrs{"bootstrap-timeout": 5},
1113
1157
err: `cannot change bootstrap-timeout from 600 to 5`,
1115
about: "Cannot change lxc-use-clone",
1116
old: testing.Attrs{"lxc-use-clone": false},
1117
new: testing.Attrs{"lxc-use-clone": true},
1118
err: `cannot change lxc-use-clone from false to true`,
1159
about: "Cannot change lxc-clone",
1160
old: testing.Attrs{"lxc-clone": false},
1161
new: testing.Attrs{"lxc-clone": true},
1162
err: `cannot change lxc-clone from false to true`,
1164
about: "Cannot change lxc-clone-aufs",
1165
old: testing.Attrs{"lxc-clone-aufs": false},
1166
new: testing.Attrs{"lxc-clone-aufs": true},
1167
err: `cannot change lxc-clone-aufs from false to true`,
1121
func (*ConfigSuite) TestValidateChange(c *gc.C) {
1170
func (s *ConfigSuite) TestValidateChange(c *gc.C) {
1122
1171
files := []testing.TestFile{
1123
1172
{".ssh/identity.pub", "identity"},
1125
h := testing.MakeFakeHomeWithFiles(c, files)
1174
s.FakeHomeSuite.Home.AddFiles(c, files...)
1128
1176
for i, test := range validationTests {
1129
1177
c.Logf("test %d: %s", i, test.about)
1131
1179
oldConfig := newTestConfig(c, test.old)
1132
1180
err := config.Validate(newConfig, oldConfig)
1133
1181
if test.err == "" {
1134
c.Assert(err, gc.IsNil)
1182
c.Check(err, gc.IsNil)
1136
c.Assert(err, gc.ErrorMatches, test.err)
1184
c.Check(err, gc.ErrorMatches, test.err)
1141
func makeFakeHome(c *gc.C) *testing.FakeHome {
1142
return testing.MakeFakeHomeWithFiles(c, []testing.TestFile{
1189
func (s *ConfigSuite) addJujuFiles(c *gc.C) {
1190
s.FakeHomeSuite.Home.AddFiles(c, []testing.TestFile{
1143
1191
{".ssh/id_rsa.pub", "rsa\n"},
1144
1192
{".juju/myenv-cert.pem", caCert},
1145
1193
{".juju/myenv-private-key.pem", caKey},
1149
func (*ConfigSuite) TestValidateUnknownAttrs(c *gc.C) {
1150
defer makeFakeHome(c).Restore()
1197
func (s *ConfigSuite) TestValidateUnknownAttrs(c *gc.C) {
1151
1199
cfg, err := config.New(config.UseDefaults, map[string]interface{}{
1152
1200
"name": "myenv",
1153
1201
"type": "other",
1202
func (*ConfigSuite) TestLoggingConfig(c *gc.C) {
1203
defer makeFakeHome(c).Restore()
1250
func (s *ConfigSuite) TestLoggingConfig(c *gc.C) {
1205
1252
config := newTestConfig(c, testing.Attrs{
1206
1253
"logging-config": "<root>=WARNING;juju=DEBUG"})
1207
1254
c.Assert(config.LoggingConfig(), gc.Equals, "<root>=WARNING;juju=DEBUG;unit=DEBUG")
1210
func (*ConfigSuite) TestLoggingConfigWithUnit(c *gc.C) {
1211
defer makeFakeHome(c).Restore()
1257
func (s *ConfigSuite) TestLoggingConfigWithUnit(c *gc.C) {
1213
1259
config := newTestConfig(c, testing.Attrs{
1214
1260
"logging-config": "<root>=WARNING;unit=INFO"})
1215
1261
c.Assert(config.LoggingConfig(), gc.Equals, "<root>=WARNING;unit=INFO")
1218
1264
func (s *ConfigSuite) TestLoggingConfigFromEnvironment(c *gc.C) {
1219
defer makeFakeHome(c).Restore()
1220
1266
s.PatchEnvironment(osenv.JujuLoggingConfigEnvKey, "<root>=INFO")
1222
1268
config := newTestConfig(c, nil)
1223
1269
c.Assert(config.LoggingConfig(), gc.Equals, "<root>=INFO;unit=DEBUG")
1226
func (*ConfigSuite) TestProxyValuesWithFallback(c *gc.C) {
1227
defer makeFakeHome(c).Restore()
1272
func (s *ConfigSuite) TestProxyValuesWithFallback(c *gc.C) {
1229
1275
config := newTestConfig(c, testing.Attrs{
1230
1276
"http-proxy": "http://user@10.0.0.1",
1241
1287
c.Assert(config.NoProxy(), gc.Equals, "localhost,10.0.3.1")
1244
func (*ConfigSuite) TestProxyValues(c *gc.C) {
1245
defer makeFakeHome(c).Restore()
1290
func (s *ConfigSuite) TestProxyValues(c *gc.C) {
1247
1292
config := newTestConfig(c, testing.Attrs{
1248
1293
"http-proxy": "http://user@10.0.0.1",
1249
1294
"https-proxy": "https://user@10.0.0.1",
1260
1305
c.Assert(config.AptFtpProxy(), gc.Equals, "ftp://user@10.0.0.2")
1263
func (*ConfigSuite) TestProxyValuesNotSet(c *gc.C) {
1264
defer makeFakeHome(c).Restore()
1308
func (s *ConfigSuite) TestProxyValuesNotSet(c *gc.C) {
1266
1310
config := newTestConfig(c, testing.Attrs{})
1267
1311
c.Assert(config.HttpProxy(), gc.Equals, "")
1268
1312
c.Assert(config.AptHttpProxy(), gc.Equals, "")
1273
1317
c.Assert(config.NoProxy(), gc.Equals, "")
1276
func (*ConfigSuite) TestProxyConfigMap(c *gc.C) {
1277
defer makeFakeHome(c).Restore()
1320
func (s *ConfigSuite) TestProxyConfigMap(c *gc.C) {
1279
1322
cfg := newTestConfig(c, testing.Attrs{})
1280
1323
proxy := osenv.ProxySettings{
1281
1324
Http: "http proxy",
1291
1334
c.Assert(cfg.AptProxySettings(), gc.DeepEquals, proxy)
1294
func (*ConfigSuite) TestAptProxyConfigMap(c *gc.C) {
1295
defer makeFakeHome(c).Restore()
1337
func (s *ConfigSuite) TestAptProxyConfigMap(c *gc.C) {
1297
1339
cfg := newTestConfig(c, testing.Attrs{})
1298
1340
proxy := osenv.ProxySettings{
1299
1341
Http: "http proxy",
1307
1349
c.Assert(cfg.AptProxySettings(), gc.DeepEquals, proxy)
1310
func (*ConfigSuite) TestGenerateStateServerCertAndKey(c *gc.C) {
1311
// In order to test missing certs, it checks the JUJU_HOME dir, so we need
1313
defer testing.MakeFakeHomeWithFiles(c, []testing.TestFile{
1314
{".ssh/id_rsa.pub", "rsa\n"},
1352
func (s *ConfigSuite) TestGenerateStateServerCertAndKey(c *gc.C) {
1354
s.FakeHomeSuite.Home.AddFiles(c, testing.TestFile{".ssh/id_rsa.pub", "rsa\n"})
1317
1356
for _, test := range []struct {
1318
1357
configValues map[string]interface{}