Merge lp:~thumper/juju-core/maas-lxc into lp:juju-core/1.16

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 1980
Proposed branch: lp:~thumper/juju-core/maas-lxc
Merge into: lp:juju-core/1.16
Diff against target: 491 lines (+142/-107)
12 files modified
container/lxc/lxc.go (+12/-47)
container/lxc/lxc_test.go (+6/-8)
environs/cloudinit.go (+20/-12)
provider/local/environ.go (+7/-9)
state/api/params/params.go (+8/-0)
state/api/provisioner/provisioner.go (+14/-0)
state/api/provisioner/provisioner_test.go (+8/-0)
state/apiserver/provisioner/provisioner.go (+14/-0)
state/apiserver/provisioner/provisioner_test.go (+8/-0)
worker/provisioner/lxc-broker.go (+21/-7)
worker/provisioner/lxc-broker_test.go (+7/-2)
worker/provisioner/provisioner.go (+17/-22)
To merge this branch: bzr merge lp:~thumper/juju-core/maas-lxc
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+193405@code.launchpad.net

Commit message

Fix LXC containers on MAAS

We can't get a real CI framework soon enough.

When the provisioner was updated to use the API, this
accidentally broke LXC on MAAS, as the secret attributes
are stripped from the environment config for non-manager
nodes. This makes a completely invalid MAAS config, which
means the LCX provisioner task never starts.

There was no easy fix for this, so the correct one had
to do. That is to provide an API call to get what the
containers actually need, and not have them depend on
things they don't need.

I took this opportunity to also simplify the parameters
for the StartContainer call.

https://codereview.appspot.com/20220043/

Description of the change

Fix LXC containers on MAAS

We can't get a real CI framework soon enough.

When the provisioner was updated to use the API, this
accidentally broke LXC on MAAS, as the secret attributes
are stripped from the environment config for non-manager
nodes. This makes a completely invalid MAAS config, which
means the LCX provisioner task never starts.

There was no easy fix for this, so the correct one had
to do. That is to provide an API call to get what the
containers actually need, and not have them depend on
things they don't need.

I took this opportunity to also simplify the parameters
for the StartContainer call.

https://codereview.appspot.com/20220043/

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

Reviewers: mp+193405_code.launchpad.net,

Message:
Please take a look.

Description:
Fix LXC containers on MAAS

We can't get a real CI framework soon enough.

When the provisioner was updated to use the API, this
accidentally broke LXC on MAAS, as the secret attributes
are stripped from the environment config for non-manager
nodes. This makes a completely invalid MAAS config, which
means the LCX provisioner task never starts.

There was no easy fix for this, so the correct one had
to do. That is to provide an API call to get what the
containers actually need, and not have them depend on
things they don't need.

I took this opportunity to also simplify the parameters
for the StartContainer call.

https://code.launchpad.net/~thumper/juju-core/maas-lxc/+merge/193405

(do not edit description out of merge proposal)

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

Affected files (+143, -107 lines):
   A [revision details]
   M container/lxc/lxc.go
   M container/lxc/lxc_test.go
   M environs/cloudinit.go
   M provider/local/environ.go
   M state/api/params/params.go
   M state/api/provisioner/provisioner.go
   M state/api/provisioner/provisioner_test.go
   M state/apiserver/provisioner/provisioner.go
   M state/apiserver/provisioner/provisioner_test.go
   M worker/provisioner/lxc-broker.go
   M worker/provisioner/lxc-broker_test.go
   M worker/provisioner/provisioner.go

Revision history for this message
Dimiter Naydenov (dimitern) wrote :

Very nice! LGTM

https://codereview.appspot.com/20220043/diff/1/state/apiserver/provisioner/provisioner.go
File state/apiserver/provisioner/provisioner.go (right):

https://codereview.appspot.com/20220043/diff/1/state/apiserver/provisioner/provisioner.go#newcode185
state/apiserver/provisioner/provisioner.go:185: // ContainerConfig
returns the current environment's configuration.
Fix the doc string please.

https://codereview.appspot.com/20220043/

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

And thanks.

https://codereview.appspot.com/20220043/diff/1/state/apiserver/provisioner/provisioner.go
File state/apiserver/provisioner/provisioner.go (right):

https://codereview.appspot.com/20220043/diff/1/state/apiserver/provisioner/provisioner.go#newcode185
state/apiserver/provisioner/provisioner.go:185: // ContainerConfig
returns the current environment's configuration.
On 2013/10/31 11:50:30, dimitern wrote:
> Fix the doc string please.

Done.

https://codereview.appspot.com/20220043/

Revision history for this message
John A Meinel (jameinel) wrote :

LGTM

https://codereview.appspot.com/20220043/diff/1/state/api/provisioner/provisioner.go
File state/api/provisioner/provisioner.go (right):

https://codereview.appspot.com/20220043/diff/1/state/api/provisioner/provisioner.go#newcode161
state/api/provisioner/provisioner.go:161: var result
params.ContainerConfig
I would actually think that ContainerConfig would just return the params
struct, rather than splitting it back out into individual args.
That way, if we do decide to add things, we don't have to change the
Client API

https://codereview.appspot.com/20220043/diff/1/worker/provisioner/lxc-broker.go
File worker/provisioner/lxc-broker.go (right):

https://codereview.appspot.com/20220043/diff/1/worker/provisioner/lxc-broker.go#newcode65
worker/provisioner/lxc-broker.go:65: providerType, authorizedKeys,
sslVerification, err := broker.api.ContainerConfig()
Just a question, would it make sense to move this API call up a level
instead of here? Most of our API calls occur in the other layer where
the watchers are going on.

Nothing you have to change, just something I thought of.

https://codereview.appspot.com/20220043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'container/lxc/lxc.go'
2--- container/lxc/lxc.go 2013-10-01 02:33:14 +0000
3+++ container/lxc/lxc.go 2013-10-31 11:53:08 +0000
4@@ -14,15 +14,9 @@
5 "launchpad.net/golxc"
6 "launchpad.net/loggo"
7
8- "launchpad.net/juju-core/constraints"
9- "launchpad.net/juju-core/environs"
10 "launchpad.net/juju-core/environs/cloudinit"
11- "launchpad.net/juju-core/environs/config"
12 "launchpad.net/juju-core/instance"
13 "launchpad.net/juju-core/names"
14- "launchpad.net/juju-core/state"
15- "launchpad.net/juju-core/state/api"
16- "launchpad.net/juju-core/tools"
17 "launchpad.net/juju-core/utils"
18 )
19
20@@ -83,12 +77,9 @@
21 type ContainerManager interface {
22 // StartContainer creates and starts a new lxc container for the specified machine.
23 StartContainer(
24- machineId, series, nonce string,
25- network *NetworkConfig,
26- tools *tools.Tools,
27- environConfig *config.Config,
28- stateInfo *state.Info,
29- apiInfo *api.Info) (instance.Instance, error)
30+ machineConfig *cloudinit.MachineConfig,
31+ series string,
32+ network *NetworkConfig) (instance.Instance, error)
33 // StopContainer stops and destroyes the lxc container identified by Instance.
34 StopContainer(instance.Instance) error
35 // ListContainers return a list of containers that have been started by
36@@ -113,14 +104,11 @@
37 }
38
39 func (manager *containerManager) StartContainer(
40- machineId, series, nonce string,
41- network *NetworkConfig,
42- tools *tools.Tools,
43- environConfig *config.Config,
44- stateInfo *state.Info,
45- apiInfo *api.Info) (instance.Instance, error) {
46+ machineConfig *cloudinit.MachineConfig,
47+ series string,
48+ network *NetworkConfig) (instance.Instance, error) {
49
50- name := names.MachineTag(machineId)
51+ name := names.MachineTag(machineConfig.MachineId)
52 if manager.name != "" {
53 name = fmt.Sprintf("%s-%s", manager.name, name)
54 }
55@@ -137,7 +125,7 @@
56 return nil, err
57 }
58 logger.Tracef("write cloud-init")
59- userDataFilename, err := writeUserData(directory, machineId, nonce, tools, environConfig, stateInfo, apiInfo)
60+ userDataFilename, err := writeUserData(machineConfig, directory)
61 if err != nil {
62 logger.Errorf("failed to write user data: %v", err)
63 return nil, err
64@@ -300,14 +288,8 @@
65 return configFilename, nil
66 }
67
68-func writeUserData(
69- directory, machineId, nonce string,
70- tools *tools.Tools,
71- environConfig *config.Config,
72- stateInfo *state.Info,
73- apiInfo *api.Info,
74-) (string, error) {
75- userData, err := cloudInitUserData(machineId, nonce, tools, environConfig, stateInfo, apiInfo)
76+func writeUserData(machineConfig *cloudinit.MachineConfig, directory string) (string, error) {
77+ userData, err := cloudInitUserData(machineConfig)
78 if err != nil {
79 logger.Errorf("failed to create user data: %v", err)
80 return "", err
81@@ -320,25 +302,8 @@
82 return userDataFilename, nil
83 }
84
85-func cloudInitUserData(
86- machineId, nonce string,
87- tools *tools.Tools,
88- environConfig *config.Config,
89- stateInfo *state.Info,
90- apiInfo *api.Info,
91-) ([]byte, error) {
92- machineConfig := &cloudinit.MachineConfig{
93- MachineId: machineId,
94- MachineNonce: nonce,
95- MachineContainerType: instance.LXC,
96- StateInfo: stateInfo,
97- APIInfo: apiInfo,
98- DataDir: "/var/lib/juju",
99- Tools: tools,
100- }
101- if err := environs.FinishMachineConfig(machineConfig, environConfig, constraints.Value{}); err != nil {
102- return nil, err
103- }
104+func cloudInitUserData(machineConfig *cloudinit.MachineConfig) ([]byte, error) {
105+ machineConfig.DataDir = "/var/lib/juju"
106 cloudConfig, err := cloudinit.New(machineConfig)
107 if err != nil {
108 return nil, err
109
110=== modified file 'container/lxc/lxc_test.go'
111--- container/lxc/lxc_test.go 2013-10-01 21:21:01 +0000
112+++ container/lxc/lxc_test.go 2013-10-31 11:53:08 +0000
113@@ -16,10 +16,10 @@
114 "launchpad.net/loggo"
115
116 "launchpad.net/juju-core/container/lxc"
117+ "launchpad.net/juju-core/environs"
118 "launchpad.net/juju-core/instance"
119 instancetest "launchpad.net/juju-core/instance/testing"
120 jujutesting "launchpad.net/juju-core/juju/testing"
121- "launchpad.net/juju-core/testing"
122 jc "launchpad.net/juju-core/testing/checkers"
123 "launchpad.net/juju-core/testing/testbase"
124 "launchpad.net/juju-core/tools"
125@@ -65,19 +65,17 @@
126 )
127
128 func StartContainer(c *gc.C, manager lxc.ContainerManager, machineId string) instance.Instance {
129- config := testing.EnvironConfig(c)
130 stateInfo := jujutesting.FakeStateInfo(machineId)
131 apiInfo := jujutesting.FakeAPIInfo(machineId)
132- network := lxc.BridgeNetworkConfig("nic42")
133-
134- series := "series"
135- nonce := "fake-nonce"
136- tools := &tools.Tools{
137+ machineConfig := environs.NewMachineConfig(machineId, "fake-nonce", stateInfo, apiInfo)
138+ machineConfig.Tools = &tools.Tools{
139 Version: version.MustParseBinary("2.3.4-foo-bar"),
140 URL: "http://tools.testing.invalid/2.3.4-foo-bar.tgz",
141 }
142
143- inst, err := manager.StartContainer(machineId, series, nonce, network, tools, config, stateInfo, apiInfo)
144+ series := "series"
145+ network := lxc.BridgeNetworkConfig("nic42")
146+ inst, err := manager.StartContainer(machineConfig, series, network)
147 c.Assert(err, gc.IsNil)
148 return inst
149 }
150
151=== modified file 'environs/cloudinit.go'
152--- environs/cloudinit.go 2013-10-02 19:30:07 +0000
153+++ environs/cloudinit.go 2013-10-31 11:53:08 +0000
154@@ -51,6 +51,23 @@
155 return mcfg
156 }
157
158+func PopulateMachineConfig(mcfg *cloudinit.MachineConfig,
159+ providerType, authorizedKeys string,
160+ sslHostnameVerification bool) error {
161+
162+ if authorizedKeys == "" {
163+ return fmt.Errorf("environment configuration has no authorized-keys")
164+ }
165+ mcfg.AuthorizedKeys = authorizedKeys
166+ if mcfg.AgentEnvironment == nil {
167+ mcfg.AgentEnvironment = make(map[string]string)
168+ }
169+ mcfg.AgentEnvironment[agent.ProviderType] = providerType
170+ mcfg.AgentEnvironment[agent.ContainerType] = string(mcfg.MachineContainerType)
171+ mcfg.DisableSSLHostnameVerification = !sslHostnameVerification
172+ return nil
173+}
174+
175 // FinishMachineConfig sets fields on a MachineConfig that can be determined by
176 // inspecting a plain config.Config and the machine constraints at the last
177 // moment before bootstrapping. It assumes that the supplied Config comes from
178@@ -64,18 +81,9 @@
179 func FinishMachineConfig(mcfg *cloudinit.MachineConfig, cfg *config.Config, cons constraints.Value) (err error) {
180 defer utils.ErrorContextf(&err, "cannot complete machine configuration")
181
182- // Everything needs the environment's authorized keys.
183- authKeys := cfg.AuthorizedKeys()
184- if authKeys == "" {
185- return fmt.Errorf("environment configuration has no authorized-keys")
186- }
187- mcfg.AuthorizedKeys = authKeys
188- if mcfg.AgentEnvironment == nil {
189- mcfg.AgentEnvironment = make(map[string]string)
190- }
191- mcfg.AgentEnvironment[agent.ProviderType] = cfg.Type()
192- mcfg.AgentEnvironment[agent.ContainerType] = string(mcfg.MachineContainerType)
193- mcfg.DisableSSLHostnameVerification = !cfg.SSLHostnameVerification()
194+ if err := PopulateMachineConfig(mcfg, cfg.Type(), cfg.AuthorizedKeys(), cfg.SSLHostnameVerification()); err != nil {
195+ return err
196+ }
197
198 // The following settings are only appropriate at bootstrap time. At the
199 // moment, the only state server is the bootstrap node, but this
200
201=== modified file 'provider/local/environ.go'
202--- provider/local/environ.go 2013-10-16 21:28:54 +0000
203+++ provider/local/environ.go 2013-10-31 11:53:08 +0000
204@@ -265,17 +265,15 @@
205 func (env *localEnviron) StartInstance(cons constraints.Value, possibleTools tools.List,
206 machineConfig *cloudinit.MachineConfig) (instance.Instance, *instance.HardwareCharacteristics, error) {
207
208- machineId := machineConfig.MachineId
209 series := possibleTools.OneSeries()
210- logger.Debugf("StartInstance: %q, %s", machineId, series)
211- agenttools := possibleTools[0]
212- logger.Debugf("tools: %#v", agenttools)
213-
214+ logger.Debugf("StartInstance: %q, %s", machineConfig.MachineId, series)
215+ machineConfig.Tools = possibleTools[0]
216+ logger.Debugf("tools: %#v", machineConfig.Tools)
217 network := lxc.BridgeNetworkConfig(env.config.networkBridge())
218- inst, err := env.containerManager.StartContainer(
219- machineId, series, machineConfig.MachineNonce, network,
220- agenttools, env.config.Config,
221- machineConfig.StateInfo, machineConfig.APIInfo)
222+ if err := environs.FinishMachineConfig(machineConfig, env.config.Config, cons); err != nil {
223+ return nil, nil, err
224+ }
225+ inst, err := env.containerManager.StartContainer(machineConfig, series, network)
226 if err != nil {
227 return nil, nil, err
228 }
229
230=== modified file 'state/api/params/params.go'
231--- state/api/params/params.go 2013-09-18 15:57:30 +0000
232+++ state/api/params/params.go 2013-10-31 11:53:08 +0000
233@@ -405,3 +405,11 @@
234 Id: i.Tag,
235 }
236 }
237+
238+// ContainerConfig contains information from the environment config that are
239+// needed for container cloud-init.
240+type ContainerConfig struct {
241+ ProviderType string
242+ AuthorizedKeys string
243+ SSLHostnameVerification bool
244+}
245
246=== modified file 'state/api/provisioner/provisioner.go'
247--- state/api/provisioner/provisioner.go 2013-10-02 14:26:55 +0000
248+++ state/api/provisioner/provisioner.go 2013-10-31 11:53:08 +0000
249@@ -154,3 +154,17 @@
250 }
251 return result.Tools, nil
252 }
253+
254+// ContainerConfig returns information from the environment config that are
255+// needed for container cloud-init.
256+func (st *State) ContainerConfig() (providerType, authorizedKeys string, sslVerification bool, err error) {
257+ var result params.ContainerConfig
258+ err = st.caller.Call("Provisioner", "", "ContainerConfig", nil, &result)
259+ if err != nil {
260+ return "", "", false, err
261+ }
262+ providerType = result.ProviderType
263+ authorizedKeys = result.AuthorizedKeys
264+ sslVerification = result.SSLHostnameVerification
265+ return providerType, authorizedKeys, sslVerification, nil
266+}
267
268=== modified file 'state/api/provisioner/provisioner_test.go'
269--- state/api/provisioner/provisioner_test.go 2013-10-02 13:14:49 +0000
270+++ state/api/provisioner/provisioner_test.go 2013-10-31 11:53:08 +0000
271@@ -357,6 +357,14 @@
272 c.Assert(addresses, gc.DeepEquals, apiInfo.Addrs)
273 }
274
275+func (s *provisionerSuite) TestContainerConfig(c *gc.C) {
276+ providerType, authKeys, sslVerify, err := s.provisioner.ContainerConfig()
277+ c.Assert(err, gc.IsNil)
278+ c.Assert(providerType, gc.Equals, "dummy")
279+ c.Assert(authKeys, gc.Equals, "my-keys")
280+ c.Assert(sslVerify, jc.IsTrue)
281+}
282+
283 func (s *provisionerSuite) TestCACert(c *gc.C) {
284 caCert, err := s.provisioner.CACert()
285 c.Assert(err, gc.IsNil)
286
287=== modified file 'state/apiserver/provisioner/provisioner.go'
288--- state/apiserver/provisioner/provisioner.go 2013-10-02 10:03:25 +0000
289+++ state/apiserver/provisioner/provisioner.go 2013-10-31 11:53:08 +0000
290@@ -182,6 +182,20 @@
291 return result, nil
292 }
293
294+// ContainerConfig returns information from the environment config that are
295+// needed for container cloud-init.
296+func (p *ProvisionerAPI) ContainerConfig() (params.ContainerConfig, error) {
297+ result := params.ContainerConfig{}
298+ config, err := p.st.EnvironConfig()
299+ if err != nil {
300+ return result, err
301+ }
302+ result.ProviderType = config.Type()
303+ result.AuthorizedKeys = config.AuthorizedKeys()
304+ result.SSLHostnameVerification = config.SSLHostnameVerification()
305+ return result, nil
306+}
307+
308 // Status returns the status of each given machine entity.
309 func (p *ProvisionerAPI) Status(args params.Entities) (params.StatusResults, error) {
310 result := params.StatusResults{
311
312=== modified file 'state/apiserver/provisioner/provisioner_test.go'
313--- state/apiserver/provisioner/provisioner_test.go 2013-10-02 13:14:49 +0000
314+++ state/apiserver/provisioner/provisioner_test.go 2013-10-31 11:53:08 +0000
315@@ -675,6 +675,14 @@
316 c.Check(results.Results, gc.HasLen, 0)
317 }
318
319+func (s *provisionerSuite) TestContainerConfig(c *gc.C) {
320+ results, err := s.provisioner.ContainerConfig()
321+ c.Check(err, gc.IsNil)
322+ c.Check(results.ProviderType, gc.Equals, "dummy")
323+ c.Check(results.AuthorizedKeys, gc.Equals, "my-keys")
324+ c.Check(results.SSLHostnameVerification, jc.IsTrue)
325+}
326+
327 func (s *provisionerSuite) TestToolsRefusesWrongAgent(c *gc.C) {
328 anAuthorizer := s.authorizer
329 anAuthorizer.Tag = "machine-12354"
330
331=== modified file 'worker/provisioner/lxc-broker.go'
332--- worker/provisioner/lxc-broker.go 2013-08-30 04:50:15 +0000
333+++ worker/provisioner/lxc-broker.go 2013-10-31 11:53:08 +0000
334@@ -11,7 +11,6 @@
335 "launchpad.net/juju-core/container/lxc"
336 "launchpad.net/juju-core/environs"
337 "launchpad.net/juju-core/environs/cloudinit"
338- "launchpad.net/juju-core/environs/config"
339 "launchpad.net/juju-core/instance"
340 "launchpad.net/juju-core/tools"
341 )
342@@ -21,10 +20,14 @@
343 var _ environs.InstanceBroker = (*lxcBroker)(nil)
344 var _ tools.HasTools = (*lxcBroker)(nil)
345
346-func NewLxcBroker(config *config.Config, tools *tools.Tools, agentConfig agent.Config) environs.InstanceBroker {
347+type APICalls interface {
348+ ContainerConfig() (providerType, authorizedKeys string, sslVerification bool, err error)
349+}
350+
351+func NewLxcBroker(api APICalls, tools *tools.Tools, agentConfig agent.Config) environs.InstanceBroker {
352 return &lxcBroker{
353 manager: lxc.NewContainerManager(lxc.ManagerConfig{Name: "juju"}),
354- config: config,
355+ api: api,
356 tools: tools,
357 agentConfig: agentConfig,
358 }
359@@ -32,7 +35,7 @@
360
361 type lxcBroker struct {
362 manager lxc.ContainerManager
363- config *config.Config
364+ api APICalls
365 tools *tools.Tools
366 agentConfig agent.Config
367 }
368@@ -56,9 +59,20 @@
369 network := lxc.BridgeNetworkConfig(bridgeDevice)
370
371 series := possibleTools.OneSeries()
372- inst, err := broker.manager.StartContainer(
373- machineId, series, machineConfig.MachineNonce, network, possibleTools[0], broker.config,
374- machineConfig.StateInfo, machineConfig.APIInfo)
375+ machineConfig.MachineContainerType = instance.LXC
376+ machineConfig.Tools = possibleTools[0]
377+
378+ providerType, authorizedKeys, sslVerification, err := broker.api.ContainerConfig()
379+ if err != nil {
380+ lxcLogger.Errorf("failed to get container config: %v", err)
381+ return nil, nil, err
382+ }
383+ if err := environs.PopulateMachineConfig(machineConfig, providerType, authorizedKeys, sslVerification); err != nil {
384+ lxcLogger.Errorf("failed to populate machine config: %v", err)
385+ return nil, nil, err
386+ }
387+
388+ inst, err := broker.manager.StartContainer(machineConfig, series, network)
389 if err != nil {
390 lxcLogger.Errorf("failed to start container: %v", err)
391 return nil, nil, err
392
393=== modified file 'worker/provisioner/lxc-broker_test.go'
394--- worker/provisioner/lxc-broker_test.go 2013-10-02 13:14:49 +0000
395+++ worker/provisioner/lxc-broker_test.go 2013-10-31 11:53:08 +0000
396@@ -64,7 +64,6 @@
397 Version: version.MustParseBinary("2.3.4-foo-bar"),
398 URL: "http://tools.testing.invalid/2.3.4-foo-bar.tgz",
399 }
400- config := coretesting.EnvironConfig(c)
401 var err error
402 s.agentConfig, err = agent.NewAgentConfig(
403 agent.AgentConfigParams{
404@@ -76,7 +75,7 @@
405 CACert: []byte(coretesting.CACert),
406 })
407 c.Assert(err, gc.IsNil)
408- s.broker = provisioner.NewLxcBroker(config, tools, s.agentConfig)
409+ s.broker = provisioner.NewLxcBroker(&fakeAPI{}, tools, s.agentConfig)
410 }
411
412 func (s *lxcBrokerSuite) startInstance(c *gc.C, machineId string) instance.Instance {
413@@ -273,3 +272,9 @@
414 s.expectStopped(c, instId)
415 s.waitRemoved(c, container)
416 }
417+
418+type fakeAPI struct{}
419+
420+func (*fakeAPI) ContainerConfig() (providerType, authorizedKeys string, sslVerification bool, err error) {
421+ return "fake", "my-keys", true, nil
422+}
423
424=== modified file 'worker/provisioner/provisioner.go'
425--- worker/provisioner/provisioner.go 2013-10-02 10:03:25 +0000
426+++ worker/provisioner/provisioner.go 2013-10-31 11:53:08 +0000
427@@ -15,6 +15,7 @@
428 "launchpad.net/juju-core/environs/config"
429 "launchpad.net/juju-core/instance"
430 apiprovisioner "launchpad.net/juju-core/state/api/provisioner"
431+ apiwatcher "launchpad.net/juju-core/state/api/watcher"
432 "launchpad.net/juju-core/state/watcher"
433 coretools "launchpad.net/juju-core/tools"
434 "launchpad.net/juju-core/worker"
435@@ -75,26 +76,21 @@
436 }
437
438 func (p *Provisioner) loop() error {
439- environWatcher, err := p.st.WatchForEnvironConfigChanges()
440- if err != nil {
441- return err
442- }
443- environConfigChanges := environWatcher.Changes()
444- defer watcher.Stop(environWatcher, &p.tomb)
445-
446- p.environ, err = worker.WaitForEnviron(environWatcher, p.st, p.tomb.Dying())
447- if err != nil {
448- return err
449- }
450-
451- if p.pt != ENVIRON {
452- // Only the environment provisioner cares about
453- // changes to the environment configuration.
454- if err := environWatcher.Stop(); err != nil {
455- return err
456- }
457- // Don't wait for changes on the channel below.
458- environConfigChanges = nil
459+ // Only wait for the environment if we are an environmental provisioner.
460+ var environConfigChanges <-chan struct{}
461+ var environWatcher apiwatcher.NotifyWatcher
462+ if p.pt == ENVIRON {
463+ environWatcher, err := p.st.WatchForEnvironConfigChanges()
464+ if err != nil {
465+ return err
466+ }
467+ environConfigChanges = environWatcher.Changes()
468+ defer watcher.Stop(environWatcher, &p.tomb)
469+
470+ p.environ, err = worker.WaitForEnviron(environWatcher, p.st, p.tomb.Dying())
471+ if err != nil {
472+ return err
473+ }
474 }
475
476 auth, err := NewAPIAuthenticator(p.st)
477@@ -177,13 +173,12 @@
478 case ENVIRON:
479 return p.environ, nil
480 case LXC:
481- config := p.environ.Config()
482 tools, err := p.getAgentTools()
483 if err != nil {
484 logger.Errorf("cannot get tools from machine for lxc broker")
485 return nil, err
486 }
487- return NewLxcBroker(config, tools, p.agentConfig), nil
488+ return NewLxcBroker(p.st, tools, p.agentConfig), nil
489 }
490 return nil, fmt.Errorf("unknown provisioner type")
491 }

Subscribers

People subscribed via source and target branches

to all changes: