Merge lp:~thumper/juju-core/configurable-lxc-bridge into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 1938
Proposed branch: lp:~thumper/juju-core/configurable-lxc-bridge
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 236 lines (+68/-40)
5 files modified
provider/local/config.go (+6/-0)
provider/local/config_test.go (+39/-28)
provider/local/environ.go (+15/-11)
provider/local/environprovider.go (+7/-0)
provider/local/instance.go (+1/-1)
To merge this branch: bzr merge lp:~thumper/juju-core/configurable-lxc-bridge
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+188980@code.launchpad.net

Commit message

Allow the network-bridge to be configured.

Enable the local provider config to accept network-bridge.
This is then passed through to the container creation
network config.

A slightly more informative message is added when the
bridge is not found.

https://codereview.appspot.com/14321043/

Description of the change

Allow the network-bridge to be configured.

Enable the local provider config to accept network-bridge.
This is then passed through to the container creation
netowrk config.

A slightly more informative message is added when the
bridge is not found.

https://codereview.appspot.com/14321043/

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

Reviewers: mp+188980_code.launchpad.net,

Message:
Please take a look.

Description:
Allow the network-bridge to be configured.

Enable the local provider config to accept network-bridge.
This is then passed through to the container creation
netowrk config.

A slightly more informative message is added when the
bridge is not found.

https://code.launchpad.net/~thumper/juju-core/configurable-lxc-bridge/+merge/188980

(do not edit description out of merge proposal)

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

Affected files (+70, -40 lines):
   A [revision details]
   M provider/local/config.go
   M provider/local/config_test.go
   M provider/local/environ.go
   M provider/local/environprovider.go
   M provider/local/instance.go

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

On 2013/10/03 03:19:09, thumper wrote:
> Please take a look.

LGTM, tho I wonder if we should be reading /etc/default/lxc to get the
right default. Fine as it is, just a nicety.

https://codereview.appspot.com/14321043/

Revision history for this message
Dave Cheney (dave-cheney) wrote :

> LGTM, tho I wonder if we should be reading /etc/default/lxc to get the
> right default. Fine as it is, just a nicety.

Maybe, that is the gold plated toilet seat option. I'm happy that it
is configurable and called out in the default config.

