Skip to content

Commit ebb2e96

Browse files
author
Cheryl Jennings
committed
lp1373516 - Change default ec2 instance to m3.medium
This PR changes the selection of ec2 instance types to follow the following rules: - m1 instances will only be selected if explicitly specified using the instance-type=m1.* constraint - if no constraints are specified, the default instance type will be m3.medium - if constraints are specified, m1 instance types which satisfy the constraints will not be selected for deployment
1 parent c859bf2 commit ebb2e96

File tree

8 files changed

+106
-51
lines changed

8 files changed

+106
-51
lines changed

environs/instances/instancetype.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ type InstanceType struct {
2020
Cost uint64
2121
RootDisk uint64
2222
// These attributes are not supported by all clouds.
23-
VirtType *string // The type of virtualisation used by the hypervisor, must match the image.
24-
CpuPower *uint64
25-
Tags []string
23+
VirtType *string // The type of virtualisation used by the hypervisor, must match the image.
24+
CpuPower *uint64
25+
Tags []string
26+
Deprecated bool
2627
}
2728

2829
func CpuPower(power uint64) *uint64 {
@@ -37,6 +38,9 @@ func (itype InstanceType) match(cons constraints.Value) (InstanceType, bool) {
3738
if cons.Arch != nil {
3839
itype.Arches = filterArches(itype.Arches, []string{*cons.Arch})
3940
}
41+
if itype.Deprecated && !cons.HasInstanceType() {
42+
return nothing, false
43+
}
4044
if cons.HasInstanceType() && itype.Name != *cons.InstanceType {
4145
return nothing, false
4246
}

environs/instances/instancetype_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ var instanceTypes = []InstanceType{
9797
Mem: 61952,
9898
Cost: 2400,
9999
VirtType: &hvm,
100+
}, {
101+
Name: "dep.small",
102+
Arches: []string{"amd64"},
103+
CpuCores: 1,
104+
CpuPower: CpuPower(100),
105+
Mem: 1740,
106+
Cost: 60,
107+
Deprecated: true,
108+
}, {
109+
Name: "dep.medium",
110+
Arches: []string{"amd64"},
111+
CpuCores: 2,
112+
CpuPower: CpuPower(200),
113+
Mem: 4096,
114+
Cost: 80,
115+
Deprecated: true,
100116
},
101117
}
102118

@@ -200,6 +216,14 @@ var getInstanceTypesTest = []struct {
200216
{Id: "1", Name: "it-1", Arches: []string{"amd64"}, Mem: 512, CpuCores: 4, Cost: 100},
201217
},
202218
expectedItypes: []string{"it-2"},
219+
}, {
220+
about: "deprecated image type requested by name",
221+
cons: "instance-type=dep.small",
222+
expectedItypes: []string{"dep.small"},
223+
}, {
224+
about: "deprecated image type requested by name with constraints",
225+
cons: "instance-type=dep.small cpu-power=100",
226+
expectedItypes: []string{"dep.small"},
203227
},
204228
}
205229

@@ -237,6 +261,9 @@ func (s *instanceTypeSuite) TestGetMatchingInstanceTypesErrors(c *gc.C) {
237261

238262
_, err = MatchingInstanceTypes(instanceTypes, "test", constraints.MustParse("mem=90000M"))
239263
c.Check(err, gc.ErrorMatches, `no instance types in test matching constraints "mem=90000M"`)
264+
265+
_, err = MatchingInstanceTypes(instanceTypes, "test", constraints.MustParse("instance-type=dep.medium mem=8G"))
266+
c.Check(err, gc.ErrorMatches, `no instance types in test matching constraints "instance-type=dep.medium mem=8192M"`)
240267
}
241268

