Merge lp:~thumper/juju-core/pass-through-agent-config 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: 1751
Proposed branch: lp:~thumper/juju-core/pass-through-agent-config
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~thumper/juju-core/agent-config-formatters
Diff against target: 733 lines (+186/-109)
15 files modified
agent/agent.go (+11/-0)
cmd/jujud/agent.go (+2/-14)
cmd/jujud/deploy_test.go (+10/-4)
cmd/jujud/machine.go (+8/-9)
cmd/jujud/machine_test.go (+3/-2)
cmd/jujud/unit.go (+3/-3)
worker/deployer/deployer.go (+13/-9)
worker/deployer/deployer_test.go (+12/-16)
worker/deployer/export_test.go (+6/-3)
worker/deployer/simple.go (+22/-25)
worker/deployer/simple_test.go (+29/-1)
worker/machiner/machiner.go (+3/-2)
worker/machiner/machiner_test.go (+26/-7)
worker/upgrader/upgrader.go (+10/-10)
worker/upgrader/upgrader_test.go (+28/-4)
To merge this branch: bzr merge lp:~thumper/juju-core/pass-through-agent-config
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+183543@code.launchpad.net

Commit message

Pass agent config through to workers.

Broke this change out of the following work.
Instead of passing through elements of the agent
config through to the workers separately, pass the
entire agent config through. This has the benefit
of simplifying a lot of call sites.

https://codereview.appspot.com/13477043/

Description of the change

Pass agent config through to workers.

Broke this change out of the following work.
Instead of passing through elements of the agent
config through to the workers separately, pass the
entire agent config through. This has the benefit
of simplifying a lot of call sites.

https://codereview.appspot.com/13477043/

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

Reviewers: mp+183543_code.launchpad.net,

Message:
Please take a look.

Description:
Pass agent config through to workers.

Broke this change out of the following work.
Instead of passing through elements of the agent
config through to the workers separately, pass the
entire agent config through. This has the benefit
of simplifying a lot of call sites.

https://code.launchpad.net/~thumper/juju-core/pass-through-agent-config/+merge/183543

Requires:
https://code.launchpad.net/~thumper/juju-core/agent-config-formatters/+merge/183074

(do not edit description out of merge proposal)

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

Affected files:
   A [revision details]
   M agent/agent.go
   M cmd/jujud/agent.go
   M cmd/jujud/deploy_test.go
   M cmd/jujud/machine.go
   M cmd/jujud/machine_test.go
   M cmd/jujud/unit.go
   M cmd/plugins/juju-metadata/metadata.go
   M cmd/plugins/juju-metadata/metadataplugin_test.go
   A cmd/plugins/juju-metadata/toolsmetadata.go
   A cmd/plugins/juju-metadata/toolsmetadata_test.go
   A environs/filestorage/filestorage.go
   M environs/localstorage/storage.go
   M environs/localstorage/storage_test.go
   A environs/simplestreams/json.go
   A environs/simplestreams/json_test.go
   M environs/simplestreams/simplestreams.go
   M environs/simplestreams/simplestreams_test.go
   M environs/sync/sync.go
   M environs/tools/boilerplate.go
   A environs/tools/marshal.go
   A environs/tools/marshal_test.go
   M environs/tools/simplestreams.go
   M environs/tools/simplestreams_test.go
   M provider/azure/config.go
   M state/api/params/internal.go
   M state/api/uniter/relationunit.go
   M state/api/uniter/unit.go
   M state/api/uniter/uniter_test.go
   M state/apiserver/uniter/uniter.go
   M state/apiserver/uniter/uniter_test.go
   M worker/deployer/deployer.go
   M worker/deployer/deployer_test.go
   M worker/deployer/export_test.go
   M worker/deployer/simple.go
   M worker/deployer/simple_test.go
   M worker/machiner/machiner.go
   M worker/machiner/machiner_test.go
   M worker/uniter/modes.go
   M worker/upgrader/upgrader.go
   M worker/upgrader/upgrader_test.go

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

Seems fairly mechanical. LGTM

https://codereview.appspot.com/13477043/

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

LGTM

https://codereview.appspot.com/13477043/diff/2/agent/agent.go
File agent/agent.go (right):

https://codereview.appspot.com/13477043/diff/2/agent/agent.go#newcode219
agent/agent.go:219: return c.caCert
Perhaps to minimise problems through API misuse, this should be a copy
of the slice. Readonly slices would be good here...

https://codereview.appspot.com/13477043/diff/2/worker/deployer/simple.go
File worker/deployer/simple.go (right):

https://codereview.appspot.com/13477043/diff/2/worker/deployer/simple.go#newcode63
worker/deployer/simple.go:63: logDir: "/var/log/juju",
Will these things be moving into agent.Config?

https://codereview.appspot.com/13477043/diff/2/worker/upgrader/upgrader.go
File worker/upgrader/upgrader.go (right):

https://codereview.appspot.com/13477043/diff/2/worker/upgrader/upgrader.go#newcode71
worker/upgrader/upgrader.go:71: func NewUpgrader(st *upgrader.State,
agentConfig agent.Config) *Upgrader {
If the name is changing, the comment needs to change too, doesn't it?

https://codereview.appspot.com/13477043/

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

Running the tests then submitting.

https://codereview.appspot.com/13477043/diff/2/agent/agent.go
File agent/agent.go (right):

https://codereview.appspot.com/13477043/diff/2/agent/agent.go#newcode219
agent/agent.go:219: return c.caCert
On 2013/09/03 01:33:12, axw1 wrote:
> Perhaps to minimise problems through API misuse, this should be a copy
of the
> slice. Readonly slices would be good here...

Done.

https://codereview.appspot.com/13477043/diff/2/worker/deployer/simple.go
File worker/deployer/simple.go (right):

https://codereview.appspot.com/13477043/diff/2/worker/deployer/simple.go#newcode63
worker/deployer/simple.go:63: logDir: "/var/log/juju",
On 2013/09/03 01:33:12, axw1 wrote:
> Will these things be moving into agent.Config?

Possibly, and probably, just not right now.

https://codereview.appspot.com/13477043/diff/2/worker/upgrader/upgrader.go
File worker/upgrader/upgrader.go (right):

https://codereview.appspot.com/13477043/diff/2/worker/upgrader/upgrader.go#newcode71
worker/upgrader/upgrader.go:71: func NewUpgrader(st *upgrader.State,
agentConfig agent.Config) *Upgrader {
On 2013/09/03 01:33:12, axw1 wrote:
> If the name is changing, the comment needs to change too, doesn't it?

Good call.

https://codereview.appspot.com/13477043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'agent/agent.go'
2--- agent/agent.go 2013-08-29 07:11:02 +0000
3+++ agent/agent.go 2013-09-03 02:24:16 +0000
4@@ -36,6 +36,10 @@
5 // TODO: make this one of the key/value pairs.
6 Nonce() string
7
8+ // CACert returns the CA certificate that is used to validate the state or
9+ // API servier's certificate.
10+ CACert() []byte
11+
12 // OpenAPI tries to connect to an API end-point. If a non-empty
13 // newPassword is returned, the password used to connect to the state
14 // should be changed accordingly - the caller should set the entity's
15@@ -211,6 +215,13 @@
16 return c.nonce
17 }
18
19+func (c *configInternal) CACert() []byte {
20+ // Give the caller their own copy of the cert to avoid any possibility of
21+ // modifying the config's copy.
22+ result := append([]byte{}, c.caCert...)
23+ return result
24+}
25+
26 func (c *configInternal) APIServerDetails() (port int, cert, key []byte) {
27 return c.apiPort, c.stateServerCert, c.stateServerKey
28 }
29
30=== modified file 'cmd/jujud/agent.go'
31--- cmd/jujud/agent.go 2013-08-22 23:29:46 +0000
32+++ cmd/jujud/agent.go 2013-09-03 02:24:16 +0000
33@@ -212,18 +212,6 @@
34 // running the tests and (2) get access to the *State used internally, so that
35 // tests can be run without waiting for the 5s watcher refresh time to which we would
36 // otherwise be restricted.
37-var newDeployContext = func(st *apideployer.State, dataDir string) (deployer.Context, error) {
38- caCert, err := st.CACert()
39- if err != nil {
40- return nil, err
41- }
42- return deployer.NewSimpleContext(dataDir, caCert, st), nil
43-}
44-
45-func newDeployer(st *apideployer.State, machineTag string, dataDir string) (worker.Worker, error) {
46- ctx, err := newDeployContext(st, dataDir)
47- if err != nil {
48- return nil, err
49- }
50- return deployer.NewDeployer(st, ctx, machineTag), nil
51+var newDeployContext = func(st *apideployer.State, agentConfig agent.Config) deployer.Context {
52+ return deployer.NewSimpleContext(agentConfig, st)
53 }
54
55=== modified file 'cmd/jujud/deploy_test.go'
56--- cmd/jujud/deploy_test.go 2013-08-21 22:43:46 +0000
57+++ cmd/jujud/deploy_test.go 2013-09-03 02:24:16 +0000
58@@ -11,6 +11,7 @@
59
60 gc "launchpad.net/gocheck"
61
62+ "launchpad.net/juju-core/agent"
63 "launchpad.net/juju-core/state"
64 "launchpad.net/juju-core/testing"
65 "launchpad.net/juju-core/utils/set"
66@@ -23,10 +24,11 @@
67 // a sync and observe changes to the set of desired units (and thereby run
68 // deployment tests in a reasonable amount of time).
69 type fakeContext struct {
70- mu sync.Mutex
71- deployed set.Strings
72- st *state.State
73- inited chan struct{}
74+ mu sync.Mutex
75+ deployed set.Strings
76+ st *state.State
77+ agentConfig agent.Config
78+ inited chan struct{}
79 }
80
81 func (ctx *fakeContext) DeployUnit(unitName, _ string) error {
82@@ -76,3 +78,7 @@
83 }
84 }
85 }
86+
87+func (ctx *fakeContext) AgentConfig() agent.Config {
88+ return ctx.agentConfig
89+}
90
91=== modified file 'cmd/jujud/machine.go'
92--- cmd/jujud/machine.go 2013-08-29 05:36:08 +0000
93+++ cmd/jujud/machine.go 2013-09-03 02:24:16 +0000
94@@ -26,6 +26,7 @@
95 "launchpad.net/juju-core/upstart"
96 "launchpad.net/juju-core/worker"
97 "launchpad.net/juju-core/worker/cleaner"
98+ "launchpad.net/juju-core/worker/deployer"
99 "launchpad.net/juju-core/worker/firewaller"
100 "launchpad.net/juju-core/worker/machiner"
101 "launchpad.net/juju-core/worker/minunitsworker"
102@@ -142,7 +143,8 @@
103 //
104 // If a state worker is necessary, APIWorker calls ensureStateWorker.
105 func (a *MachineAgent) APIWorker(ensureStateWorker func()) (worker.Worker, error) {
106- st, entity, err := openAPIState(a.Conf.config, a)
107+ agentConfig := a.Conf.config
108+ st, entity, err := openAPIState(agentConfig, a)
109 if err != nil {
110 // There was an error connecting to the API,
111 // https://launchpad.net/bugs/1199915 means that we may just
112@@ -168,21 +170,18 @@
113 // Only the machiner currently connects to the API.
114 // Add other workers here as they are ready.
115 runner.StartWorker("machiner", func() (worker.Worker, error) {
116- return machiner.NewMachiner(st.Machiner(), a.Tag()), nil
117+ return machiner.NewMachiner(st.Machiner(), agentConfig), nil
118 })
119 runner.StartWorker("upgrader", func() (worker.Worker, error) {
120- // TODO(rog) use id instead of *Machine (or introduce Clone method)
121- return upgrader.New(st.Upgrader(), a.Tag(), a.Conf.dataDir), nil
122+ return upgrader.NewUpgrader(st.Upgrader(), agentConfig), nil
123 })
124 for _, job := range entity.Jobs() {
125 switch job {
126 case params.JobHostUnits:
127- deployerTask, err := newDeployer(st.Deployer(), a.Tag(), a.Conf.dataDir)
128- if err != nil {
129- return nil, err
130- }
131 runner.StartWorker("deployer", func() (worker.Worker, error) {
132- return deployerTask, nil
133+ apiDeployer := st.Deployer()
134+ context := newDeployContext(apiDeployer, agentConfig)
135+ return deployer.NewDeployer(apiDeployer, context), nil
136 })
137 case params.JobManageEnviron:
138 // Not yet implemented with the API.
139
140=== modified file 'cmd/jujud/machine_test.go'
141--- cmd/jujud/machine_test.go 2013-09-02 08:35:00 +0000
142+++ cmd/jujud/machine_test.go 2013-09-03 02:24:16 +0000
143@@ -248,10 +248,11 @@
144 inited: make(chan struct{}),
145 }
146 orig := newDeployContext
147- newDeployContext = func(dst *apideployer.State, dataDir string) (deployer.Context, error) {
148+ newDeployContext = func(dst *apideployer.State, agentConfig agent.Config) deployer.Context {
149 ctx.st = st
150+ ctx.agentConfig = agentConfig
151 close(ctx.inited)
152- return ctx, nil
153+ return ctx
154 }
155 return ctx, func() { newDeployContext = orig }
156 }
157
158=== modified file 'cmd/jujud/unit.go'
159--- cmd/jujud/unit.go 2013-08-21 04:12:32 +0000
160+++ cmd/jujud/unit.go 2013-09-03 02:24:16 +0000
161@@ -93,14 +93,14 @@
162 }
163
164 func (a *UnitAgent) APIWorkers() (worker.Worker, error) {
165- st, entity, err := openAPIState(a.Conf.config, a)
166+ agentConfig := a.Conf.config
167+ st, _, err := openAPIState(agentConfig, a)
168 if err != nil {
169 return nil, err
170 }
171- dataDir := a.Conf.dataDir
172 runner := worker.NewRunner(allFatal, moreImportant)
173 runner.StartWorker("upgrader", func() (worker.Worker, error) {
174- return upgrader.New(st.Upgrader(), entity.Tag(), dataDir), nil
175+ return upgrader.NewUpgrader(st.Upgrader(), agentConfig), nil
176 })
177 return newCloseWorker(runner, st), nil
178 }
179
180=== modified file 'worker/deployer/deployer.go'
181--- worker/deployer/deployer.go 2013-08-28 14:03:08 +0000
182+++ worker/deployer/deployer.go 2013-09-03 02:24:16 +0000
183@@ -8,6 +8,7 @@
184
185 "launchpad.net/loggo"
186
187+ "launchpad.net/juju-core/agent"
188 "launchpad.net/juju-core/errors"
189 "launchpad.net/juju-core/names"
190 apideployer "launchpad.net/juju-core/state/api/deployer"
191@@ -24,10 +25,9 @@
192 // to changes in a set of state units; and for the final removal of its agents'
193 // units from state when they are no longer needed.
194 type Deployer struct {
195- st *apideployer.State
196- ctx Context
197- machineTag string
198- deployed set.Strings
199+ st *apideployer.State
200+ ctx Context
201+ deployed set.Strings
202 }
203
204 // Context abstracts away the differences between different unit deployment
205@@ -46,15 +46,18 @@
206
207 // DeployedUnits returns the names of all units deployed by the manager.
208 DeployedUnits() ([]string, error)
209+
210+ // AgentConfig returns the agent config for the machine agent that is
211+ // running the deployer.
212+ AgentConfig() agent.Config
213 }
214
215 // NewDeployer returns a Worker that deploys and recalls unit agents
216 // via ctx, taking a machine id to operate on.
217-func NewDeployer(st *apideployer.State, ctx Context, machineTag string) worker.Worker {
218+func NewDeployer(st *apideployer.State, ctx Context) worker.Worker {
219 d := &Deployer{
220- st: st,
221- ctx: ctx,
222- machineTag: machineTag,
223+ st: st,
224+ ctx: ctx,
225 }
226 return worker.NewStringsWorker(d)
227 }
228@@ -64,7 +67,8 @@
229 }
230
231 func (d *Deployer) SetUp() (watcher.StringsWatcher, error) {
232- machine, err := d.st.Machine(d.machineTag)
233+ machineTag := d.ctx.AgentConfig().Tag()
234+ machine, err := d.st.Machine(machineTag)
235 if err != nil {
236 return nil, err
237 }
238
239=== modified file 'worker/deployer/deployer_test.go'
240--- worker/deployer/deployer_test.go 2013-08-01 13:49:08 +0000
241+++ worker/deployer/deployer_test.go 2013-09-03 02:24:16 +0000
242@@ -13,7 +13,6 @@
243
244 "launchpad.net/juju-core/errors"
245 jujutesting "launchpad.net/juju-core/juju/testing"
246- "launchpad.net/juju-core/names"
247 "launchpad.net/juju-core/state"
248 "launchpad.net/juju-core/state/api"
249 apideployer "launchpad.net/juju-core/state/api/deployer"
250@@ -71,6 +70,12 @@
251 s.JujuConnSuite.TearDownTest(c)
252 }
253
254+func (s *deployerSuite) makeDeployerAndContext(c *gc.C) (worker.Worker, deployer.Context) {
255+ // Create a deployer acting on behalf of the machine.
256+ ctx := s.getContextForMachine(c, s.machine.Tag())
257+ return deployer.NewDeployer(s.deployerState, ctx), ctx
258+}
259+
260 func (s *deployerSuite) TestDeployRecallRemovePrincipals(c *gc.C) {
261 // Create a machine, and a couple of units.
262 svc, err := s.State.AddService("wordpress", s.AddTestingCharm(c, "wordpress"))
263@@ -80,9 +85,7 @@
264 u1, err := svc.AddUnit()
265 c.Assert(err, gc.IsNil)
266
267- // Create a deployer acting on behalf of the machine.
268- ctx := s.getContext(c)
269- dep := deployer.NewDeployer(s.deployerState, ctx, s.machine.Tag())
270+ dep, ctx := s.makeDeployerAndContext(c)
271 defer stop(c, dep)
272
273 // Assign one unit, and wait for it to be deployed.
274@@ -147,8 +150,7 @@
275
276 // When the deployer is started, in each case (1) no unit agent is deployed
277 // and (2) the non-Alive unit is been removed from state.
278- ctx := s.getContext(c)
279- dep := deployer.NewDeployer(s.deployerState, ctx, s.machine.Tag())
280+ dep, ctx := s.makeDeployerAndContext(c)
281 defer stop(c, dep)
282 s.waitFor(c, isRemoved(s.State, u0.Name()))
283 s.waitFor(c, isRemoved(s.State, u1.Name()))
284@@ -181,14 +183,11 @@
285 func (s *deployerSuite) TestDeployRecallRemoveSubordinates(c *gc.C) {
286 // Create a deployer acting on behalf of the principal.
287 u, rus := s.prepareSubordinates(c)
288- ctx := s.getContext(c)
289- machineId, err := u.AssignedMachineId()
290- c.Assert(err, gc.IsNil)
291- dep := deployer.NewDeployer(s.deployerState, ctx, names.MachineTag(machineId))
292+ dep, ctx := s.makeDeployerAndContext(c)
293 defer stop(c, dep)
294
295 // Add a subordinate, and wait for it to be deployed.
296- err = rus[0].EnterScope(nil)
297+ err := rus[0].EnterScope(nil)
298 c.Assert(err, gc.IsNil)
299 sub0, err := s.State.Unit("subsvc0/0")
300 c.Assert(err, gc.IsNil)
301@@ -218,7 +217,7 @@
302
303 func (s *deployerSuite) TestNonAliveSubordinates(c *gc.C) {
304 // Add two subordinate units and set them to Dead/Dying respectively.
305- u, rus := s.prepareSubordinates(c)
306+ _, rus := s.prepareSubordinates(c)
307 err := rus[0].EnterScope(nil)
308 c.Assert(err, gc.IsNil)
309 sub0, err := s.State.Unit("subsvc0/0")
310@@ -234,10 +233,7 @@
311
312 // When we start a new deployer, neither unit will be deployed and
313 // both will be removed.
314- ctx := s.getContext(c)
315- machineId, err := u.AssignedMachineId()
316- c.Assert(err, gc.IsNil)
317- dep := deployer.NewDeployer(s.deployerState, ctx, names.MachineTag(machineId))
318+ dep, _ := s.makeDeployerAndContext(c)
319 defer stop(c, dep)
320 s.waitFor(c, isRemoved(s.State, sub0.Name()))
321 s.waitFor(c, isRemoved(s.State, sub1.Name()))
322
323=== modified file 'worker/deployer/export_test.go'
324--- worker/deployer/export_test.go 2013-07-25 11:03:16 +0000
325+++ worker/deployer/export_test.go 2013-09-03 02:24:16 +0000
326@@ -3,6 +3,10 @@
327
328 package deployer
329
330+import (
331+ "launchpad.net/juju-core/agent"
332+)
333+
334 type fakeAddresser struct{}
335
336 func (*fakeAddresser) StateAddresses() ([]string, error) {
337@@ -13,12 +17,11 @@
338 return []string{"a1:123", "a2:123"}, nil
339 }
340
341-func NewTestSimpleContext(initDir, dataDir, logDir, syslogConfigDir string) *SimpleContext {
342+func NewTestSimpleContext(agentConfig agent.Config, initDir, logDir, syslogConfigDir string) *SimpleContext {
343 return &SimpleContext{
344 addresser: &fakeAddresser{},
345- caCert: []byte("test-cert"),
346+ agentConfig: agentConfig,
347 initDir: initDir,
348- dataDir: dataDir,
349 logDir: logDir,
350 syslogConfigDir: syslogConfigDir,
351 }
352
353=== modified file 'worker/deployer/simple.go'
354--- worker/deployer/simple.go 2013-08-30 02:38:39 +0000
355+++ worker/deployer/simple.go 2013-09-03 02:24:16 +0000
356@@ -28,18 +28,14 @@
357 // the given unit is deployed.
358 addresser Addresser
359
360- // caCert holds the CA certificate that will be used
361- // to validate the state server's certificate, in PEM format.
362- caCert []byte
363+ // agentConfig returns the agent config for the machine agent that is
364+ // running the deployer.
365+ agentConfig agent.Config
366
367 // initDir specifies the directory used by upstart on the local system.
368 // It is typically set to "/etc/init".
369 initDir string
370
371- // dataDir specifies the directory used by juju to store its state. It
372- // is typically set to "/var/lib/juju".
373- dataDir string
374-
375 // logDir specifies the directory to which installed units will write
376 // their log files. It is typically set to "/var/log/juju".
377 logDir string
378@@ -58,21 +54,20 @@
379 // NewSimpleContext returns a new SimpleContext, acting on behalf of the
380 // specified deployer, that deploys unit agents as upstart jobs in
381 // "/etc/init" logging to "/var/log/juju". Paths to which agents and tools
382-// are installed are relative to dataDir; if dataDir is empty, it will be
383-// set to "/var/lib/juju".
384-func NewSimpleContext(dataDir string, caCert []byte, addresser Addresser) *SimpleContext {
385- if dataDir == "" {
386- dataDir = "/var/lib/juju"
387- }
388+// are installed are relative to dataDir.
389+func NewSimpleContext(agentConfig agent.Config, addresser Addresser) *SimpleContext {
390 return &SimpleContext{
391- addresser: addresser,
392- caCert: caCert,
393- initDir: "/etc/init",
394- dataDir: dataDir,
395- logDir: "/var/log/juju",
396+ addresser: addresser,
397+ agentConfig: agentConfig,
398+ initDir: "/etc/init",
399+ logDir: "/var/log/juju",
400 }
401 }
402
403+func (ctx *SimpleContext) AgentConfig() agent.Config {
404+ return ctx.agentConfig
405+}
406+
407 func (ctx *SimpleContext) DeployUnit(unitName, initialPassword string) (err error) {
408 // Check sanity.
409 svc := ctx.upstartService(unitName)
410@@ -82,8 +77,9 @@
411
412 // Link the current tools for use by the new agent.
413 tag := names.UnitTag(unitName)
414- _, err = tools.ChangeAgentTools(ctx.dataDir, tag, version.Current)
415- toolsDir := tools.ToolsDir(ctx.dataDir, tag)
416+ dataDir := ctx.agentConfig.DataDir()
417+ _, err = tools.ChangeAgentTools(dataDir, tag, version.Current)
418+ toolsDir := tools.ToolsDir(dataDir, tag)
419 defer removeOnErr(&err, toolsDir)
420
421 // Retrieve the state addresses.
422@@ -100,13 +96,13 @@
423 logger.Debugf("API addresses: %q", apiAddrs)
424 conf, err := agent.NewAgentConfig(
425 agent.AgentConfigParams{
426- DataDir: ctx.dataDir,
427+ DataDir: dataDir,
428 Tag: tag,
429 Password: initialPassword,
430 Nonce: "unused",
431 StateAddresses: stateAddrs,
432 APIAddresses: apiAddrs,
433- CACert: ctx.caCert,
434+ CACert: ctx.agentConfig.CACert(),
435 })
436 if err != nil {
437 return err
438@@ -132,7 +128,7 @@
439
440 cmd := strings.Join([]string{
441 path.Join(toolsDir, "jujud"), "unit",
442- "--data-dir", conf.DataDir(),
443+ "--data-dir", dataDir,
444 "--unit-name", unitName,
445 "--debug", // TODO: propagate debug state sensibly
446 }, " ")
447@@ -176,7 +172,8 @@
448 return err
449 }
450 tag := names.UnitTag(unitName)
451- agentDir := agent.Dir(ctx.dataDir, tag)
452+ dataDir := ctx.agentConfig.DataDir()
453+ agentDir := agent.Dir(dataDir, tag)
454 if err := os.RemoveAll(agentDir); err != nil {
455 return err
456 }
457@@ -189,7 +186,7 @@
458 logger.Warningf("installer: cannot restart syslog daemon: %v", err)
459 }
460 }()
461- toolsDir := tools.ToolsDir(ctx.dataDir, tag)
462+ toolsDir := tools.ToolsDir(dataDir, tag)
463 return os.Remove(toolsDir)
464 }
465
466
467=== modified file 'worker/deployer/simple_test.go'
468--- worker/deployer/simple_test.go 2013-08-28 22:59:45 +0000
469+++ worker/deployer/simple_test.go 2013-09-03 02:24:16 +0000
470@@ -183,7 +183,13 @@
471 }
472
473 func (fix *SimpleToolsFixture) getContext(c *gc.C) *deployer.SimpleContext {
474- return deployer.NewTestSimpleContext(fix.initDir, fix.dataDir, fix.logDir, fix.syslogConfigDir)
475+ config := agentConfig("machine-tag", fix.dataDir)
476+ return deployer.NewTestSimpleContext(config, fix.initDir, fix.logDir, fix.syslogConfigDir)
477+}
478+
479+func (fix *SimpleToolsFixture) getContextForMachine(c *gc.C, machineTag string) *deployer.SimpleContext {
480+ config := agentConfig(machineTag, fix.dataDir)
481+ return deployer.NewTestSimpleContext(config, fix.initDir, fix.logDir, fix.syslogConfigDir)
482 }
483
484 func (fix *SimpleToolsFixture) paths(tag string) (confPath, agentDir, toolsDir, syslogConfPath string) {
485@@ -279,3 +285,25 @@
486 err = os.MkdirAll(toolsDir, 0755)
487 c.Assert(err, gc.IsNil)
488 }
489+
490+type mockConfig struct {
491+ agent.Config
492+ tag string
493+ datadir string
494+}
495+
496+func (mock *mockConfig) Tag() string {
497+ return mock.tag
498+}
499+
500+func (mock *mockConfig) DataDir() string {
501+ return mock.datadir
502+}
503+
504+func (mock *mockConfig) CACert() []byte {
505+ return []byte(testing.CACert)
506+}
507+
508+func agentConfig(tag, datadir string) agent.Config {
509+ return &mockConfig{tag: tag, datadir: datadir}
510+}
511
512=== modified file 'worker/machiner/machiner.go'
513--- worker/machiner/machiner.go 2013-08-28 14:03:08 +0000
514+++ worker/machiner/machiner.go 2013-09-03 02:24:16 +0000
515@@ -5,6 +5,7 @@
516 import (
517 "launchpad.net/loggo"
518
519+ "launchpad.net/juju-core/agent"
520 "launchpad.net/juju-core/errors"
521 "launchpad.net/juju-core/state/api/machiner"
522 "launchpad.net/juju-core/state/api/params"
523@@ -24,8 +25,8 @@
524 // NewMachiner returns a Worker that will wait for the identified machine
525 // to become Dying and make it Dead; or until the machine becomes Dead by
526 // other means.
527-func NewMachiner(st *machiner.State, tag string) worker.Worker {
528- mr := &Machiner{st: st, tag: tag}
529+func NewMachiner(st *machiner.State, agentConfig agent.Config) worker.Worker {
530+ mr := &Machiner{st: st, tag: agentConfig.Tag()}
531 return worker.NewNotifyWorker(mr)
532 }
533
534
535=== modified file 'worker/machiner/machiner_test.go'
536--- worker/machiner/machiner_test.go 2013-08-19 11:20:02 +0000
537+++ worker/machiner/machiner_test.go 2013-09-03 02:24:16 +0000
538@@ -5,6 +5,10 @@
539
540 import (
541 gc "launchpad.net/gocheck"
542+ stdtesting "testing"
543+ "time"
544+
545+ "launchpad.net/juju-core/agent"
546 "launchpad.net/juju-core/juju/testing"
547 "launchpad.net/juju-core/state"
548 "launchpad.net/juju-core/state/api"
549@@ -13,8 +17,6 @@
550 coretesting "launchpad.net/juju-core/testing"
551 "launchpad.net/juju-core/worker"
552 "launchpad.net/juju-core/worker/machiner"
553- stdtesting "testing"
554- "time"
555 )
556
557 // worstCase is used for timeouts when timing out
558@@ -87,13 +89,30 @@
559
560 var _ worker.NotifyWatchHandler = (*machiner.Machiner)(nil)
561
562+type mockConfig struct {
563+ agent.Config
564+ tag string
565+}
566+
567+func (mock *mockConfig) Tag() string {
568+ return mock.tag
569+}
570+
571+func agentConfig(tag string) agent.Config {
572+ return &mockConfig{tag: tag}
573+}
574+
575 func (s *MachinerSuite) TestNotFoundOrUnauthorized(c *gc.C) {
576- mr := machiner.NewMachiner(s.machinerState, "eleventy-one")
577+ mr := machiner.NewMachiner(s.machinerState, agentConfig("eleventy-one"))
578 c.Assert(mr.Wait(), gc.Equals, worker.ErrTerminateAgent)
579 }
580
581+func (s *MachinerSuite) makeMachiner() worker.Worker {
582+ return machiner.NewMachiner(s.machinerState, agentConfig(s.apiMachine.Tag()))
583+}
584+
585 func (s *MachinerSuite) TestRunStop(c *gc.C) {
586- mr := machiner.NewMachiner(s.machinerState, s.apiMachine.Tag())
587+ mr := s.makeMachiner()
588 c.Assert(worker.Stop(mr), gc.IsNil)
589 c.Assert(s.apiMachine.Refresh(), gc.IsNil)
590 c.Assert(s.apiMachine.Life(), gc.Equals, params.Alive)
591@@ -105,21 +124,21 @@
592 c.Assert(status, gc.Equals, params.StatusPending)
593 c.Assert(info, gc.Equals, "")
594
595- mr := machiner.NewMachiner(s.machinerState, s.apiMachine.Tag())
596+ mr := s.makeMachiner()
597 defer worker.Stop(mr)
598
599 s.waitMachineStatus(c, s.machine, params.StatusStarted)
600 }
601
602 func (s *MachinerSuite) TestSetsStatusWhenDying(c *gc.C) {
603- mr := machiner.NewMachiner(s.machinerState, s.apiMachine.Tag())
604+ mr := s.makeMachiner()
605 defer worker.Stop(mr)
606 c.Assert(s.machine.Destroy(), gc.IsNil)
607 s.waitMachineStatus(c, s.machine, params.StatusStopped)
608 }
609
610 func (s *MachinerSuite) TestSetDead(c *gc.C) {
611- mr := machiner.NewMachiner(s.machinerState, s.machine.Tag())
612+ mr := s.makeMachiner()
613 defer worker.Stop(mr)
614 c.Assert(s.machine.Destroy(), gc.IsNil)
615 s.State.StartSync()
616
617=== modified file 'worker/upgrader/upgrader.go'
618--- worker/upgrader/upgrader.go 2013-08-29 11:29:57 +0000
619+++ worker/upgrader/upgrader.go 2013-09-03 02:24:16 +0000
620@@ -11,6 +11,7 @@
621 "launchpad.net/loggo"
622 "launchpad.net/tomb"
623
624+ "launchpad.net/juju-core/agent"
625 agenttools "launchpad.net/juju-core/agent/tools"
626 "launchpad.net/juju-core/state/api/upgrader"
627 "launchpad.net/juju-core/state/watcher"
628@@ -60,18 +61,17 @@
629 tag string
630 }
631
632-// New returns a new upgrader worker. It watches changes to the
633-// current version of the current agent (with the given tag)
634-// and tries to download the tools for any new version
635-// into the given data directory.
636-// If an upgrade is needed, the worker will exit with an
637-// UpgradeReadyError holding details of the requested upgrade. The tools
638-// will have been downloaded and unpacked.
639-func New(st *upgrader.State, tag, dataDir string) *Upgrader {
640+// NewUpgrader returns a new upgrader worker. It watches changes to the
641+// current version of the current agent (with the given tag) and tries to
642+// download the tools for any new version into the given data directory. If
643+// an upgrade is needed, the worker will exit with an UpgradeReadyError
644+// holding details of the requested upgrade. The tools will have been
645+// downloaded and unpacked.
646+func NewUpgrader(st *upgrader.State, agentConfig agent.Config) *Upgrader {
647 u := &Upgrader{
648 st: st,
649- dataDir: dataDir,
650- tag: tag,
651+ dataDir: agentConfig.DataDir(),
652+ tag: agentConfig.Tag(),
653 }
654 go func() {
655 defer u.tomb.Done()
656
657=== modified file 'worker/upgrader/upgrader_test.go'
658--- worker/upgrader/upgrader_test.go 2013-08-22 21:59:32 +0000
659+++ worker/upgrader/upgrader_test.go 2013-09-03 02:24:16 +0000
660@@ -14,6 +14,7 @@
661
662 gc "launchpad.net/gocheck"
663
664+ "launchpad.net/juju-core/agent"
665 agenttools "launchpad.net/juju-core/agent/tools"
666 envtools "launchpad.net/juju-core/environs/tools"
667 "launchpad.net/juju-core/errors"
668@@ -99,6 +100,29 @@
669 return &coretools.Tools{URL: url, Version: vers}
670 }
671
672+type mockConfig struct {
673+ agent.Config
674+ tag string
675+ datadir string
676+}
677+
678+func (mock *mockConfig) Tag() string {
679+ return mock.tag
680+}
681+
682+func (mock *mockConfig) DataDir() string {
683+ return mock.datadir
684+}
685+
686+func agentConfig(tag, datadir string) agent.Config {
687+ return &mockConfig{tag: tag, datadir: datadir}
688+}
689+
690+func (s *UpgraderSuite) makeUpgrader() *upgrader.Upgrader {
691+ config := agentConfig(s.machine.Tag(), s.DataDir())
692+ return upgrader.NewUpgrader(s.state.Upgrader(), config)
693+}
694+
695 func (s *UpgraderSuite) TestUpgraderSetsTools(c *gc.C) {
696 vers := version.MustParseBinary("5.4.3-foo-bar")
697 err := statetesting.SetAgentVersion(s.State, vers.Number)
698@@ -108,7 +132,7 @@
699 _, err = s.machine.AgentTools()
700 c.Assert(err, jc.Satisfies, errors.IsNotFoundError)
701
702- u := upgrader.New(s.state.Upgrader(), s.machine.Tag(), s.DataDir())
703+ u := s.makeUpgrader()
704 statetesting.AssertStop(c, u)
705 s.machine.Refresh()
706 gotTools, err := s.machine.AgentTools()
707@@ -127,7 +151,7 @@
708 err = statetesting.SetAgentVersion(s.State, vers.Number)
709 c.Assert(err, gc.IsNil)
710
711- u := upgrader.New(s.state.Upgrader(), s.machine.Tag(), s.DataDir())
712+ u := s.makeUpgrader()
713 statetesting.AssertStop(c, u)
714 s.machine.Refresh()
715 gotTools, err := s.machine.AgentTools()
716@@ -147,7 +171,7 @@
717 // it's been stopped.
718 dummy.SetStorageDelay(coretesting.ShortWait)
719
720- u := upgrader.New(s.state.Upgrader(), s.machine.Tag(), s.DataDir())
721+ u := s.makeUpgrader()
722 err = u.Stop()
723 c.Assert(err, gc.DeepEquals, &upgrader.UpgradeReadyError{
724 AgentName: s.machine.Tag(),
725@@ -173,7 +197,7 @@
726 return retryc
727 }
728 dummy.Poison(s.Conn.Environ.Storage(), envtools.StorageName(newTools.Version), fmt.Errorf("a non-fatal dose"))
729- u := upgrader.New(s.state.Upgrader(), s.machine.Tag(), s.DataDir())
730+ u := s.makeUpgrader()
731 defer u.Stop()
732
733 for i := 0; i < 3; i++ {

Subscribers

People subscribed via source and target branches

to status/vote changes: