OLD | NEW |
1 // Copyright 2013 Canonical Ltd. | 1 // Copyright 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 azure | 4 package azure |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | |
8 | |
9 gc "launchpad.net/gocheck" | 7 gc "launchpad.net/gocheck" |
10 "launchpad.net/gwacl" | 8 "launchpad.net/gwacl" |
11 | 9 |
12 "launchpad.net/juju-core/constraints" | 10 "launchpad.net/juju-core/constraints" |
| 11 "launchpad.net/juju-core/environs" |
13 "launchpad.net/juju-core/environs/imagemetadata" | 12 "launchpad.net/juju-core/environs/imagemetadata" |
14 "launchpad.net/juju-core/environs/instances" | 13 "launchpad.net/juju-core/environs/instances" |
15 "launchpad.net/juju-core/environs/jujutest" | |
16 "launchpad.net/juju-core/environs/simplestreams" | 14 "launchpad.net/juju-core/environs/simplestreams" |
| 15 "launchpad.net/juju-core/environs/testing" |
17 ) | 16 ) |
18 | 17 |
19 type instanceTypeSuite struct{} | 18 type instanceTypeSuite struct { |
| 19 » providerSuite |
| 20 } |
20 | 21 |
21 var _ = gc.Suite(&instanceTypeSuite{}) | 22 var _ = gc.Suite(&instanceTypeSuite{}) |
22 | 23 |
| 24 func (s *instanceTypeSuite) SetUpTest(c *gc.C) { |
| 25 s.providerSuite.SetUpTest(c) |
| 26 s.PatchValue(&imagemetadata.DefaultBaseURL, "") |
| 27 s.PatchValue(&signedImageDataOnly, false) |
| 28 } |
| 29 |
| 30 // setDummyStorage injects the local provider's fake storage implementation |
| 31 // into the given environment, so that tests can manipulate storage as if it |
| 32 // were real. |
| 33 func (s *instanceTypeSuite) setDummyStorage(c *gc.C, env *azureEnviron) { |
| 34 closer, storage, _ := testing.CreateLocalTestStorage(c) |
| 35 env.storage = storage |
| 36 s.AddCleanup(func(c *gc.C) { closer.Close() }) |
| 37 } |
| 38 |
23 func (*instanceTypeSuite) TestNewPreferredTypesAcceptsNil(c *gc.C) { | 39 func (*instanceTypeSuite) TestNewPreferredTypesAcceptsNil(c *gc.C) { |
24 types := newPreferredTypes(nil) | 40 types := newPreferredTypes(nil) |
25 | 41 |
26 c.Check(types, gc.HasLen, 0) | 42 c.Check(types, gc.HasLen, 0) |
27 c.Check(types.Len(), gc.Equals, 0) | 43 c.Check(types.Len(), gc.Equals, 0) |
28 } | 44 } |
29 | 45 |
30 func (*instanceTypeSuite) TestNewPreferredTypesRepresentsInput(c *gc.C) { | 46 func (*instanceTypeSuite) TestNewPreferredTypesRepresentsInput(c *gc.C) { |
31 availableTypes := []gwacl.RoleSize{{Name: "Humongous", Cost: 123}} | 47 availableTypes := []gwacl.RoleSize{{Name: "Humongous", Cost: 123}} |
32 | 48 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 223 |
208 choice, err := selectMachineType(availableTypes, constraints.Value{CpuCo
res: &desiredCores}) | 224 choice, err := selectMachineType(availableTypes, constraints.Value{CpuCo
res: &desiredCores}) |
209 c.Assert(err, gc.IsNil) | 225 c.Assert(err, gc.IsNil) |
210 | 226 |
211 // Out of these options, selectMachineType picks not the first; not | 227 // Out of these options, selectMachineType picks not the first; not |
212 // the cheapest; not the biggest; not the last; but the cheapest type | 228 // the cheapest; not the biggest; not the last; but the cheapest type |
213 // of machine that meets requirements. | 229 // of machine that meets requirements. |
214 c.Check(choice.Name, gc.Equals, "Lambo") | 230 c.Check(choice.Name, gc.Equals, "Lambo") |
215 } | 231 } |
216 | 232 |
217 // fakeSimpleStreamsScheme is a fake protocol which tests can use for their | 233 func (s *instanceTypeSuite) setupEnvWithDummyMetadata(c *gc.C) *azureEnviron { |
218 // simplestreams base URLs. | 234 » envAttrs := makeAzureConfigMap(c) |
219 const fakeSimpleStreamsScheme = "azure-simplestreams-test" | 235 » envAttrs["location"] = "West US" |
220 | 236 » env := makeEnvironWithConfig(c, envAttrs) |
221 // testRoundTripper is a fake http-like transport for injecting fake | 237 » s.setDummyStorage(c, env) |
222 // simplestream responses into these tests. | 238 » images := []*imagemetadata.ImageMetadata{ |
223 var testRoundTripper = jujutest.ProxyRoundTripper{} | 239 » » { |
224 | 240 » » » Id: "image-id", |
225 func init() { | 241 » » » VirtType: "Hyper-V", |
226 » // Route any request for a URL on the fakeSimpleStreamsScheme protocol | 242 » » » Arch: "amd64", |
227 » // to testRoundTripper. | 243 » » » RegionName: "West US", |
228 » testRoundTripper.RegisterForScheme(fakeSimpleStreamsScheme) | 244 » » » Endpoint: "https://management.core.windows.net/", |
| 245 » » }, |
| 246 » } |
| 247 » makeTestMetadata(c, env, "precise", "West US", images) |
| 248 » return env |
229 } | 249 } |
230 | 250 |
231 // prepareSimpleStreamsResponse sets up a fake response for our query to | 251 func (s *instanceTypeSuite) TestFindMatchingImagesReturnsErrorIfNoneFound(c *gc.
C) { |
232 // SimpleStreams. | 252 » env := s.setupEnvWithDummyMetadata(c) |
233 // | 253 » _, err := findMatchingImages(env, "West US", "saucy", []string{"amd64"}) |
234 // It returns a cleanup function, which you must call to reset things when | 254 » c.Assert(err, gc.NotNil) |
235 // done. | 255 » c.Assert(err, gc.ErrorMatches, "no OS images found for location .*") |
236 func prepareSimpleStreamsResponse(stream, location, series, release, arch, json
string) func() { | |
237 » fakeURL := fakeSimpleStreamsScheme + "://" | |
238 » originalAzureURLs := baseURLs | |
239 » originalDefaultURL := imagemetadata.DefaultBaseURL | |
240 » baseURLs = []string{fakeURL} | |
241 » imagemetadata.DefaultBaseURL = "" | |
242 | |
243 » originalSignedOnly := signedImageDataOnly | |
244 » signedImageDataOnly = false | |
245 | |
246 » azureName := fmt.Sprintf("com.ubuntu.cloud:%s:azure", stream) | |
247 » streamSuffix := "" | |
248 » if stream != "released" { | |
249 » » streamSuffix = "." + stream | |
250 » } | |
251 | |
252 » // Generate an index. It will point to an Azure index with the | |
253 » // caller's json. | |
254 » index := fmt.Sprintf(` | |
255 » » { | |
256 » » "index": { | |
257 » » %q: { | |
258 » » "updated": "Thu, 08 Aug 2013 07:55:58 +0000", | |
259 » » "clouds": [ | |
260 » » » { | |
261 » » » "region": %q, | |
262 » » » "endpoint": "https://management.core.windows.net/" | |
263 » » » } | |
264 » » ], | |
265 » » "format": "products:1.0", | |
266 » » "datatype": "image-ids", | |
267 » » "cloudname": "azure", | |
268 » » "products": [ | |
269 » » » "com.ubuntu.cloud%s:server:%s:%s" | |
270 » » ], | |
271 » » "path": "/v1/%s.json" | |
272 » » } | |
273 » » }, | |
274 » » "updated": "Thu, 08 Aug 2013 07:55:58 +0000", | |
275 » » "format": "index:1.0" | |
276 » » } | |
277 » » `, azureName, location, streamSuffix, release, arch, azureName) | |
278 » files := map[string]string{ | |
279 » » "/v1/index.json": index, | |
280 » » "/v1/" + azureName + ".json": json, | |
281 » } | |
282 » testRoundTripper.Sub = jujutest.NewCannedRoundTripper(files, nil) | |
283 » return func() { | |
284 » » baseURLs = originalAzureURLs | |
285 » » imagemetadata.DefaultBaseURL = originalDefaultURL | |
286 » » signedImageDataOnly = originalSignedOnly | |
287 » » testRoundTripper.Sub = nil | |
288 » } | |
289 } | 256 } |
290 | 257 |
291 func (*environSuite) TestGetEndpoint(c *gc.C) { | 258 func (s *instanceTypeSuite) TestFindMatchingImagesReturnsReleasedImages(c *gc.C)
{ |
292 » c.Check( | 259 » env := s.setupEnvWithDummyMetadata(c) |
293 » » getEndpoint("West US"), | 260 » images, err := findMatchingImages(env, "West US", "precise", []string{"a
md64"}) |
294 » » gc.Equals, | 261 » c.Assert(err, gc.IsNil) |
295 » » "https://management.core.windows.net/") | 262 » c.Assert(images, gc.HasLen, 1) |
296 » c.Check( | 263 » c.Check(images[0].Id, gc.Equals, "image-id") |
297 » » getEndpoint("China East"), | |
298 » » gc.Equals, | |
299 » » "https://management.core.chinacloudapi.cn/") | |
300 } | 264 } |
301 | 265 |
302 func (*instanceTypeSuite) TestFindMatchingImagesReturnsErrorIfNoneFound(c *gc.C)
{ | 266 func (s *instanceTypeSuite) TestFindMatchingImagesReturnsDailyImages(c *gc.C) { |
303 » emptyResponse := ` | |
304 » » { | |
305 » » "format": "products:1.0" | |
306 » » } | |
307 » » ` | |
308 » cleanup := prepareSimpleStreamsResponse("released", "West US", "precise"
, "12.04", "amd64", emptyResponse) | |
309 » defer cleanup() | |
310 | |
311 » env := makeEnviron(c) | |
312 » _, err := findMatchingImages(env, "West US", "saucy", []string{"amd64"}) | |
313 » c.Assert(err, gc.NotNil) | |
314 | |
315 » c.Check(err, gc.ErrorMatches, "no OS images found for location .*") | |
316 } | |
317 | |
318 func (*instanceTypeSuite) TestFindMatchingImagesReturnsReleasedImages(c *gc.C) { | |
319 » // Based on real-world simplestreams data, pared down to a minimum: | |
320 » response := ` | |
321 » { | |
322 » "updated": "Tue, 09 Jul 2013 22:35:10 +0000", | |
323 » "datatype": "image-ids", | |
324 » "content_id": "com.ubuntu.cloud:released", | |
325 » "products": { | |
326 » "com.ubuntu.cloud:server:12.04:amd64": { | |
327 » "release": "precise", | |
328 » "version": "12.04", | |
329 » "arch": "amd64", | |
330 » "versions": { | |
331 » "20130603": { | |
332 » "items": { | |
333 » "euww1i3": { | |
334 » "virt": "Hyper-V", | |
335 » "crsn": "West Europe", | |
336 » "root_size": "30GB", | |
337 » "id": "MATCHING-IMAGE" | |
338 » } | |
339 » }, | |
340 » "pub_name": "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-12_04_2-LTS-a
md64-server-20130603-en-us-30GB", | |
341 » "publabel": "Ubuntu Server 12.04.2 LTS", | |
342 » "label": "release" | |
343 » } | |
344 » } | |
345 » } | |
346 » }, | |
347 » "format": "products:1.0", | |
348 » "_aliases": { | |
349 » "crsn": { | |
350 » "West Europe": { | |
351 » "region": "West Europe", | |
352 » "endpoint": "https://management.core.windows.net/" | |
353 » } | |
354 » } | |
355 » } | |
356 » } | |
357 » ` | |
358 » cleanup := prepareSimpleStreamsResponse("released", "West Europe", "prec
ise", "12.04", "amd64", response) | |
359 » defer cleanup() | |
360 | |
361 » env := makeEnviron(c) | |
362 » images, err := findMatchingImages(env, "West Europe", "precise", []strin
g{"amd64"}) | |
363 » c.Assert(err, gc.IsNil) | |
364 | |
365 » c.Assert(images, gc.HasLen, 1) | |
366 » c.Check(images[0].Id, gc.Equals, "MATCHING-IMAGE") | |
367 } | |
368 | |
369 func (*instanceTypeSuite) TestFindMatchingImagesReturnsDailyImages(c *gc.C) { | |
370 » // Based on real-world simplestreams data, pared down to a minimum: | |
371 » response := ` | |
372 » { | |
373 » "updated": "Tue, 09 Jul 2013 22:35:10 +0000", | |
374 » "datatype": "image-ids", | |
375 » "content_id": "com.ubuntu.cloud:daily:azure", | |
376 » "products": { | |
377 » "com.ubuntu.cloud.daily:server:12.04:amd64": { | |
378 » "release": "precise", | |
379 » "version": "12.04", | |
380 » "arch": "amd64", | |
381 » "versions": { | |
382 » "20130603": { | |
383 » "items": { | |
384 » "euww1i3": { | |
385 » "virt": "Hyper-V", | |
386 » "crsn": "West Europe", | |
387 » "root_size": "30GB", | |
388 » "id": "MATCHING-IMAGE" | |
389 » } | |
390 » }, | |
391 » "pub_name": "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-12_04_2-LTS-a
md64-server-20130603-en-us-30GB", | |
392 » "publabel": "Ubuntu Server 12.04.2 LTS", | |
393 » "label": "release" | |
394 » } | |
395 » } | |
396 » } | |
397 » }, | |
398 » "format": "products:1.0", | |
399 » "_aliases": { | |
400 » "crsn": { | |
401 » "West Europe": { | |
402 » "region": "West Europe", | |
403 » "endpoint": "https://management.core.windows.net/" | |
404 » } | |
405 » } | |
406 » } | |
407 » } | |
408 » ` | |
409 » cleanup := prepareSimpleStreamsResponse("daily", "West Europe", "precise
", "12.04", "amd64", response) | |
410 » defer cleanup() | |
411 | |
412 envAttrs := makeAzureConfigMap(c) | 267 envAttrs := makeAzureConfigMap(c) |
413 envAttrs["image-stream"] = "daily" | 268 envAttrs["image-stream"] = "daily" |
| 269 envAttrs["location"] = "West US" |
414 env := makeEnvironWithConfig(c, envAttrs) | 270 env := makeEnvironWithConfig(c, envAttrs) |
415 » images, err := findMatchingImages(env, "West Europe", "precise", []strin
g{"amd64"}) | 271 » s.setDummyStorage(c, env) |
| 272 » images := []*imagemetadata.ImageMetadata{ |
| 273 » » { |
| 274 » » » Id: "image-id", |
| 275 » » » VirtType: "Hyper-V", |
| 276 » » » Arch: "amd64", |
| 277 » » » RegionName: "West US", |
| 278 » » » Endpoint: "https://management.core.windows.net/", |
| 279 » » » Stream: "daily", |
| 280 » » }, |
| 281 » } |
| 282 » makeTestMetadata(c, env, "precise", "West US", images) |
| 283 » images, err := findMatchingImages(env, "West US", "precise", []string{"a
md64"}) |
416 c.Assert(err, gc.IsNil) | 284 c.Assert(err, gc.IsNil) |
417 | |
418 c.Assert(images, gc.HasLen, 1) | 285 c.Assert(images, gc.HasLen, 1) |
419 » c.Check(images[0].Id, gc.Equals, "MATCHING-IMAGE") | 286 » c.Assert(images[0].Id, gc.Equals, "image-id") |
420 } | 287 } |
421 | 288 |
422 func (*instanceTypeSuite) TestNewInstanceTypeConvertsRoleSize(c *gc.C) { | 289 func (*instanceTypeSuite) TestNewInstanceTypeConvertsRoleSize(c *gc.C) { |
423 roleSize := gwacl.RoleSize{ | 290 roleSize := gwacl.RoleSize{ |
424 Name: "Outrageous", | 291 Name: "Outrageous", |
425 CpuCores: 128, | 292 CpuCores: 128, |
426 Mem: 4 * gwacl.TB, | 293 Mem: 4 * gwacl.TB, |
427 OSDiskSpaceCloud: 48 * gwacl.TB, | 294 OSDiskSpaceCloud: 48 * gwacl.TB, |
428 OSDiskSpaceVirt: 50 * gwacl.TB, | 295 OSDiskSpaceVirt: 50 * gwacl.TB, |
429 MaxDataDisks: 20, | 296 MaxDataDisks: 20, |
430 Cost: 999999500, | 297 Cost: 999999500, |
431 } | 298 } |
432 vtype := "Hyper-V" | 299 vtype := "Hyper-V" |
433 var cpupower uint64 = 100 | 300 var cpupower uint64 = 100 |
434 expectation := instances.InstanceType{ | 301 expectation := instances.InstanceType{ |
435 Id: roleSize.Name, | 302 Id: roleSize.Name, |
436 Name: roleSize.Name, | 303 Name: roleSize.Name, |
437 Arches: []string{"amd64", "i386"}, | |
438 CpuCores: roleSize.CpuCores, | 304 CpuCores: roleSize.CpuCores, |
439 Mem: roleSize.Mem, | 305 Mem: roleSize.Mem, |
440 RootDisk: roleSize.OSDiskSpaceVirt, | 306 RootDisk: roleSize.OSDiskSpaceVirt, |
441 Cost: roleSize.Cost, | 307 Cost: roleSize.Cost, |
442 » » VType: &vtype, | 308 » » VirtType: &vtype, |
443 CpuPower: &cpupower, | 309 CpuPower: &cpupower, |
444 } | 310 } |
445 » c.Check(newInstanceType(roleSize), gc.DeepEquals, expectation) | 311 » c.Assert(newInstanceType(roleSize), gc.DeepEquals, expectation) |
446 } | 312 } |
447 | 313 |
448 func (*instanceTypeSuite) TestListInstanceTypesAcceptsNil(c *gc.C) { | 314 func (s *instanceTypeSuite) TestListInstanceTypesAcceptsNil(c *gc.C) { |
449 » c.Check(listInstanceTypes(nil), gc.HasLen, 0) | 315 » env := s.setupEnvWithDummyMetadata(c) |
| 316 » types, err := listInstanceTypes(env, nil) |
| 317 » c.Assert(err, gc.IsNil) |
| 318 » c.Check(types, gc.HasLen, 0) |
450 } | 319 } |
451 | 320 |
452 func (*instanceTypeSuite) TestListInstanceTypesMaintainsOrder(c *gc.C) { | 321 func (s *instanceTypeSuite) TestListInstanceTypesMaintainsOrder(c *gc.C) { |
453 roleSizes := []gwacl.RoleSize{ | 322 roleSizes := []gwacl.RoleSize{ |
454 {Name: "Biggish"}, | 323 {Name: "Biggish"}, |
455 {Name: "Tiny"}, | 324 {Name: "Tiny"}, |
456 {Name: "Huge"}, | 325 {Name: "Huge"}, |
457 {Name: "Miniscule"}, | 326 {Name: "Miniscule"}, |
458 } | 327 } |
459 | 328 |
460 expectation := make([]instances.InstanceType, len(roleSizes)) | 329 expectation := make([]instances.InstanceType, len(roleSizes)) |
461 for index, roleSize := range roleSizes { | 330 for index, roleSize := range roleSizes { |
462 expectation[index] = newInstanceType(roleSize) | 331 expectation[index] = newInstanceType(roleSize) |
| 332 expectation[index].Arches = []string{"amd64"} |
463 } | 333 } |
464 | 334 |
465 » c.Check(listInstanceTypes(roleSizes), gc.DeepEquals, expectation) | 335 » env := s.setupEnvWithDummyMetadata(c) |
| 336 » types, err := listInstanceTypes(env, roleSizes) |
| 337 » c.Assert(err, gc.IsNil) |
| 338 » c.Assert(types, gc.DeepEquals, expectation) |
466 } | 339 } |
467 | 340 |
468 func (*instanceTypeSuite) TestFindInstanceSpecFailsImpossibleRequest(c *gc.C) { | 341 func (*instanceTypeSuite) TestFindInstanceSpecFailsImpossibleRequest(c *gc.C) { |
469 » impossibleConstraint := instances.InstanceConstraint{ | 342 » impossibleConstraint := &instances.InstanceConstraint{ |
470 Series: "precise", | 343 Series: "precise", |
471 Arches: []string{"axp"}, | 344 Arches: []string{"axp"}, |
472 } | 345 } |
473 | 346 |
474 env := makeEnviron(c) | 347 env := makeEnviron(c) |
475 _, err := findInstanceSpec(env, impossibleConstraint) | 348 _, err := findInstanceSpec(env, impossibleConstraint) |
476 c.Assert(err, gc.NotNil) | 349 c.Assert(err, gc.NotNil) |
477 c.Check(err, gc.ErrorMatches, "no OS images found for .*") | 350 c.Check(err, gc.ErrorMatches, "no OS images found for .*") |
478 } | 351 } |
479 | 352 |
480 // patchFetchImageMetadata temporarily replaces imagemetadata.Fetch() with a | 353 func makeTestMetadata(c *gc.C, env environs.Environ, series, location string, im
[]*imagemetadata.ImageMetadata) { |
481 // fake that returns the given canned answer. | 354 » cloudSpec := simplestreams.CloudSpec{ |
482 // It returns a cleanup function, which you must call when done. | 355 » » Region: location, |
483 func patchFetchImageMetadata(cannedResponse []*imagemetadata.ImageMetadata, cann
edError error) func() { | 356 » » Endpoint: "https://management.core.windows.net/", |
484 » original := fetchImageMetadata | |
485 » fetchImageMetadata = func([]simplestreams.DataSource, string, *imagemeta
data.ImageConstraint, bool) ( | |
486 » » []*imagemetadata.ImageMetadata, *simplestreams.ResolveInfo, erro
r) { | |
487 » » return cannedResponse, nil, cannedError | |
488 } | 357 } |
489 » return func() { fetchImageMetadata = original } | 358 » err := imagemetadata.MergeAndWriteMetadata(series, im, &cloudSpec, env.S
torage()) |
| 359 » c.Assert(err, gc.IsNil) |
490 } | 360 } |
491 | 361 |
492 func (*instanceTypeSuite) TestFindInstanceSpecFindsMatch(c *gc.C) { | 362 func (s *instanceTypeSuite) TestFindInstanceSpecFindsMatch(c *gc.C) { |
493 » // We have one OS image. | 363 » env := s.setupEnvWithDummyMetadata(c) |
494 » images := []*imagemetadata.ImageMetadata{ | |
495 » » { | |
496 » » » Id: "image-id", | |
497 » » » VType: "Hyper-V", | |
498 » » » Arch: "amd64", | |
499 » » » RegionAlias: "West US", | |
500 » » » RegionName: "West US", | |
501 » » » Endpoint: "http://localhost/", | |
502 » » }, | |
503 » } | |
504 » cleanup := patchFetchImageMetadata(images, nil) | |
505 » defer cleanup() | |
506 | 364 |
507 // We'll tailor our constraints to describe one particular Azure | 365 // We'll tailor our constraints to describe one particular Azure |
508 // instance type: | 366 // instance type: |
509 aim := gwacl.RoleNameMap["Large"] | 367 aim := gwacl.RoleNameMap["Large"] |
510 » constraints := instances.InstanceConstraint{ | 368 » constraints := &instances.InstanceConstraint{ |
511 Region: "West US", | 369 Region: "West US", |
512 Series: "precise", | 370 Series: "precise", |
513 Arches: []string{"amd64"}, | 371 Arches: []string{"amd64"}, |
514 Constraints: constraints.Value{ | 372 Constraints: constraints.Value{ |
515 CpuCores: &aim.CpuCores, | 373 CpuCores: &aim.CpuCores, |
516 Mem: &aim.Mem, | 374 Mem: &aim.Mem, |
517 }, | 375 }, |
518 } | 376 } |
519 | 377 |
520 // Find a matching instance type and image. | 378 // Find a matching instance type and image. |
521 env := makeEnviron(c) | |
522 spec, err := findInstanceSpec(env, constraints) | 379 spec, err := findInstanceSpec(env, constraints) |
523 c.Assert(err, gc.IsNil) | 380 c.Assert(err, gc.IsNil) |
524 | 381 |
525 // We got the instance type we described in our constraints, and | 382 // We got the instance type we described in our constraints, and |
526 // the image returned by (the fake) simplestreams. | 383 // the image returned by (the fake) simplestreams. |
527 c.Check(spec.InstanceType.Name, gc.Equals, aim.Name) | 384 c.Check(spec.InstanceType.Name, gc.Equals, aim.Name) |
528 c.Check(spec.Image.Id, gc.Equals, "image-id") | 385 c.Check(spec.Image.Id, gc.Equals, "image-id") |
529 } | 386 } |
530 | 387 |
531 func (*instanceTypeSuite) TestFindInstanceSpecSetsBaseline(c *gc.C) { | 388 func (s *instanceTypeSuite) TestFindInstanceSpecSetsBaseline(c *gc.C) { |
532 » images := []*imagemetadata.ImageMetadata{ | 389 » env := s.setupEnvWithDummyMetadata(c) |
533 » » { | |
534 » » » Id: "image-id", | |
535 » » » VType: "Hyper-V", | |
536 » » » Arch: "amd64", | |
537 » » » RegionAlias: "West US", | |
538 » » » RegionName: "West US", | |
539 » » » Endpoint: "http://localhost/", | |
540 » » }, | |
541 » } | |
542 » cleanup := patchFetchImageMetadata(images, nil) | |
543 » defer cleanup() | |
544 | 390 |
545 // findInstanceSpec sets baseline constraints, so that it won't pick | 391 // findInstanceSpec sets baseline constraints, so that it won't pick |
546 // ExtraSmall (which is too small for routine tasks) if you fail to | 392 // ExtraSmall (which is too small for routine tasks) if you fail to |
547 // set sufficient hardware constraints. | 393 // set sufficient hardware constraints. |
548 » anyInstanceType := instances.InstanceConstraint{ | 394 » anyInstanceType := &instances.InstanceConstraint{ |
549 Region: "West US", | 395 Region: "West US", |
550 Series: "precise", | 396 Series: "precise", |
551 Arches: []string{"amd64"}, | 397 Arches: []string{"amd64"}, |
552 } | 398 } |
553 | 399 |
554 env := makeEnviron(c) | |
555 spec, err := findInstanceSpec(env, anyInstanceType) | 400 spec, err := findInstanceSpec(env, anyInstanceType) |
556 c.Assert(err, gc.IsNil) | 401 c.Assert(err, gc.IsNil) |
557 | 402 |
558 c.Check(spec.InstanceType.Name, gc.Equals, "Small") | 403 c.Check(spec.InstanceType.Name, gc.Equals, "Small") |
559 } | 404 } |
OLD | NEW |