Merge lp:~wallyworld/juju-core/amd64plz into lp:~go-bot/juju-core/trunk

Proposed by Ian Booth
Status: Merged
Approved by: Ian Booth
Approved revision: no longer in the source branch.
Merged at revision: 2675
Proposed branch: lp:~wallyworld/juju-core/amd64plz
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 138 lines (+65/-2)
4 files modified
environs/instances/image.go (+24/-1)
environs/instances/image_test.go (+39/-0)
provider/ec2/export_test.go (+1/-0)
provider/ec2/image_test.go (+1/-1)
To merge this branch: bzr merge lp:~wallyworld/juju-core/amd64plz
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+216977@code.launchpad.net

Commit message

Always pick amd64 if it's an option

This branch takes lp:~natefinch/juju-core/045-amd64plz
and fixes some tests.
See https://codereview.appspot.com/89900043/

https://codereview.appspot.com/90720043/

Description of the change

Always pick amd64 if it's an option

This branch takes lp:~natefinch/juju-core/045-amd64plz
and fixes some tests.
See https://codereview.appspot.com/89900043/

https://codereview.appspot.com/90720043/

To post a comment you must log in.
Revision history for this message
Ian Booth (wallyworld) wrote :
Download full text (4.8 KiB)

Reviewers: mp+216977_code.launchpad.net,

Message:
Please take a look.

Description:
Always pick amd64 if it's an option

This branch takes lp:~natefinch/juju-core/045-amd64plz
and fixes some tests.
See https://codereview.appspot.com/89900043/

https://code.launchpad.net/~wallyworld/juju-core/amd64plz/+merge/216977

(do not edit description out of merge proposal)

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

Affected files (+67, -2 lines):
   A [revision details]
   M environs/instances/image.go
   M environs/instances/image_test.go
   M provider/ec2/export_test.go
   M provider/ec2/image_test.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20140424033650-9am3xzxfcelms2x8
+New revision: <email address hidden>

Index: environs/instances/image.go
=== modified file 'environs/instances/image.go'
--- environs/instances/image.go 2014-04-17 05:44:57 +0000
+++ environs/instances/image.go 2014-04-24 04:56:36 +0000
@@ -8,6 +8,7 @@

   "launchpad.net/juju-core/constraints"
   "launchpad.net/juju-core/environs/imagemetadata"
+ "launchpad.net/juju-core/juju/arch"
  )

  // InstanceConstraint constrains the possible instances that may be
@@ -78,14 +79,19 @@
    return nil, fmt.Errorf("no instance types found matching
constraint: %s", ic)
   }

+ specs := []*InstanceSpec{}
   for _, itype := range matchingTypes {
    for _, image := range possibleImages {
     if image.match(itype) {
- return &InstanceSpec{itype, image}, nil
+ specs = append(specs, &InstanceSpec{itype, image})
     }
    }
   }

+ if spec := preferredSpec(specs); spec != nil {
+ return spec, nil
+ }
+
   names := make([]string, len(matchingTypes))
   for i, itype := range matchingTypes {
    names[i] = itype.Name
@@ -93,6 +99,23 @@
   return nil, fmt.Errorf("no %q images in %s matching instance types %v",
ic.Series, ic.Region, names)
  }

+// preferredSpec will if possible return a spec with arch matching that
+// of the host machine.
+func preferredSpec(specs []*InstanceSpec) *InstanceSpec {
+ if len(specs) > 1 {
+ hostArch := arch.HostArch()
+ for _, spec := range specs {
+ if spec.Image.Arch == hostArch {
+ return spec
+ }
+ }
+ }
+ if len(specs) > 0 {
+ return specs[0]
+ }
+ return nil
+}
+
  // Image holds the attributes that vary amongst relevant images for
  // a given series in a given region.
  type Image struct {

Index: environs/instances/image_test.go
=== modified file 'environs/instances/image_test.go'
--- environs/instances/image_test.go 2014-04-18 13:58:13 +0000
+++ environs/instances/image_test.go 2014-04-23 21:04:24 +0000
@@ -11,6 +11,7 @@
   "launchpad.net/juju-core/constraints"
   "launchpad.net/juju-core/environs/imagemetadata"
   "launchpad.net/juju-core/environs/simplestreams"
+ "launchpad.net/juju-core/juju/arch"
   "launchpad.net/juju-core/testing/testbase"
   "launchpad.net/juju-core/utils"
  )
@@ -306,6 +307,44 @@
   }
  }

+func (s *imageSuite) TestPreferredSpec(c *gc.C) {
+ type prefTest struct {
+ desc string
+ specs []*Instan...

Read more...

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'environs/instances/image.go'
--- environs/instances/image.go 2014-04-17 05:44:57 +0000
+++ environs/instances/image.go 2014-04-24 05:00:30 +0000
@@ -8,6 +8,7 @@
88
9 "launchpad.net/juju-core/constraints"9 "launchpad.net/juju-core/constraints"
10 "launchpad.net/juju-core/environs/imagemetadata"10 "launchpad.net/juju-core/environs/imagemetadata"
11 "launchpad.net/juju-core/juju/arch"
11)12)
1213
13// InstanceConstraint constrains the possible instances that may be14// InstanceConstraint constrains the possible instances that may be
@@ -78,14 +79,19 @@
78 return nil, fmt.Errorf("no instance types found matching constraint: %s", ic)79 return nil, fmt.Errorf("no instance types found matching constraint: %s", ic)
79 }80 }
8081
82 specs := []*InstanceSpec{}
81 for _, itype := range matchingTypes {83 for _, itype := range matchingTypes {
82 for _, image := range possibleImages {84 for _, image := range possibleImages {
83 if image.match(itype) {85 if image.match(itype) {
84 return &InstanceSpec{itype, image}, nil86 specs = append(specs, &InstanceSpec{itype, image})
85 }87 }
86 }88 }
87 }89 }
8890
91 if spec := preferredSpec(specs); spec != nil {
92 return spec, nil
93 }
94
89 names := make([]string, len(matchingTypes))95 names := make([]string, len(matchingTypes))
90 for i, itype := range matchingTypes {96 for i, itype := range matchingTypes {
91 names[i] = itype.Name97 names[i] = itype.Name
@@ -93,6 +99,23 @@
93 return nil, fmt.Errorf("no %q images in %s matching instance types %v", ic.Series, ic.Region, names)99 return nil, fmt.Errorf("no %q images in %s matching instance types %v", ic.Series, ic.Region, names)
94}100}
95101
102// preferredSpec will if possible return a spec with arch matching that
103// of the host machine.
104func preferredSpec(specs []*InstanceSpec) *InstanceSpec {
105 if len(specs) > 1 {
106 hostArch := arch.HostArch()
107 for _, spec := range specs {
108 if spec.Image.Arch == hostArch {
109 return spec
110 }
111 }
112 }
113 if len(specs) > 0 {
114 return specs[0]
115 }
116 return nil
117}
118
96// Image holds the attributes that vary amongst relevant images for119// Image holds the attributes that vary amongst relevant images for
97// a given series in a given region.120// a given series in a given region.
98type Image struct {121type Image struct {
99122
=== modified file 'environs/instances/image_test.go'
--- environs/instances/image_test.go 2014-04-18 13:58:13 +0000
+++ environs/instances/image_test.go 2014-04-24 05:00:30 +0000
@@ -11,6 +11,7 @@
11 "launchpad.net/juju-core/constraints"11 "launchpad.net/juju-core/constraints"
12 "launchpad.net/juju-core/environs/imagemetadata"12 "launchpad.net/juju-core/environs/imagemetadata"
13 "launchpad.net/juju-core/environs/simplestreams"13 "launchpad.net/juju-core/environs/simplestreams"
14 "launchpad.net/juju-core/juju/arch"
14 "launchpad.net/juju-core/testing/testbase"15 "launchpad.net/juju-core/testing/testbase"
15 "launchpad.net/juju-core/utils"16 "launchpad.net/juju-core/utils"
16)17)
@@ -306,6 +307,44 @@
306 }307 }
307}308}
308309
310func (s *imageSuite) TestPreferredSpec(c *gc.C) {
311 type prefTest struct {
312 desc string
313 specs []*InstanceSpec
314 expected *InstanceSpec
315 }
316
317 s.PatchValue(&arch.HostArch, func() string { return arch.ARM64 })
318
319 amd64 := &InstanceSpec{Image: Image{Arch: arch.AMD64}}
320 i386 := &InstanceSpec{Image: Image{Arch: arch.I386}}
321 arm64 := &InstanceSpec{Image: Image{Arch: arch.ARM64}}
322
323 prefTests := []prefTest{
324 {
325 "choose hostarch (arm64) over other arches",
326 []*InstanceSpec{i386, arm64, amd64},
327 arm64,
328 },
329 {
330 "choose first image if no arm64",
331 []*InstanceSpec{i386, amd64},
332 i386,
333 },
334 {
335 "choose only image only one there",
336 []*InstanceSpec{amd64},
337 amd64,
338 },
339 }
340
341 for n, test := range prefTests {
342 c.Logf("PreferredSpec test %d: %s", n, test.desc)
343 actual := preferredSpec(test.specs)
344 c.Assert(actual, gc.Equals, test.expected)
345 }
346}
347
309var imageMatchtests = []struct {348var imageMatchtests = []struct {
310 image Image349 image Image
311 itype InstanceType350 itype InstanceType
312351
=== modified file 'provider/ec2/export_test.go'
--- provider/ec2/export_test.go 2014-04-02 11:35:49 +0000
+++ provider/ec2/export_test.go 2014-04-24 05:00:30 +0000
@@ -152,6 +152,7 @@
152 "com.ubuntu.cloud:server:12.04:i386",152 "com.ubuntu.cloud:server:12.04:i386",
153 "com.ubuntu.cloud:server:12.04:amd64",153 "com.ubuntu.cloud:server:12.04:amd64",
154 "com.ubuntu.cloud:server:12.10:amd64",154 "com.ubuntu.cloud:server:12.10:amd64",
155 "com.ubuntu.cloud:server:12.10:i386",
155 "com.ubuntu.cloud:server:13.04:i386"156 "com.ubuntu.cloud:server:13.04:i386"
156 ],157 ],
157 "path": "streams/v1/com.ubuntu.cloud:released:aws.js"158 "path": "streams/v1/com.ubuntu.cloud:released:aws.js"
158159
=== modified file 'provider/ec2/image_test.go'
--- provider/ec2/image_test.go 2014-04-17 05:44:57 +0000
+++ provider/ec2/image_test.go 2014-04-24 05:00:30 +0000
@@ -64,7 +64,7 @@
64 image: "ami-00000033",64 image: "ami-00000033",
65 }, {65 }, {
66 series: "quantal",66 series: "quantal",
67 arches: both,67 arches: []string{"i386"},
68 itype: "m1.small",68 itype: "m1.small",
69 image: "ami-01000034",69 image: "ami-01000034",
70 }, {70 }, {

Subscribers

People subscribed via source and target branches

to status/vote changes: