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 {
+ // 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.
+ }
+ return n
+}
+
// UnknownAttrs returns a copy of the raw configuration attributes
// that are supposedly specific to the environment type. They could
// also be wrong attributes, though. Only the specific environment
@@ -112,12 +133,14 @@
"default-series": schema.String(),
"authorized-keys": schema.String(),
"authorized-keys-path": schema.String(),
+ "agent-version": schema.String(),
}
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: config/ config. go config/ config_ test.go schema_ test.go
A [revision details]
M environs/
M environs/
M schema/schema.go
M schema/
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 interface{ }.
=== 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]
func FieldMap(fields Fields, defaults Defaults) Checker {
Index: schema/ schema_ test.go schema_ test.go' schema_ test.go 2012-07-26 18:08:04 +0000 schema_ test.go 2012-08-30 09:11:09 +0000 map[string] interface{ }{"a": "A", "b": "B", "d": "D"}, aPath) interface{ }{"a": "A", "b": "B", "c": "C"}) map[string] interface{ }{"a": "A", "d": "D"}, aPath) interface{ }{"a": "A", "c": "C"})
=== modified file 'schema/
--- schema/
+++ schema/
@@ -285,6 +285,10 @@
out, err :=
sch.Coerce(
c.Assert(err, IsNil)
c.Assert(out, DeepEquals,
map[string]
+
+ out, err = sch.Coerce(
+ c.Assert(err, IsNil)
+ c.Assert(out, DeepEquals, map[string]
}
func (s *S) TestFieldMapDef aultInvalid( c *C) {
Index: environs/ config/ config. go config/ config. go' config/ config. go 2012-08-02 08:29:38 +0000 config/ config. go 2012-08-30 09:11:09 +0000
=== modified file 'environs/
--- environs/
+++ environs/
@@ -47,6 +47,13 @@
}
}
+ // Check that the agent version parses ok if set. version" ].(string) ; ok { -keys"] .(string)
+ if v, ok := c.m["agent-
+ 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
}
+// AgentVersion returns the proposed version number for the agent tools. version" ].(string) series" : schema.String(), keys": schema.String(), keys-path" : schema.String(),
+// It returns the zero version if unset.
+func (c *Config) AgentVersion() version.Number {
+ v, ok := c.m["agent-
+ if !ok {
+ return version.Number{}
+ }
+ n, err := version.Parse(v)
+ if err != nil {
+ panic(err) // We should have checked it earlier.
+ }
+ return n
+}
+
// UnknownAttrs returns a copy of the raw configuration attributes
// that are supposedly specific to the environment type. They could
// also be wrong attributes, though. Only the specific environment
@@ -112,12 +133,14 @@
"default-
"authorized-
"authorized-
+ "agent-version": schema.String(),
}
var defaults = schema.Defaults{ series" : version. Current. Series, keys": "", keys-path" : "",
"default-
"authorized-
"authorized-
+ "agent-version": schema.Omit,
}
var checker = schema. FieldMap( fields, defaults)
Index: environs/ config/ config_ test.go config/ config_ test.go' config/ config_ test.go 2012-08-02 08:29:38 +0000 config/ config_ test.go 2012-08-30 09:11:09 +0000
=== modified file 'environs/
--- environs/
+++ environs/
@@ -70,6 +70,22 @@
"",
}, {
attrs{
+ "type": "my-type",
+ "name": "my-name",
+ "authorized-keys": "my-keys",
+ "agent-version": "1.2.3",
+ },
+ "",
+ }, {
+ attrs{
+ "type": "my-type",
+ "name": "my-name",
+ "authorized-keys": "my-keys",
+ "agent-version": "2",
+ },
+ `invalid agent version in environment configuration: "2"`,
+ }, {
+ attrs{
"name": "my-name",
},
"type: expected string, got nothing",
@@ -90,7 +106,8 @@
"name": "",
},
"empty name in environment configuration",
- }}
+ },
+}
func (*ConfigSuite) TestConfig(c *C) {
homedir := c.MkDir()
@@ -114,7 +131,8 @@
c.Assert(err, IsNil)
}
- for _, test := range configTests { New(test. attrs) "name"] .(string) cfg.Type( ), Equals, typ) cfg.Name( ), Equals, name) "agent- version" ]; s != nil { Parse(s. (string) ) cfg.AgentVersio n(), Equals, vers) cfg.AgentVersio n(), Equals, version.Number{}) "default- series" ].(string) ; series != "" { Assert( cfg.DefaultSeri es(), Equals, series)
+ for i, test := range configTests {
+ c.Logf("test %d", i)
cfg, err := config.
if test.err != "" {
c.Assert(err, ErrorMatches, test.err)
@@ -127,7 +145,13 @@
name, _ := test.attrs[
c.Assert(
c.Assert(
-
+ if s := test.attrs[
+ vers, err := version.
+ c.Assert(err, IsNil)
+ c.Assert(
+ } else {
+ c.Assert(
+ }
if series, _ := test.attrs[
c.
} else {