Merge lp:~thumper/juju-core/fix-local-bootstrap-json into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Merge reported by: Tim Penhey
Merged at revision: not available
Proposed branch: lp:~thumper/juju-core/fix-local-bootstrap-json
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 53 lines (+18/-4)
2 files modified
provider/local/config.go (+4/-4)
provider/local/config_test.go (+14/-0)
To merge this branch: bzr merge lp:~thumper/juju-core/fix-local-bootstrap-json
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+187955@code.launchpad.net

Commit message

Fix local provider bootstrap.

The environment configuration was being serialized
through JSON, which was coercing the integer values
to float64.

The validation schema checks were strictly looking for
integers. This has now been changed to ForceInt.

Test added.

https://codereview.appspot.com/14006043/

Description of the change

Fix local provider bootstrap.

The environment configuration was being serialized
through JSON, which was coercing the integer values
to float64.

The validation schema checks were strictly looking for
integers. This has now been changed to ForceInt.

Test added.

https://codereview.appspot.com/14006043/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Reviewers: mp+187955_code.launchpad.net,

Message:
Please take a look.

Description:
Fix local provider bootstrap.

The environment configuration was being serialized
through JSON, which was coercing the integer values
to float64.

The validation schema checks were strictly looking for
integers. This has now been changed to ForceInt.

Test added.

https://code.launchpad.net/~thumper/juju-core/fix-local-bootstrap/+merge/187955

(do not edit description out of merge proposal)

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

Affected files (+20, -4 lines):
   A [revision details]
   M provider/local/config.go
   M provider/local/config_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: tarmac-20130926184157-5d305cr4rb895lnt
+New revision: <email address hidden>

Index: provider/local/config.go
=== modified file 'provider/local/config.go'
--- provider/local/config.go 2013-07-17 02:40:31 +0000
+++ provider/local/config.go 2013-09-26 23:34:07 +0000
@@ -21,8 +21,8 @@
   configFields = schema.Fields{
    "root-dir": schema.String(),
    "bootstrap-ip": schema.String(),
- "storage-port": schema.Int(),
- "shared-storage-port": schema.Int(),
+ "storage-port": schema.ForceInt(),
+ "shared-storage-port": schema.ForceInt(),
   }
   // The port defaults below are not entirely arbitrary. Local user web
   // frameworks often use 8000 or 8080, so I didn't want to use either of
@@ -102,11 +102,11 @@
  }

  func (c *environConfig) storagePort() int {
- return int(c.attrs["storage-port"].(int64))
+ return c.attrs["storage-port"].(int)
  }

  func (c *environConfig) sharedStoragePort() int {
- return int(c.attrs["shared-storage-port"].(int64))
+ return c.attrs["shared-storage-port"].(int)
  }

  func (c *environConfig) storageAddr() string {

Index: provider/local/config_test.go
=== modified file 'provider/local/config_test.go'
--- provider/local/config_test.go 2013-09-12 14:16:48 +0000
+++ provider/local/config_test.go 2013-09-26 23:34:58 +0000
@@ -89,6 +89,20 @@
   c.Assert(unknownAttrs["root-dir"], gc.Equals, expectedRootDir)
  }

+func (s *configSuite) TestValidateConfigWithFloatPort(c *gc.C) {
+ // When the config values get serialized through JSON, the integers
+ // get coerced to float64 values. The parsing needs to handle this.
+ values := minimalConfigValues()
+ values["storage-port"] = float64(8040)
+ testConfig, err := config.New(config.NoDefaults, values)
+ c.Assert(err, gc.IsNil)
+
+ valid, err := local.Provider.Validate(testConfig, nil)
+ c.Assert(err, gc.IsNil)
+ unknownAttrs := valid.UnknownAttrs()
+ c.Assert(unknownAttrs["storage-port"], gc.Equals, int(8040))
+}
+
  func (s *configSuite) TestNamespace(c *gc.C) {
   testConfig := minimalConfig(c)
   c.Assert(local.ConfigNamespace(testConfig), gc.Equals, "tester-test")

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'provider/local/config.go'
2--- provider/local/config.go 2013-07-17 02:40:31 +0000
3+++ provider/local/config.go 2013-09-26 23:36:46 +0000
4@@ -21,8 +21,8 @@
5 configFields = schema.Fields{
6 "root-dir": schema.String(),
7 "bootstrap-ip": schema.String(),
8- "storage-port": schema.Int(),
9- "shared-storage-port": schema.Int(),
10+ "storage-port": schema.ForceInt(),
11+ "shared-storage-port": schema.ForceInt(),
12 }
13 // The port defaults below are not entirely arbitrary. Local user web
14 // frameworks often use 8000 or 8080, so I didn't want to use either of
15@@ -102,11 +102,11 @@
16 }
17
18 func (c *environConfig) storagePort() int {
19- return int(c.attrs["storage-port"].(int64))
20+ return c.attrs["storage-port"].(int)
21 }
22
23 func (c *environConfig) sharedStoragePort() int {
24- return int(c.attrs["shared-storage-port"].(int64))
25+ return c.attrs["shared-storage-port"].(int)
26 }
27
28 func (c *environConfig) storageAddr() string {
29
30=== modified file 'provider/local/config_test.go'
31--- provider/local/config_test.go 2013-09-12 14:16:48 +0000
32+++ provider/local/config_test.go 2013-09-26 23:36:46 +0000
33@@ -89,6 +89,20 @@
34 c.Assert(unknownAttrs["root-dir"], gc.Equals, expectedRootDir)
35 }
36
37+func (s *configSuite) TestValidateConfigWithFloatPort(c *gc.C) {
38+ // When the config values get serialized through JSON, the integers
39+ // get coerced to float64 values. The parsing needs to handle this.
40+ values := minimalConfigValues()
41+ values["storage-port"] = float64(8040)
42+ testConfig, err := config.New(config.NoDefaults, values)
43+ c.Assert(err, gc.IsNil)
44+
45+ valid, err := local.Provider.Validate(testConfig, nil)
46+ c.Assert(err, gc.IsNil)
47+ unknownAttrs := valid.UnknownAttrs()
48+ c.Assert(unknownAttrs["storage-port"], gc.Equals, int(8040))
49+}
50+
51 func (s *configSuite) TestNamespace(c *gc.C) {
52 testConfig := minimalConfig(c)
53 c.Assert(local.ConfigNamespace(testConfig), gc.Equals, "tester-test")

Subscribers

People subscribed via source and target branches

to status/vote changes: