Merge lp:~wallyworld/juju-core/upgrade-remove-old-config into lp:~go-bot/juju-core/trunk

Proposed by Ian Booth
Status: Merged
Approved by: Ian Booth
Approved revision: no longer in the source branch.
Merged at revision: 2374
Proposed branch: lp:~wallyworld/juju-core/upgrade-remove-old-config
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~axwalk/juju-core/upgrade-syslog-port
Diff against target: 282 lines (+161/-12)
9 files modified
cmd/jujud/upgrade_test.go (+6/-0)
provider/openstack/config.go (+12/-5)
provider/openstack/config_test.go (+22/-6)
upgrades/deprecatedattributes.go (+30/-0)
upgrades/deprecatedattributes_test.go (+83/-0)
upgrades/export_test.go (+1/-0)
upgrades/steps118.go (+5/-0)
upgrades/steps118_test.go (+1/-0)
upgrades/systemsshkey_test.go (+1/-1)
To merge this branch: bzr merge lp:~wallyworld/juju-core/upgrade-remove-old-config
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+208986@code.launchpad.net

Description of the change

Deprecated attributes upgrader

Previous versions of Juju will have left deprecated
attributes hanging around in the environment. This
upgrader will remove such attributes from env state.
eg default-image-id which is ignored will be put
into env state. This upgrader removes it. Also,
the deprecated attributes are no longer propagated
when a new env config is made.

https://codereview.appspot.com/70230049/

To post a comment you must log in.
Revision history for this message
Ian Booth (wallyworld) wrote :

Reviewers: mp+208986_code.launchpad.net,

Message:
Please take a look.

Description:
Deprecated attributes upgrader

Previous versions of Juju will have left deprecated
attributes hanging around in the environment. This
upgrader will remove such attributes from env state.
eg default-image-id which is ignored will be put
into env state. This upgrader removes it. Also,
the deprecated attributes are no longer propagated
when a new env config is made.

https://code.launchpad.net/~wallyworld/juju-core/upgrade-remove-old-config/+merge/208986

Requires:
https://code.launchpad.net/~axwalk/juju-core/upgrade-syslog-port/+merge/208724

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/70230049/

Affected files (+165, -16 lines):
   A [revision details]
   M cmd/jujud/machine.go
   M cmd/jujud/unit.go
   M cmd/jujud/upgrade_test.go
   M cmd/logging.go
   M cmd/logging_test.go
   M provider/openstack/config.go
   M provider/openstack/config_test.go
   A upgrades/deprecatedattributes.go
   A upgrades/deprecatedattributes_test.go
   M upgrades/export_test.go
   M upgrades/steps118.go
   M upgrades/steps118_test.go
   M upgrades/systemsshkey_test.go

Revision history for this message
Tim Penhey (thumper) wrote :

LGTM - although not a fan of all the value asserts in the setup.

https://codereview.appspot.com/70230049/diff/1/cmd/jujud/machine.go
File cmd/jujud/machine.go (right):

https://codereview.appspot.com/70230049/diff/1/cmd/jujud/machine.go#newcode121
cmd/jujud/machine.go:121: logger.Infof("machine agent %v start (%s)",
a.Tag(), version.Current)
I'm sure I saw this somewhere else, missing prereq?

https://codereview.appspot.com/70230049/diff/1/upgrades/deprecatedattributes_test.go
File upgrades/deprecatedattributes_test.go (right):

https://codereview.appspot.com/70230049/diff/1/upgrades/deprecatedattributes_test.go#newcode46
upgrades/deprecatedattributes_test.go:46:
c.Assert(allAttrs["public-bucket"], gc.Equals, "foo")
Seems a lot to me to have the asserts in setup for this

https://codereview.appspot.com/70230049/

Revision history for this message
Ian Booth (wallyworld) wrote :

https://codereview.appspot.com/70230049/diff/1/upgrades/deprecatedattributes_test.go
File upgrades/deprecatedattributes_test.go (right):

https://codereview.appspot.com/70230049/diff/1/upgrades/deprecatedattributes_test.go#newcode46
upgrades/deprecatedattributes_test.go:46:
c.Assert(allAttrs["public-bucket"], gc.Equals, "foo")
On 2014/03/04 03:04:57, thumper wrote:
> Seems a lot to me to have the asserts in setup for this

I can remove them but these serve to double check that the attributes
really are set so that we can be sure the test is testing what we think
it is.

https://codereview.appspot.com/70230049/

Revision history for this message
Ian Booth (wallyworld) wrote :

https://codereview.appspot.com/70230049/diff/1/upgrades/deprecatedattributes_test.go
File upgrades/deprecatedattributes_test.go (right):

