Skip to content

Commit 2859994

Browse files
committed
In local environments, by default, don't run OS updates/upgrades.
1 parent a7acb16 commit 2859994

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

environs/cloudinit/cloudinit.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,17 @@ func AddAptCommands(
189189
c.SetAptUpgrade(addUpgradeScripts)
190190
c.SetAptGetWrapper("eatmydata")
191191

192-
c.AddPackage("curl")
193-
c.AddPackage("cpu-checker")
194-
// TODO(axw) 2014-07-02 #1277359
195-
// Don't install bridge-utils in cloud-init;
196-
// leave it to the networker worker.
197-
c.AddPackage("bridge-utils")
198-
c.AddPackage("rsyslog-gnutls")
192+
// If we're not doing an update, adding these packages is
193+
// meaningless.
194+
if addUpdateScripts {
195+
c.AddPackage("curl")
196+
c.AddPackage("cpu-checker")
197+
// TODO(axw) 2014-07-02 #1277359
198+
// Don't install bridge-utils in cloud-init;
199+
// leave it to the networker worker.
200+
c.AddPackage("bridge-utils")
201+
c.AddPackage("rsyslog-gnutls")
202+
}
199203

200204
// Write out the apt proxy settings
201205
if (proxySettings != proxy.Settings{}) {

provider/local/environ.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ func ensureNotRoot() error {
106106
}
107107

108108
// Bootstrap is specified in the Environ interface.
109-
func (env *localEnviron) Bootstrap(ctx environs.BootstrapContext, args environs.BootstrapParams) (arch, series string, _ environs.BootstrapFinalizer, _ error) {
109+
func (env *localEnviron) Bootstrap(
110+
ctx environs.BootstrapContext,
111+
args environs.BootstrapParams,
112+
) (arch, series string, _ environs.BootstrapFinalizer, _ error) {
110113
if err := ensureNotRoot(); err != nil {
111114
return "", "", nil, err
112115
}
@@ -120,10 +123,24 @@ func (env *localEnviron) Bootstrap(ctx environs.BootstrapContext, args environs.
120123
return "", "", nil, err
121124
}
122125

123-
// Record the bootstrap IP, so the containers know where to go for storage.
124-
cfg, err := env.Config().Apply(map[string]interface{}{
126+
configAttrs := env.Config().AllAttrs()
127+
toApply := map[string]interface{}{
128+
// Record the bootstrap IP, so the containers know where to go for storage.
125129
"bootstrap-ip": env.bridgeAddress,
126-
})
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)
127144
if err == nil {
128145
err = env.SetConfig(cfg)
129146
}

provider/local/environ_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ func (s *localJujuTestSuite) testBootstrap(c *gc.C, cfg *config.Config) environs
195195
func (s *localJujuTestSuite) TestBootstrap(c *gc.C) {
196196

197197
mockFinish := func(ctx environs.BootstrapContext, mcfg *cloudinit.MachineConfig, cloudcfg *coreCloudinit.Config) error {
198-
c.Assert(cloudcfg.AptUpdate(), jc.IsTrue)
199-
c.Assert(cloudcfg.AptUpgrade(), jc.IsTrue)
198+
c.Assert(cloudcfg.AptUpdate(), gc.Equals, mcfg.EnableOSRefreshUpdate)
199+
c.Assert(cloudcfg.AptUpgrade(), gc.Equals, mcfg.EnableOSUpgrade)
200200
if !mcfg.EnableOSRefreshUpdate {
201201
c.Assert(cloudcfg.Packages(), gc.HasLen, 0)
202202
}
@@ -206,7 +206,18 @@ func (s *localJujuTestSuite) TestBootstrap(c *gc.C) {
206206
return nil
207207
}
208208
s.PatchValue(local.ExecuteCloudConfig, mockFinish)
209-
s.testBootstrap(c, minimalConfig(c))
209+
210+
// Test that defaults are correct.
211+
minCfg := minimalConfig(c)
212+
s.testBootstrap(c, minCfg)
213+
214+
// Test that overrides work.
215+
minCfg, err := minCfg.Apply(map[string]interface{}{
216+
"enable-os-refresh-update": true,
217+
"enable-os-upgrade": true,
218+
})
219+
c.Assert(err, gc.IsNil)
220+
s.testBootstrap(c, minCfg)
210221
}
211222

212223
func (s *localJujuTestSuite) TestDestroy(c *gc.C) {

0 commit comments

Comments
 (0)