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
// 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 {
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 /codereview. appspot. com/89900043/
and fixes some tests.
See https:/
https:/ /code.launchpad .net/~wallyworl d/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): instances/ image.go instances/ image_test. go ec2/export_ test.go ec2/image_ test.go
A [revision details]
M environs/
M environs/
M provider/
M provider/
Index: [revision details] 20140424033650- 9am3xzxfcelms2x 8
=== 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-
+New revision: <email address hidden>
Index: environs/ instances/ image.go instances/ image.go' instances/ image.go 2014-04-17 05:44:57 +0000 instances/ image.go 2014-04-24 04:56:36 +0000
=== modified file 'environs/
--- environs/
+++ environs/
@@ -8,6 +8,7 @@
"launchpad. net/juju- core/constraint s" net/juju- core/environs/ imagemetadata" net/juju- core/juju/ arch"
"launchpad.
+ "launchpad.
)
// 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{} itype, image}, nil itype, image})
for _, itype := range matchingTypes {
for _, image := range possibleImages {
if image.match(itype) {
- return &InstanceSpec{
+ specs = append(specs, &InstanceSpec{
}
}
}
+ 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 instances/ image_test. go' instances/ image_test. go 2014-04-18 13:58:13 +0000 instances/ image_test. go 2014-04-23 21:04:24 +0000 net/juju- core/constraint s" net/juju- core/environs/ imagemetadata" net/juju- core/environs/ simplestreams" net/juju- core/juju/ arch" net/juju- core/testing/ testbase" net/juju- core/utils"
=== modified file 'environs/
--- environs/
+++ environs/
@@ -11,6 +11,7 @@
"launchpad.
"launchpad.
"launchpad.
+ "launchpad.
"launchpad.
"launchpad.
)
@@ -306,6 +307,44 @@
}
}
+func (s *imageSuite) TestPreferredSpec(c *gc.C) { &arch.HostArch, func() string { return arch.ARM64 }) Image: Image{Arch: arch.AMD64}} Image: Image{Arch: arch.I386}} Image: Image{Arch: arch.ARM64}} {i386, arm64, amd64}, {i386, amd64}, {amd64} , "PreferredSpec test %d: %s", n, test.desc) test.specs)
+ type prefTest struct {
+ desc string
+ specs []*InstanceSpec
+ expected *InstanceSpec
+ }
+
+ s.PatchValue(
+
+ amd64 := &InstanceSpec{
+ i386 := &InstanceSpec{
+ arm64 := &InstanceSpec{
+
+ prefTests := []prefTest{
+ {
+ "choose hostarch (arm64) over other arches",
+ []*InstanceSpec
+ arm64,
+ },
+ {
+ "choose first image if no arm64",
+ []*InstanceSpec
+ i386,
+ },
+ {
+ "choose only image only one there",
+ []*InstanceSpec
+ amd64,
+ },
+ }
+
+ for n, test := range prefTests {
+ c.Logf(
+ actual := preferredSpec(
+ c.Assert(actual, gc.Equals, test.expected)
+ }
+}
+
var imageMatchtests = []struct {
image Image
itype InstanceType
Index: provider/ ec2/export_ test.go ec2/export_ test.go' ec2/export_ test.go 2014-04-02 11:35:49 +0000 ec2/export_ test.go 2014-04-24 04:56:36 +0000 ubuntu. cloud:server: 12.04:i386" , ubuntu. cloud:server: 12.04:amd64" , ubuntu. cloud:server: 12.10:amd64" , cloud:server: 12.10:i386" , ubuntu. cloud:server: 13.04:i386" v1/com. ubuntu. cloud:released: aws.js"
=== modified file 'provider/
--- provider/
+++ provider/
@@ -152,6 +152,7 @@
"com.
"com.
"com.
+ "com.ubuntu.
"com.
],
"path": "streams/
Index: provider/ ec2/image_ test.go ec2/image_ test.go' ec2/image_ test.go 2014-04-17 05:44:57 +0000 ec2/image_ test.go 2014-04-24 04:56:36 +0000
=== modified file 'provider/
--- provider/
+++ provider/
@@ -64,7 +64,7 @@
image: "ami-00000033",
}, {
series: "quantal",
- arches: both,
+ arches: []string{"i386"},
itype: "m1.small",
image: "ami-01000034",
}, {