>
> https://codereview.appspot.com/14321043/
>
> --
> https://code.launchpad.net/~thumper/juju-core/configurable-lxc-bridge/+merge/188980
> You are subscribed to branch lp:juju-core.

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-10-02 01:48:17 +0000
3+++ provider/local/config.go 2013-10-03 03:13:31 +0000
4@@ -21,6 +21,7 @@
5 configFields = schema.Fields{
6 "root-dir": schema.String(),
7 "bootstrap-ip": schema.String(),
8+ "network-bridge": schema.String(),
9 "storage-port": schema.ForceInt(),
10 "shared-storage-port": schema.ForceInt(),
11 }
12@@ -30,6 +31,7 @@
13 // range.
14 configDefaults = schema.Defaults{
15 "root-dir": "",
16+ "network-bridge": "lxcbr0",
17 "bootstrap-ip": schema.Omit,
18 "storage-port": 8040,
19 "shared-storage-port": 8041,
20@@ -71,6 +73,10 @@
21 return c.attrs["root-dir"].(string)
22 }
23
24+func (c *environConfig) networkBridge() string {
25+ return c.attrs["network-bridge"].(string)
26+}
27+
28 func (c *environConfig) sharedStorageDir() string {
29 return filepath.Join(c.rootDir(), "shared-storage")
30 }
31
32=== modified file 'provider/local/config_test.go'
33--- provider/local/config_test.go 2013-10-02 01:27:45 +0000
34+++ provider/local/config_test.go 2013-10-03 03:13:31 +0000
35@@ -40,42 +40,57 @@
36 minimal := minimalConfigValues()
37 testConfig, err := config.New(config.NoDefaults, minimal)
38 c.Assert(err, gc.IsNil)
39- return testConfig
40+ valid, err := local.Provider.Validate(testConfig, nil)
41+ c.Assert(err, gc.IsNil)
42+ return valid
43+}
44+
45+func localConfig(c *gc.C, extra map[string]interface{}) *config.Config {
46+ values := minimalConfigValues()
47+ for key, value := range extra {
48+ values[key] = value
49+ }
50+ testConfig, err := config.New(config.NoDefaults, values)
51+ c.Assert(err, gc.IsNil)
52+ valid, err := local.Provider.Validate(testConfig, nil)
53+ c.Assert(err, gc.IsNil)
54+ return valid
55+}
56+
57+func (s *configSuite) TestDefaultNetworkBridge(c *gc.C) {
58+ config := minimalConfig(c)
59+ unknownAttrs := config.UnknownAttrs()
60+ c.Assert(unknownAttrs["network-bridge"], gc.Equals, "lxcbr0")
61+}
62+
63+func (s *configSuite) TestSetNetworkBridge(c *gc.C) {
64+ config := localConfig(c, map[string]interface{}{
65+ "network-bridge": "br0",
66+ })
67+ unknownAttrs := config.UnknownAttrs()
68+ c.Assert(unknownAttrs["network-bridge"], gc.Equals, "br0")
69 }
70
71 func (s *configSuite) TestValidateConfig(c *gc.C) {
72- testConfig := minimalConfig(c)
73-
74- valid, err := local.Provider.Validate(testConfig, nil)
75- c.Assert(err, gc.IsNil)
76-
77+ valid := minimalConfig(c)
78 expectedRootDir := filepath.Join(osenv.Home(), ".juju", "test")
79 unknownAttrs := valid.UnknownAttrs()
80 c.Assert(unknownAttrs["root-dir"], gc.Equals, expectedRootDir)
81 }
82
83 func (s *configSuite) TestValidateConfigWithRootDir(c *gc.C) {
84- values := minimalConfigValues()
85 root := c.MkDir()
86- values["root-dir"] = root
87- testConfig, err := config.New(config.NoDefaults, values)
88- c.Assert(err, gc.IsNil)
89-
90- valid, err := local.Provider.Validate(testConfig, nil)
91- c.Assert(err, gc.IsNil)
92+ valid := localConfig(c, map[string]interface{}{
93+ "root-dir": root,
94+ })
95 unknownAttrs := valid.UnknownAttrs()
96 c.Assert(unknownAttrs["root-dir"], gc.Equals, root)
97 }
98
99 func (s *configSuite) TestValidateConfigWithTildeInRootDir(c *gc.C) {
100- values := minimalConfigValues()
101- values["root-dir"] = "~/.juju/foo"
102- testConfig, err := config.New(config.NoDefaults, values)
103- c.Assert(err, gc.IsNil)
104-
105- valid, err := local.Provider.Validate(testConfig, nil)
106- c.Assert(err, gc.IsNil)
107-
108+ valid := localConfig(c, map[string]interface{}{
109+ "root-dir": "~/.juju/foo",
110+ })
111 expectedRootDir := filepath.Join(osenv.Home(), ".juju", "foo")
112 unknownAttrs := valid.UnknownAttrs()
113 c.Assert(unknownAttrs["root-dir"], gc.Equals, expectedRootDir)
114@@ -84,13 +99,9 @@
115 func (s *configSuite) TestValidateConfigWithFloatPort(c *gc.C) {
116 // When the config values get serialized through JSON, the integers
117 // get coerced to float64 values. The parsing needs to handle this.
118- values := minimalConfigValues()
119- values["storage-port"] = float64(8040)
120- testConfig, err := config.New(config.NoDefaults, values)
121- c.Assert(err, gc.IsNil)
122-
123- valid, err := local.Provider.Validate(testConfig, nil)
124- c.Assert(err, gc.IsNil)
125+ valid := localConfig(c, map[string]interface{}{
126+ "storage-port": float64(8040),
127+ })
128 unknownAttrs := valid.UnknownAttrs()
129 c.Assert(unknownAttrs["storage-port"], gc.Equals, int(8040))
130 }
131
132=== modified file 'provider/local/environ.go'
133--- provider/local/environ.go 2013-10-02 10:38:04 +0000
134+++ provider/local/environ.go 2013-10-03 03:13:31 +0000
135@@ -38,11 +38,6 @@
136 "launchpad.net/juju-core/version"
137 )
138
139-// lxcBridgeName is the name of the network interface that the local provider
140-// uses to determine the ip address to use for machine-0 such that the
141-// containers being created are able to communicate with it simply.
142-const lxcBridgeName = "lxcbr0"
143-
144 // boostrapInstanceId is just the name we give to the bootstrap machine.
145 // Using "localhost" because it is, and it makes sense.
146 const boostrapInstanceId = "localhost"
147@@ -233,11 +228,19 @@
148 return err
149 }
150
151- bridgeAddress, err := env.findBridgeAddress()
152+ // We need the provider config to get the network bridge.
153+ config, err := providerInstance.newConfig(cfg)
154 if err != nil {
155+ logger.Errorf("failed to create new environ config: %v", err)
156 return err
157 }
158- logger.Debugf("found %q as address for %q", bridgeAddress, lxcBridgeName)
159+ networkBridge := config.networkBridge()
160+ bridgeAddress, err := env.findBridgeAddress(networkBridge)
161+ if err != nil {
162+ logger.Infof("configure a different bridge using 'network-bridge' in the config file")
163+ return fmt.Errorf("cannot find address of network-bridge: %q", networkBridge)
164+ }
165+ logger.Debugf("found %q as address for %q", bridgeAddress, networkBridge)
166 cfg, err = cfg.Apply(map[string]interface{}{
167 "bootstrap-ip": bridgeAddress,
168 })
169@@ -245,7 +248,8 @@
170 logger.Errorf("failed to apply new addresses to config: %v", err)
171 return err
172 }
173- config, err := providerInstance.newConfig(cfg)
174+ // Now recreate the config based on the settings with the bootstrap id.
175+ config, err = providerInstance.newConfig(cfg)
176 if err != nil {
177 logger.Errorf("failed to create new environ config: %v", err)
178 return err
179@@ -293,7 +297,7 @@
180 agenttools := possibleTools[0]
181 logger.Debugf("tools: %#v", agenttools)
182
183- network := lxc.DefaultNetworkConfig()
184+ network := lxc.BridgeNetworkConfig(env.config.networkBridge())
185 inst, err := env.containerManager.StartContainer(
186 machineId, series, machineConfig.MachineNonce, network,
187 agenttools, env.config.Config,
188@@ -509,8 +513,8 @@
189 return nil
190 }
191
192-func (env *localEnviron) findBridgeAddress() (string, error) {
193- return getAddressForInterface(lxcBridgeName)
194+func (env *localEnviron) findBridgeAddress(networkBridge string) (string, error) {
195+ return getAddressForInterface(networkBridge)
196 }
197
198 func (env *localEnviron) writeBootstrapAgentConfFile(secret string, cert, key []byte) (agent.Config, error) {
199
200=== modified file 'provider/local/environprovider.go'
201--- provider/local/environprovider.go 2013-09-26 23:26:19 +0000
202+++ provider/local/environprovider.go 2013-10-03 03:13:31 +0000
203@@ -81,6 +81,11 @@
204 oldLocalConfig.rootDir(),
205 localConfig.rootDir())
206 }
207+ if localConfig.networkBridge() != oldLocalConfig.networkBridge() {
208+ return nil, fmt.Errorf("cannot change network-bridge from %q to %q",
209+ oldLocalConfig.rootDir(),
210+ localConfig.rootDir())
211+ }
212 if localConfig.storagePort() != oldLocalConfig.storagePort() {
213 return nil, fmt.Errorf("cannot change storage-port from %v to %v",
214 oldLocalConfig.storagePort(),
215@@ -120,6 +125,8 @@
216 # Override the shared storage port if you have multiple local providers, or if the
217 # default port is used by another program.
218 # shared-storage-port: 8041
219+ # Override the network bridge if you have changed the default lxc bridge
220+ # network-bridge: lxcbr0
221
222 `[1:]
223 }
224
225=== modified file 'provider/local/instance.go'
226--- provider/local/instance.go 2013-09-30 19:40:06 +0000
227+++ provider/local/instance.go 2013-10-03 03:13:31 +0000
228@@ -36,7 +36,7 @@
229 func (inst *localInstance) DNSName() (string, error) {
230 if string(inst.id) == "localhost" {
231 // get the bridge address from the environment
232- addr, err := inst.env.findBridgeAddress()
233+ addr, err := inst.env.findBridgeAddress(inst.env.config.networkBridge())
234 if err != nil {
235 logger.Errorf("failed to get bridge address: %v", err)
236 return "", instance.ErrNoDNSName

Subscribers

People subscribed via source and target branches

to status/vote changes: