Skip to content

Commit f71ac7a

Browse files
committed
Updated tests to reflect behavior when updates are off.
1 parent afebdc0 commit f71ac7a

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed

environs/cloudinit/cloudinit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ func (*cloudinitSuite) TestCloudInit(c *gc.C) {
543543
if test.cfg.Config != nil {
544544
checkEnvConfig(c, test.cfg.Config, configKeyValues, scripts)
545545
}
546-
checkPackage(c, configKeyValues, "curl", true)
546+
checkPackage(c, configKeyValues, "curl", test.cfg.EnableOSRefreshUpdate)
547547

548548
tag := names.NewMachineTag(test.cfg.MachineId).String()
549549
acfg := getAgentConfig(c, tag, scripts)

provider/local/environ.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,10 @@ func (env *localEnviron) Bootstrap(
123123
return "", "", nil, err
124124
}
125125

126-
configAttrs := env.Config().AllAttrs()
127-
toApply := map[string]interface{}{
126+
cfg, err := env.Config().Apply(map[string]interface{}{
128127
// Record the bootstrap IP, so the containers know where to go for storage.
129128
"bootstrap-ip": env.bridgeAddress,
130-
}
131-
132-
setIfNot := func(key string, value interface{}) {
133-
if _, ok := configAttrs[key]; !ok {
134-
toApply[key] = value
135-
}
136-
}
137-
138-
// Since Juju's state machine is currently the host machine
139-
// for local providers, don't stomp on it.
140-
setIfNot("enable-os-refresh-update", false)
141-
setIfNot("enable-os-upgrade", false)
142-
143-
cfg, err := env.Config().Apply(toApply)
129+
})
144130
if err == nil {
145131
err = env.SetConfig(cfg)
146132
}
@@ -159,8 +145,7 @@ func (env *localEnviron) finishBootstrap(ctx environs.BootstrapContext, mcfg *cl
159145
mcfg.LogDir = fmt.Sprintf("/var/log/juju-%s", env.config.namespace())
160146
mcfg.Jobs = []params.MachineJob{params.JobManageEnviron}
161147
mcfg.CloudInitOutputLog = filepath.Join(mcfg.DataDir, "cloud-init-output.log")
162-
mcfg.EnableOSRefreshUpdate = env.config.Config.EnableOSRefreshUpdate()
163-
mcfg.EnableOSUpgrade = env.config.Config.EnableOSUpgrade()
148+
164149
mcfg.MachineAgentServiceName = env.machineAgentServiceName()
165150
mcfg.AgentEnvironment = map[string]string{
166151
agent.Namespace: env.config.namespace(),
@@ -172,10 +157,27 @@ func (env *localEnviron) finishBootstrap(ctx environs.BootstrapContext, mcfg *cl
172157
// the preallocation faster with no disadvantage.
173158
agent.MongoOplogSize: "1", // 1MB
174159
}
160+
175161
if err := environs.FinishMachineConfig(mcfg, env.Config()); err != nil {
176162
return err
177163
}
178164

165+
// Since Juju's state machine is currently the host machine
166+
// for local providers, don't stomp on it.
167+
cfgAttrs := env.config.AllAttrs()
168+
if val, ok := cfgAttrs["enable-os-refresh-update"].(bool); !ok {
169+
logger.Infof("local provider; disabling refreshing OS updates.")
170+
mcfg.EnableOSRefreshUpdate = false
171+
} else {
172+
mcfg.EnableOSRefreshUpdate = val
173+
}
174+
if val, ok := cfgAttrs["enable-os-upgrade"].(bool); !ok {
175+
logger.Infof("local provider; disabling OS upgrades.")
176+
mcfg.EnableOSUpgrade = false
177+
} else {
178+
mcfg.EnableOSUpgrade = val
179+
}
180+
179181
// don't write proxy settings for local machine
180182
mcfg.AptProxySettings = proxy.Settings{}
181183
mcfg.ProxySettings = proxy.Settings{}

provider/local/environ_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,23 @@ func (s *localJujuTestSuite) testBootstrap(c *gc.C, cfg *config.Config) environs
194194

195195
func (s *localJujuTestSuite) TestBootstrap(c *gc.C) {
196196

197+
minCfg := minimalConfig(c)
198+
197199
mockFinish := func(ctx environs.BootstrapContext, mcfg *cloudinit.MachineConfig, cloudcfg *coreCloudinit.Config) error {
198-
c.Assert(cloudcfg.AptUpdate(), gc.Equals, mcfg.EnableOSRefreshUpdate)
199-
c.Assert(cloudcfg.AptUpgrade(), gc.Equals, mcfg.EnableOSUpgrade)
200+
201+
envCfgAttrs := minCfg.AllAttrs()
202+
if val, ok := envCfgAttrs["enable-os-refresh-update"]; !ok {
203+
c.Check(cloudcfg.AptUpdate(), gc.Equals, false)
204+
} else {
205+
c.Check(cloudcfg.AptUpdate(), gc.Equals, val)
206+
}
207+
208+
if val, ok := envCfgAttrs["enable-os-upgrade"]; !ok {
209+
c.Check(cloudcfg.AptUpgrade(), gc.Equals, false)
210+
} else {
211+
c.Check(cloudcfg.AptUpgrade(), gc.Equals, val)
212+
}
213+
200214
if !mcfg.EnableOSRefreshUpdate {
201215
c.Assert(cloudcfg.Packages(), gc.HasLen, 0)
202216
}
@@ -208,7 +222,6 @@ func (s *localJujuTestSuite) TestBootstrap(c *gc.C) {
208222
s.PatchValue(local.ExecuteCloudConfig, mockFinish)
209223

210224
// Test that defaults are correct.
211-
minCfg := minimalConfig(c)
212225
s.testBootstrap(c, minCfg)
213226

214227
// Test that overrides work.

0 commit comments

Comments
 (0)