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
=== 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:19:28 +0000
@@ -47,6 +47,13 @@
47 }47 }
48 }48 }
4949
50 // Check that the agent version parses ok if set.
51 if v, ok := c.m["agent-version"].(string); ok {
52 if _, err := version.Parse(v); err != nil {
53 return nil, fmt.Errorf("invalid agent version in environment configuration: %q", v)
54 }
55 }
56
50 // Copy unknown attributes onto the type-specific map.57 // Copy unknown attributes onto the type-specific map.
51 for k, v := range attrs {58 for k, v := range attrs {
52 if _, ok := fields[k]; !ok {59 if _, ok := fields[k]; !ok {
@@ -76,6 +83,20 @@
76 return c.m["authorized-keys"].(string)83 return c.m["authorized-keys"].(string)
77}84}
7885
86// AgentVersion returns the proposed version number for the agent tools.
87// It returns the zero version if unset.
88func (c *Config) AgentVersion() version.Number {
89 v, ok := c.m["agent-version"].(string)
90 if !ok {
91 return version.Number{}
92 }
93 n, err := version.Parse(v)
94 if err != nil {
95 panic(err) // We should have checked it earlier.
96 }
97 return n
98}
99
79// UnknownAttrs returns a copy of the raw configuration attributes100// UnknownAttrs returns a copy of the raw configuration attributes
80// that are supposedly specific to the environment type. They could101// that are supposedly specific to the environment type. They could
81// also be wrong attributes, though. Only the specific environment102// also be wrong attributes, though. Only the specific environment
@@ -112,12 +133,14 @@
112 "default-series": schema.String(),133 "default-series": schema.String(),
113 "authorized-keys": schema.String(),134 "authorized-keys": schema.String(),
114 "authorized-keys-path": schema.String(),135 "authorized-keys-path": schema.String(),
136 "agent-version": schema.String(),
115}137}
116138
117var defaults = schema.Defaults{139var defaults = schema.Defaults{
118 "default-series": version.Current.Series,140 "default-series": version.Current.Series,
119 "authorized-keys": "",141 "authorized-keys": "",
120 "authorized-keys-path": "",142 "authorized-keys-path": "",
143 "agent-version": schema.Omit,
121}144}
122145
123var checker = schema.FieldMap(fields, defaults)146var checker = schema.FieldMap(fields, defaults)
124147
=== modified file 'environs/config/config_test.go'
--- environs/config/config_test.go 2012-08-02 08:29:38 +0000
+++ environs/config/config_test.go 2012-08-30 09:19:28 +0000
@@ -70,6 +70,22 @@
70 "",70 "",
71 }, {71 }, {
72 attrs{72 attrs{
73 "type": "my-type",
74 "name": "my-name",
75 "authorized-keys": "my-keys",
76 "agent-version": "1.2.3",
77 },
78 "",
79 }, {
80 attrs{
81 "type": "my-type",
82 "name": "my-name",
83 "authorized-keys": "my-keys",
84 "agent-version": "2",
85 },
86 `invalid agent version in environment configuration: "2"`,
87 }, {
88 attrs{
73 "name": "my-name",89 "name": "my-name",
74 },90 },
75 "type: expected string, got nothing",91 "type: expected string, got nothing",
@@ -90,7 +106,8 @@
90 "name": "",106 "name": "",
91 },107 },
92 "empty name in environment configuration",108 "empty name in environment configuration",
93 }}109 },
110}
94111
95func (*ConfigSuite) TestConfig(c *C) {112func (*ConfigSuite) TestConfig(c *C) {
96 homedir := c.MkDir()113 homedir := c.MkDir()
@@ -114,7 +131,8 @@
114 c.Assert(err, IsNil)131 c.Assert(err, IsNil)
115 }132 }
116133
117 for _, test := range configTests {134 for i, test := range configTests {
135 c.Logf("test %d", i)
118 cfg, err := config.New(test.attrs)136 cfg, err := config.New(test.attrs)
119 if test.err != "" {137 if test.err != "" {
120 c.Assert(err, ErrorMatches, test.err)138 c.Assert(err, ErrorMatches, test.err)
@@ -127,7 +145,13 @@
127 name, _ := test.attrs["name"].(string)145 name, _ := test.attrs["name"].(string)
128 c.Assert(cfg.Type(), Equals, typ)146 c.Assert(cfg.Type(), Equals, typ)
129 c.Assert(cfg.Name(), Equals, name)147 c.Assert(cfg.Name(), Equals, name)
130148 if s := test.attrs["agent-version"]; s != nil {
149 vers, err := version.Parse(s.(string))
150 c.Assert(err, IsNil)
151 c.Assert(cfg.AgentVersion(), Equals, vers)
152 } else {
153 c.Assert(cfg.AgentVersion(), Equals, version.Number{})
154 }
131 if series, _ := test.attrs["default-series"].(string); series != "" {155 if series, _ := test.attrs["default-series"].(string); series != "" {
132 c.Assert(cfg.DefaultSeries(), Equals, series)156 c.Assert(cfg.DefaultSeries(), Equals, series)
133 } else {157 } else {
134158
=== modified file 'schema/schema.go'
--- schema/schema.go 2012-07-26 18:01:24 +0000
+++ schema/schema.go 2012-08-30 09:19:28 +0000
@@ -322,8 +322,8 @@
322// and returns with the underlying error.322// and returns with the underlying error.
323//323//
324// Fields in defaults will be set to the provided value if not present324// Fields in defaults will be set to the provided value if not present
325// in the coerced map. If the default value is schema.Omit, the field325// in the coerced map. If the default value is schema.Omit, the
326// missing field will be ommitted from the coerced map as well.326// missing field will be omitted from the coerced map.
327//327//
328// The coerced output value has type map[string]interface{}.328// The coerced output value has type map[string]interface{}.
329func FieldMap(fields Fields, defaults Defaults) Checker {329func FieldMap(fields Fields, defaults Defaults) Checker {
330330
=== 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:19:28 +0000
@@ -285,6 +285,10 @@
285 out, err := sch.Coerce(map[string]interface{}{"a": "A", "b": "B", "d": "D"}, aPath)285 out, err := sch.Coerce(map[string]interface{}{"a": "A", "b": "B", "d": "D"}, aPath)
286 c.Assert(err, IsNil)286 c.Assert(err, IsNil)
287 c.Assert(out, DeepEquals, map[string]interface{}{"a": "A", "b": "B", "c": "C"})287 c.Assert(out, DeepEquals, map[string]interface{}{"a": "A", "b": "B", "c": "C"})
288
289 out, err = sch.Coerce(map[string]interface{}{"a": "A", "d": "D"}, aPath)
290 c.Assert(err, IsNil)
291 c.Assert(out, DeepEquals, map[string]interface{}{"a": "A", "c": "C"})
288}292}
289293
290func (s *S) TestFieldMapDefaultInvalid(c *C) {294func (s *S) TestFieldMapDefaultInvalid(c *C) {

Subscribers

People subscribed via source and target branches