242269
var instanceTypeMatchTests = []struct {

provider/ec2/environ.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,10 @@ func (e *environ) StartInstance(args environs.StartInstanceParams) (_ *environs.
539539
return nil, errors.Errorf("chosen architecture %v not present in %v", spec.Image.Arch, arches)
540540
}
541541

542+
if spec.InstanceType.Deprecated {
543+
logger.Warningf("deprecated instance type specified: %s", spec.InstanceType.Name)
544+
}
545+
542546
args.InstanceConfig.Tools = tools[0]
543547
if err := instancecfg.FinishInstanceConfig(args.InstanceConfig, e.Config()); err != nil {
544548
return nil, err

provider/ec2/export_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ var TestInstanceTypeCosts = instanceTypeCost{
362362
"m1.medium": 120,
363363
"m1.large": 240,
364364
"m1.xlarge": 480,
365+
"m3.medium": 95,
366+
"m3.large": 190,
367+
"m3.xlarge": 385,
368+
"m3.2xlarge": 765,
365369
"t1.micro": 20,
366370
"c1.medium": 145,
367371
"c1.xlarge": 580,

provider/ec2/image_test.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ var findInstanceSpecTests = []struct {
4646
{
4747
series: testing.FakeDefaultSeries,
4848
arches: both,
49-
itype: "m1.small",
49+
itype: "m3.medium",
5050
image: "ami-00000033",
5151
}, {
5252
series: "quantal",
5353
arches: []string{"i386"},
54-
itype: "m1.small",
54+
itype: "c1.medium",
5555
image: "ami-01000034",
5656
}, {
5757
series: testing.FakeDefaultSeries,
5858
arches: both,
5959
cons: "cpu-cores=4",
60-
itype: "m1.xlarge",
60+
itype: "m3.xlarge",
6161
image: "ami-00000033",
6262
}, {
6363
series: testing.FakeDefaultSeries,
@@ -69,25 +69,25 @@ var findInstanceSpecTests = []struct {
6969
series: testing.FakeDefaultSeries,
7070
arches: both,
7171
cons: "mem=10G",
72-
itype: "m1.xlarge",
72+
itype: "m3.xlarge",
7373
image: "ami-00000033",
7474
}, {
7575
series: testing.FakeDefaultSeries,
7676
arches: both,
7777
cons: "mem=",
78-
itype: "m1.small",
78+
itype: "m3.medium",
7979
image: "ami-00000033",
8080
}, {
8181
series: testing.FakeDefaultSeries,
8282
arches: both,
8383
cons: "cpu-power=",
84-
itype: "m1.small",
84+
itype: "m3.medium",
8585
image: "ami-00000033",
8686
}, {
8787
series: testing.FakeDefaultSeries,
8888
arches: both,
8989
cons: "cpu-power=800",
90-
itype: "m1.xlarge",
90+
itype: "m3.xlarge",
9191
image: "ami-00000033",
9292
}, {
9393
series: testing.FakeDefaultSeries,
@@ -119,31 +119,37 @@ var findInstanceSpecTests = []struct {
119119
cons: "instance-type=c1.medium",
120120
itype: "c1.medium",
121121
image: "ami-00000034",
122+
}, {
123+
series: testing.FakeDefaultSeries,
124+
arches: []string{"amd64"},
125+
cons: "instance-type=m1.medium cpu-power=200",
126+
itype: "m1.medium",
127+
image: "ami-00000033",
122128
}, {
123129
series: testing.FakeDefaultSeries,
124130
arches: both,
125-
cons: "mem=4G root-disk=16384M",
126-
itype: "m1.large",
131+
cons: "mem=2G root-disk=16384M",
132+
itype: "m3.medium",
127133
image: "ami-00000033",
128134
}, {
129135
series: testing.FakeDefaultSeries,
130136
arches: both,
131137
cons: "mem=4G root-disk=16384M",
132-
itype: "m1.large",
138+
itype: "m3.large",
133139
storage: []string{"ssd", "ebs"},
134140
image: "ami-00000033",
135141
}, {
136142
series: testing.FakeDefaultSeries,
137143
arches: both,
138144
cons: "mem=4G root-disk=16384M",
139-
itype: "m1.large",
145+
itype: "m3.large",
140146
storage: []string{"ebs", "ssd"},
141147
image: "ami-00000039",
142148
}, {
143149
series: testing.FakeDefaultSeries,
144150
arches: both,
145151
cons: "mem=4G root-disk=16384M",
146-
itype: "m1.large",
152+
itype: "m3.large",
147153
storage: []string{"ebs"},
148154
image: "ami-00000039",
149155
},
@@ -208,7 +214,12 @@ var findInstanceSpecErrorTests = []struct {
208214
series: "raring",
209215
arches: both,
210216
cons: "mem=4G",
211-
err: `no "raring" images in test matching instance types \[m1.large m1.xlarge c1.xlarge cc2.8xlarge\]`,
217+
err: `no "raring" images in test matching instance types \[m3.large m3.xlarge c1.xlarge m3.2xlarge cc2.8xlarge\]`,
218+
}, {
219+
series: testing.FakeDefaultSeries,
220+
arches: both,
221+
cons: "instance-type=m1.small mem=4G",
222+
err: `no instance types in test matching constraints "instance-type=m1.small mem=4096M"`,
212223
},
213224
}
214225

provider/ec2/instancetype.go

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,39 @@ var allRegions = aws.Regions
3131
// disk for amazon will simply cause the root disk to grow to match
3232
// the constraint
3333
var allInstanceTypes = []instances.InstanceType{
34-
{ // General purpose, 1st generation.
35-
Name: "m1.small",
36-
Arches: both,
37-
CpuCores: 1,
38-
CpuPower: instances.CpuPower(100),
39-
Mem: 1740,
40-
VirtType: &paravirtual,
34+
{ // General purpose, 1st generation. m1.* instance types are deprecated
35+
// and should only be used if explicitly requested by name.
36+
Name: "m1.small",
37+
Arches: both,
38+
CpuCores: 1,
39+
CpuPower: instances.CpuPower(100),
40+
Mem: 1740,
41+
VirtType: &paravirtual,
42+
Deprecated: true,
4143
}, {
42-
Name: "m1.medium",
43-
Arches: both,
44-
CpuCores: 1,
45-
CpuPower: instances.CpuPower(200),
46-
Mem: 3840,
47-
VirtType: &paravirtual,
44+
Name: "m1.medium",
45+
Arches: both,
46+
CpuCores: 1,
47+
CpuPower: instances.CpuPower(200),
48+
Mem: 3840,
49+
VirtType: &paravirtual,
50+
Deprecated: true,
4851
}, {
49-
Name: "m1.large",
50-
Arches: amd64,
51-
CpuCores: 2,
52-
CpuPower: instances.CpuPower(400),
53-
Mem: 7680,
54-
VirtType: &paravirtual,
52+
Name: "m1.large",
53+
Arches: amd64,
54+
CpuCores: 2,
55+
CpuPower: instances.CpuPower(400),
56+
Mem: 7680,
57+
VirtType: &paravirtual,
58+
Deprecated: true,
5559
}, {
56-
Name: "m1.xlarge",
57-
Arches: amd64,
58-
CpuCores: 4,
59-
CpuPower: instances.CpuPower(800),
60-
Mem: 15360,
61-
VirtType: &paravirtual,
60+
Name: "m1.xlarge",
61+
Arches: amd64,
62+
CpuCores: 4,
63+
CpuPower: instances.CpuPower(800),
64+
Mem: 15360,
65+
VirtType: &paravirtual,
66+
Deprecated: true,
6267
},
6368
// M4 instances are the latest generation of General Purpose
6469
// Instances. This family provides a balance of compute, memory,

provider/ec2/live_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,21 @@ func (t *LiveTests) TestInstanceAttributes(c *gc.C) {
124124

125125
ec2inst := ec2.InstanceEC2(insts[0])
126126
c.Assert(ec2inst.IPAddress, gc.Equals, addresses[0].Value)
127-
c.Assert(ec2inst.InstanceType, gc.Equals, "m1.small")
127+
c.Assert(ec2inst.InstanceType, gc.Equals, "m3.medium")
128128
}
129129

130130
func (t *LiveTests) TestStartInstanceConstraints(c *gc.C) {
131131
t.PrepareOnce(c)
132-
cons := constraints.MustParse("mem=2G")
132+
cons := constraints.MustParse("mem=4G")
133133
inst, hc := testing.AssertStartInstanceWithConstraints(c, t.Env, "30", cons)
134134
defer t.Env.StopInstances(inst.Id())
135135
ec2inst := ec2.InstanceEC2(inst)
136-
c.Assert(ec2inst.InstanceType, gc.Equals, "m1.medium")
136+
c.Assert(ec2inst.InstanceType, gc.Equals, "m3.large")
137137
c.Assert(*hc.Arch, gc.Equals, "amd64")
138-
c.Assert(*hc.Mem, gc.Equals, uint64(3840))
138+
c.Assert(*hc.Mem, gc.Equals, uint64(7680))
139139
c.Assert(*hc.RootDisk, gc.Equals, uint64(8192))
140-
c.Assert(*hc.CpuCores, gc.Equals, uint64(1))
141-
c.Assert(*hc.CpuPower, gc.Equals, uint64(200))
140+
c.Assert(*hc.CpuCores, gc.Equals, uint64(2))
141+
c.Assert(*hc.CpuPower, gc.Equals, uint64(650))
142142
}
143143

144144
func (t *LiveTests) TestInstanceGroups(c *gc.C) {

provider/ec2/local_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ func (t *localServerSuite) TestBootstrapInstanceUserDataAndState(c *gc.C) {
265265
// check that a new instance will be started with a machine agent
266266
inst1, hc := testing.AssertStartInstance(c, env, "1")
267267
c.Check(*hc.Arch, gc.Equals, "amd64")
268-
c.Check(*hc.Mem, gc.Equals, uint64(1740))
268+
c.Check(*hc.Mem, gc.Equals, uint64(3840))
269269
c.Check(*hc.CpuCores, gc.Equals, uint64(1))
270-
c.Assert(*hc.CpuPower, gc.Equals, uint64(100))
270+
c.Assert(*hc.CpuPower, gc.Equals, uint64(300))
271271
inst = t.srv.ec2srv.Instance(string(inst1.Id()))
272272
c.Assert(inst, gc.NotNil)
273273
userData, err = utils.Gunzip(inst.UserData)
@@ -319,9 +319,9 @@ func (t *localServerSuite) TestStartInstanceHardwareCharacteristics(c *gc.C) {
319319
c.Assert(err, jc.ErrorIsNil)
320320
_, hc := testing.AssertStartInstance(c, env, "1")
321321
c.Check(*hc.Arch, gc.Equals, "amd64")
322-
c.Check(*hc.Mem, gc.Equals, uint64(1740))
322+
c.Check(*hc.Mem, gc.Equals, uint64(3840))
323323
c.Check(*hc.CpuCores, gc.Equals, uint64(1))
324-
c.Assert(*hc.CpuPower, gc.Equals, uint64(100))
324+
c.Assert(*hc.CpuPower, gc.Equals, uint64(300))
325325
}
326326

327327
func (t *localServerSuite) TestStartInstanceAvailZone(c *gc.C) {

0 commit comments

Comments
 (0)