Merge lp:~axwalk/juju-core/lp1279259-part1-prepare-context into lp:~go-bot/juju-core/trunk
- lp1279259-part1-prepare-context
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Andrew Wilkins | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 2335 | ||||
Proposed branch: | lp:~axwalk/juju-core/lp1279259-part1-prepare-context | ||||
Merge into: | lp:~go-bot/juju-core/trunk | ||||
Diff against target: |
1921 lines (+223/-273) 58 files modified
cmd/cmd.go (+17/-2) cmd/juju/bootstrap.go (+3/-21) cmd/juju/bootstrap_test.go (+1/-1) cmd/juju/destroyenvironment_test.go (+5/-5) cmd/juju/synctools.go (+1/-1) cmd/juju/synctools_test.go (+1/-1) cmd/plugins/juju-metadata/imagemetadata.go (+11/-4) cmd/plugins/juju-metadata/imagemetadata_test.go (+1/-1) cmd/plugins/juju-metadata/toolsmetadata_test.go (+1/-1) cmd/plugins/juju-metadata/validateimagemetadata.go (+1/-1) cmd/plugins/juju-metadata/validatetoolsmetadata.go (+1/-1) cmd/plugins/juju-restore/restore.go (+3/-26) environs/bootstrap/bootstrap_test.go (+9/-14) environs/emptystorage_test.go (+4/-2) environs/imagemetadata/urls_test.go (+1/-1) environs/interface.go (+4/-4) environs/jujutest/livetests.go (+5/-5) environs/jujutest/tests.go (+3/-7) environs/manual/bootstrap.go (+1/-1) environs/manual/bootstrap_test.go (+1/-2) environs/open.go (+6/-6) environs/open_test.go (+25/-15) environs/storage/storage_test.go (+1/-1) environs/sync/sync_test.go (+2/-2) environs/testing/bootstrap.go (+0/-23) environs/tools/storage_test.go (+2/-1) environs/tools/tools_test.go (+2/-1) environs/tools/urls_test.go (+1/-1) juju/apiconn_test.go (+3/-2) juju/conn_test.go (+18/-16) juju/testing/conn.go (+2/-2) provider/azure/environprovider.go (+1/-1) provider/common/bootstrap.go (+7/-7) provider/common/bootstrap_test.go (+19/-28) provider/dummy/config_test.go (+4/-2) provider/dummy/environs.go (+1/-1) provider/ec2/config_test.go (+4/-3) provider/ec2/ec2.go (+1/-1) provider/ec2/local_test.go (+6/-10) provider/joyent/config_test.go (+1/-1) provider/joyent/provider.go (+1/-1) provider/local/config_test.go (+2/-3) provider/local/environ.go (+2/-2) provider/local/environ_test.go (+2/-2) provider/local/environprovider.go (+1/-1) provider/local/environprovider_test.go (+2/-2) provider/maas/environ_whitebox_test.go (+5/-9) provider/maas/environprovider.go (+1/-1) provider/maas/environprovider_test.go (+4/-2) provider/manual/environ.go (+1/-1) provider/manual/environ_test.go (+1/-2) provider/manual/provider.go (+1/-1) provider/manual/provider_test.go (+4/-3) provider/openstack/config_test.go (+4/-3) provider/openstack/live_test.go (+1/-1) provider/openstack/local_test.go (+8/-12) provider/openstack/provider.go (+1/-1) state/apiserver/common/environwatcher_test.go (+2/-1) |
||||
To merge this branch: | bzr merge lp:~axwalk/juju-core/lp1279259-part1-prepare-context | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+206082@code.launchpad.net |
Commit message
Pass environs.
This is part one of fixing lp:1279259.
In this CL, we pass context to Prepare,
giving providers an opportunity to prompt
the user to initialise an environment.
Passing context was previously restricted to
Bootstrap and EnableBootstrap
insufficient, as there are many ways to prepare
an environment. It is currently possible to
successfully "Prepare" and environment, but
for the result to be unusable in the manual
provider (e.g. if the bootstrap-host address is
invalid). We should that a successfully Prepared
environment should be able to be Destroyed
(with force).
Description of the change
Pass environs.
This is part one of fixing lp:1279259.
In this CL, we pass context to Prepare,
giving providers an opportunity to prompt
the user to initialise an environment.
Passing context was previously restricted to
Bootstrap and EnableBootstrap
insufficient, as there are many ways to prepare
an environment. It is currently possible to
successfully "Prepare" and environment, but
for the result to be unusable in the manual
provider (e.g. if the bootstrap-host address is
invalid). We should that a successfully Prepared
environment should be able to be Destroyed
(with force).
The next CL will remove BootstrapStorager and fix
lp:1279259 by initialising the ubuntu user during
Prepare.
Andrew Wilkins (axwalk) wrote : | # |
Dimiter Naydenov (dimitern) wrote : | # |
The diff is missing, repropose please.
Andrew Wilkins (axwalk) wrote : | # |
Please take a look.
William Reade (fwereade) wrote : | # |
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~axwalk/juju-core/lp1279259-part1-prepare-context into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.net/j...
Preview Diff
1 | === modified file 'cmd/cmd.go' |
2 | --- cmd/cmd.go 2013-12-19 09:15:40 +0000 |
3 | +++ cmd/cmd.go 2014-02-18 02:14:09 +0000 |
4 | @@ -112,12 +112,27 @@ |
5 | return filepath.Join(ctx.Dir, path) |
6 | } |
7 | |
8 | -// InterruptNotify partially satisfies environs/bootstrap.BootstrapContext |
9 | +// GetStdin satisfies environs.BootstrapContext |
10 | +func (ctx *Context) GetStdin() io.Reader { |
11 | + return ctx.Stdin |
12 | +} |
13 | + |
14 | +// GetStdout satisfies environs.BootstrapContext |
15 | +func (ctx *Context) GetStdout() io.Writer { |
16 | + return ctx.Stdout |
17 | +} |
18 | + |
19 | +// GetStderr satisfies environs.BootstrapContext |
20 | +func (ctx *Context) GetStderr() io.Writer { |
21 | + return ctx.Stderr |
22 | +} |
23 | + |
24 | +// InterruptNotify satisfies environs.BootstrapContext |
25 | func (ctx *Context) InterruptNotify(c chan<- os.Signal) { |
26 | signal.Notify(c, os.Interrupt) |
27 | } |
28 | |
29 | -// StopInterruptNotify partially satisfies environs/bootstrap.BootstrapContext |
30 | +// StopInterruptNotify satisfies environs.BootstrapContext |
31 | func (ctx *Context) StopInterruptNotify(c chan<- os.Signal) { |
32 | signal.Stop(c) |
33 | } |
34 | |
35 | === modified file 'cmd/juju/bootstrap.go' |
36 | --- cmd/juju/bootstrap.go 2014-02-11 01:35:20 +0000 |
37 | +++ cmd/juju/bootstrap.go 2014-02-18 02:14:09 +0000 |
38 | @@ -5,7 +5,6 @@ |
39 | |
40 | import ( |
41 | "fmt" |
42 | - "io" |
43 | "os" |
44 | "strings" |
45 | |
46 | @@ -97,22 +96,6 @@ |
47 | return cmd.CheckEmpty(args) |
48 | } |
49 | |
50 | -type bootstrapContext struct { |
51 | - *cmd.Context |
52 | -} |
53 | - |
54 | -func (c bootstrapContext) Stdin() io.Reader { |
55 | - return c.Context.Stdin |
56 | -} |
57 | - |
58 | -func (c bootstrapContext) Stdout() io.Writer { |
59 | - return c.Context.Stdout |
60 | -} |
61 | - |
62 | -func (c bootstrapContext) Stderr() io.Writer { |
63 | - return c.Context.Stderr |
64 | -} |
65 | - |
66 | func destroyPreparedEnviron(env environs.Environ, store configstore.Storage, err *error, action string) { |
67 | if *err == nil { |
68 | return |
69 | @@ -134,18 +117,17 @@ |
70 | if _, err := store.ReadInfo(c.EnvName); !errors.IsNotFoundError(err) { |
71 | existing = true |
72 | } |
73 | - environ, err := environs.PrepareFromName(c.EnvName, store) |
74 | + environ, err := environs.PrepareFromName(c.EnvName, ctx, store) |
75 | if err != nil { |
76 | return err |
77 | } |
78 | if !existing { |
79 | defer destroyPreparedEnviron(environ, store, &resultErr, "Bootstrap") |
80 | } |
81 | - bootstrapContext := bootstrapContext{ctx} |
82 | // If the environment has a special bootstrap Storage, use it wherever |
83 | // we'd otherwise use environ.Storage. |
84 | if bs, ok := environ.(environs.BootstrapStorager); ok { |
85 | - if err := bs.EnableBootstrapStorage(bootstrapContext); err != nil { |
86 | + if err := bs.EnableBootstrapStorage(ctx); err != nil { |
87 | return errgo.Annotate(err, "failed to enable bootstrap storage") |
88 | } |
89 | } |
90 | @@ -179,7 +161,7 @@ |
91 | return err |
92 | } |
93 | } |
94 | - return bootstrap.Bootstrap(bootstrapContext, environ, c.Constraints) |
95 | + return bootstrap.Bootstrap(ctx, environ, c.Constraints) |
96 | } |
97 | |
98 | func (c *BootstrapCommand) uploadTools(environ environs.Environ) error { |
99 | |
100 | === modified file 'cmd/juju/bootstrap_test.go' |
101 | --- cmd/juju/bootstrap_test.go 2014-02-03 06:58:26 +0000 |
102 | +++ cmd/juju/bootstrap_test.go 2014-02-18 02:14:09 +0000 |
103 | @@ -516,7 +516,7 @@ |
104 | dummy.Reset() |
105 | store, err := configstore.Default() |
106 | c.Assert(err, gc.IsNil) |
107 | - env, err := environs.PrepareFromName("peckham", store) |
108 | + env, err := environs.PrepareFromName("peckham", nullContext(), store) |
109 | c.Assert(err, gc.IsNil) |
110 | envtesting.RemoveAllTools(c, env) |
111 | return env, fake |
112 | |
113 | === modified file 'cmd/juju/destroyenvironment_test.go' |
114 | --- cmd/juju/destroyenvironment_test.go 2014-02-03 09:09:49 +0000 |
115 | +++ cmd/juju/destroyenvironment_test.go 2014-02-18 02:14:09 +0000 |
116 | @@ -27,7 +27,7 @@ |
117 | |
118 | func (s *destroyEnvSuite) TestDestroyEnvironmentCommand(c *gc.C) { |
119 | // Prepare the environment so we can destroy it. |
120 | - _, err := environs.PrepareFromName("dummyenv", s.ConfigStore) |
121 | + _, err := environs.PrepareFromName("dummyenv", nullContext(), s.ConfigStore) |
122 | c.Assert(err, gc.IsNil) |
123 | |
124 | // check environment is mandatory |
125 | @@ -46,7 +46,7 @@ |
126 | |
127 | func (s *destroyEnvSuite) TestDestroyEnvironmentCommandEFlag(c *gc.C) { |
128 | // Prepare the environment so we can destroy it. |
129 | - _, err := environs.PrepareFromName("dummyenv", s.ConfigStore) |
130 | + _, err := environs.PrepareFromName("dummyenv", nullContext(), s.ConfigStore) |
131 | c.Assert(err, gc.IsNil) |
132 | |
133 | // check that either environment or the flag is mandatory |
134 | @@ -89,7 +89,7 @@ |
135 | c.Assert(err, gc.IsNil) |
136 | |
137 | // Prepare the environment so we can destroy it. |
138 | - _, err = environs.PrepareFromName("dummyenv", s.ConfigStore) |
139 | + _, err = environs.PrepareFromName("dummyenv", nullContext(), s.ConfigStore) |
140 | c.Assert(err, gc.IsNil) |
141 | |
142 | // destroy with broken environment |
143 | @@ -122,7 +122,7 @@ |
144 | ctx.Stdin = &stdin |
145 | |
146 | // Prepare the environment so we can destroy it. |
147 | - env, err := environs.PrepareFromName("dummyenv", s.ConfigStore) |
148 | + env, err := environs.PrepareFromName("dummyenv", nullContext(), s.ConfigStore) |
149 | c.Assert(err, gc.IsNil) |
150 | |
151 | assertEnvironNotDestroyed(c, env, s.ConfigStore) |
152 | @@ -156,7 +156,7 @@ |
153 | for _, answer := range []string{"y", "Y", "yes", "YES"} { |
154 | // Prepare the environment so we can destroy it. |
155 | s.Reset(c) |
156 | - env, err := environs.PrepareFromName("dummyenv", s.ConfigStore) |
157 | + env, err := environs.PrepareFromName("dummyenv", nullContext(), s.ConfigStore) |
158 | c.Assert(err, gc.IsNil) |
159 | |
160 | stdin.Reset() |
161 | |
162 | === modified file 'cmd/juju/synctools.go' |
163 | --- cmd/juju/synctools.go 2014-02-17 21:23:26 +0000 |
164 | +++ cmd/juju/synctools.go 2014-02-18 02:14:09 +0000 |
165 | @@ -92,7 +92,7 @@ |
166 | if _, err := store.ReadInfo(c.EnvName); !errors.IsNotFoundError(err) { |
167 | existing = true |
168 | } |
169 | - environ, err := environs.PrepareFromName(c.EnvName, store) |
170 | + environ, err := environs.PrepareFromName(c.EnvName, ctx, store) |
171 | if err != nil { |
172 | return err |
173 | } |
174 | |
175 | === modified file 'cmd/juju/synctools_test.go' |
176 | --- cmd/juju/synctools_test.go 2014-02-17 21:23:26 +0000 |
177 | +++ cmd/juju/synctools_test.go 2014-02-18 02:14:09 +0000 |
178 | @@ -125,7 +125,7 @@ |
179 | func (s *syncToolsSuite) TestSyncToolsCommand(c *gc.C) { |
180 | for i, test := range syncToolsCommandTests { |
181 | c.Logf("test %d: %s", i, test.description) |
182 | - targetEnv, err := environs.PrepareFromName("test-target", s.configStore) |
183 | + targetEnv, err := environs.PrepareFromName("test-target", nullContext(), s.configStore) |
184 | c.Assert(err, gc.IsNil) |
185 | called := false |
186 | syncTools = func(sctx *sync.SyncContext) error { |
187 | |
188 | === modified file 'cmd/plugins/juju-metadata/imagemetadata.go' |
189 | --- cmd/plugins/juju-metadata/imagemetadata.go 2014-01-31 00:14:11 +0000 |
190 | +++ cmd/plugins/juju-metadata/imagemetadata.go 2014-02-18 02:14:09 +0000 |
191 | @@ -61,10 +61,16 @@ |
192 | } |
193 | |
194 | func (c *ImageMetadataCommand) Init(args []string) error { |
195 | + return cmd.CheckEmpty(args) |
196 | +} |
197 | + |
198 | +// setParams sets parameters based on the environment configuration |
199 | +// for those which have not been explicitly specified. |
200 | +func (c *ImageMetadataCommand) setParams(context *cmd.Context) error { |
201 | c.privateStorage = "<private storage name>" |
202 | var environ environs.Environ |
203 | if store, err := configstore.Default(); err == nil { |
204 | - if environ, err = environs.PrepareFromName(c.EnvName, store); err == nil { |
205 | + if environ, err = environs.PrepareFromName(c.EnvName, context, store); err == nil { |
206 | logger.Infof("creating image metadata for environment %q", environ.Name()) |
207 | // If the user has not specified region and endpoint, try and get it from the environment. |
208 | if c.Region == "" || c.Endpoint == "" { |
209 | @@ -120,8 +126,7 @@ |
210 | return err |
211 | } |
212 | } |
213 | - |
214 | - return cmd.CheckEmpty(args) |
215 | + return nil |
216 | } |
217 | |
218 | var helpDoc = ` |
219 | @@ -143,8 +148,10 @@ |
220 | ` |
221 | |
222 | func (c *ImageMetadataCommand) Run(context *cmd.Context) error { |
223 | + if err := c.setParams(context); err != nil { |
224 | + return err |
225 | + } |
226 | out := context.Stdout |
227 | - |
228 | im := &imagemetadata.ImageMetadata{ |
229 | Id: c.ImageId, |
230 | Arch: c.Arch, |
231 | |
232 | === modified file 'cmd/plugins/juju-metadata/imagemetadata_test.go' |
233 | --- cmd/plugins/juju-metadata/imagemetadata_test.go 2013-11-04 00:24:21 +0000 |
234 | +++ cmd/plugins/juju-metadata/imagemetadata_test.go 2014-02-18 02:14:09 +0000 |
235 | @@ -228,6 +228,6 @@ |
236 | c.Logf("test: %d", i) |
237 | ctx := testing.Context(c) |
238 | code := cmd.Main(&ImageMetadataCommand{}, ctx, t.args) |
239 | - c.Check(code, gc.Equals, 2) |
240 | + c.Check(code, gc.Equals, 1) |
241 | } |
242 | } |
243 | |
244 | === modified file 'cmd/plugins/juju-metadata/toolsmetadata_test.go' |
245 | --- cmd/plugins/juju-metadata/toolsmetadata_test.go 2014-01-31 04:29:28 +0000 |
246 | +++ cmd/plugins/juju-metadata/toolsmetadata_test.go 2014-02-18 02:14:09 +0000 |
247 | @@ -43,7 +43,7 @@ |
248 | dummy.Reset() |
249 | loggo.ResetLoggers() |
250 | }) |
251 | - env, err := environs.PrepareFromName("erewhemos", configstore.NewMem()) |
252 | + env, err := environs.PrepareFromName("erewhemos", coretesting.Context(c), configstore.NewMem()) |
253 | c.Assert(err, gc.IsNil) |
254 | s.env = env |
255 | envtesting.RemoveAllTools(c, s.env) |
256 | |
257 | === modified file 'cmd/plugins/juju-metadata/validateimagemetadata.go' |
258 | --- cmd/plugins/juju-metadata/validateimagemetadata.go 2014-01-29 06:45:16 +0000 |
259 | +++ cmd/plugins/juju-metadata/validateimagemetadata.go 2014-02-18 02:14:09 +0000 |
260 | @@ -134,7 +134,7 @@ |
261 | if err != nil { |
262 | return err |
263 | } |
264 | - environ, err := environs.PrepareFromName(c.EnvName, store) |
265 | + environ, err := environs.PrepareFromName(c.EnvName, context, store) |
266 | if err != nil { |
267 | return err |
268 | } |
269 | |
270 | === modified file 'cmd/plugins/juju-metadata/validatetoolsmetadata.go' |
271 | --- cmd/plugins/juju-metadata/validatetoolsmetadata.go 2013-10-10 11:40:54 +0000 |
272 | +++ cmd/plugins/juju-metadata/validatetoolsmetadata.go 2014-02-18 02:14:09 +0000 |
273 | @@ -141,7 +141,7 @@ |
274 | if err != nil { |
275 | return err |
276 | } |
277 | - environ, err := environs.PrepareFromName(c.EnvName, store) |
278 | + environ, err := environs.PrepareFromName(c.EnvName, context, store) |
279 | if err == nil { |
280 | mdLookup, ok := environ.(simplestreams.MetadataValidator) |
281 | if !ok { |
282 | |
283 | === modified file 'cmd/plugins/juju-restore/restore.go' |
284 | --- cmd/plugins/juju-restore/restore.go 2014-02-06 11:18:27 +0000 |
285 | +++ cmd/plugins/juju-restore/restore.go 2014-02-18 02:14:09 +0000 |
286 | @@ -12,7 +12,6 @@ |
287 | "io/ioutil" |
288 | "os" |
289 | "os/exec" |
290 | - "os/signal" |
291 | "path" |
292 | "text/template" |
293 | |
294 | @@ -154,7 +153,7 @@ |
295 | if err != nil { |
296 | return err |
297 | } |
298 | - env, err := rebootstrap(cfg, c.Constraints) |
299 | + env, err := rebootstrap(cfg, ctx, c.Constraints) |
300 | if err != nil { |
301 | return fmt.Errorf("cannot re-bootstrap environment: %v", err) |
302 | } |
303 | @@ -203,7 +202,7 @@ |
304 | fmt.Printf("%s\n", fmt.Sprintf(f, a...)) |
305 | } |
306 | |
307 | -func rebootstrap(cfg *config.Config, cons constraints.Value) (environs.Environ, error) { |
308 | +func rebootstrap(cfg *config.Config, ctx *cmd.Context, cons constraints.Value) (environs.Environ, error) { |
309 | progress("re-bootstrapping environment") |
310 | // Turn on safe mode so that the newly bootstrapped instance |
311 | // will not destroy all the instances it does not know about. |
312 | @@ -245,7 +244,7 @@ |
313 | // error-prone) or we could provide a --no-check flag to make |
314 | // it go ahead anyway without the check. |
315 | |
316 | - if err := bootstrap.Bootstrap(bootstrapContext{}, env, cons); err != nil { |
317 | + if err := bootstrap.Bootstrap(ctx, env, cons); err != nil { |
318 | return nil, fmt.Errorf("cannot bootstrap new instance: %v", err) |
319 | } |
320 | return env, nil |
321 | @@ -462,25 +461,3 @@ |
322 | } |
323 | return buf.String() |
324 | } |
325 | - |
326 | -type bootstrapContext struct{} |
327 | - |
328 | -func (bootstrapContext) Stdin() io.Reader { |
329 | - return os.Stdin |
330 | -} |
331 | - |
332 | -func (bootstrapContext) Stdout() io.Writer { |
333 | - return os.Stdout |
334 | -} |
335 | - |
336 | -func (bootstrapContext) Stderr() io.Writer { |
337 | - return os.Stderr |
338 | -} |
339 | - |
340 | -func (bootstrapContext) InterruptNotify(c chan<- os.Signal) { |
341 | - signal.Notify(c, os.Interrupt) |
342 | -} |
343 | - |
344 | -func (bootstrapContext) StopInterruptNotify(c chan<- os.Signal) { |
345 | - signal.Stop(c) |
346 | -} |
347 | |
348 | === modified file 'environs/bootstrap/bootstrap_test.go' |
349 | --- environs/bootstrap/bootstrap_test.go 2014-01-20 23:32:00 +0000 |
350 | +++ environs/bootstrap/bootstrap_test.go 2014-02-18 02:14:09 +0000 |
351 | @@ -53,11 +53,6 @@ |
352 | s.LoggingSuite.TearDownTest(c) |
353 | } |
354 | |
355 | -func bootstrapContext(c *gc.C) environs.BootstrapContext { |
356 | - ctx := coretesting.Context(c) |
357 | - return envtesting.NewBootstrapContext(ctx) |
358 | -} |
359 | - |
360 | func (s *bootstrapSuite) TestBootstrapNeedsSettings(c *gc.C) { |
361 | env := newEnviron("bar", noKeysDefined) |
362 | s.setDummyStorage(c, env) |
363 | @@ -69,20 +64,20 @@ |
364 | env.cfg = cfg |
365 | } |
366 | |
367 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
368 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
369 | c.Assert(err, gc.ErrorMatches, "environment configuration has no admin-secret") |
370 | |
371 | fixEnv("admin-secret", "whatever") |
372 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
373 | + err = bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
374 | c.Assert(err, gc.ErrorMatches, "environment configuration has no ca-cert") |
375 | |
376 | fixEnv("ca-cert", coretesting.CACert) |
377 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
378 | + err = bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
379 | c.Assert(err, gc.ErrorMatches, "environment configuration has no ca-private-key") |
380 | |
381 | fixEnv("ca-private-key", coretesting.CAKey) |
382 | uploadTools(c, env) |
383 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
384 | + err = bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
385 | c.Assert(err, gc.IsNil) |
386 | } |
387 | |
388 | @@ -95,7 +90,7 @@ |
389 | func (s *bootstrapSuite) TestBootstrapEmptyConstraints(c *gc.C) { |
390 | env := newEnviron("foo", useDefaultKeys) |
391 | s.setDummyStorage(c, env) |
392 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
393 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
394 | c.Assert(err, gc.IsNil) |
395 | c.Assert(env.bootstrapCount, gc.Equals, 1) |
396 | c.Assert(env.constraints, gc.DeepEquals, constraints.Value{}) |
397 | @@ -105,7 +100,7 @@ |
398 | env := newEnviron("foo", useDefaultKeys) |
399 | s.setDummyStorage(c, env) |
400 | cons := constraints.MustParse("cpu-cores=2 mem=4G") |
401 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, cons) |
402 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, cons) |
403 | c.Assert(err, gc.IsNil) |
404 | c.Assert(env.bootstrapCount, gc.Equals, 1) |
405 | c.Assert(env.constraints, gc.DeepEquals, cons) |
406 | @@ -157,7 +152,7 @@ |
407 | } |
408 | cfg, err := config.New(config.NoDefaults, attrs) |
409 | c.Assert(err, gc.IsNil) |
410 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
411 | + env, err := environs.Prepare(cfg, coretesting.Context(c), configstore.NewMem()) |
412 | c.Assert(err, gc.IsNil) |
413 | envtesting.RemoveAllTools(c, env) |
414 | |
415 | @@ -170,7 +165,7 @@ |
416 | if test.Arch != "" { |
417 | cons = constraints.MustParse("arch=" + test.Arch) |
418 | } |
419 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, cons) |
420 | + err = bootstrap.Bootstrap(coretesting.Context(c), env, cons) |
421 | if test.Err != nil { |
422 | c.Check(err, gc.ErrorMatches, ".*"+test.Err.Error()) |
423 | continue |
424 | @@ -193,7 +188,7 @@ |
425 | env := newEnviron("foo", useDefaultKeys) |
426 | s.setDummyStorage(c, env) |
427 | envtesting.RemoveFakeTools(c, env.Storage()) |
428 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
429 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
430 | // bootstrap.Bootstrap leaves it to the provider to |
431 | // locate bootstrap tools. |
432 | c.Assert(err, gc.IsNil) |
433 | |
434 | === modified file 'environs/emptystorage_test.go' |
435 | --- environs/emptystorage_test.go 2013-10-03 01:28:51 +0000 |
436 | +++ environs/emptystorage_test.go 2014-02-18 02:14:09 +0000 |
437 | @@ -63,7 +63,8 @@ |
438 | func (s *verifyStorageSuite) TestVerifyStorage(c *gc.C) { |
439 | defer testing.MakeFakeHome(c, existingEnv, "existing").Restore() |
440 | |
441 | - environ, err := environs.PrepareFromName("test", configstore.NewMem()) |
442 | + ctx := testing.Context(c) |
443 | + environ, err := environs.PrepareFromName("test", ctx, configstore.NewMem()) |
444 | c.Assert(err, gc.IsNil) |
445 | stor := environ.Storage() |
446 | err = environs.VerifyStorage(stor) |
447 | @@ -80,7 +81,8 @@ |
448 | func (s *verifyStorageSuite) TestVerifyStorageFails(c *gc.C) { |
449 | defer testing.MakeFakeHome(c, existingEnv, "existing").Restore() |
450 | |
451 | - environ, err := environs.PrepareFromName("test", configstore.NewMem()) |
452 | + ctx := testing.Context(c) |
453 | + environ, err := environs.PrepareFromName("test", ctx, configstore.NewMem()) |
454 | c.Assert(err, gc.IsNil) |
455 | stor := environ.Storage() |
456 | someError := errors.Unauthorizedf("you shall not pass") |
457 | |
458 | === modified file 'environs/imagemetadata/urls_test.go' |
459 | --- environs/imagemetadata/urls_test.go 2014-01-30 07:37:38 +0000 |
460 | +++ environs/imagemetadata/urls_test.go 2014-02-18 02:14:09 +0000 |
461 | @@ -46,7 +46,7 @@ |
462 | } |
463 | cfg, err := config.New(config.NoDefaults, attrs) |
464 | c.Assert(err, gc.IsNil) |
465 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
466 | + env, err := environs.Prepare(cfg, testing.Context(c), configstore.NewMem()) |
467 | c.Assert(err, gc.IsNil) |
468 | // Put a file in images since the dummy storage provider requires a |
469 | // file to exist before the URL can be found. This is to ensure it behaves |
470 | |
471 | === modified file 'environs/interface.go' |
472 | --- environs/interface.go 2013-12-20 02:38:56 +0000 |
473 | +++ environs/interface.go 2014-02-18 02:14:09 +0000 |
474 | @@ -21,7 +21,7 @@ |
475 | // configuration attributes in the returned environment should |
476 | // be saved to be used later. If the environment is already |
477 | // prepared, this call is equivalent to Open. |
478 | - Prepare(cfg *config.Config) (Environ, error) |
479 | + Prepare(ctx BootstrapContext, cfg *config.Config) (Environ, error) |
480 | |
481 | // Open opens the environment and returns it. |
482 | // The configuration must have come from a previously |
483 | @@ -201,9 +201,9 @@ |
484 | // information about and manipulating the context in which |
485 | // it is being invoked. |
486 | type BootstrapContext interface { |
487 | - Stdin() io.Reader |
488 | - Stdout() io.Writer |
489 | - Stderr() io.Writer |
490 | + GetStdin() io.Reader |
491 | + GetStdout() io.Writer |
492 | + GetStderr() io.Writer |
493 | |
494 | // InterruptNotify starts watching for interrupt signals |
495 | // on behalf of the caller, sending them to the supplied |
496 | |
497 | === modified file 'environs/jujutest/livetests.go' |
498 | --- environs/jujutest/livetests.go 2014-01-07 07:35:12 +0000 |
499 | +++ environs/jujutest/livetests.go 2014-02-18 02:14:09 +0000 |
500 | @@ -118,7 +118,7 @@ |
501 | } |
502 | cfg, err := config.New(config.NoDefaults, t.TestConfig) |
503 | c.Assert(err, gc.IsNil) |
504 | - e, err := environs.Prepare(cfg, t.ConfigStore) |
505 | + e, err := environs.Prepare(cfg, coretesting.Context(c), t.ConfigStore) |
506 | c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", t.TestConfig)) |
507 | c.Assert(e, gc.NotNil) |
508 | t.Env = e |
509 | @@ -140,7 +140,7 @@ |
510 | envtesting.UploadFakeTools(c, t.Env.Storage()) |
511 | err := common.EnsureNotBootstrapped(t.Env) |
512 | c.Assert(err, gc.IsNil) |
513 | - err = bootstrap.Bootstrap(bootstrapContext(c), t.Env, cons) |
514 | + err = bootstrap.Bootstrap(coretesting.Context(c), t.Env, cons) |
515 | c.Assert(err, gc.IsNil) |
516 | t.bootstrapped = true |
517 | } |
518 | @@ -895,7 +895,7 @@ |
519 | "state-server": false, |
520 | "name": "dummy storage", |
521 | })) |
522 | - dummyenv, err := environs.Prepare(dummyCfg, configstore.NewMem()) |
523 | + dummyenv, err := environs.Prepare(dummyCfg, coretesting.Context(c), configstore.NewMem()) |
524 | c.Assert(err, gc.IsNil) |
525 | defer dummyenv.Destroy() |
526 | |
527 | @@ -904,7 +904,7 @@ |
528 | attrs := t.TestConfig.Merge(coretesting.Attrs{"default-series": other.Series}) |
529 | cfg, err := config.New(config.NoDefaults, attrs) |
530 | c.Assert(err, gc.IsNil) |
531 | - env, err := environs.Prepare(cfg, t.ConfigStore) |
532 | + env, err := environs.Prepare(cfg, coretesting.Context(c), t.ConfigStore) |
533 | c.Assert(err, gc.IsNil) |
534 | defer environs.Destroy(env, t.ConfigStore) |
535 | |
536 | @@ -924,7 +924,7 @@ |
537 | err = storageCopy(dummyStorage, currentName, envStorage, otherName) |
538 | c.Assert(err, gc.IsNil) |
539 | |
540 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
541 | + err = bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
542 | c.Assert(err, gc.IsNil) |
543 | |
544 | conn, err := juju.NewConn(env) |
545 | |
546 | === modified file 'environs/jujutest/tests.go' |
547 | --- environs/jujutest/tests.go 2013-12-20 02:38:56 +0000 |
548 | +++ environs/jujutest/tests.go 2014-02-18 02:14:09 +0000 |
549 | @@ -61,7 +61,7 @@ |
550 | func (t *Tests) Prepare(c *gc.C) environs.Environ { |
551 | cfg, err := config.New(config.NoDefaults, t.TestConfig) |
552 | c.Assert(err, gc.IsNil) |
553 | - e, err := environs.Prepare(cfg, t.ConfigStore) |
554 | + e, err := environs.Prepare(cfg, coretesting.Context(c), t.ConfigStore) |
555 | c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", t.TestConfig)) |
556 | c.Assert(e, gc.NotNil) |
557 | return e |
558 | @@ -78,10 +78,6 @@ |
559 | t.LoggingSuite.TearDownTest(c) |
560 | } |
561 | |
562 | -func bootstrapContext(c *gc.C) environs.BootstrapContext { |
563 | - return envtesting.NewBootstrapContext(coretesting.Context(c)) |
564 | -} |
565 | - |
566 | func (t *Tests) TestStartStop(c *gc.C) { |
567 | e := t.Prepare(c) |
568 | envtesting.UploadFakeTools(c, e.Storage()) |
569 | @@ -138,7 +134,7 @@ |
570 | envtesting.UploadFakeTools(c, e.Storage()) |
571 | err := common.EnsureNotBootstrapped(e) |
572 | c.Assert(err, gc.IsNil) |
573 | - err = bootstrap.Bootstrap(bootstrapContext(c), e, constraints.Value{}) |
574 | + err = bootstrap.Bootstrap(coretesting.Context(c), e, constraints.Value{}) |
575 | c.Assert(err, gc.IsNil) |
576 | |
577 | info, apiInfo, err := e.StateInfo() |
578 | @@ -166,7 +162,7 @@ |
579 | |
580 | err = common.EnsureNotBootstrapped(e3) |
581 | c.Assert(err, gc.IsNil) |
582 | - err = bootstrap.Bootstrap(bootstrapContext(c), e3, constraints.Value{}) |
583 | + err = bootstrap.Bootstrap(coretesting.Context(c), e3, constraints.Value{}) |
584 | c.Assert(err, gc.IsNil) |
585 | |
586 | err = common.EnsureNotBootstrapped(e3) |
587 | |
588 | === modified file 'environs/manual/bootstrap.go' |
589 | --- environs/manual/bootstrap.go 2014-01-06 07:38:53 +0000 |
590 | +++ environs/manual/bootstrap.go 2014-02-18 02:14:09 +0000 |
591 | @@ -136,5 +136,5 @@ |
592 | for k, v := range agentEnv { |
593 | mcfg.AgentEnvironment[k] = v |
594 | } |
595 | - return provisionMachineAgent(args.Host, mcfg, args.Context.Stderr()) |
596 | + return provisionMachineAgent(args.Host, mcfg, args.Context.GetStderr()) |
597 | } |
598 | |
599 | === modified file 'environs/manual/bootstrap_test.go' |
600 | --- environs/manual/bootstrap_test.go 2014-01-06 07:17:46 +0000 |
601 | +++ environs/manual/bootstrap_test.go 2014-02-18 02:14:09 +0000 |
602 | @@ -12,7 +12,6 @@ |
603 | "launchpad.net/juju-core/environs/bootstrap" |
604 | "launchpad.net/juju-core/environs/filestorage" |
605 | "launchpad.net/juju-core/environs/storage" |
606 | - envtesting "launchpad.net/juju-core/environs/testing" |
607 | "launchpad.net/juju-core/environs/tools" |
608 | "launchpad.net/juju-core/instance" |
609 | "launchpad.net/juju-core/juju/testing" |
610 | @@ -81,7 +80,7 @@ |
611 | HardwareCharacteristics: &instance.HardwareCharacteristics{ |
612 | Arch: &arch, |
613 | }, |
614 | - Context: envtesting.NewBootstrapContext(coretesting.Context(c)), |
615 | + Context: coretesting.Context(c), |
616 | } |
617 | } |
618 | |
619 | |
620 | === modified file 'environs/open.go' |
621 | --- environs/open.go 2014-02-13 10:08:31 +0000 |
622 | +++ environs/open.go 2014-02-18 02:14:09 +0000 |
623 | @@ -118,12 +118,12 @@ |
624 | // and environment information is created using the |
625 | // given store. If the environment is already prepared, |
626 | // it behaves like NewFromName. |
627 | -func PrepareFromName(name string, store configstore.Storage) (Environ, error) { |
628 | +func PrepareFromName(name string, ctx BootstrapContext, store configstore.Storage) (Environ, error) { |
629 | cfg, _, err := ConfigForName(name, store) |
630 | if err != nil { |
631 | return nil, err |
632 | } |
633 | - return Prepare(cfg, store) |
634 | + return Prepare(cfg, ctx, store) |
635 | } |
636 | |
637 | // NewFromAttrs returns a new environment based on the provided configuration |
638 | @@ -148,7 +148,7 @@ |
639 | |
640 | // Prepare prepares a new environment based on the provided configuration. |
641 | // If the environment is already prepared, it behaves like New. |
642 | -func Prepare(cfg *config.Config, store configstore.Storage) (Environ, error) { |
643 | +func Prepare(cfg *config.Config, ctx BootstrapContext, store configstore.Storage) (Environ, error) { |
644 | p, err := Provider(cfg.Type()) |
645 | if err != nil { |
646 | return nil, err |
647 | @@ -175,7 +175,7 @@ |
648 | if err != nil { |
649 | return nil, fmt.Errorf("cannot create new info for environment %q: %v", cfg.Name(), err) |
650 | } |
651 | - env, err := prepare(cfg, info, p) |
652 | + env, err := prepare(ctx, cfg, info, p) |
653 | if err != nil { |
654 | if err := info.Destroy(); err != nil { |
655 | logger.Warningf("cannot destroy newly created environment info: %v", err) |
656 | @@ -189,7 +189,7 @@ |
657 | return env, nil |
658 | } |
659 | |
660 | -func prepare(cfg *config.Config, info configstore.EnvironInfo, p EnvironProvider) (Environ, error) { |
661 | +func prepare(ctx BootstrapContext, cfg *config.Config, info configstore.EnvironInfo, p EnvironProvider) (Environ, error) { |
662 | cfg, err := ensureAdminSecret(cfg) |
663 | if err != nil { |
664 | return nil, fmt.Errorf("cannot generate admin-secret: %v", err) |
665 | @@ -198,7 +198,7 @@ |
666 | if err != nil { |
667 | return nil, fmt.Errorf("cannot ensure CA certificate: %v", err) |
668 | } |
669 | - return p.Prepare(cfg) |
670 | + return p.Prepare(ctx, cfg) |
671 | } |
672 | |
673 | // ensureAdminSecret returns a config with a non-empty admin-secret. |
674 | |
675 | === modified file 'environs/open_test.go' |
676 | --- environs/open_test.go 2014-02-11 02:50:17 +0000 |
677 | +++ environs/open_test.go 2014-02-18 02:14:09 +0000 |
678 | @@ -37,10 +37,10 @@ |
679 | // matches *Settings.Map() |
680 | cfg, err := config.New(config.NoDefaults, dummySampleConfig()) |
681 | c.Assert(err, gc.IsNil) |
682 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
683 | + ctx := testing.Context(c) |
684 | + env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) |
685 | c.Assert(err, gc.IsNil) |
686 | envtesting.UploadFakeTools(c, env.Storage()) |
687 | - ctx := envtesting.NewBootstrapContext(testing.Context(c)) |
688 | err = bootstrap.Bootstrap(ctx, env, constraints.Value{}) |
689 | c.Assert(err, gc.IsNil) |
690 | } |
691 | @@ -57,7 +57,8 @@ |
692 | func (*OpenSuite) TestNewFromName(c *gc.C) { |
693 | defer testing.MakeFakeHome(c, testing.MultipleEnvConfigNoDefault, testing.SampleCertName).Restore() |
694 | store := configstore.NewMem() |
695 | - e, err := environs.PrepareFromName("erewhemos", store) |
696 | + ctx := testing.Context(c) |
697 | + e, err := environs.PrepareFromName("erewhemos", ctx, store) |
698 | c.Assert(err, gc.IsNil) |
699 | |
700 | e, err = environs.NewFromName("erewhemos", store) |
701 | @@ -96,7 +97,8 @@ |
702 | |
703 | func (*OpenSuite) TestPrepareFromName(c *gc.C) { |
704 | defer testing.MakeFakeHome(c, testing.MultipleEnvConfigNoDefault, testing.SampleCertName).Restore() |
705 | - e, err := environs.PrepareFromName("erewhemos", configstore.NewMem()) |
706 | + ctx := testing.Context(c) |
707 | + e, err := environs.PrepareFromName("erewhemos", ctx, configstore.NewMem()) |
708 | c.Assert(err, gc.IsNil) |
709 | c.Assert(e.Name(), gc.Equals, "erewhemos") |
710 | // Check we can access storage ok, which implies the environment has been prepared. |
711 | @@ -175,7 +177,8 @@ |
712 | cfg, err := config.New(config.NoDefaults, baselineAttrs) |
713 | c.Assert(err, gc.IsNil) |
714 | store := configstore.NewMem() |
715 | - env, err := environs.Prepare(cfg, store) |
716 | + ctx := testing.Context(c) |
717 | + env, err := environs.Prepare(cfg, ctx, store) |
718 | c.Assert(err, gc.IsNil) |
719 | // Check we can access storage ok, which implies the environment has been prepared. |
720 | c.Assert(env.Storage(), gc.NotNil) |
721 | @@ -204,7 +207,7 @@ |
722 | c.Assert(caCert.Subject.CommonName, gc.Equals, `juju-generated CA for environment "`+testing.SampleEnvName+`"`) |
723 | |
724 | // Check we can call Prepare again. |
725 | - env, err = environs.Prepare(cfg, store) |
726 | + env, err = environs.Prepare(cfg, ctx, store) |
727 | c.Assert(err, gc.IsNil) |
728 | c.Assert(env.Name(), gc.Equals, "erewhemos") |
729 | c.Assert(env.Storage(), gc.NotNil) |
730 | @@ -221,13 +224,14 @@ |
731 | cfg, err := config.New(config.NoDefaults, baselineAttrs) |
732 | c.Assert(err, gc.IsNil) |
733 | |
734 | - env0, err := environs.Prepare(cfg, configstore.NewMem()) |
735 | + ctx := testing.Context(c) |
736 | + env0, err := environs.Prepare(cfg, ctx, configstore.NewMem()) |
737 | c.Assert(err, gc.IsNil) |
738 | adminSecret0 := env0.Config().AdminSecret() |
739 | c.Assert(adminSecret0, gc.HasLen, 32) |
740 | c.Assert(adminSecret0, gc.Matches, "^[0-9a-f]*$") |
741 | |
742 | - env1, err := environs.Prepare(cfg, configstore.NewMem()) |
743 | + env1, err := environs.Prepare(cfg, ctx, configstore.NewMem()) |
744 | c.Assert(err, gc.IsNil) |
745 | adminSecret1 := env1.Config().AdminSecret() |
746 | c.Assert(adminSecret1, gc.HasLen, 32) |
747 | @@ -246,7 +250,7 @@ |
748 | )) |
749 | c.Assert(err, gc.IsNil) |
750 | store := configstore.NewMem() |
751 | - env, err := environs.Prepare(cfg, store) |
752 | + env, err := environs.Prepare(cfg, testing.Context(c), store) |
753 | c.Assert(err, gc.ErrorMatches, "cannot ensure CA certificate: environment configuration with a certificate but no CA private key") |
754 | c.Assert(env, gc.IsNil) |
755 | // Ensure that the config storage info is cleaned up. |
756 | @@ -264,7 +268,8 @@ |
757 | }, |
758 | )) |
759 | c.Assert(err, gc.IsNil) |
760 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
761 | + ctx := testing.Context(c) |
762 | + env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) |
763 | c.Assert(err, gc.IsNil) |
764 | cfgCertPEM, cfgCertOK := env.Config().CACert() |
765 | cfgKeyPEM, cfgKeyOK := env.Config().CAPrivateKey() |
766 | @@ -286,7 +291,8 @@ |
767 | store := configstore.NewMem() |
768 | // Prepare the environment and sanity-check that |
769 | // the config storage info has been made. |
770 | - e, err := environs.Prepare(cfg, store) |
771 | + ctx := testing.Context(c) |
772 | + e, err := environs.Prepare(cfg, ctx, store) |
773 | c.Assert(err, gc.IsNil) |
774 | _, err = store.ReadInfo(e.Name()) |
775 | c.Assert(err, gc.IsNil) |
776 | @@ -332,7 +338,8 @@ |
777 | func (s *checkEnvironmentSuite) TestCheckEnvironment(c *gc.C) { |
778 | defer testing.MakeFakeHome(c, checkEnv, "existing").Restore() |
779 | |
780 | - environ, err := environs.PrepareFromName("test", configstore.NewMem()) |
781 | + ctx := testing.Context(c) |
782 | + environ, err := environs.PrepareFromName("test", ctx, configstore.NewMem()) |
783 | c.Assert(err, gc.IsNil) |
784 | |
785 | // VerifyStorage is sufficient for our tests and much simpler |
786 | @@ -347,7 +354,8 @@ |
787 | func (s *checkEnvironmentSuite) TestCheckEnvironmentFileNotFound(c *gc.C) { |
788 | defer testing.MakeFakeHome(c, checkEnv, "existing").Restore() |
789 | |
790 | - environ, err := environs.PrepareFromName("test", configstore.NewMem()) |
791 | + ctx := testing.Context(c) |
792 | + environ, err := environs.PrepareFromName("test", ctx, configstore.NewMem()) |
793 | c.Assert(err, gc.IsNil) |
794 | |
795 | // VerifyStorage is sufficient for our tests and much simpler |
796 | @@ -368,7 +376,8 @@ |
797 | func (s *checkEnvironmentSuite) TestCheckEnvironmentGetFails(c *gc.C) { |
798 | defer testing.MakeFakeHome(c, checkEnv, "existing").Restore() |
799 | |
800 | - environ, err := environs.PrepareFromName("test", configstore.NewMem()) |
801 | + ctx := testing.Context(c) |
802 | + environ, err := environs.PrepareFromName("test", ctx, configstore.NewMem()) |
803 | c.Assert(err, gc.IsNil) |
804 | |
805 | // VerifyStorage is sufficient for our tests and much simpler |
806 | @@ -388,7 +397,8 @@ |
807 | func (s *checkEnvironmentSuite) TestCheckEnvironmentBadContent(c *gc.C) { |
808 | defer testing.MakeFakeHome(c, checkEnv, "existing").Restore() |
809 | |
810 | - environ, err := environs.PrepareFromName("test", configstore.NewMem()) |
811 | + ctx := testing.Context(c) |
812 | + environ, err := environs.PrepareFromName("test", ctx, configstore.NewMem()) |
813 | c.Assert(err, gc.IsNil) |
814 | |
815 | // We mock a bad (eg. from a Python-juju environment) bootstrap-verify. |
816 | |
817 | === modified file 'environs/storage/storage_test.go' |
818 | --- environs/storage/storage_test.go 2014-01-31 00:14:11 +0000 |
819 | +++ environs/storage/storage_test.go 2014-02-18 02:14:09 +0000 |
820 | @@ -42,7 +42,7 @@ |
821 | |
822 | func (s *datasourceSuite) SetUpTest(c *gc.C) { |
823 | s.home = testing.MakeFakeHome(c, existingEnv, "existing") |
824 | - environ, err := environs.PrepareFromName("test", configstore.NewMem()) |
825 | + environ, err := environs.PrepareFromName("test", testing.Context(c), configstore.NewMem()) |
826 | c.Assert(err, gc.IsNil) |
827 | s.stor = environ.Storage() |
828 | s.baseURL, err = s.stor.URL("") |
829 | |
830 | === modified file 'environs/sync/sync_test.go' |
831 | --- environs/sync/sync_test.go 2014-01-30 06:21:03 +0000 |
832 | +++ environs/sync/sync_test.go 2014-02-18 02:14:09 +0000 |
833 | @@ -68,7 +68,7 @@ |
834 | `) |
835 | s.AddCleanup(func(*gc.C) { fakeHome.Restore() }) |
836 | var err error |
837 | - s.targetEnv, err = environs.PrepareFromName("test-target", configstore.NewMem()) |
838 | + s.targetEnv, err = environs.PrepareFromName("test-target", coretesting.Context(c), configstore.NewMem()) |
839 | c.Assert(err, gc.IsNil) |
840 | envtesting.RemoveAllTools(c, s.targetEnv) |
841 | |
842 | @@ -264,7 +264,7 @@ |
843 | // We only want to use simplestreams to find any synced tools. |
844 | cfg, err := config.New(config.NoDefaults, dummy.SampleConfig()) |
845 | c.Assert(err, gc.IsNil) |
846 | - s.env, err = environs.Prepare(cfg, configstore.NewMem()) |
847 | + s.env, err = environs.Prepare(cfg, coretesting.Context(c), configstore.NewMem()) |
848 | c.Assert(err, gc.IsNil) |
849 | } |
850 | |
851 | |
852 | === modified file 'environs/testing/bootstrap.go' |
853 | --- environs/testing/bootstrap.go 2014-01-28 04:58:43 +0000 |
854 | +++ environs/testing/bootstrap.go 2014-02-18 02:14:09 +0000 |
855 | @@ -4,11 +4,8 @@ |
856 | package testing |
857 | |
858 | import ( |
859 | - "io" |
860 | - |
861 | "github.com/loggo/loggo" |
862 | |
863 | - "launchpad.net/juju-core/cmd" |
864 | "launchpad.net/juju-core/environs" |
865 | "launchpad.net/juju-core/environs/cloudinit" |
866 | "launchpad.net/juju-core/instance" |
867 | @@ -29,23 +26,3 @@ |
868 | } |
869 | return testbase.PatchValue(&common.FinishBootstrap, f) |
870 | } |
871 | - |
872 | -type bootstrapContext struct { |
873 | - *cmd.Context |
874 | -} |
875 | - |
876 | -func (c bootstrapContext) Stdin() io.Reader { |
877 | - return c.Context.Stdin |
878 | -} |
879 | - |
880 | -func (c bootstrapContext) Stdout() io.Writer { |
881 | - return c.Context.Stdout |
882 | -} |
883 | - |
884 | -func (c bootstrapContext) Stderr() io.Writer { |
885 | - return c.Context.Stderr |
886 | -} |
887 | - |
888 | -func NewBootstrapContext(ctx *cmd.Context) environs.BootstrapContext { |
889 | - return bootstrapContext{ctx} |
890 | -} |
891 | |
892 | === modified file 'environs/tools/storage_test.go' |
893 | --- environs/tools/storage_test.go 2013-09-27 02:31:45 +0000 |
894 | +++ environs/tools/storage_test.go 2014-02-18 02:14:09 +0000 |
895 | @@ -12,6 +12,7 @@ |
896 | envtesting "launchpad.net/juju-core/environs/testing" |
897 | envtools "launchpad.net/juju-core/environs/tools" |
898 | "launchpad.net/juju-core/provider/dummy" |
899 | + "launchpad.net/juju-core/testing" |
900 | "launchpad.net/juju-core/testing/testbase" |
901 | coretools "launchpad.net/juju-core/tools" |
902 | "launchpad.net/juju-core/version" |
903 | @@ -29,7 +30,7 @@ |
904 | s.LoggingSuite.SetUpTest(c) |
905 | cfg, err := config.New(config.NoDefaults, dummy.SampleConfig()) |
906 | c.Assert(err, gc.IsNil) |
907 | - s.env, err = environs.Prepare(cfg, configstore.NewMem()) |
908 | + s.env, err = environs.Prepare(cfg, testing.Context(c), configstore.NewMem()) |
909 | c.Assert(err, gc.IsNil) |
910 | s.dataDir = c.MkDir() |
911 | } |
912 | |
913 | === modified file 'environs/tools/tools_test.go' |
914 | --- environs/tools/tools_test.go 2014-01-30 07:37:38 +0000 |
915 | +++ environs/tools/tools_test.go 2014-02-18 02:14:09 +0000 |
916 | @@ -25,6 +25,7 @@ |
917 | envtools "launchpad.net/juju-core/environs/tools" |
918 | "launchpad.net/juju-core/errors" |
919 | "launchpad.net/juju-core/provider/dummy" |
920 | + "launchpad.net/juju-core/testing" |
921 | jc "launchpad.net/juju-core/testing/checkers" |
922 | "launchpad.net/juju-core/testing/testbase" |
923 | coretools "launchpad.net/juju-core/tools" |
924 | @@ -171,7 +172,7 @@ |
925 | dummy.Reset() |
926 | cfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(attrs)) |
927 | c.Assert(err, gc.IsNil) |
928 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
929 | + env, err := environs.Prepare(cfg, testing.Context(c), configstore.NewMem()) |
930 | c.Assert(err, gc.IsNil) |
931 | s.env = env |
932 | s.removeTools(c) |
933 | |
934 | === modified file 'environs/tools/urls_test.go' |
935 | --- environs/tools/urls_test.go 2014-01-31 00:14:11 +0000 |
936 | +++ environs/tools/urls_test.go 2014-02-18 02:14:09 +0000 |
937 | @@ -43,7 +43,7 @@ |
938 | } |
939 | cfg, err := config.New(config.NoDefaults, attrs) |
940 | c.Assert(err, gc.IsNil) |
941 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
942 | + env, err := environs.Prepare(cfg, testing.Context(c), configstore.NewMem()) |
943 | c.Assert(err, gc.IsNil) |
944 | return env |
945 | } |
946 | |
947 | === modified file 'juju/apiconn_test.go' |
948 | --- juju/apiconn_test.go 2014-01-22 22:48:54 +0000 |
949 | +++ juju/apiconn_test.go 2014-02-18 02:14:09 +0000 |
950 | @@ -46,11 +46,12 @@ |
951 | func (*NewAPIConnSuite) TestNewConn(c *gc.C) { |
952 | cfg, err := config.New(config.NoDefaults, dummy.SampleConfig()) |
953 | c.Assert(err, gc.IsNil) |
954 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
955 | + ctx := coretesting.Context(c) |
956 | + env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) |
957 | c.Assert(err, gc.IsNil) |
958 | |
959 | envtesting.UploadFakeTools(c, env.Storage()) |
960 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
961 | + err = bootstrap.Bootstrap(ctx, env, constraints.Value{}) |
962 | c.Assert(err, gc.IsNil) |
963 | |
964 | cfg = env.Config() |
965 | |
966 | === modified file 'juju/conn_test.go' |
967 | --- juju/conn_test.go 2014-01-30 13:50:27 +0000 |
968 | +++ juju/conn_test.go 2014-02-18 02:14:09 +0000 |
969 | @@ -62,17 +62,14 @@ |
970 | c.Assert(err, gc.IsNil) |
971 | } |
972 | |
973 | -func bootstrapContext(c *gc.C) environs.BootstrapContext { |
974 | - return envtesting.NewBootstrapContext(coretesting.Context(c)) |
975 | -} |
976 | - |
977 | func (*NewConnSuite) TestNewConnWithoutAdminSecret(c *gc.C) { |
978 | cfg, err := config.New(config.NoDefaults, dummy.SampleConfig()) |
979 | c.Assert(err, gc.IsNil) |
980 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
981 | + ctx := coretesting.Context(c) |
982 | + env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) |
983 | c.Assert(err, gc.IsNil) |
984 | envtesting.UploadFakeTools(c, env.Storage()) |
985 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
986 | + err = bootstrap.Bootstrap(ctx, env, constraints.Value{}) |
987 | c.Assert(err, gc.IsNil) |
988 | |
989 | attrs := env.Config().AllAttrs() |
990 | @@ -88,10 +85,11 @@ |
991 | if store == nil { |
992 | store = configstore.NewMem() |
993 | } |
994 | - env, err := environs.PrepareFromName(envName, store) |
995 | + ctx := coretesting.Context(c) |
996 | + env, err := environs.PrepareFromName(envName, ctx, store) |
997 | c.Assert(err, gc.IsNil) |
998 | envtesting.UploadFakeTools(c, env.Storage()) |
999 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1000 | + err = bootstrap.Bootstrap(ctx, env, constraints.Value{}) |
1001 | c.Assert(err, gc.IsNil) |
1002 | } |
1003 | |
1004 | @@ -133,10 +131,11 @@ |
1005 | }) |
1006 | cfg, err := config.New(config.NoDefaults, attrs) |
1007 | c.Assert(err, gc.IsNil) |
1008 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
1009 | + ctx := coretesting.Context(c) |
1010 | + env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) |
1011 | c.Assert(err, gc.IsNil) |
1012 | envtesting.UploadFakeTools(c, env.Storage()) |
1013 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1014 | + err = bootstrap.Bootstrap(ctx, env, constraints.Value{}) |
1015 | c.Assert(err, gc.IsNil) |
1016 | info, _, err := env.StateInfo() |
1017 | c.Assert(err, gc.IsNil) |
1018 | @@ -182,10 +181,11 @@ |
1019 | }) |
1020 | cfg, err := config.New(config.NoDefaults, attrs) |
1021 | c.Assert(err, gc.IsNil) |
1022 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
1023 | + ctx := coretesting.Context(c) |
1024 | + env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) |
1025 | c.Assert(err, gc.IsNil) |
1026 | envtesting.UploadFakeTools(c, env.Storage()) |
1027 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1028 | + err = bootstrap.Bootstrap(ctx, env, constraints.Value{}) |
1029 | c.Assert(err, gc.IsNil) |
1030 | |
1031 | // Make a new Conn, which will push the secrets. |
1032 | @@ -218,10 +218,11 @@ |
1033 | }) |
1034 | cfg, err := config.New(config.NoDefaults, attrs) |
1035 | c.Assert(err, gc.IsNil) |
1036 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
1037 | + ctx := coretesting.Context(c) |
1038 | + env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) |
1039 | c.Assert(err, gc.IsNil) |
1040 | envtesting.UploadFakeTools(c, env.Storage()) |
1041 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1042 | + err = bootstrap.Bootstrap(ctx, env, constraints.Value{}) |
1043 | c.Assert(err, gc.IsNil) |
1044 | |
1045 | // Check that Bootstrap has correctly used a hash |
1046 | @@ -272,10 +273,11 @@ |
1047 | s.ToolsFixture.SetUpTest(c) |
1048 | cfg, err := config.New(config.NoDefaults, dummy.SampleConfig()) |
1049 | c.Assert(err, gc.IsNil) |
1050 | - environ, err := environs.Prepare(cfg, configstore.NewMem()) |
1051 | + ctx := coretesting.Context(c) |
1052 | + environ, err := environs.Prepare(cfg, ctx, configstore.NewMem()) |
1053 | c.Assert(err, gc.IsNil) |
1054 | envtesting.UploadFakeTools(c, environ.Storage()) |
1055 | - err = bootstrap.Bootstrap(bootstrapContext(c), environ, constraints.Value{}) |
1056 | + err = bootstrap.Bootstrap(ctx, environ, constraints.Value{}) |
1057 | c.Assert(err, gc.IsNil) |
1058 | s.conn, err = juju.NewConn(environ) |
1059 | c.Assert(err, gc.IsNil) |
1060 | |
1061 | === modified file 'juju/testing/conn.go' |
1062 | --- juju/testing/conn.go 2014-02-13 00:54:09 +0000 |
1063 | +++ juju/testing/conn.go 2014-02-18 02:14:09 +0000 |
1064 | @@ -196,13 +196,13 @@ |
1065 | c.Assert(err, gc.IsNil) |
1066 | s.ConfigStore = store |
1067 | |
1068 | - environ, err := environs.PrepareFromName("dummyenv", s.ConfigStore) |
1069 | + ctx := testing.Context(c) |
1070 | + environ, err := environs.PrepareFromName("dummyenv", ctx, s.ConfigStore) |
1071 | c.Assert(err, gc.IsNil) |
1072 | // sanity check we've got the correct environment. |
1073 | c.Assert(environ.Name(), gc.Equals, "dummyenv") |
1074 | |
1075 | envtesting.MustUploadFakeTools(environ.Storage()) |
1076 | - ctx := envtesting.NewBootstrapContext(testing.Context(c)) |
1077 | c.Assert(bootstrap.Bootstrap(ctx, environ, constraints.Value{}), gc.IsNil) |
1078 | |
1079 | s.BackingState = environ.(GetStater).GetStateInAPIServer() |
1080 | |
1081 | === modified file 'provider/azure/environprovider.go' |
1082 | --- provider/azure/environprovider.go 2014-01-28 04:58:43 +0000 |
1083 | +++ provider/azure/environprovider.go 2014-02-18 02:14:09 +0000 |
1084 | @@ -42,7 +42,7 @@ |
1085 | } |
1086 | |
1087 | // Prepare is specified in the EnvironProvider interface. |
1088 | -func (prov azureEnvironProvider) Prepare(cfg *config.Config) (environs.Environ, error) { |
1089 | +func (prov azureEnvironProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) { |
1090 | // TODO prepare environment as necessary |
1091 | return prov.Open(cfg) |
1092 | } |
1093 | |
1094 | === modified file 'provider/common/bootstrap.go' |
1095 | --- provider/common/bootstrap.go 2014-01-30 14:13:54 +0000 |
1096 | +++ provider/common/bootstrap.go 2014-02-18 02:14:09 +0000 |
1097 | @@ -68,12 +68,12 @@ |
1098 | return err |
1099 | } |
1100 | |
1101 | - fmt.Fprintln(ctx.Stderr(), "Launching instance") |
1102 | + fmt.Fprintln(ctx.GetStderr(), "Launching instance") |
1103 | inst, hw, err := env.StartInstance(cons, selectedTools, machineConfig) |
1104 | if err != nil { |
1105 | return fmt.Errorf("cannot start bootstrap instance: %v", err) |
1106 | } |
1107 | - fmt.Fprintf(ctx.Stderr(), " - %s\n", inst.Id()) |
1108 | + fmt.Fprintf(ctx.GetStderr(), " - %s\n", inst.Id()) |
1109 | |
1110 | var characteristics []instance.HardwareCharacteristics |
1111 | if hw != nil { |
1112 | @@ -144,12 +144,12 @@ |
1113 | defer close(ch) |
1114 | go func() { |
1115 | for _ = range ch { |
1116 | - fmt.Fprintln(ctx.Stderr(), "Cleaning up failed bootstrap") |
1117 | + fmt.Fprintln(ctx.GetStderr(), "Cleaning up failed bootstrap") |
1118 | } |
1119 | }() |
1120 | |
1121 | if inst != nil { |
1122 | - fmt.Fprintln(ctx.Stderr(), "Stopping instance...") |
1123 | + fmt.Fprintln(ctx.GetStderr(), "Stopping instance...") |
1124 | if stoperr := env.StopInstances([]instance.Instance{inst}); stoperr != nil { |
1125 | logger.Errorf("cannot stop failed bootstrap instance %q: %v", inst.Id(), stoperr) |
1126 | } else { |
1127 | @@ -217,7 +217,7 @@ |
1128 | Host: "ubuntu@" + addr, |
1129 | Client: client, |
1130 | Config: cloudcfg, |
1131 | - ProgressWriter: ctx.Stderr(), |
1132 | + ProgressWriter: ctx.GetStderr(), |
1133 | }) |
1134 | } |
1135 | |
1136 | @@ -365,14 +365,14 @@ |
1137 | checker := parallelHostChecker{ |
1138 | Try: parallel.NewTry(0, nil), |
1139 | client: client, |
1140 | - stderr: ctx.Stderr(), |
1141 | + stderr: ctx.GetStderr(), |
1142 | active: make(map[instance.Address]chan struct{}), |
1143 | checkDelay: timeout.RetryDelay, |
1144 | checkHostScript: checkHostScript, |
1145 | } |
1146 | defer checker.Kill() |
1147 | |
1148 | - fmt.Fprintln(ctx.Stderr(), "Waiting for address") |
1149 | + fmt.Fprintln(ctx.GetStderr(), "Waiting for address") |
1150 | for { |
1151 | select { |
1152 | case <-pollAddresses.C: |
1153 | |
1154 | === modified file 'provider/common/bootstrap_test.go' |
1155 | --- provider/common/bootstrap_test.go 2014-01-30 17:27:26 +0000 |
1156 | +++ provider/common/bootstrap_test.go 2014-02-18 02:14:09 +0000 |
1157 | @@ -4,7 +4,6 @@ |
1158 | package common_test |
1159 | |
1160 | import ( |
1161 | - "bytes" |
1162 | "fmt" |
1163 | "os" |
1164 | "time" |
1165 | @@ -76,22 +75,13 @@ |
1166 | return func() *config.Config { return cfg } |
1167 | } |
1168 | |
1169 | -// bootstrapContext creates a BootstrapContext which |
1170 | -// writes stderr to the bytes.Buffer returned. |
1171 | -func bootstrapContext(c *gc.C) (ctx environs.BootstrapContext, stderr *bytes.Buffer) { |
1172 | - cmdContext := coretesting.Context(c) |
1173 | - stderr = &bytes.Buffer{} |
1174 | - cmdContext.Stderr = stderr |
1175 | - return envtesting.NewBootstrapContext(cmdContext), stderr |
1176 | -} |
1177 | - |
1178 | func (s *BootstrapSuite) TestCannotWriteStateFile(c *gc.C) { |
1179 | brokenStorage := &mockStorage{ |
1180 | Storage: newStorage(s, c), |
1181 | putErr: fmt.Errorf("noes!"), |
1182 | } |
1183 | env := &mockEnviron{storage: brokenStorage} |
1184 | - ctx, _ := bootstrapContext(c) |
1185 | + ctx := coretesting.Context(c) |
1186 | err := common.Bootstrap(ctx, env, constraints.Value{}) |
1187 | c.Assert(err, gc.ErrorMatches, "cannot create initial state file: noes!") |
1188 | } |
1189 | @@ -118,7 +108,7 @@ |
1190 | config: configGetter(c), |
1191 | } |
1192 | |
1193 | - ctx, _ := bootstrapContext(c) |
1194 | + ctx := coretesting.Context(c) |
1195 | err = common.Bootstrap(ctx, env, checkCons) |
1196 | c.Assert(err, gc.ErrorMatches, "cannot start bootstrap instance: meh, not started") |
1197 | } |
1198 | @@ -149,7 +139,7 @@ |
1199 | config: configGetter(c), |
1200 | } |
1201 | |
1202 | - ctx, _ := bootstrapContext(c) |
1203 | + ctx := coretesting.Context(c) |
1204 | err := common.Bootstrap(ctx, env, constraints.Value{}) |
1205 | c.Assert(err, gc.ErrorMatches, "cannot save state: suddenly a wild blah") |
1206 | c.Assert(stopped, gc.HasLen, 1) |
1207 | @@ -186,7 +176,7 @@ |
1208 | config: configGetter(c), |
1209 | } |
1210 | |
1211 | - ctx, _ := bootstrapContext(c) |
1212 | + ctx := coretesting.Context(c) |
1213 | err := common.Bootstrap(ctx, env, constraints.Value{}) |
1214 | c.Assert(err, gc.ErrorMatches, "cannot save state: suddenly a wild blah") |
1215 | c.Assert(stopped, gc.HasLen, 1) |
1216 | @@ -231,7 +221,7 @@ |
1217 | setConfig: setConfig, |
1218 | } |
1219 | originalAuthKeys := env.Config().AuthorizedKeys() |
1220 | - ctx, _ := bootstrapContext(c) |
1221 | + ctx := coretesting.Context(c) |
1222 | err := common.Bootstrap(ctx, env, constraints.Value{}) |
1223 | c.Assert(err, gc.IsNil) |
1224 | |
1225 | @@ -268,14 +258,14 @@ |
1226 | } |
1227 | |
1228 | func (s *BootstrapSuite) TestWaitSSHTimesOutWaitingForAddresses(c *gc.C) { |
1229 | - ctx, stderr := bootstrapContext(c) |
1230 | + ctx := coretesting.Context(c) |
1231 | _, err := common.WaitSSH(ctx, nil, ssh.DefaultClient, "/bin/true", neverAddresses{}, testSSHTimeout) |
1232 | c.Check(err, gc.ErrorMatches, `waited for `+testSSHTimeout.Timeout.String()+` without getting any addresses`) |
1233 | - c.Check(stderr.String(), gc.Matches, "Waiting for address\n") |
1234 | + c.Check(coretesting.Stderr(ctx), gc.Matches, "Waiting for address\n") |
1235 | } |
1236 | |
1237 | func (s *BootstrapSuite) TestWaitSSHKilledWaitingForAddresses(c *gc.C) { |
1238 | - ctx, stderr := bootstrapContext(c) |
1239 | + ctx := coretesting.Context(c) |
1240 | interrupted := make(chan os.Signal, 1) |
1241 | go func() { |
1242 | <-time.After(2 * time.Millisecond) |
1243 | @@ -283,7 +273,7 @@ |
1244 | }() |
1245 | _, err := common.WaitSSH(ctx, interrupted, ssh.DefaultClient, "/bin/true", neverAddresses{}, testSSHTimeout) |
1246 | c.Check(err, gc.ErrorMatches, "interrupted") |
1247 | - c.Check(stderr.String(), gc.Matches, "Waiting for address\n") |
1248 | + c.Check(coretesting.Stderr(ctx), gc.Matches, "Waiting for address\n") |
1249 | } |
1250 | |
1251 | type brokenAddresses struct { |
1252 | @@ -295,10 +285,10 @@ |
1253 | } |
1254 | |
1255 | func (s *BootstrapSuite) TestWaitSSHStopsOnBadError(c *gc.C) { |
1256 | - ctx, stderr := bootstrapContext(c) |
1257 | + ctx := coretesting.Context(c) |
1258 | _, err := common.WaitSSH(ctx, nil, ssh.DefaultClient, "/bin/true", brokenAddresses{}, testSSHTimeout) |
1259 | c.Check(err, gc.ErrorMatches, "getting addresses: Addresses will never work") |
1260 | - c.Check(stderr.String(), gc.Equals, "Waiting for address\n") |
1261 | + c.Check(coretesting.Stderr(ctx), gc.Equals, "Waiting for address\n") |
1262 | } |
1263 | |
1264 | type neverOpensPort struct { |
1265 | @@ -311,12 +301,12 @@ |
1266 | } |
1267 | |
1268 | func (s *BootstrapSuite) TestWaitSSHTimesOutWaitingForDial(c *gc.C) { |
1269 | - ctx, stderr := bootstrapContext(c) |
1270 | + ctx := coretesting.Context(c) |
1271 | // 0.x.y.z addresses are always invalid |
1272 | _, err := common.WaitSSH(ctx, nil, ssh.DefaultClient, "/bin/true", &neverOpensPort{addr: "0.1.2.3"}, testSSHTimeout) |
1273 | c.Check(err, gc.ErrorMatches, |
1274 | `waited for `+testSSHTimeout.Timeout.String()+` without being able to connect: mock connection failure to 0.1.2.3`) |
1275 | - c.Check(stderr.String(), gc.Matches, |
1276 | + c.Check(coretesting.Stderr(ctx), gc.Matches, |
1277 | "Waiting for address\n"+ |
1278 | "(Attempting to connect to 0.1.2.3:22\n)+") |
1279 | } |
1280 | @@ -339,14 +329,14 @@ |
1281 | } |
1282 | |
1283 | func (s *BootstrapSuite) TestWaitSSHKilledWaitingForDial(c *gc.C) { |
1284 | - ctx, stderr := bootstrapContext(c) |
1285 | + ctx := coretesting.Context(c) |
1286 | timeout := testSSHTimeout |
1287 | timeout.Timeout = 1 * time.Minute |
1288 | interrupted := make(chan os.Signal, 1) |
1289 | _, err := common.WaitSSH(ctx, interrupted, ssh.DefaultClient, "", &interruptOnDial{name: "0.1.2.3", interrupted: interrupted}, timeout) |
1290 | c.Check(err, gc.ErrorMatches, "interrupted") |
1291 | // Exact timing is imprecise but it should have tried a few times before being killed |
1292 | - c.Check(stderr.String(), gc.Matches, |
1293 | + c.Check(coretesting.Stderr(ctx), gc.Matches, |
1294 | "Waiting for address\n"+ |
1295 | "(Attempting to connect to 0.1.2.3:22\n)+") |
1296 | } |
1297 | @@ -371,7 +361,7 @@ |
1298 | } |
1299 | |
1300 | func (s *BootstrapSuite) TestWaitSSHRefreshAddresses(c *gc.C) { |
1301 | - ctx, stderr := bootstrapContext(c) |
1302 | + ctx := coretesting.Context(c) |
1303 | _, err := common.WaitSSH(ctx, nil, ssh.DefaultClient, "", &addressesChange{addrs: [][]string{ |
1304 | nil, |
1305 | nil, |
1306 | @@ -383,10 +373,11 @@ |
1307 | // Not necessarily the last one in the list, due to scheduling. |
1308 | c.Check(err, gc.ErrorMatches, |
1309 | `waited for `+testSSHTimeout.Timeout.String()+` without being able to connect: mock connection failure to 0.1.2.[34]`) |
1310 | - c.Check(stderr.String(), gc.Matches, |
1311 | + stderr := coretesting.Stderr(ctx) |
1312 | + c.Check(stderr, gc.Matches, |
1313 | "Waiting for address\n"+ |
1314 | "(.|\n)*(Attempting to connect to 0.1.2.3:22\n)+(.|\n)*") |
1315 | - c.Check(stderr.String(), gc.Matches, |
1316 | + c.Check(stderr, gc.Matches, |
1317 | "Waiting for address\n"+ |
1318 | "(.|\n)*(Attempting to connect to 0.1.2.4:22\n)+(.|\n)*") |
1319 | } |
1320 | |
1321 | === modified file 'provider/dummy/config_test.go' |
1322 | --- provider/dummy/config_test.go 2013-10-01 16:46:31 +0000 |
1323 | +++ provider/dummy/config_test.go 2014-02-18 02:14:09 +0000 |
1324 | @@ -29,7 +29,8 @@ |
1325 | attrs := dummy.SampleConfig().Delete("secret") |
1326 | cfg, err := config.New(config.NoDefaults, attrs) |
1327 | c.Assert(err, gc.IsNil) |
1328 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
1329 | + ctx := testing.Context(c) |
1330 | + env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) |
1331 | c.Assert(err, gc.IsNil) |
1332 | defer env.Destroy() |
1333 | expected := map[string]string{ |
1334 | @@ -81,7 +82,8 @@ |
1335 | c.Assert(err, gc.ErrorMatches, test.errorMsg) |
1336 | continue |
1337 | } |
1338 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
1339 | + ctx := testing.Context(c) |
1340 | + env, err := environs.Prepare(cfg, ctx, configstore.NewMem()) |
1341 | if test.errorMsg != "" { |
1342 | c.Assert(err, gc.ErrorMatches, test.errorMsg) |
1343 | continue |
1344 | |
1345 | === modified file 'provider/dummy/environs.go' |
1346 | --- provider/dummy/environs.go 2014-02-03 06:58:26 +0000 |
1347 | +++ provider/dummy/environs.go 2014-02-18 02:14:09 +0000 |
1348 | @@ -422,7 +422,7 @@ |
1349 | return env, nil |
1350 | } |
1351 | |
1352 | -func (p *environProvider) Prepare(cfg *config.Config) (environs.Environ, error) { |
1353 | +func (p *environProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) { |
1354 | cfg, err := p.prepare(cfg) |
1355 | if err != nil { |
1356 | return nil, err |
1357 | |
1358 | === modified file 'provider/ec2/config_test.go' |
1359 | --- provider/ec2/config_test.go 2013-10-24 00:20:59 +0000 |
1360 | +++ provider/ec2/config_test.go 2014-02-18 02:14:09 +0000 |
1361 | @@ -294,12 +294,13 @@ |
1362 | cfg, err := config.New(config.NoDefaults, attrs) |
1363 | c.Assert(err, gc.IsNil) |
1364 | |
1365 | - env0, err := providerInstance.Prepare(cfg) |
1366 | + ctx := testing.Context(c) |
1367 | + env0, err := providerInstance.Prepare(ctx, cfg) |
1368 | c.Assert(err, gc.IsNil) |
1369 | bucket0 := env0.(*environ).ecfg().controlBucket() |
1370 | c.Assert(bucket0, gc.Matches, "[a-f0-9]{32}") |
1371 | |
1372 | - env1, err := providerInstance.Prepare(cfg) |
1373 | + env1, err := providerInstance.Prepare(ctx, cfg) |
1374 | c.Assert(err, gc.IsNil) |
1375 | bucket1 := env1.(*environ).ecfg().controlBucket() |
1376 | c.Assert(bucket1, gc.Matches, "[a-f0-9]{32}") |
1377 | @@ -315,7 +316,7 @@ |
1378 | cfg, err := config.New(config.NoDefaults, attrs) |
1379 | c.Assert(err, gc.IsNil) |
1380 | |
1381 | - env, err := providerInstance.Prepare(cfg) |
1382 | + env, err := providerInstance.Prepare(testing.Context(c), cfg) |
1383 | c.Assert(err, gc.IsNil) |
1384 | bucket := env.(*environ).ecfg().controlBucket() |
1385 | c.Assert(bucket, gc.Equals, "burblefoo") |
1386 | |
1387 | === modified file 'provider/ec2/ec2.go' |
1388 | --- provider/ec2/ec2.go 2014-01-29 09:58:08 +0000 |
1389 | +++ provider/ec2/ec2.go 2014-02-18 02:14:09 +0000 |
1390 | @@ -207,7 +207,7 @@ |
1391 | return e, nil |
1392 | } |
1393 | |
1394 | -func (p environProvider) Prepare(cfg *config.Config) (environs.Environ, error) { |
1395 | +func (p environProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) { |
1396 | attrs := cfg.UnknownAttrs() |
1397 | if _, ok := attrs["control-bucket"]; !ok { |
1398 | uuid, err := utils.NewUUID() |
1399 | |
1400 | === modified file 'provider/ec2/local_test.go' |
1401 | --- provider/ec2/local_test.go 2014-01-29 06:45:16 +0000 |
1402 | +++ provider/ec2/local_test.go 2014-02-18 02:14:09 +0000 |
1403 | @@ -74,7 +74,7 @@ |
1404 | } |
1405 | cfg, err := config.New(config.NoDefaults, envAttrs) |
1406 | c.Assert(err, gc.IsNil) |
1407 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
1408 | + env, err := environs.Prepare(cfg, coretesting.Context(c), configstore.NewMem()) |
1409 | c.Assert(err, gc.IsNil) |
1410 | c.Assert(env, gc.NotNil) |
1411 | |
1412 | @@ -229,10 +229,6 @@ |
1413 | t.srv.stopServer(c) |
1414 | } |
1415 | |
1416 | -func bootstrapContext(c *gc.C) environs.BootstrapContext { |
1417 | - return envtesting.NewBootstrapContext(coretesting.Context(c)) |
1418 | -} |
1419 | - |
1420 | func (t *localServerSuite) TestPrecheck(c *gc.C) { |
1421 | env := t.Prepare(c) |
1422 | prechecker, ok := env.(environs.Prechecker) |
1423 | @@ -247,7 +243,7 @@ |
1424 | func (t *localServerSuite) TestBootstrapInstanceUserDataAndState(c *gc.C) { |
1425 | env := t.Prepare(c) |
1426 | envtesting.UploadFakeTools(c, env.Storage()) |
1427 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1428 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1429 | c.Assert(err, gc.IsNil) |
1430 | |
1431 | // check that the state holds the id of the bootstrap machine. |
1432 | @@ -334,7 +330,7 @@ |
1433 | func (t *localServerSuite) TestInstanceStatus(c *gc.C) { |
1434 | env := t.Prepare(c) |
1435 | envtesting.UploadFakeTools(c, env.Storage()) |
1436 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1437 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1438 | c.Assert(err, gc.IsNil) |
1439 | t.srv.ec2srv.SetInitialInstanceState(ec2test.Terminated) |
1440 | inst, _ := testing.AssertStartInstance(c, env, "1") |
1441 | @@ -345,7 +341,7 @@ |
1442 | func (t *localServerSuite) TestStartInstanceHardwareCharacteristics(c *gc.C) { |
1443 | env := t.Prepare(c) |
1444 | envtesting.UploadFakeTools(c, env.Storage()) |
1445 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1446 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1447 | c.Assert(err, gc.IsNil) |
1448 | _, hc := testing.AssertStartInstance(c, env, "1") |
1449 | c.Check(*hc.Arch, gc.Equals, "amd64") |
1450 | @@ -357,7 +353,7 @@ |
1451 | func (t *localServerSuite) TestAddresses(c *gc.C) { |
1452 | env := t.Prepare(c) |
1453 | envtesting.UploadFakeTools(c, env.Storage()) |
1454 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1455 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1456 | c.Assert(err, gc.IsNil) |
1457 | inst, _ := testing.AssertStartInstance(c, env, "1") |
1458 | c.Assert(err, gc.IsNil) |
1459 | @@ -442,7 +438,7 @@ |
1460 | |
1461 | cfg, err := config.New(config.NoDefaults, localConfigAttrs) |
1462 | c.Assert(err, gc.IsNil) |
1463 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
1464 | + env, err := environs.Prepare(cfg, coretesting.Context(c), configstore.NewMem()) |
1465 | c.Assert(err, gc.IsNil) |
1466 | t.env = env |
1467 | } |
1468 | |
1469 | === modified file 'provider/joyent/config_test.go' |
1470 | --- provider/joyent/config_test.go 2013-11-21 17:53:05 +0000 |
1471 | +++ provider/joyent/config_test.go 2014-02-18 02:14:09 +0000 |
1472 | @@ -286,7 +286,7 @@ |
1473 | c.Logf("test %d: %s", i, test.info) |
1474 | attrs := validAttrs().Merge(test.insert).Delete(test.remove...) |
1475 | testConfig := newConfig(c, attrs) |
1476 | - preparedConfig, err := joyent.Provider.Prepare(testConfig) |
1477 | + preparedConfig, err := joyent.Provider.Prepare(testing.Context(c), testConfig) |
1478 | if test.err == "" { |
1479 | c.Assert(err, gc.IsNil) |
1480 | attrs := preparedConfig.Config().AllAttrs() |
1481 | |
1482 | === modified file 'provider/joyent/provider.go' |
1483 | --- provider/joyent/provider.go 2014-01-28 04:58:43 +0000 |
1484 | +++ provider/joyent/provider.go 2014-02-18 02:14:09 +0000 |
1485 | @@ -30,7 +30,7 @@ |
1486 | |
1487 | var errNotImplemented = errors.New("not implemented in Joyent provider") |
1488 | |
1489 | -func (environProvider) Prepare(cfg *config.Config) (environs.Environ, error) { |
1490 | +func (environProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) { |
1491 | // This method may be called with an incomplete cfg. It should make every |
1492 | // reasonable effort to create a valid configuration based on the supplied, |
1493 | // and open the resulting environment. |
1494 | |
1495 | === modified file 'provider/local/config_test.go' |
1496 | --- provider/local/config_test.go 2014-01-31 08:44:08 +0000 |
1497 | +++ provider/local/config_test.go 2014-02-18 02:14:09 +0000 |
1498 | @@ -10,7 +10,6 @@ |
1499 | |
1500 | "launchpad.net/juju-core/constraints" |
1501 | "launchpad.net/juju-core/environs/config" |
1502 | - envtesting "launchpad.net/juju-core/environs/testing" |
1503 | "launchpad.net/juju-core/juju/osenv" |
1504 | "launchpad.net/juju-core/provider" |
1505 | "launchpad.net/juju-core/provider/local" |
1506 | @@ -109,8 +108,8 @@ |
1507 | func (s *configSuite) TestBootstrapAsRoot(c *gc.C) { |
1508 | restore := local.SetRootCheckFunction(func() bool { return true }) |
1509 | defer restore() |
1510 | - env, err := local.Provider.Prepare(minimalConfig(c)) |
1511 | + env, err := local.Provider.Prepare(testing.Context(c), minimalConfig(c)) |
1512 | c.Assert(err, gc.IsNil) |
1513 | - err = env.Bootstrap(envtesting.NewBootstrapContext(testing.Context(c)), constraints.Value{}) |
1514 | + err = env.Bootstrap(testing.Context(c), constraints.Value{}) |
1515 | c.Assert(err, gc.ErrorMatches, "bootstrapping a local environment must not be done as root") |
1516 | } |
1517 | |
1518 | === modified file 'provider/local/environ.go' |
1519 | --- provider/local/environ.go 2014-02-14 03:11:25 +0000 |
1520 | +++ provider/local/environ.go 2014-02-18 02:14:09 +0000 |
1521 | @@ -195,8 +195,8 @@ |
1522 | } |
1523 | cmd := exec.Command("sudo", "/bin/bash", "-s") |
1524 | cmd.Stdin = strings.NewReader(script) |
1525 | - cmd.Stdout = ctx.Stdout() |
1526 | - cmd.Stderr = ctx.Stderr() |
1527 | + cmd.Stdout = ctx.GetStdout() |
1528 | + cmd.Stderr = ctx.GetStderr() |
1529 | return cmd.Run() |
1530 | } |
1531 | |
1532 | |
1533 | === modified file 'provider/local/environ_test.go' |
1534 | --- provider/local/environ_test.go 2014-02-12 02:56:13 +0000 |
1535 | +++ provider/local/environ_test.go 2014-02-18 02:14:09 +0000 |
1536 | @@ -161,11 +161,11 @@ |
1537 | return nil |
1538 | }) |
1539 | testConfig := minimalConfig(c) |
1540 | - environ, err := local.Provider.Prepare(testConfig) |
1541 | + ctx := coretesting.Context(c) |
1542 | + environ, err := local.Provider.Prepare(ctx, testConfig) |
1543 | c.Assert(err, gc.IsNil) |
1544 | envtesting.UploadFakeTools(c, environ.Storage()) |
1545 | defer environ.Storage().RemoveAll() |
1546 | - ctx := envtesting.NewBootstrapContext(coretesting.Context(c)) |
1547 | err = environ.Bootstrap(ctx, constraints.Value{}) |
1548 | c.Assert(err, gc.IsNil) |
1549 | } |
1550 | |
1551 | === modified file 'provider/local/environprovider.go' |
1552 | --- provider/local/environprovider.go 2014-02-14 04:26:21 +0000 |
1553 | +++ provider/local/environprovider.go 2014-02-18 02:14:09 +0000 |
1554 | @@ -86,7 +86,7 @@ |
1555 | var detectAptProxies = utils.DetectAptProxies |
1556 | |
1557 | // Prepare implements environs.EnvironProvider.Prepare. |
1558 | -func (p environProvider) Prepare(cfg *config.Config) (environs.Environ, error) { |
1559 | +func (p environProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) { |
1560 | // The user must not set bootstrap-ip; this is determined by the provider, |
1561 | // and its presence used to determine whether the environment has yet been |
1562 | // bootstrapped. |
1563 | |
1564 | === modified file 'provider/local/environprovider_test.go' |
1565 | --- provider/local/environprovider_test.go 2014-02-14 03:41:57 +0000 |
1566 | +++ provider/local/environprovider_test.go 2014-02-18 02:14:09 +0000 |
1567 | @@ -215,7 +215,7 @@ |
1568 | testConfig, err = baseConfig.Apply(test.extraConfig) |
1569 | c.Assert(err, gc.IsNil) |
1570 | } |
1571 | - env, err := provider.Prepare(testConfig) |
1572 | + env, err := provider.Prepare(testing.Context(c), testConfig) |
1573 | c.Assert(err, gc.IsNil) |
1574 | |
1575 | envConfig := env.Config() |
1576 | @@ -269,7 +269,7 @@ |
1577 | s.PatchValue(local.UserCurrent, func() (*user.User, error) { |
1578 | return &user.User{Username: test.userOS}, test.userOSErr |
1579 | }) |
1580 | - env, err := provider.Prepare(basecfg) |
1581 | + env, err := provider.Prepare(testing.Context(c), basecfg) |
1582 | if test.err == "" { |
1583 | c.Assert(err, gc.IsNil) |
1584 | cfg := env.Config() |
1585 | |
1586 | === modified file 'provider/maas/environ_whitebox_test.go' |
1587 | --- provider/maas/environ_whitebox_test.go 2014-01-29 06:45:16 +0000 |
1588 | +++ provider/maas/environ_whitebox_test.go 2014-02-18 02:14:09 +0000 |
1589 | @@ -149,16 +149,12 @@ |
1590 | return utils.Gunzip(data) |
1591 | } |
1592 | |
1593 | -func bootstrapContext(c *gc.C) environs.BootstrapContext { |
1594 | - return envtesting.NewBootstrapContext(coretesting.Context(c)) |
1595 | -} |
1596 | - |
1597 | func (suite *environSuite) TestStartInstanceStartsInstance(c *gc.C) { |
1598 | suite.setupFakeTools(c) |
1599 | env := suite.makeEnviron() |
1600 | // Create node 0: it will be used as the bootstrap node. |
1601 | suite.testMAASObject.TestServer.NewNode(`{"system_id": "node0", "hostname": "host0"}`) |
1602 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1603 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1604 | c.Assert(err, gc.IsNil) |
1605 | // The bootstrap node has been acquired and started. |
1606 | operations := suite.testMAASObject.TestServer.NodeOperations() |
1607 | @@ -372,7 +368,7 @@ |
1608 | suite.setupFakeTools(c) |
1609 | env := suite.makeEnviron() |
1610 | suite.testMAASObject.TestServer.NewNode(`{"system_id": "thenode", "hostname": "host"}`) |
1611 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1612 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1613 | c.Assert(err, gc.IsNil) |
1614 | } |
1615 | |
1616 | @@ -388,14 +384,14 @@ |
1617 | c.Assert(err, gc.IsNil) |
1618 | err = env.SetConfig(cfg) |
1619 | c.Assert(err, gc.IsNil) |
1620 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1621 | + err = bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1622 | c.Check(err, gc.ErrorMatches, "cannot find bootstrap tools.*") |
1623 | } |
1624 | |
1625 | func (suite *environSuite) TestBootstrapFailsIfNoNodes(c *gc.C) { |
1626 | suite.setupFakeTools(c) |
1627 | env := suite.makeEnviron() |
1628 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1629 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1630 | // Since there are no nodes, the attempt to allocate one returns a |
1631 | // 409: Conflict. |
1632 | c.Check(err, gc.ErrorMatches, ".*409.*") |
1633 | @@ -407,7 +403,7 @@ |
1634 | suite.testMAASObject.TestServer.NewNode(`{"system_id": "bootstrapnode", "hostname": "host"}`) |
1635 | |
1636 | // bootstrap.Bootstrap calls Environ.Bootstrap. This works. |
1637 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1638 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1639 | c.Assert(err, gc.IsNil) |
1640 | } |
1641 | |
1642 | |
1643 | === modified file 'provider/maas/environprovider.go' |
1644 | --- provider/maas/environprovider.go 2014-01-28 04:58:43 +0000 |
1645 | +++ provider/maas/environprovider.go 2014-02-18 02:14:09 +0000 |
1646 | @@ -41,7 +41,7 @@ |
1647 | var errAgentNameAlreadySet = errors.New( |
1648 | "maas-agent-name is already set; this should not be set by hand") |
1649 | |
1650 | -func (p maasEnvironProvider) Prepare(cfg *config.Config) (environs.Environ, error) { |
1651 | +func (p maasEnvironProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) { |
1652 | attrs := cfg.UnknownAttrs() |
1653 | oldName, found := attrs["maas-agent-name"] |
1654 | if found && oldName != "" { |
1655 | |
1656 | === modified file 'provider/maas/environprovider_test.go' |
1657 | --- provider/maas/environprovider_test.go 2014-01-22 22:48:54 +0000 |
1658 | +++ provider/maas/environprovider_test.go 2014-02-18 02:14:09 +0000 |
1659 | @@ -52,7 +52,8 @@ |
1660 | config, err := config.New(config.NoDefaults, attrs) |
1661 | c.Assert(err, gc.IsNil) |
1662 | |
1663 | - environ, err := suite.makeEnviron().Provider().Prepare(config) |
1664 | + ctx := testing.Context(c) |
1665 | + environ, err := suite.makeEnviron().Provider().Prepare(ctx, config) |
1666 | c.Assert(err, gc.IsNil) |
1667 | |
1668 | preparedConfig := environ.Config() |
1669 | @@ -76,7 +77,8 @@ |
1670 | config, err := config.New(config.NoDefaults, attrs) |
1671 | c.Assert(err, gc.IsNil) |
1672 | |
1673 | - _, err = suite.makeEnviron().Provider().Prepare(config) |
1674 | + ctx := testing.Context(c) |
1675 | + _, err = suite.makeEnviron().Provider().Prepare(ctx, config) |
1676 | c.Assert(err, gc.Equals, errAgentNameAlreadySet) |
1677 | } |
1678 | |
1679 | |
1680 | === modified file 'provider/manual/environ.go' |
1681 | --- provider/manual/environ.go 2014-02-10 11:35:13 +0000 |
1682 | +++ provider/manual/environ.go 2014-02-18 02:14:09 +0000 |
1683 | @@ -100,7 +100,7 @@ |
1684 | return nil |
1685 | } |
1686 | cfg := e.envConfig() |
1687 | - err := initUbuntuUser(cfg.bootstrapHost(), cfg.bootstrapUser(), cfg.AuthorizedKeys(), ctx.Stdin(), ctx.Stdout()) |
1688 | + err := initUbuntuUser(cfg.bootstrapHost(), cfg.bootstrapUser(), cfg.AuthorizedKeys(), ctx.GetStdin(), ctx.GetStdout()) |
1689 | if err != nil { |
1690 | logger.Errorf("initializing ubuntu user: %v", err) |
1691 | return err |
1692 | |
1693 | === modified file 'provider/manual/environ_test.go' |
1694 | --- provider/manual/environ_test.go 2014-02-10 07:27:49 +0000 |
1695 | +++ provider/manual/environ_test.go 2014-02-18 02:14:09 +0000 |
1696 | @@ -13,7 +13,6 @@ |
1697 | "launchpad.net/juju-core/environs" |
1698 | "launchpad.net/juju-core/environs/manual" |
1699 | "launchpad.net/juju-core/environs/storage" |
1700 | - envtesting "launchpad.net/juju-core/environs/testing" |
1701 | "launchpad.net/juju-core/environs/tools" |
1702 | "launchpad.net/juju-core/instance" |
1703 | coretesting "launchpad.net/juju-core/testing" |
1704 | @@ -139,7 +138,7 @@ |
1705 | return initUbuntuResult |
1706 | }) |
1707 | |
1708 | - ctx := envtesting.NewBootstrapContext(coretesting.Context(c)) |
1709 | + ctx := coretesting.Context(c) |
1710 | initUbuntuResult = errors.New("failed to initialise ubuntu user") |
1711 | c.Assert(s.env.EnableBootstrapStorage(ctx), gc.Equals, initUbuntuResult) |
1712 | initUbuntuResult = nil |
1713 | |
1714 | === modified file 'provider/manual/provider.go' |
1715 | --- provider/manual/provider.go 2014-02-10 12:32:35 +0000 |
1716 | +++ provider/manual/provider.go 2014-02-18 02:14:09 +0000 |
1717 | @@ -21,7 +21,7 @@ |
1718 | |
1719 | var errNoBootstrapHost = errors.New("bootstrap-host must be specified") |
1720 | |
1721 | -func (p manualProvider) Prepare(cfg *config.Config) (environs.Environ, error) { |
1722 | +func (p manualProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) { |
1723 | if _, ok := cfg.UnknownAttrs()["storage-auth-key"]; !ok { |
1724 | uuid, err := utils.NewUUID() |
1725 | if err != nil { |
1726 | |
1727 | === modified file 'provider/manual/provider_test.go' |
1728 | --- provider/manual/provider_test.go 2014-02-10 12:32:35 +0000 |
1729 | +++ provider/manual/provider_test.go 2014-02-18 02:14:09 +0000 |
1730 | @@ -12,6 +12,7 @@ |
1731 | "launchpad.net/juju-core/environs/config" |
1732 | "launchpad.net/juju-core/environs/storage" |
1733 | "launchpad.net/juju-core/provider/manual" |
1734 | + coretesting "launchpad.net/juju-core/testing" |
1735 | jc "launchpad.net/juju-core/testing/checkers" |
1736 | "launchpad.net/juju-core/testing/testbase" |
1737 | "launchpad.net/juju-core/utils" |
1738 | @@ -29,7 +30,7 @@ |
1739 | delete(minimal, "storage-auth-key") |
1740 | testConfig, err := config.New(config.UseDefaults, minimal) |
1741 | c.Assert(err, gc.IsNil) |
1742 | - env, err := manual.ProviderInstance.Prepare(testConfig) |
1743 | + env, err := manual.ProviderInstance.Prepare(coretesting.Context(c), testConfig) |
1744 | c.Assert(err, gc.IsNil) |
1745 | cfg := env.Config() |
1746 | key, _ := cfg.UnknownAttrs()["storage-auth-key"].(string) |
1747 | @@ -41,7 +42,7 @@ |
1748 | minimal["use-sshstorage"] = false |
1749 | testConfig, err := config.New(config.UseDefaults, minimal) |
1750 | c.Assert(err, gc.IsNil) |
1751 | - _, err = manual.ProviderInstance.Prepare(testConfig) |
1752 | + _, err = manual.ProviderInstance.Prepare(coretesting.Context(c), testConfig) |
1753 | c.Assert(err, gc.ErrorMatches, "use-sshstorage must not be specified") |
1754 | |
1755 | s.PatchValue(manual.NewSSHStorage, func(sshHost, storageDir, storageTmpdir string) (storage.Storage, error) { |
1756 | @@ -50,7 +51,7 @@ |
1757 | minimal["use-sshstorage"] = true |
1758 | testConfig, err = config.New(config.UseDefaults, minimal) |
1759 | c.Assert(err, gc.IsNil) |
1760 | - _, err = manual.ProviderInstance.Prepare(testConfig) |
1761 | + _, err = manual.ProviderInstance.Prepare(coretesting.Context(c), testConfig) |
1762 | c.Assert(err, gc.ErrorMatches, "initialising SSH storage failed: newSSHStorage failed") |
1763 | } |
1764 | |
1765 | |
1766 | === modified file 'provider/openstack/config_test.go' |
1767 | --- provider/openstack/config_test.go 2014-01-28 04:58:43 +0000 |
1768 | +++ provider/openstack/config_test.go 2014-02-18 02:14:09 +0000 |
1769 | @@ -460,12 +460,13 @@ |
1770 | cfg, err := config.New(config.NoDefaults, attrs) |
1771 | c.Assert(err, gc.IsNil) |
1772 | |
1773 | - env0, err := providerInstance.Prepare(cfg) |
1774 | + ctx := testing.Context(c) |
1775 | + env0, err := providerInstance.Prepare(ctx, cfg) |
1776 | c.Assert(err, gc.IsNil) |
1777 | bucket0 := env0.(*environ).ecfg().controlBucket() |
1778 | c.Assert(bucket0, gc.Matches, "[a-f0-9]{32}") |
1779 | |
1780 | - env1, err := providerInstance.Prepare(cfg) |
1781 | + env1, err := providerInstance.Prepare(ctx, cfg) |
1782 | c.Assert(err, gc.IsNil) |
1783 | bucket1 := env1.(*environ).ecfg().controlBucket() |
1784 | c.Assert(bucket1, gc.Matches, "[a-f0-9]{32}") |
1785 | @@ -482,7 +483,7 @@ |
1786 | cfg, err := config.New(config.NoDefaults, attrs) |
1787 | c.Assert(err, gc.IsNil) |
1788 | |
1789 | - env, err := providerInstance.Prepare(cfg) |
1790 | + env, err := providerInstance.Prepare(testing.Context(c), cfg) |
1791 | c.Assert(err, gc.IsNil) |
1792 | bucket := env.(*environ).ecfg().controlBucket() |
1793 | c.Assert(bucket, gc.Equals, "burblefoo") |
1794 | |
1795 | === modified file 'provider/openstack/live_test.go' |
1796 | --- provider/openstack/live_test.go 2014-02-17 12:57:06 +0000 |
1797 | +++ provider/openstack/live_test.go 2014-02-18 02:14:09 +0000 |
1798 | @@ -230,7 +230,7 @@ |
1799 | c.Assert(env, gc.NotNil) |
1800 | defer env.Destroy() |
1801 | // Bootstrap and start an instance. |
1802 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1803 | + err = bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1804 | c.Assert(err, gc.IsNil) |
1805 | inst, _ := jujutesting.AssertStartInstance(c, env, "100") |
1806 | // Check whether the instance has the default security group assigned. |
1807 | |
1808 | === modified file 'provider/openstack/local_test.go' |
1809 | --- provider/openstack/local_test.go 2014-02-14 01:03:03 +0000 |
1810 | +++ provider/openstack/local_test.go 2014-02-18 02:14:09 +0000 |
1811 | @@ -252,10 +252,6 @@ |
1812 | s.LoggingSuite.TearDownTest(c) |
1813 | } |
1814 | |
1815 | -func bootstrapContext(c *gc.C) environs.BootstrapContext { |
1816 | - return envtesting.NewBootstrapContext(coretesting.Context(c)) |
1817 | -} |
1818 | - |
1819 | func (s *localServerSuite) TestPrecheck(c *gc.C) { |
1820 | var cons constraints.Value |
1821 | env := s.Prepare(c) |
1822 | @@ -285,7 +281,7 @@ |
1823 | c.Assert(err, gc.IsNil) |
1824 | env, err := environs.New(cfg) |
1825 | c.Assert(err, gc.IsNil) |
1826 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1827 | + err = bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1828 | c.Assert(err, gc.ErrorMatches, "(.|\n)*cannot allocate a public IP as needed(.|\n)*") |
1829 | } |
1830 | |
1831 | @@ -312,9 +308,9 @@ |
1832 | "use-floating-ip": false, |
1833 | })) |
1834 | c.Assert(err, gc.IsNil) |
1835 | - env, err := environs.Prepare(cfg, s.ConfigStore) |
1836 | + env, err := environs.Prepare(cfg, coretesting.Context(c), s.ConfigStore) |
1837 | c.Assert(err, gc.IsNil) |
1838 | - err = bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1839 | + err = bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1840 | c.Assert(err, gc.IsNil) |
1841 | inst, _ := testing.AssertStartInstance(c, env, "100") |
1842 | err = env.StopInstances([]instance.Instance{inst}) |
1843 | @@ -323,7 +319,7 @@ |
1844 | |
1845 | func (s *localServerSuite) TestStartInstanceHardwareCharacteristics(c *gc.C) { |
1846 | env := s.Prepare(c) |
1847 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1848 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1849 | c.Assert(err, gc.IsNil) |
1850 | _, hc := testing.AssertStartInstanceWithConstraints(c, env, "100", constraints.MustParse("mem=1024")) |
1851 | c.Check(*hc.Arch, gc.Equals, "amd64") |
1852 | @@ -522,7 +518,7 @@ |
1853 | // It should be moved to environs.jujutests.Tests. |
1854 | func (s *localServerSuite) TestBootstrapInstanceUserDataAndState(c *gc.C) { |
1855 | env := s.Prepare(c) |
1856 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1857 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1858 | c.Assert(err, gc.IsNil) |
1859 | |
1860 | // check that the state holds the id of the bootstrap machine. |
1861 | @@ -760,7 +756,7 @@ |
1862 | c.Assert(attrs["auth-url"].(string)[:8], gc.Equals, "https://") |
1863 | cfg, err := config.New(config.NoDefaults, attrs) |
1864 | c.Assert(err, gc.IsNil) |
1865 | - s.env, err = environs.Prepare(cfg, configstore.NewMem()) |
1866 | + s.env, err = environs.Prepare(cfg, coretesting.Context(c), configstore.NewMem()) |
1867 | c.Assert(err, gc.IsNil) |
1868 | s.attrs = s.env.Config().AllAttrs() |
1869 | } |
1870 | @@ -817,7 +813,7 @@ |
1871 | openstack.UseTestImageData(metadataStorage, s.cred) |
1872 | defer openstack.RemoveTestImageData(metadataStorage) |
1873 | |
1874 | - err = bootstrap.Bootstrap(bootstrapContext(c), s.env, constraints.Value{}) |
1875 | + err = bootstrap.Bootstrap(coretesting.Context(c), s.env, constraints.Value{}) |
1876 | c.Assert(err, gc.IsNil) |
1877 | } |
1878 | |
1879 | @@ -960,7 +956,7 @@ |
1880 | |
1881 | func (s *localServerSuite) TestAllInstancesIgnoresOtherMachines(c *gc.C) { |
1882 | env := s.Prepare(c) |
1883 | - err := bootstrap.Bootstrap(bootstrapContext(c), env, constraints.Value{}) |
1884 | + err := bootstrap.Bootstrap(coretesting.Context(c), env, constraints.Value{}) |
1885 | c.Assert(err, gc.IsNil) |
1886 | |
1887 | // Check that we see 1 instance in the environment |
1888 | |
1889 | === modified file 'provider/openstack/provider.go' |
1890 | --- provider/openstack/provider.go 2014-01-29 09:58:08 +0000 |
1891 | +++ provider/openstack/provider.go 2014-02-18 02:14:09 +0000 |
1892 | @@ -180,7 +180,7 @@ |
1893 | return e, nil |
1894 | } |
1895 | |
1896 | -func (p environProvider) Prepare(cfg *config.Config) (environs.Environ, error) { |
1897 | +func (p environProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) { |
1898 | attrs := cfg.UnknownAttrs() |
1899 | if _, ok := attrs["control-bucket"]; !ok { |
1900 | uuid, err := utils.NewUUID() |
1901 | |
1902 | === modified file 'state/apiserver/common/environwatcher_test.go' |
1903 | --- state/apiserver/common/environwatcher_test.go 2014-01-21 13:56:50 +0000 |
1904 | +++ state/apiserver/common/environwatcher_test.go 2014-02-18 02:14:09 +0000 |
1905 | @@ -16,6 +16,7 @@ |
1906 | "launchpad.net/juju-core/state/api/params" |
1907 | "launchpad.net/juju-core/state/apiserver/common" |
1908 | apiservertesting "launchpad.net/juju-core/state/apiserver/testing" |
1909 | + "launchpad.net/juju-core/testing" |
1910 | jc "launchpad.net/juju-core/testing/checkers" |
1911 | "launchpad.net/juju-core/testing/testbase" |
1912 | ) |
1913 | @@ -187,7 +188,7 @@ |
1914 | func testingEnvConfig(c *gc.C) *config.Config { |
1915 | cfg, err := config.New(config.NoDefaults, dummy.SampleConfig()) |
1916 | c.Assert(err, gc.IsNil) |
1917 | - env, err := environs.Prepare(cfg, configstore.NewMem()) |
1918 | + env, err := environs.Prepare(cfg, testing.Context(c), configstore.NewMem()) |
1919 | c.Assert(err, gc.IsNil) |
1920 | return env.Config() |
1921 | } |
Reviewers: mp+206082_ code.launchpad. net,
Message:
Please take a look.
Description: BootstrapContex t to Prepare
Pass environs.
This is part one of fixing lp:1279259.
In this CL, we pass context to Prepare,
giving providers an opportunity to prompt
the user to initialise an environment.
Passing context was previously restricted to Storage; this is
Bootstrap and EnableBootstrap
insufficient, as there are many ways to prepare
an environment. It is currently possible to
successfully "Prepare" and environment, but
for the result to be unusable in the manual
provider (e.g. if the bootstrap-host address is
invalid). We should that a successfully Prepared
environment should be able to be Destroyed
(with force).
The next CL will remove BootstrapStorager and fix
lp:1279259 by initialising the ubuntu user during
Prepare.
https:/ /code.launchpad .net/~axwalk/ juju-core/ lp1279259- part1-prepare- context/ +merge/ 206082
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/62780044/
Affected files (+223, -270 lines): juju/bootstrap. go juju/bootstrap_ test.go juju/destroyenv ironment_ test.go juju/synctools. go juju/synctools_ test.go plugins/ juju-metadata/ imagemetadata. go plugins/ juju-metadata/ imagemetadata_ test.go plugins/ juju-metadata/ toolsmetadata_ test.go plugins/ juju-metadata/ validateimageme tadata. go plugins/ juju-metadata/ validatetoolsme tadata. go plugins/ juju-restore/ restore. go bootstrap/ bootstrap_ test.go emptystorage_ test.go imagemetadata/ urls_test. go interface. go jujutest/ livetests. go jujutest/ tests.go manual/ bootstrap. go manual/ bootstrap_ test.go open_test. go storage/ storage_ test.go sync/sync_ test.go testing/ bootstrap. go tools/storage_ test.go tools/tools_ test.go tools/urls_ test.go apiconn_ test.go conn_test. go testing/ conn.go azure/environpr ovider. go common/ bootstrap. go common/ bootstrap_ test.go dummy/config_ test.go dummy/environs. go ec2/config_ test.go ec2/ec2. go ec2/local_ test.go joyent/ config_ test.go joyent/ provider. go local/config_ test.go local/environ. go local/environ_ test.go local/environpr ovider. go local/environpr ovider_ test.go maas/environ_ whitebox_ test.go maas/environpro vider.go maas/environpro vider_test. go manual/ environ. go manual/ environ_ test.go manual/ provider. go manual/ provider_ test.go openstack/ config_ test.go openstack/ live_test. go openstack/ local_test. go openstack/ provider. go apiserver/ common/ environwatcher_ test.go
[revision details]
cmd/cmd.go
cmd/
cmd/
cmd/
cmd/
cmd/
cmd/
cmd/
cmd/
cmd/
cmd/
cmd/
environs/
environs/
environs/
environs/
environs/
environs/
environs/
environs/
environs/open.go
environs/
environs/
environs/
environs/
environs/
environs/
environs/
juju/
juju/
juju/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
provider/
state/