Merge lp:~rogpeppe/juju-core/041-config-agent-version into lp:~juju/juju-core/trunk

Proposed by Roger Peppe
Status: Merged
Approved by: Gustavo Niemeyer
Approved revision: 444
Merged at revision: 450
Proposed branch: lp:~rogpeppe/juju-core/041-config-agent-version
Merge into: lp:~juju/juju-core/trunk
Diff against target: 145 lines (+56/-5)
4 files modified
environs/config/config.go (+23/-0)
environs/config/config_test.go (+27/-3)
schema/schema.go (+2/-2)
schema/schema_test.go (+4/-0)
To merge this branch: bzr merge lp:~rogpeppe/juju-core/041-config-agent-version
Reviewer Review Type Date Requested Status
The Go Language Gophers Pending
Review via email: mp+122016@code.launchpad.net

Description of the change

environs/config: add support for agent version.

Also adjust documentation for schema.Omit slightly
and add a test.

https://codereview.appspot.com/6499055/

To post a comment you must log in.
Revision history for this message
Roger Peppe (rogpeppe) wrote :
Download full text (5.4 KiB)

Reviewers: mp+122016_code.launchpad.net,

Message:
Please take a look.

Description:
environs/config: add support for agent version.

Also adjust documentation for schema.Omit slightly
and add a test.

https://code.launchpad.net/~rogpeppe/juju-core/041-config-agent-version/+merge/122016

(do not edit description out of merge proposal)

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

Affected files:
   A [revision details]
   M environs/config/config.go
   M environs/config/config_test.go
   M schema/schema.go
   M schema/schema_test.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: schema/schema.go
=== modified file 'schema/schema.go'
--- schema/schema.go 2012-07-26 18:01:24 +0000
+++ schema/schema.go 2012-08-30 09:11:09 +0000
@@ -322,8 +322,8 @@
  // and returns with the underlying error.
  //
  // Fields in defaults will be set to the provided value if not present
-// in the coerced map. If the default value is schema.Omit, the field
-// missing field will be ommitted from the coerced map as well.
+// in the coerced map. If the default value is schema.Omit, the
+// missing field will be omitted from the coerced map.
  //
  // The coerced output value has type map[string]interface{}.
  func FieldMap(fields Fields, defaults Defaults) Checker {

Index: schema/schema_test.go
=== modified file 'schema/schema_test.go'
--- schema/schema_test.go 2012-07-26 18:08:04 +0000
+++ schema/schema_test.go 2012-08-30 09:11:09 +0000
@@ -285,6 +285,10 @@
   out, err :=
sch.Coerce(map[string]interface{}{"a": "A", "b": "B", "d": "D"}, aPath)
   c.Assert(err, IsNil)
   c.Assert(out, DeepEquals,
map[string]interface{}{"a": "A", "b": "B", "c": "C"})
+
+ out, err = sch.Coerce(map[string]interface{}{"a": "A", "d": "D"}, aPath)
+ c.Assert(err, IsNil)
+ c.Assert(out, DeepEquals, map[string]interface{}{"a": "A", "c": "C"})
  }

  func (s *S) TestFieldMapDefaultInvalid(c *C) {

Index: environs/config/config.go
=== modified file 'environs/config/config.go'
--- environs/config/config.go 2012-08-02 08:29:38 +0000
+++ environs/config/config.go 2012-08-30 09:11:09 +0000
@@ -47,6 +47,13 @@
    }
   }

+ // Check that the agent version parses ok if set.
+ if v, ok := c.m["agent-version"].(string); ok {
+ if _, err := version.Parse(v); err != nil {
+ return nil, fmt.Errorf("invalid agent version in environment
configuration: %q", v)
+ }
+ }
+
   // Copy unknown attributes onto the type-specific map.
   for k, v := range attrs {
    if _, ok := fields[k]; !ok {
@@ -76,6 +83,20 @@
   return c.m["authorized-keys"].(string)
  }

+// AgentVersion returns the proposed version number for the agent tools.
+// It returns the zero version if unset.
+func (c *Config) AgentVersion() version.Number {
+ v, ok := c.m["agent-version"].(string)
+ if !ok {
+ return version.Number{}
+ }
+ n, err := version.Parse(v)
+ if err != nil {
+ panic(err) // We should have checked it earlier.
+ }
...

Read more...

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

LGTM

https://codereview.appspot.com/6499055/diff/2001/environs/config/config.go
File environs/config/config.go (right):

https://codereview.appspot.com/6499055/diff/2001/environs/config/config.go#newcode95
environs/config/config.go:95: panic(err) // We should have checked it
earlier.
s/should have//

The long spacing between the panic and the comment makes it harder to
read.

https://codereview.appspot.com/6499055/diff/2001/environs/config/config.go#newcode136
environs/config/config.go:136: "agent-version": schema.String(),
go fmt

https://codereview.appspot.com/6499055/diff/2001/schema/schema.go
File schema/schema.go (right):

https://codereview.appspot.com/6499055/diff/2001/schema/schema.go#newcode326
schema/schema.go:326: // missing field will be omitted from the coerced
map.
Cheers!

https://codereview.appspot.com/6499055/

445. By Roger Peppe

gofmt

Revision history for this message
Roger Peppe (rogpeppe) wrote :

*** Submitted:

environs/config: add support for agent version.

Also adjust documentation for schema.Omit slightly
and add a test.

R=niemeyer
CC=
https://codereview.appspot.com/6499055

https://codereview.appspot.com/6499055/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'environs/config/config.go'
2--- environs/config/config.go 2012-08-02 08:29:38 +0000
3+++ environs/config/config.go 2012-08-30 09:19:28 +0000
4@@ -47,6 +47,13 @@
5 }
6 }
7
8+ // Check that the agent version parses ok if set.
9+ if v, ok := c.m["agent-version"].(string); ok {
10+ if _, err := version.Parse(v); err != nil {
11+ return nil, fmt.Errorf("invalid agent version in environment configuration: %q", v)
12+ }
13+ }
14+
15 // Copy unknown attributes onto the type-specific map.
16 for k, v := range attrs {
17 if _, ok := fields[k]; !ok {
18@@ -76,6 +83,20 @@
19 return c.m["authorized-keys"].(string)
20 }
21
22+// AgentVersion returns the proposed version number for the agent tools.
23+// It returns the zero version if unset.
24+func (c *Config) AgentVersion() version.Number {
25+ v, ok := c.m["agent-version"].(string)
26+ if !ok {
27+ return version.Number{}
28+ }
29+ n, err := version.Parse(v)
30+ if err != nil {
31+ panic(err) // We should have checked it earlier.
32+ }
33+ return n
34+}
35+
36 // UnknownAttrs returns a copy of the raw configuration attributes
37 // that are supposedly specific to the environment type. They could
38 // also be wrong attributes, though. Only the specific environment
39@@ -112,12 +133,14 @@
40 "default-series": schema.String(),
41 "authorized-keys": schema.String(),
42 "authorized-keys-path": schema.String(),
43+ "agent-version": schema.String(),
44 }
45
46 var defaults = schema.Defaults{
47 "default-series": version.Current.Series,
48 "authorized-keys": "",
49 "authorized-keys-path": "",
50+ "agent-version": schema.Omit,
51 }
52
53 var checker = schema.FieldMap(fields, defaults)
54
55=== modified file 'environs/config/config_test.go'
56--- environs/config/config_test.go 2012-08-02 08:29:38 +0000
57+++ environs/config/config_test.go 2012-08-30 09:19:28 +0000
58@@ -70,6 +70,22 @@
59 "",
60 }, {
61 attrs{
62+ "type": "my-type",
63+ "name": "my-name",
64+ "authorized-keys": "my-keys",
65+ "agent-version": "1.2.3",
66+ },
67+ "",
68+ }, {
69+ attrs{
70+ "type": "my-type",
71+ "name": "my-name",
72+ "authorized-keys": "my-keys",
73+ "agent-version": "2",
74+ },
75+ `invalid agent version in environment configuration: "2"`,
76+ }, {
77+ attrs{
78 "name": "my-name",
79 },
80 "type: expected string, got nothing",
81@@ -90,7 +106,8 @@
82 "name": "",
83 },
84 "empty name in environment configuration",
85- }}
86+ },
87+}
88
89 func (*ConfigSuite) TestConfig(c *C) {
90 homedir := c.MkDir()
91@@ -114,7 +131,8 @@
92 c.Assert(err, IsNil)
93 }
94
95- for _, test := range configTests {
96+ for i, test := range configTests {
97+ c.Logf("test %d", i)
98 cfg, err := config.New(test.attrs)
99 if test.err != "" {
100 c.Assert(err, ErrorMatches, test.err)
101@@ -127,7 +145,13 @@
102 name, _ := test.attrs["name"].(string)
103 c.Assert(cfg.Type(), Equals, typ)
104 c.Assert(cfg.Name(), Equals, name)
105-
106+ if s := test.attrs["agent-version"]; s != nil {
107+ vers, err := version.Parse(s.(string))
108+ c.Assert(err, IsNil)
109+ c.Assert(cfg.AgentVersion(), Equals, vers)
110+ } else {
111+ c.Assert(cfg.AgentVersion(), Equals, version.Number{})
112+ }
113 if series, _ := test.attrs["default-series"].(string); series != "" {
114 c.Assert(cfg.DefaultSeries(), Equals, series)
115 } else {
116
117=== modified file 'schema/schema.go'
118--- schema/schema.go 2012-07-26 18:01:24 +0000
119+++ schema/schema.go 2012-08-30 09:19:28 +0000
120@@ -322,8 +322,8 @@
121 // and returns with the underlying error.
122 //
123 // Fields in defaults will be set to the provided value if not present
124-// in the coerced map. If the default value is schema.Omit, the field
125-// missing field will be ommitted from the coerced map as well.
126+// in the coerced map. If the default value is schema.Omit, the
127+// missing field will be omitted from the coerced map.
128 //
129 // The coerced output value has type map[string]interface{}.
130 func FieldMap(fields Fields, defaults Defaults) Checker {
131
132=== modified file 'schema/schema_test.go'
133--- schema/schema_test.go 2012-07-26 18:08:04 +0000
134+++ schema/schema_test.go 2012-08-30 09:19:28 +0000
135@@ -285,6 +285,10 @@
136 out, err := sch.Coerce(map[string]interface{}{"a": "A", "b": "B", "d": "D"}, aPath)
137 c.Assert(err, IsNil)
138 c.Assert(out, DeepEquals, map[string]interface{}{"a": "A", "b": "B", "c": "C"})
139+
140+ out, err = sch.Coerce(map[string]interface{}{"a": "A", "d": "D"}, aPath)
141+ c.Assert(err, IsNil)
142+ c.Assert(out, DeepEquals, map[string]interface{}{"a": "A", "c": "C"})
143 }
144
145 func (s *S) TestFieldMapDefaultInvalid(c *C) {

Subscribers

People subscribed via source and target branches