@@ -133,19 +133,20 @@ var _ = Describe("Instance", func() {
133
133
Ω (client .GetOrCreateVMInstance (csMachine , machine , csCluster , "" )).Should (MatchError ("unknown err" ))
134
134
})
135
135
136
- It ("handles errors occuring while fetching sevice offering information" , func () {
136
+ It ("returns errors occuring while fetching sevice offering information" , func () {
137
137
vms .EXPECT ().GetVirtualMachinesMetricByID (* csMachine .Spec .InstanceID ).Return (nil , - 1 , notFoundError )
138
138
vms .EXPECT ().GetVirtualMachinesMetricByName (csMachine .Name ).Return (nil , - 1 , notFoundError )
139
139
sos .EXPECT ().GetServiceOfferingID (csMachine .Spec .Offering ).Return ("" , - 1 , unknownError )
140
- Ω (client .GetOrCreateVMInstance (csMachine , machine , csCluster , "" )).Should (MatchError ("unknown err" ))
140
+ sos .EXPECT ().GetServiceOfferingByID (csMachine .Spec .Offering ).Return (nil , - 1 , unknownError )
141
+ Ω (client .GetOrCreateVMInstance (csMachine , machine , csCluster , "" )).ShouldNot (Succeed ())
141
142
})
142
143
143
- It ("returns an appropriate error if more than one sevice offering found" , func () {
144
+ It ("returns errors if more than one sevice offering found" , func () {
144
145
vms .EXPECT ().GetVirtualMachinesMetricByID (* csMachine .Spec .InstanceID ).Return (nil , - 1 , notFoundError )
145
146
vms .EXPECT ().GetVirtualMachinesMetricByName (csMachine .Name ).Return (nil , - 1 , notFoundError )
146
147
sos .EXPECT ().GetServiceOfferingID (csMachine .Spec .Offering ).Return ("" , 2 , nil )
147
- Ω ( client . GetOrCreateVMInstance (csMachine , machine , csCluster , "" )). Should (
148
- MatchError ( "Did not find exactly one machine offering with the name service-offering-name" ))
148
+ sos . EXPECT (). GetServiceOfferingByID (csMachine . Spec . Offering ). Return ( nil , - 1 , unknownError )
149
+ Ω ( client . GetOrCreateVMInstance ( csMachine , machine , csCluster , "" )). ShouldNot ( Succeed ( ))
149
150
})
150
151
151
152
It ("returns errors encountered while fetching template" , func () {
@@ -154,18 +155,17 @@ var _ = Describe("Instance", func() {
154
155
sos .EXPECT ().GetServiceOfferingID (csMachine .Spec .Offering ).Return (serviceOfferingID , 1 , nil )
155
156
ts .EXPECT ().GetTemplateID (csMachine .Spec .Template , "all" , csCluster .Status .ZoneID ).
156
157
Return ("" , - 1 , unknownError )
157
-
158
- Ω (client .GetOrCreateVMInstance (csMachine , machine , csCluster , "" )).Should ( MatchError ( "unknown err" ))
158
+ ts . EXPECT (). GetTemplateByID ( csMachine . Spec . Template , "all" ). Return ( nil , - 1 , unknownError )
159
+ Ω (client .GetOrCreateVMInstance (csMachine , machine , csCluster , "" )).ShouldNot ( Succeed ( ))
159
160
})
160
161
161
- It ("returns an appropriate error when more than one template found" , func () {
162
+ It ("returns errors when more than one template found" , func () {
162
163
vms .EXPECT ().GetVirtualMachinesMetricByID (* csMachine .Spec .InstanceID ).Return (nil , - 1 , notFoundError )
163
164
vms .EXPECT ().GetVirtualMachinesMetricByName (csMachine .Name ).Return (nil , - 1 , notFoundError )
164
165
sos .EXPECT ().GetServiceOfferingID (csMachine .Spec .Offering ).Return (serviceOfferingID , 1 , nil )
165
166
ts .EXPECT ().GetTemplateID (csMachine .Spec .Template , "all" , csCluster .Status .ZoneID ).Return ("" , 2 , nil )
166
-
167
- Ω (client .GetOrCreateVMInstance (csMachine , machine , csCluster , "" )).
168
- Should (MatchError ("Did not find exactly one template with the name template-name" ))
167
+ ts .EXPECT ().GetTemplateByID (csMachine .Spec .Template , "all" ).Return (nil , - 1 , unknownError )
168
+ Ω (client .GetOrCreateVMInstance (csMachine , machine , csCluster , "" )).ShouldNot (Succeed ())
169
169
})
170
170
171
171
It ("handles deployment errors" , func () {
@@ -181,27 +181,68 @@ var _ = Describe("Instance", func() {
181
181
Ω (client .GetOrCreateVMInstance (csMachine , machine , csCluster , "" )).Should (MatchError ("unknown err" ))
182
182
})
183
183
184
- It ("calls CloudStack to deploy a VM Instance and succeeds" , func () {
185
- gomock .InOrder (
186
- vms .EXPECT ().GetVirtualMachinesMetricByID (* csMachine .Spec .InstanceID ).
187
- Return (nil , - 1 , notFoundError ),
188
- vms .EXPECT ().GetVirtualMachinesMetricByID (* csMachine .Spec .InstanceID ).
189
- Return (& cloudstack.VirtualMachinesMetric {}, 1 , nil ))
190
-
191
- vms .EXPECT ().GetVirtualMachinesMetricByName (csMachine .Name ).Return (nil , - 1 , notFoundError )
192
-
193
- sos .EXPECT ().GetServiceOfferingID (csMachine .Spec .Offering ).Return (serviceOfferingID , 1 , nil )
194
- ts .EXPECT ().GetTemplateID (csMachine .Spec .Template , "all" , csCluster .Status .ZoneID ).
195
- Return (templateID , 1 , nil )
196
-
197
- vms .EXPECT ().NewDeployVirtualMachineParams (serviceOfferingID , templateID , csCluster .Status .ZoneID ).
198
- Return (& cloudstack.DeployVirtualMachineParams {})
199
-
200
- deploymentResp := & cloudstack.DeployVirtualMachineResponse {Id : * csMachine .Spec .InstanceID }
201
- vms .EXPECT ().DeployVirtualMachine (gomock .Any ()).Return (deploymentResp , nil )
202
-
203
- Ω (client .GetOrCreateVMInstance (csMachine , machine , csCluster , "" )).Should (Succeed ())
204
- Ω (csMachine .Status .Ready ).Should (BeFalse ())
184
+ Context ("when using UUIDs and/or names to locate service offerings and templates" , func () {
185
+ BeforeEach (func () {
186
+ gomock .InOrder (
187
+ vms .EXPECT ().GetVirtualMachinesMetricByID (* csMachine .Spec .InstanceID ).
188
+ Return (nil , - 1 , notFoundError ),
189
+ vms .EXPECT ().GetVirtualMachinesMetricByID (* csMachine .Spec .InstanceID ).
190
+ Return (& cloudstack.VirtualMachinesMetric {}, 1 , nil ))
191
+
192
+ vms .EXPECT ().GetVirtualMachinesMetricByName (csMachine .Name ).Return (nil , - 1 , notFoundError )
193
+ })
194
+
195
+ ActionAndAssert := func () {
196
+ vms .EXPECT ().NewDeployVirtualMachineParams (serviceOfferingID , templateID , csCluster .Status .ZoneID ).
197
+ Return (& cloudstack.DeployVirtualMachineParams {})
198
+
199
+ deploymentResp := & cloudstack.DeployVirtualMachineResponse {Id : * csMachine .Spec .InstanceID }
200
+ vms .EXPECT ().DeployVirtualMachine (gomock .Any ()).Return (deploymentResp , nil )
201
+
202
+ Ω (client .GetOrCreateVMInstance (csMachine , machine , csCluster , "" )).Should (Succeed ())
203
+ }
204
+
205
+ It ("works with service offering name and template name" , func () {
206
+ sos .EXPECT ().GetServiceOfferingID (csMachine .Spec .Offering ).Return (serviceOfferingID , 1 , nil )
207
+ ts .EXPECT ().GetTemplateID (csMachine .Spec .Template , "all" , csCluster .Status .ZoneID ).
208
+ Return (templateID , 1 , nil )
209
+
210
+ ActionAndAssert ()
211
+ })
212
+
213
+ It ("works with service offering ID and template name" , func () {
214
+ csMachine .Spec .Offering = serviceOfferingID
215
+ sos .EXPECT ().GetServiceOfferingID (csMachine .Spec .Offering ).Return ("" , - 1 , notFoundError )
216
+ sos .EXPECT ().GetServiceOfferingByID (csMachine .Spec .Offering ).Return (& cloudstack.ServiceOffering {}, 1 , nil )
217
+ ts .EXPECT ().GetTemplateID (csMachine .Spec .Template , "all" , csCluster .Status .ZoneID ).
218
+ Return (templateID , 1 , nil )
219
+
220
+ ActionAndAssert ()
221
+ })
222
+
223
+ It ("works with service offering name and template ID" , func () {
224
+ csMachine .Spec .Template = templateID
225
+ sos .EXPECT ().GetServiceOfferingID (csMachine .Spec .Offering ).Return (serviceOfferingID , 1 , nil )
226
+ ts .EXPECT ().GetTemplateID (csMachine .Spec .Template , "all" , csCluster .Status .ZoneID ).
227
+ Return ("" , - 1 , notFoundError )
228
+ ts .EXPECT ().GetTemplateByID (csMachine .Spec .Template , "all" ).
229
+ Return (& cloudstack.Template {}, 1 , nil )
230
+
231
+ ActionAndAssert ()
232
+ })
233
+
234
+ It ("works with service offering ID and template ID" , func () {
235
+ csMachine .Spec .Offering = serviceOfferingID
236
+ csMachine .Spec .Template = templateID
237
+ sos .EXPECT ().GetServiceOfferingID (csMachine .Spec .Offering ).Return ("" , - 1 , notFoundError )
238
+ sos .EXPECT ().GetServiceOfferingByID (csMachine .Spec .Offering ).Return (& cloudstack.ServiceOffering {}, 1 , nil )
239
+ ts .EXPECT ().GetTemplateID (csMachine .Spec .Template , "all" , csCluster .Status .ZoneID ).
240
+ Return ("" , - 1 , notFoundError )
241
+ ts .EXPECT ().GetTemplateByID (csMachine .Spec .Template , "all" ).
242
+ Return (& cloudstack.Template {}, 1 , nil )
243
+
244
+ ActionAndAssert ()
245
+ })
205
246
})
206
247
})
207
248
})
0 commit comments