@@ -140,24 +140,66 @@ var getInstanceTypesTest = []struct {
140
140
arches : []string {"arm" },
141
141
},
142
142
{
143
- about : "fallback instance type, enough memory for mongodb" ,
144
- cons : "mem=8G " ,
143
+ about : "enough memory for mongodb if mem not specified " ,
144
+ cons : "cpu-cores=4 " ,
145
145
itypesToUse : []InstanceType {
146
+ {Id : "4" , Name : "it-4" , Arches : []string {"amd64" }, Mem : 2048 , CpuCores : 4 },
147
+ {Id : "3" , Name : "it-3" , Arches : []string {"amd64" }, Mem : 1024 , CpuCores : 4 },
148
+ {Id : "2" , Name : "it-2" , Arches : []string {"amd64" }, Mem : 256 , CpuCores : 4 },
149
+ {Id : "1" , Name : "it-1" , Arches : []string {"amd64" }, Mem : 512 , CpuCores : 4 },
150
+ },
151
+ expectedItypes : []string {"it-3" , "it-4" },
152
+ },
153
+ {
154
+ about : "small mem specified, use that even though less than needed for mongodb" ,
155
+ cons : "mem=300M" ,
156
+ itypesToUse : []InstanceType {
157
+ {Id : "3" , Name : "it-3" , Arches : []string {"amd64" }, Mem : 2048 },
158
+ {Id : "2" , Name : "it-2" , Arches : []string {"amd64" }, Mem : 256 },
159
+ {Id : "1" , Name : "it-1" , Arches : []string {"amd64" }, Mem : 512 },
160
+ },
161
+ expectedItypes : []string {"it-1" , "it-3" },
162
+ },
163
+ {
164
+ about : "mem specified but no mem matches, choose largest memory type with enough memory for mongdb" ,
165
+ cons : "mem=8G arch=amd64" ,
166
+ itypesToUse : []InstanceType {
167
+ {Id : "4" , Name : "it-4" , Arches : []string {"arm" }, Mem : 8096 },
146
168
{Id : "3" , Name : "it-3" , Arches : []string {"amd64" }, Mem : 4096 },
147
169
{Id : "2" , Name : "it-2" , Arches : []string {"amd64" }, Mem : 2048 },
148
170
{Id : "1" , Name : "it-1" , Arches : []string {"amd64" }, Mem : 512 },
149
171
},
150
- expectedItypes : []string {"it-2 " },
172
+ expectedItypes : []string {"it-3 " },
151
173
},
152
174
{
153
- about : "fallback instance type, not enough memory for mongodb " ,
175
+ about : "mem specified but no mem matches, choose largest memory type " ,
154
176
cons : "mem=4G" ,
155
177
itypesToUse : []InstanceType {
156
178
{Id : "2" , Name : "it-2" , Arches : []string {"amd64" }, Mem : 256 },
157
179
{Id : "1" , Name : "it-1" , Arches : []string {"amd64" }, Mem : 512 },
158
180
},
159
181
expectedItypes : []string {"it-1" },
160
182
},
183
+ {
184
+ about : "mem specified but no mem matches, choose largest memory type matching other constraints" ,
185
+ cons : "mem=4G arch=amd64" ,
186
+ itypesToUse : []InstanceType {
187
+ {Id : "3" , Name : "it-3" , Arches : []string {"arm" }, Mem : 1024 },
188
+ {Id : "2" , Name : "it-2" , Arches : []string {"amd64" }, Mem : 256 },
189
+ {Id : "1" , Name : "it-1" , Arches : []string {"amd64" }, Mem : 512 },
190
+ },
191
+ expectedItypes : []string {"it-1" },
192
+ },
193
+ {
194
+ about : "largest mem available matching other constraints if mem not specified" ,
195
+ cons : "cpu-cores=4" ,
196
+ itypesToUse : []InstanceType {
197
+ {Id : "3" , Name : "it-3" , Arches : []string {"amd64" }, Mem : 1024 , CpuCores : 2 },
198
+ {Id : "2" , Name : "it-2" , Arches : []string {"amd64" }, Mem : 256 , CpuCores : 4 },
199
+ {Id : "1" , Name : "it-1" , Arches : []string {"amd64" }, Mem : 512 , CpuCores : 4 },
200
+ },
201
+ expectedItypes : []string {"it-1" },
202
+ },
161
203
}
162
204
163
205
func constraint (region , cons string ) * InstanceConstraint {
@@ -195,6 +237,9 @@ func (s *instanceTypeSuite) TestGetMatchingInstanceTypesErrors(c *gc.C) {
195
237
196
238
_ , err = getMatchingInstanceTypes (constraint ("test" , "arch=i386 mem=8G" ), instanceTypes )
197
239
c .Check (err , gc .ErrorMatches , `no instance types in test matching constraints "arch=i386 mem=8192M"` )
240
+
241
+ _ , err = getMatchingInstanceTypes (constraint ("test" , "cpu-cores=9000" ), instanceTypes )
242
+ c .Check (err , gc .ErrorMatches , `no instance types in test matching constraints "cpu-cores=9000"` )
198
243
}
199
244
200
245
var instanceTypeMatchTests = []struct {
0 commit comments