https://codereview.appspot.com/70230049/diff/1/upgrades/deprecatedattributes_test.go#newcode46
upgrades/deprecatedattributes_test.go:46:
c.Assert(allAttrs["public-bucket"], gc.Equals, "foo")
On 2014/03/04 03:04:57, thumper wrote:
> Seems a lot to me to have the asserts in setup for this

I added an explicit test

https://codereview.appspot.com/70230049/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/jujud/upgrade_test.go'
2--- cmd/jujud/upgrade_test.go 2014-03-04 04:39:34 +0000
3+++ cmd/jujud/upgrade_test.go 2014-03-04 04:39:35 +0000
4@@ -114,6 +114,12 @@
5 cfg, err := s.State.EnvironConfig()
6 c.Assert(err, gc.IsNil)
7 c.Assert(cfg.SyslogPort(), gc.Equals, config.DefaultSyslogPort)
8+ // Deprecated attributes should have been deleted - just test a couple.
9+ allAttrs := cfg.AllAttrs()
10+ _, ok := allAttrs["public-bucket"]
11+ c.Assert(ok, jc.IsFalse)
12+ _, ok = allAttrs["public-bucket-region"]
13+ c.Assert(ok, jc.IsFalse)
14 }
15
16 func (s *UpgradeSuite) assertHostUpgrades(c *gc.C) {
17
18=== modified file 'provider/openstack/config.go'
19--- provider/openstack/config.go 2014-01-24 16:32:15 +0000
20+++ provider/openstack/config.go 2014-03-04 04:39:35 +0000
21@@ -198,7 +198,8 @@
22
23 // Check for deprecated fields and log a warning. We also print to stderr to ensure the user sees the message
24 // even if they are not running with --debug.
25- if defaultImageId := cfg.AllAttrs()["default-image-id"]; defaultImageId != nil && defaultImageId.(string) != "" {
26+ cfgAttrs := cfg.AllAttrs()
27+ if defaultImageId := cfgAttrs["default-image-id"]; defaultImageId != nil && defaultImageId.(string) != "" {
28 msg := fmt.Sprintf(
29 "Config attribute %q (%v) is deprecated and ignored.\n"+
30 "Your cloud provider should have set up image metadata to provide the correct image id\n"+
31@@ -208,7 +209,7 @@
32 "default-image-id", defaultImageId)
33 logger.Warningf(msg)
34 }
35- if defaultInstanceType := cfg.AllAttrs()["default-instance-type"]; defaultInstanceType != nil && defaultInstanceType.(string) != "" {
36+ if defaultInstanceType := cfgAttrs["default-instance-type"]; defaultInstanceType != nil && defaultInstanceType.(string) != "" {
37 msg := fmt.Sprintf(
38 "Config attribute %q (%v) is deprecated and ignored.\n"+
39 "The correct instance flavor is determined using constraints, globally specified\n"+
40@@ -217,7 +218,13 @@
41 "default-instance-type", defaultInstanceType)
42 logger.Warningf(msg)
43 }
44-
45- // Apply the coerced unknown values back into the config.
46- return cfg.Apply(ecfg.attrs)
47+ // Construct a new config with the deprecated attributes removed.
48+ for _, attr := range []string{"default-image-id", "default-instance-type"} {
49+ delete(cfgAttrs, attr)
50+ delete(ecfg.attrs, attr)
51+ }
52+ for k, v := range ecfg.attrs {
53+ cfgAttrs[k] = v
54+ }
55+ return config.New(config.NoDefaults, cfgAttrs)
56 }
57
58=== modified file 'provider/openstack/config_test.go'
59--- provider/openstack/config_test.go 2014-02-13 02:46:58 +0000
60+++ provider/openstack/config_test.go 2014-03-04 04:39:35 +0000
61@@ -55,7 +55,6 @@
62 envVars map[string]string
63 region string
64 controlBucket string
65- toolsURL string
66 useFloatingIP bool
67 useDefaultSecurityGroup bool
68 network string
69@@ -152,11 +151,6 @@
70 c.Assert(err, gc.IsNil)
71 c.Assert(expected, gc.DeepEquals, actual)
72 }
73- if t.toolsURL != "" {
74- toolsURL, ok := ecfg.ToolsURL()
75- c.Assert(ok, jc.IsTrue)
76- c.Assert(toolsURL, gc.Equals, t.toolsURL)
77- }
78 if t.firewallMode != "" {
79 c.Assert(ecfg.FirewallMode(), gc.Equals, t.firewallMode)
80 }
81@@ -452,6 +446,28 @@
82 }
83 }
84
85+func (s *ConfigSuite) TestDeprecatedAttributesRemoved(c *gc.C) {
86+ s.setupEnvCredentials()
87+ attrs := testing.FakeConfig().Merge(testing.Attrs{
88+ "type": "openstack",
89+ "control-bucket": "x",
90+ "default-image-id": "id-1234",
91+ "default-instance-type": "big",
92+ })
93+
94+ cfg, err := config.New(config.NoDefaults, attrs)
95+ c.Assert(err, gc.IsNil)
96+ // Keep err for validation below.
97+ valid, err := providerInstance.Validate(cfg, nil)
98+ c.Assert(err, gc.IsNil)
99+ // Check deprecated attributes removed.
100+ allAttrs := valid.AllAttrs()
101+ for _, attr := range []string{"default-image-id", "default-instance-type"} {
102+ _, ok := allAttrs[attr]
103+ c.Assert(ok, jc.IsFalse)
104+ }
105+}
106+
107 func (s *ConfigSuite) TestPrepareInsertsUniqueControlBucket(c *gc.C) {
108 s.setupEnvCredentials()
109 attrs := testing.FakeConfig().Merge(testing.Attrs{
110
111=== added file 'upgrades/deprecatedattributes.go'
112--- upgrades/deprecatedattributes.go 1970-01-01 00:00:00 +0000
113+++ upgrades/deprecatedattributes.go 2014-03-04 04:39:35 +0000
114@@ -0,0 +1,30 @@
115+// Copyright 2014 Canonical Ltd.
116+// Licensed under the AGPLv3, see LICENCE file for details.
117+
118+package upgrades
119+
120+import (
121+ "fmt"
122+
123+ "launchpad.net/juju-core/environs/config"
124+)
125+
126+func processDeprecatedAttributes(context Context) error {
127+ st := context.State()
128+ cfg, err := st.EnvironConfig()
129+ if err != nil {
130+ return fmt.Errorf("failed to read current config: %v", err)
131+ }
132+ newAttrs := cfg.AllAttrs()
133+ delete(newAttrs, "public-bucket")
134+ delete(newAttrs, "public-bucket-region")
135+ delete(newAttrs, "public-bucket-url")
136+ delete(newAttrs, "default-image-id")
137+ delete(newAttrs, "default-instance-type")
138+ // TODO (wallyworld) - delete tools-url in 1.20
139+ newCfg, err := config.New(config.NoDefaults, newAttrs)
140+ if err != nil {
141+ return fmt.Errorf("failed to create new config: %v", err)
142+ }
143+ return st.SetEnvironConfig(newCfg, cfg)
144+}
145
146=== added file 'upgrades/deprecatedattributes_test.go'
147--- upgrades/deprecatedattributes_test.go 1970-01-01 00:00:00 +0000
148+++ upgrades/deprecatedattributes_test.go 2014-03-04 04:39:35 +0000
149@@ -0,0 +1,83 @@
150+// Copyright 2014 Canonical Ltd.
151+// Licensed under the AGPLv3, see LICENCE file for details.
152+
153+package upgrades_test
154+
155+import (
156+ gc "launchpad.net/gocheck"
157+
158+ jujutesting "launchpad.net/juju-core/juju/testing"
159+ "launchpad.net/juju-core/state"
160+ jc "launchpad.net/juju-core/testing/checkers"
161+ "launchpad.net/juju-core/upgrades"
162+)
163+
164+type processDeprecatedAttributesSuite struct {
165+ jujutesting.JujuConnSuite
166+ ctx upgrades.Context
167+}
168+
169+var _ = gc.Suite(&processDeprecatedAttributesSuite{})
170+
171+func (s *processDeprecatedAttributesSuite) SetUpTest(c *gc.C) {
172+ s.JujuConnSuite.SetUpTest(c)
173+ apiState, _ := s.OpenAPIAsNewMachine(c, state.JobManageEnviron)
174+ s.ctx = &mockContext{
175+ agentConfig: &mockAgentConfig{dataDir: s.DataDir()},
176+ apiState: apiState,
177+ state: s.State,
178+ }
179+ cfg, err := s.State.EnvironConfig()
180+ c.Assert(err, gc.IsNil)
181+ // Add in old public bucket config.
182+ newCfg, err := cfg.Apply(map[string]interface{}{
183+ "public-bucket": "foo",
184+ "public-bucket-region": "bar",
185+ "public-bucket-url": "shazbot",
186+ "default-instance-type": "vulch",
187+ "default-image-id": "1234",
188+ })
189+ c.Assert(err, gc.IsNil)
190+ err = s.State.SetEnvironConfig(newCfg, cfg)
191+ c.Assert(err, gc.IsNil)
192+}
193+
194+func (s *processDeprecatedAttributesSuite) TestAttributesSet(c *gc.C) {
195+ cfg, err := s.State.EnvironConfig()
196+ c.Assert(err, gc.IsNil)
197+ allAttrs := cfg.AllAttrs()
198+ c.Assert(allAttrs["public-bucket"], gc.Equals, "foo")
199+ c.Assert(allAttrs["public-bucket-region"], gc.Equals, "bar")
200+ c.Assert(allAttrs["public-bucket-url"], gc.Equals, "shazbot")
201+ c.Assert(allAttrs["default-instance-type"], gc.Equals, "vulch")
202+ c.Assert(allAttrs["default-image-id"], gc.Equals, "1234")
203+}
204+
205+func (s *processDeprecatedAttributesSuite) assertConfigProcessed(c *gc.C) {
206+ cfg, err := s.State.EnvironConfig()
207+ c.Assert(err, gc.IsNil)
208+ allAttrs := cfg.AllAttrs()
209+ for _, deprecated := range []string{
210+ "public-bucket", "public-bucket-region", "public-bucket-url",
211+ "default-image-id", "default-instance-type",
212+ } {
213+ _, ok := allAttrs[deprecated]
214+ c.Assert(ok, jc.IsFalse)
215+ }
216+}
217+
218+func (s *processDeprecatedAttributesSuite) TestOldConfigRemoved(c *gc.C) {
219+ err := upgrades.ProcessDeprecatedAttributes(s.ctx)
220+ c.Assert(err, gc.IsNil)
221+ s.assertConfigProcessed(c)
222+}
223+
224+func (s *processDeprecatedAttributesSuite) TestIdempotent(c *gc.C) {
225+ err := upgrades.ProcessDeprecatedAttributes(s.ctx)
226+ c.Assert(err, gc.IsNil)
227+ s.assertConfigProcessed(c)
228+
229+ err = upgrades.ProcessDeprecatedAttributes(s.ctx)
230+ c.Assert(err, gc.IsNil)
231+ s.assertConfigProcessed(c)
232+}
233
234=== modified file 'upgrades/export_test.go'
235--- upgrades/export_test.go 2014-03-04 04:39:34 +0000
236+++ upgrades/export_test.go 2014-03-04 04:39:35 +0000
237@@ -12,4 +12,5 @@
238 EnsureLockDirExistsAndUbuntuWritable = ensureLockDirExistsAndUbuntuWritable
239 EnsureSystemSSHKey = ensureSystemSSHKey
240 UpdateRsyslogPort = updateRsyslogPort
241+ ProcessDeprecatedAttributes = processDeprecatedAttributes
242 )
243
244=== modified file 'upgrades/steps118.go'
245--- upgrades/steps118.go 2014-03-04 04:39:34 +0000
246+++ upgrades/steps118.go 2014-03-04 04:39:35 +0000
247@@ -26,5 +26,10 @@
248 targets: []Target{AllMachines},
249 run: installRsyslogGnutls,
250 },
251+ &upgradeStep{
252+ description: "remove deprecated attribute values",
253+ targets: []Target{StateServer},
254+ run: processDeprecatedAttributes,
255+ },
256 }
257 }
258
259=== modified file 'upgrades/steps118_test.go'
260--- upgrades/steps118_test.go 2014-03-04 04:39:34 +0000
261+++ upgrades/steps118_test.go 2014-03-04 04:39:35 +0000
262@@ -21,6 +21,7 @@
263 "generate system ssh key",
264 "update rsyslog port",
265 "install rsyslog-gnutls",
266+ "remove deprecated attribute values",
267 }
268
269 func (s *steps118Suite) TestUpgradeOperationsContent(c *gc.C) {
270
271=== modified file 'upgrades/systemsshkey_test.go'
272--- upgrades/systemsshkey_test.go 2014-02-27 03:17:45 +0000
273+++ upgrades/systemsshkey_test.go 2014-03-04 04:39:35 +0000
274@@ -34,7 +34,7 @@
275 _, err := os.Stat(s.keyFile())
276 c.Assert(err, jc.Satisfies, os.IsNotExist)
277 // There's initially one authorised key for the test user.
278- cfg, err := s.JujuConnSuite.State.EnvironConfig()
279+ cfg, err := s.State.EnvironConfig()
280 c.Assert(err, gc.IsNil)
281 authKeys := ssh.SplitAuthorisedKeys(cfg.AuthorizedKeys())
282 c.Assert(authKeys, gc.HasLen, 1)

Subscribers

People subscribed via source and target branches

to status/vote changes: