Merge lp:~wallyworld/juju-core/log-deprecated-config-warnings 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: 2161
Proposed branch: lp:~wallyworld/juju-core/log-deprecated-config-warnings
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 259 lines (+108/-82)
5 files modified
environs/config.go (+22/-0)
environs/config/config.go (+19/-23)
environs/config/config_test.go (+0/-59)
environs/config_test.go (+61/-0)
environs/export_test.go (+6/-0)
To merge this branch: bzr merge lp:~wallyworld/juju-core/log-deprecated-config-warnings
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+199597@code.launchpad.net

Commit message

Fix config depcared attr warnings

Deprecated config warnings are being logged
multiple times. A previous fix moved the entire
deprecated config processing logic so that the
warnings were only logged once. However this broke
upgrades.

This new fix moves the logging of the deprecation
warnings but leaves the processing of the depcated
attributes in the config Validate method so
upgrades continue to work.

https://codereview.appspot.com/37720049/

Description of the change

Fix config depcared attr warnings

Deprecated config warnings are being logged
multiple times. A previous fix moved the entire
deprecated config processing logic so that the
warnings were only logged once. However this broke
upgrades.

This new fix moves the logging of the deprecation
warnings but leaves the processing of the depcated
attributes in the config Validate method so
upgrades continue to work.

https://codereview.appspot.com/37720049/

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

Reviewers: mp+199597_code.launchpad.net,

Message:
Please take a look.

Description:
Fix config depcared attr warnings

Deprecated config warnings are being logged
multiple times. A previous fix moved the entire
deprecated config processing logic so that the
warnings were only logged once. However this broke
upgrades.

This new fix moves the logging of the deprecation
warnings but leaves the processing of the depcated
attributes in the config Validate method so
upgrades continue to work.

https://code.launchpad.net/~wallyworld/juju-core/log-deprecated-config-warnings/+merge/199597

(do not edit description out of merge proposal)

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

Affected files (+110, -123 lines):
   A [revision details]
   M environs/config.go
   M environs/config/config.go
   M environs/config/config_test.go
   M environs/config_test.go
   M environs/export_test.go

Revision history for this message
Andrew Wilkins (axwalk) wrote :

https://codereview.appspot.com/37720049/diff/1/environs/config/config.go
File environs/config/config.go (right):

https://codereview.appspot.com/37720049/diff/1/environs/config/config.go#newcode190
environs/config/config.go:190: cfg.m["tools-metadata-url"] = oldToolsURL
Doesn't doing this cause the second of the deprecation warnings to never
be hit?

https://codereview.appspot.com/37720049/

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

https://codereview.appspot.com/37720049/diff/1/environs/config/config.go
File environs/config/config.go (right):

https://codereview.appspot.com/37720049/diff/1/environs/config/config.go#newcode190
environs/config/config.go:190: cfg.m["tools-metadata-url"] = oldToolsURL
On 2013/12/19 02:28:12, axw wrote:
> Doesn't doing this cause the second of the deprecation warnings to
never be hit?

This code is executed after the warnings are logged. The warnings are
logged as the environment is parsed from the yaml. The config validation
is done after that as the environment is constructed.

https://codereview.appspot.com/37720049/

Revision history for this message
Andrew Wilkins (axwalk) wrote :

LGTM apart from the removed test

https://codereview.appspot.com/37720049/diff/1/environs/config/config.go
File environs/config/config.go (right):

https://codereview.appspot.com/37720049/diff/1/environs/config/config.go#newcode190
environs/config/config.go:190: cfg.m["tools-metadata-url"] = oldToolsURL
On 2013/12/19 02:43:33, wallyworld wrote:
> On 2013/12/19 02:28:12, axw wrote:
> > Doesn't doing this cause the second of the deprecation warnings to
never be
> hit?

> This code is executed after the warnings are logged. The warnings are
logged as
> the environment is parsed from the yaml. The config validation is done
after
> that as the environment is constructed.

Got it. Sorry, wasn't looking at the full context.

https://codereview.appspot.com/37720049/diff/1/environs/config_test.go
File environs/config_test.go (left):

https://codereview.appspot.com/37720049/diff/1/environs/config_test.go#oldcode91
environs/config_test.go:91: func (*suite)
TestNoWarningForDeprecatedButUnusedEnv(c *gc.C) {
I think this is still relevant?

https://codereview.appspot.com/37720049/

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

Please take a look.

https://codereview.appspot.com/37720049/diff/1/environs/config_test.go
File environs/config_test.go (left):

https://codereview.appspot.com/37720049/diff/1/environs/config_test.go#oldcode91
environs/config_test.go:91: func (*suite)
TestNoWarningForDeprecatedButUnusedEnv(c *gc.C) {
On 2013/12/19 02:56:57, axw wrote:
> I think this is still relevant?

Yes it is. I messed up merging back my previous work into the trunk
which had the code reverted.

https://codereview.appspot.com/37720049/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'environs/config.go'
2--- environs/config.go 2013-12-18 08:45:42 +0000
3+++ environs/config.go 2013-12-19 03:01:43 +0000
4@@ -68,6 +68,28 @@
5 if err := validateEnvironmentKind(attrs); err != nil {
6 return nil, err
7 }
8+
9+ // If deprecated config attributes are used, log warnings so the user can know
10+ // that they need to be fixed.
11+ if oldToolsURL := attrs["tools-url"]; oldToolsURL != nil && oldToolsURL.(string) != "" {
12+ _, newToolsSpecified := attrs["tools-metadata-url"]
13+ var msg string
14+ if newToolsSpecified {
15+ msg = fmt.Sprintf(
16+ "Config attribute %q (%v) is deprecated and will be ignored since\n"+
17+ "the new tools URL attribute %q has also been used.\n"+
18+ "The attribute %q should be removed from your configuration.",
19+ "tools-url", oldToolsURL, "tools-metadata-url", "tools-url")
20+ } else {
21+ msg = fmt.Sprintf(
22+ "Config attribute %q (%v) is deprecated.\n"+
23+ "The location to find tools is now specified using the %q attribute.\n"+
24+ "Your configuration should be updated to set %q as follows\n%v: %v.",
25+ "tools-url", oldToolsURL, "tools-metadata-url", "tools-metadata-url", "tools-metadata-url", oldToolsURL)
26+ }
27+ logger.Warningf(msg)
28+ }
29+
30 cfg, err := config.New(config.UseDefaults, attrs)
31 if err != nil {
32 return nil, err
33
34=== modified file 'environs/config/config.go'
35--- environs/config/config.go 2013-12-18 08:45:42 +0000
36+++ environs/config/config.go 2013-12-19 03:01:43 +0000
37@@ -177,6 +177,24 @@
38 }
39 }
40
41+// processDeprecatedAttributes ensures that the config is set up so that it works
42+// correctly when used with older versions of Juju which require that deprecated
43+// attribute values still be used.
44+func (cfg *Config) processDeprecatedAttributes() {
45+ // The tools url has changed so ensure that both old and new values are in the config so that
46+ // upgrades work. "tools-url" is the old attribute name.
47+ if oldToolsURL := cfg.m["tools-url"]; oldToolsURL != nil && oldToolsURL.(string) != "" {
48+ _, newToolsSpecified := cfg.ToolsURL()
49+ // Ensure the new attribute name "tools-metadata-url" is set.
50+ if !newToolsSpecified {
51+ cfg.m["tools-metadata-url"] = oldToolsURL
52+ }
53+ }
54+ // Even if the user has edited their environment yaml to remove the deprecated tools-url value,
55+ // we still want it in the config for upgrades.
56+ cfg.m["tools-url"], _ = cfg.ToolsURL()
57+}
58+
59 // Validate ensures that config is a valid configuration. If old is not nil,
60 // it holds the previous environment configuration for consideration when
61 // validating changes.
62@@ -259,29 +277,7 @@
63 }
64 }
65
66- // The tools url has changed so see if the old one is still in use.
67- if oldToolsURL := cfg.m["tools-url"]; oldToolsURL != nil && oldToolsURL.(string) != "" {
68- _, newToolsSpecified := cfg.ToolsURL()
69- var msg string
70- if newToolsSpecified {
71- msg = fmt.Sprintf(
72- "Config attribute %q (%v) is deprecated and will be ignored since\n"+
73- "the new tools URL attribute %q has also been used.\n"+
74- "The attribute %q should be removed from your configuration.",
75- "tools-url", oldToolsURL, "tools-metadata-url", "tools-url")
76- } else {
77- msg = fmt.Sprintf(
78- "Config attribute %q (%v) is deprecated.\n"+
79- "The location to find tools is now specified using the %q attribute.\n"+
80- "Your configuration should be updated to set %q as follows\n%v: %v.",
81- "tools-url", oldToolsURL, "tools-metadata-url", "tools-metadata-url", "tools-metadata-url", oldToolsURL)
82- cfg.m["tools-metadata-url"] = oldToolsURL
83- }
84- logger.Warningf(msg)
85- }
86- // Even if the user has edited their environment yaml to remove the deprecated tools-url value,
87- // we still want it in the config for upgrades.
88- cfg.m["tools-url"], _ = cfg.ToolsURL()
89+ cfg.processDeprecatedAttributes()
90 return nil
91 }
92
93
94=== modified file 'environs/config/config_test.go'
95--- environs/config/config_test.go 2013-12-18 08:45:42 +0000
96+++ environs/config/config_test.go 2013-12-19 03:01:43 +0000
97@@ -6,7 +6,6 @@
98 import (
99 "fmt"
100 "regexp"
101- "strings"
102 stdtesting "testing"
103 "time"
104
105@@ -1232,61 +1231,3 @@
106 MIIBOgIBAAJAZabKgKInuOxj5vDWLwHHQtK3/45KB+32D15w94Nt83BmuGxo90lw
107 -----END CERTIFICATE-----
108 `[1:]
109-
110-type ConfigDeprecationSuite struct {
111- ConfigSuite
112- writer *testWriter
113-}
114-
115-var _ = gc.Suite(&ConfigDeprecationSuite{})
116-
117-func (s *ConfigDeprecationSuite) SetUpTest(c *gc.C) {
118- s.ConfigSuite.SetUpTest(c)
119-}
120-
121-func (s *ConfigDeprecationSuite) TearDownTest(c *gc.C) {
122- s.ConfigSuite.TearDownTest(c)
123-}
124-
125-func (s *ConfigDeprecationSuite) setupLogger(c *gc.C) {
126- var err error
127- s.writer = &testWriter{}
128- err = loggo.RegisterWriter("test", s.writer, loggo.WARNING)
129- c.Assert(err, gc.IsNil)
130-}
131-
132-func (s *ConfigDeprecationSuite) resetLogger(c *gc.C) {
133- _, _, err := loggo.RemoveWriter("test")
134- c.Assert(err, gc.IsNil)
135-}
136-
137-type testWriter struct {
138- messages []string
139-}
140-
141-func (t *testWriter) Write(level loggo.Level, module, filename string, line int, timestamp time.Time, message string) {
142- t.messages = append(t.messages, message)
143-}
144-
145-func (s *ConfigDeprecationSuite) setupEnv(c *gc.C, deprecatedKey, value string) {
146- attrs := testing.FakeConfig().Merge(testing.Attrs{
147- "name": "testenv",
148- "type": "openstack",
149- deprecatedKey: value,
150- })
151- _, err := config.New(config.NoDefaults, attrs)
152- c.Assert(err, gc.IsNil)
153-}
154-
155-func (s *ConfigDeprecationSuite) TestDeprecationWarnings(c *gc.C) {
156- for attr, value := range map[string]string{
157- "tools-url": "foo",
158- } {
159- s.setupLogger(c)
160- s.setupEnv(c, attr, value)
161- s.resetLogger(c)
162- stripped := strings.Replace(s.writer.messages[0], "\n", "", -1)
163- expected := fmt.Sprintf(`.*Config attribute "%s" \(%s\) is deprecated.*`, attr, value)
164- c.Assert(stripped, gc.Matches, expected)
165- }
166-}
167
168=== modified file 'environs/config_test.go'
169--- environs/config_test.go 2013-12-18 08:45:42 +0000
170+++ environs/config_test.go 2013-12-19 03:01:43 +0000
171@@ -4,9 +4,11 @@
172 package environs_test
173
174 import (
175+ "fmt"
176 "os"
177 "path/filepath"
178 "sort"
179+ "strings"
180
181 gc "launchpad.net/gocheck"
182 "launchpad.net/loggo"
183@@ -300,3 +302,62 @@
184 expect["ca-private-key"] = ""
185 c.Assert(cfg1.AllAttrs(), gc.DeepEquals, expect)
186 }
187+
188+type ConfigDeprecationSuite struct {
189+ suite
190+ writer *loggo.TestWriter
191+}
192+
193+var _ = gc.Suite(&ConfigDeprecationSuite{})
194+
195+func (s *ConfigDeprecationSuite) setupLogger(c *gc.C) func() {
196+ var err error
197+ s.writer = &loggo.TestWriter{}
198+ err = loggo.RegisterWriter("test", s.writer, loggo.WARNING)
199+ c.Assert(err, gc.IsNil)
200+ return func() {
201+ _, _, err := loggo.RemoveWriter("test")
202+ c.Assert(err, gc.IsNil)
203+ }
204+}
205+
206+func (s *ConfigDeprecationSuite) checkDeprecationWarning(c *gc.C, attrs testing.Attrs, expectedMsg string) {
207+ defer testing.MakeFakeHomeNoEnvironments(c, "only").Restore()
208+ content := `
209+environments:
210+ deprecated:
211+ type: dummy
212+ state-server: false
213+`
214+ restore := s.setupLogger(c)
215+ defer restore()
216+
217+ envs, err := environs.ReadEnvironsBytes([]byte(content))
218+ c.Check(err, gc.IsNil)
219+ environs.UpdateEnvironAttrs(envs, "deprecated", attrs)
220+ _, err = envs.Config("deprecated")
221+ c.Check(err, gc.IsNil)
222+ c.Assert(s.writer.Log, gc.HasLen, 1)
223+ stripped := strings.Replace(s.writer.Log[0].Message, "\n", "", -1)
224+ c.Assert(stripped, gc.Matches, expectedMsg)
225+}
226+
227+func (s *ConfigDeprecationSuite) TestDeprecatedToolsURLWarning(c *gc.C) {
228+ attrs := testing.Attrs{
229+ "tools-url": "aknowndeprecatedfield",
230+ }
231+ expected := fmt.Sprintf(`.*Config attribute "tools-url" \(aknowndeprecatedfield\) is deprecated\.` +
232+ `The location to find tools is now specified using the "tools-metadata-url" attribute.*`)
233+ s.checkDeprecationWarning(c, attrs, expected)
234+}
235+
236+func (s *ConfigDeprecationSuite) TestDeprecatedToolsURLWithNewURLWarning(c *gc.C) {
237+ attrs := testing.Attrs{
238+ "tools-url": "aknowndeprecatedfield",
239+ "tools-metadata-url": "newvalue",
240+ }
241+ expected := fmt.Sprintf(
242+ `.*Config attribute "tools-url" \(aknowndeprecatedfield\) is deprecated and will be ignored since` +
243+ `the new tools URL attribute "tools-metadata-url".*`)
244+ s.checkDeprecationWarning(c, attrs, expected)
245+}
246
247=== modified file 'environs/export_test.go'
248--- environs/export_test.go 2013-12-18 08:45:42 +0000
249+++ environs/export_test.go 2013-12-19 03:01:43 +0000
250@@ -6,3 +6,9 @@
251 func Providers() map[string]EnvironProvider {
252 return providers
253 }
254+
255+func UpdateEnvironAttrs(envs *Environs, name string, newAttrs map[string]interface{}) {
256+ for k, v := range newAttrs {
257+ envs.rawEnvirons[name][k] = v
258+ }
259+}

Subscribers

People subscribed via source and target branches

to status/vote changes: