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
1=== modified file 'environs/instances/image.go'
2--- environs/instances/image.go 2014-04-17 05:44:57 +0000
3+++ environs/instances/image.go 2014-04-24 05:00:30 +0000
4@@ -8,6 +8,7 @@
5
6 "launchpad.net/juju-core/constraints"
7 "launchpad.net/juju-core/environs/imagemetadata"
8+ "launchpad.net/juju-core/juju/arch"
9 )
10
11 // InstanceConstraint constrains the possible instances that may be
12@@ -78,14 +79,19 @@
13 return nil, fmt.Errorf("no instance types found matching constraint: %s", ic)
14 }
15
16+ specs := []*InstanceSpec{}
17 for _, itype := range matchingTypes {
18 for _, image := range possibleImages {
19 if image.match(itype) {
20- return &InstanceSpec{itype, image}, nil
21+ specs = append(specs, &InstanceSpec{itype, image})
22 }
23 }
24 }
25
26+ if spec := preferredSpec(specs); spec != nil {
27+ return spec, nil
28+ }
29+
30 names := make([]string, len(matchingTypes))
31 for i, itype := range matchingTypes {
32 names[i] = itype.Name
33@@ -93,6 +99,23 @@
34 return nil, fmt.Errorf("no %q images in %s matching instance types %v", ic.Series, ic.Region, names)
35 }
36
37+// preferredSpec will if possible return a spec with arch matching that
38+// of the host machine.
39+func preferredSpec(specs []*InstanceSpec) *InstanceSpec {
40+ if len(specs) > 1 {
41+ hostArch := arch.HostArch()
42+ for _, spec := range specs {
43+ if spec.Image.Arch == hostArch {
44+ return spec
45+ }
46+ }
47+ }
48+ if len(specs) > 0 {
49+ return specs[0]
50+ }
51+ return nil
52+}
53+
54 // Image holds the attributes that vary amongst relevant images for
55 // a given series in a given region.
56 type Image struct {
57
58=== modified file 'environs/instances/image_test.go'
59--- environs/instances/image_test.go 2014-04-18 13:58:13 +0000
60+++ environs/instances/image_test.go 2014-04-24 05:00:30 +0000
61@@ -11,6 +11,7 @@
62 "launchpad.net/juju-core/constraints"
63 "launchpad.net/juju-core/environs/imagemetadata"
64 "launchpad.net/juju-core/environs/simplestreams"
65+ "launchpad.net/juju-core/juju/arch"
66 "launchpad.net/juju-core/testing/testbase"
67 "launchpad.net/juju-core/utils"
68 )
69@@ -306,6 +307,44 @@
70 }
71 }
72
73+func (s *imageSuite) TestPreferredSpec(c *gc.C) {
74+ type prefTest struct {
75+ desc string
76+ specs []*InstanceSpec
77+ expected *InstanceSpec
78+ }
79+
80+ s.PatchValue(&arch.HostArch, func() string { return arch.ARM64 })
81+
82+ amd64 := &InstanceSpec{Image: Image{Arch: arch.AMD64}}
83+ i386 := &InstanceSpec{Image: Image{Arch: arch.I386}}
84+ arm64 := &InstanceSpec{Image: Image{Arch: arch.ARM64}}
85+
86+ prefTests := []prefTest{
87+ {
88+ "choose hostarch (arm64) over other arches",
89+ []*InstanceSpec{i386, arm64, amd64},
90+ arm64,
91+ },
92+ {
93+ "choose first image if no arm64",
94+ []*InstanceSpec{i386, amd64},
95+ i386,
96+ },
97+ {
98+ "choose only image only one there",
99+ []*InstanceSpec{amd64},
100+ amd64,
101+ },
102+ }
103+
104+ for n, test := range prefTests {
105+ c.Logf("PreferredSpec test %d: %s", n, test.desc)
106+ actual := preferredSpec(test.specs)
107+ c.Assert(actual, gc.Equals, test.expected)
108+ }
109+}
110+
111 var imageMatchtests = []struct {
112 image Image
113 itype InstanceType
114
115=== modified file 'provider/ec2/export_test.go'
116--- provider/ec2/export_test.go 2014-04-02 11:35:49 +0000
117+++ provider/ec2/export_test.go 2014-04-24 05:00:30 +0000
118@@ -152,6 +152,7 @@
119 "com.ubuntu.cloud:server:12.04:i386",
120 "com.ubuntu.cloud:server:12.04:amd64",
121 "com.ubuntu.cloud:server:12.10:amd64",
122+ "com.ubuntu.cloud:server:12.10:i386",
123 "com.ubuntu.cloud:server:13.04:i386"
124 ],
125 "path": "streams/v1/com.ubuntu.cloud:released:aws.js"
126
127=== modified file 'provider/ec2/image_test.go'
128--- provider/ec2/image_test.go 2014-04-17 05:44:57 +0000
129+++ provider/ec2/image_test.go 2014-04-24 05:00:30 +0000
130@@ -64,7 +64,7 @@
131 image: "ami-00000033",
132 }, {
133 series: "quantal",
134- arches: both,
135+ arches: []string{"i386"},
136 itype: "m1.small",
137 image: "ami-01000034",
138 }, {

Subscribers

People subscribed via source and target branches

to status/vote changes: