Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package main | 4 package main |
5 | 5 |
6 import ( | 6 import ( |
7 "io/ioutil" | 7 "io/ioutil" |
8 "os" | 8 "os" |
9 "path/filepath" | 9 "path/filepath" |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 usefulVersion.Series = env.Config().DefaultSeries() | 95 usefulVersion.Series = env.Config().DefaultSeries() |
96 envtesting.UploadFakeToolsVersion(c, env.Storage(), usefulVersio n) | 96 envtesting.UploadFakeToolsVersion(c, env.Storage(), usefulVersio n) |
97 } | 97 } |
98 | 98 |
99 // Run command and check for uploads. | 99 // Run command and check for uploads. |
100 opc, errc := runCommand(nil, new(BootstrapCommand), test.args...) | 100 opc, errc := runCommand(nil, new(BootstrapCommand), test.args...) |
101 if uploadCount > 0 { | 101 if uploadCount > 0 { |
102 for i := 0; i < uploadCount; i++ { | 102 for i := 0; i < uploadCount; i++ { |
103 c.Check((<-opc).(dummy.OpPutFile).Env, gc.Equals, "peckh am") | 103 c.Check((<-opc).(dummy.OpPutFile).Env, gc.Equals, "peckh am") |
104 } | 104 } |
105 » » list, err := envtools.FindTools(env, version.Current.Major, core tools.Filter{}) | 105 » » list, err := envtools.FindTools(environs.StorageInstances(env), version.Current.Major, version.Current.Minor, coretools.Filter{}) |
106 c.Check(err, gc.IsNil) | 106 c.Check(err, gc.IsNil) |
107 c.Logf("found: " + list.String()) | 107 c.Logf("found: " + list.String()) |
108 urls := list.URLs() | 108 urls := list.URLs() |
109 c.Check(urls, gc.HasLen, len(test.uploads)) | 109 c.Check(urls, gc.HasLen, len(test.uploads)) |
110 for _, v := range test.uploads { | 110 for _, v := range test.uploads { |
111 c.Logf("seeking: " + v) | 111 c.Logf("seeking: " + v) |
112 vers := version.MustParseBinary(v) | 112 vers := version.MustParseBinary(v) |
113 _, found := urls[vers] | 113 _, found := urls[vers] |
114 c.Check(found, gc.Equals, true) | 114 c.Check(found, gc.Equals, true) |
115 } | 115 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 defer fake.Restore() | 221 defer fake.Restore() |
222 | 222 |
223 // Bootstrap the environment now detects the missing | 223 // Bootstrap the environment now detects the missing |
224 // tools and automatically synchronizes them from the | 224 // tools and automatically synchronizes them from the |
225 // storage above. | 225 // storage above. |
226 ctx := coretesting.Context(c) | 226 ctx := coretesting.Context(c) |
227 code := cmd.Main(&BootstrapCommand{}, ctx, nil) | 227 code := cmd.Main(&BootstrapCommand{}, ctx, nil) |
228 c.Check(code, gc.Equals, 0) | 228 c.Check(code, gc.Equals, 0) |
229 | 229 |
230 // Now check the available tools which are the 1.0.0 envtools. | 230 // Now check the available tools which are the 1.0.0 envtools. |
231 » checkTools(c, env, v100All) | 231 » checkTools(c, env, v120All) |
jameinel
2013/08/27 13:08:52
the comment should be updated to match.
wallyworld
2013/08/27 13:26:24
Done.
| |
232 } | 232 } |
233 | 233 |
234 func (s *BootstrapSuite) TestAutoSyncLocalSource(c *gc.C) { | 234 func (s *BootstrapSuite) TestAutoSyncLocalSource(c *gc.C) { |
235 // Prepare a tools directory for testing and store the | 235 // Prepare a tools directory for testing and store the |
236 // dummy tools in there. | 236 // dummy tools in there. |
237 source := createToolsSource(c) | 237 source := createToolsSource(c) |
238 | 238 |
239 // Change the version and ensure its later restoring. | 239 // Change the version and ensure its later restoring. |
240 origVersion := version.Current | 240 origVersion := version.Current |
241 version.Current.Number = version.MustParse("1.2.3") | 241 version.Current.Number = version.MustParse("1.2.3") |
242 defer func() { | 242 defer func() { |
243 version.Current = origVersion | 243 version.Current = origVersion |
244 }() | 244 }() |
245 | 245 |
246 // Create home with dummy provider and remove all | 246 // Create home with dummy provider and remove all |
247 // of its envtools. | 247 // of its envtools. |
248 env, fake := makeEmptyFakeHome(c) | 248 env, fake := makeEmptyFakeHome(c) |
249 defer fake.Restore() | 249 defer fake.Restore() |
250 | 250 |
251 // Bootstrap the environment with an invalid source. | 251 // Bootstrap the environment with an invalid source. |
252 // The command returns with an error. | 252 // The command returns with an error. |
253 ctx := coretesting.Context(c) | 253 ctx := coretesting.Context(c) |
254 code := cmd.Main(&BootstrapCommand{}, ctx, []string{"--source", c.MkDir( )}) | 254 code := cmd.Main(&BootstrapCommand{}, ctx, []string{"--source", c.MkDir( )}) |
255 c.Check(code, gc.Equals, 1) | 255 c.Check(code, gc.Equals, 1) |
256 | 256 |
257 // Now check that there are no tools available. | 257 // Now check that there are no tools available. |
258 » _, err := envtools.FindTools(env, version.Current.Major, coretools.Filte r{}) | 258 » _, err := envtools.FindTools(environs.StorageInstances(env), version.Cur rent.Major, version.Current.Minor, coretools.Filter{}) |
259 c.Assert(err, gc.ErrorMatches, "no tools available") | 259 c.Assert(err, gc.ErrorMatches, "no tools available") |
260 | 260 |
261 // Bootstrap the environment with the valid source. This time | 261 // Bootstrap the environment with the valid source. This time |
262 // the bootstrapping has to show no error, because the tools | 262 // the bootstrapping has to show no error, because the tools |
263 // are automatically synchronized. | 263 // are automatically synchronized. |
264 ctx = coretesting.Context(c) | 264 ctx = coretesting.Context(c) |
265 code = cmd.Main(&BootstrapCommand{}, ctx, []string{"--source", source}) | 265 code = cmd.Main(&BootstrapCommand{}, ctx, []string{"--source", source}) |
266 c.Check(code, gc.Equals, 0) | 266 c.Check(code, gc.Equals, 0) |
267 | 267 |
268 // Now check the available tools which are the 1.0.0 envtools. | 268 // Now check the available tools which are the 1.0.0 envtools. |
269 » checkTools(c, env, v100All) | 269 » checkTools(c, env, v120All) |
jameinel
2013/08/27 13:08:52
ditto
wallyworld
2013/08/27 13:26:24
Done.
| |
270 } | 270 } |
271 | 271 |
272 // createToolsStore creates the fake tools store. | 272 // createToolsStore creates the fake tools store. |
273 func createToolsStore(c *gc.C) func() { | 273 func createToolsStore(c *gc.C) func() { |
274 storage, err := envtesting.NewEC2HTTPTestStorage("127.0.0.1") | 274 storage, err := envtesting.NewEC2HTTPTestStorage("127.0.0.1") |
275 c.Assert(err, gc.IsNil) | 275 c.Assert(err, gc.IsNil) |
276 origLocation := sync.DefaultToolsLocation | 276 origLocation := sync.DefaultToolsLocation |
277 sync.DefaultToolsLocation = storage.Location() | 277 sync.DefaultToolsLocation = storage.Location() |
278 for _, vers := range vAll { | 278 for _, vers := range vAll { |
279 storage.PutBinary(vers) | 279 storage.PutBinary(vers) |
(...skipping 26 matching lines...) Expand all Loading... | |
306 fake := coretesting.MakeFakeHome(c, envConfig) | 306 fake := coretesting.MakeFakeHome(c, envConfig) |
307 dummy.Reset() | 307 dummy.Reset() |
308 env, err := environs.NewFromName("peckham") | 308 env, err := environs.NewFromName("peckham") |
309 c.Assert(err, gc.IsNil) | 309 c.Assert(err, gc.IsNil) |
310 envtesting.RemoveAllTools(c, env) | 310 envtesting.RemoveAllTools(c, env) |
311 return env, fake | 311 return env, fake |
312 } | 312 } |
313 | 313 |
314 // checkTools check if the environment contains the passed envtools. | 314 // checkTools check if the environment contains the passed envtools. |
315 func checkTools(c *gc.C, env environs.Environ, expected []version.Binary) { | 315 func checkTools(c *gc.C, env environs.Environ, expected []version.Binary) { |
316 » list, err := envtools.FindTools(env, version.Current.Major, coretools.Fi lter{}) | 316 » list, err := envtools.FindTools(environs.StorageInstances(env), version. Current.Major, version.Current.Minor, coretools.Filter{}) |
317 c.Check(err, gc.IsNil) | 317 c.Check(err, gc.IsNil) |
318 c.Logf("found: " + list.String()) | 318 c.Logf("found: " + list.String()) |
319 urls := list.URLs() | 319 urls := list.URLs() |
320 c.Check(urls, gc.HasLen, len(expected)) | 320 c.Check(urls, gc.HasLen, len(expected)) |
321 } | 321 } |
322 | 322 |
323 var ( | 323 var ( |
324 v100d64 = version.MustParseBinary("1.0.0-defaultseries-amd64") | 324 v100d64 = version.MustParseBinary("1.0.0-defaultseries-amd64") |
325 v100p64 = version.MustParseBinary("1.0.0-precise-amd64") | 325 v100p64 = version.MustParseBinary("1.0.0-precise-amd64") |
326 v100q32 = version.MustParseBinary("1.0.0-quantal-i386") | 326 v100q32 = version.MustParseBinary("1.0.0-quantal-i386") |
327 v100q64 = version.MustParseBinary("1.0.0-quantal-amd64") | 327 v100q64 = version.MustParseBinary("1.0.0-quantal-amd64") |
328 v120d64 = version.MustParseBinary("1.2.0-defaultseries-amd64") | |
329 v120p64 = version.MustParseBinary("1.2.0-precise-amd64") | |
330 v120q32 = version.MustParseBinary("1.2.0-quantal-i386") | |
331 v120q64 = version.MustParseBinary("1.2.0-quantal-amd64") | |
328 v190p32 = version.MustParseBinary("1.9.0-precise-i386") | 332 v190p32 = version.MustParseBinary("1.9.0-precise-i386") |
329 v190q64 = version.MustParseBinary("1.9.0-quantal-amd64") | 333 v190q64 = version.MustParseBinary("1.9.0-quantal-amd64") |
330 v200p64 = version.MustParseBinary("2.0.0-precise-amd64") | 334 v200p64 = version.MustParseBinary("2.0.0-precise-amd64") |
331 v100All = []version.Binary{ | 335 v100All = []version.Binary{ |
332 v100d64, v100p64, v100q64, v100q32, | 336 v100d64, v100p64, v100q64, v100q32, |
333 } | 337 } |
338 v120All = []version.Binary{ | |
339 v120d64, v120p64, v120q64, v120q32, | |
340 } | |
334 vAll = []version.Binary{ | 341 vAll = []version.Binary{ |
335 v100d64, v100p64, v100q32, v100q64, | 342 v100d64, v100p64, v100q32, v100q64, |
343 v120d64, v120p64, v120q32, v120q64, | |
336 v190p32, v190q64, | 344 v190p32, v190q64, |
337 v200p64, | 345 v200p64, |
338 } | 346 } |
339 ) | 347 ) |
OLD | NEW |