Skip to content

Commit de86e5e

Browse files
Girish ShilamkarPrasanna Santhanam
authored andcommitted
CLOUDSTACK-4407: Use extractTemplate API to get hypervisor specific template information
Template url, hypervisor and format were defined in Service class to be Xenserver specific and therefore registering a new template failed on Vmware and KVM. Fixed this to get hypervisor specific info for registering new template. Signed-off-by: Prasanna Santhanam <tsp@apache.org> (cherry picked from commit 20256706b376551fe8993ee2e73c61df31dcb6de)
1 parent dc071e9 commit de86e5e

3 files changed

Lines changed: 69 additions & 37 deletions

File tree

‎test/integration/component/test_templates.py‎

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -174,67 +174,69 @@ def test_01_create_template(self):
174174
# tar bzip template.
175175
# 6. Verify VMs & Templates is up and in ready state
176176

177-
for k, v in self.services["templates"].items():
177+
builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
178+
self.services["templates"][0]["url"] = builtin_info[0]
179+
self.services["templates"][0]["hypervisor"] = builtin_info[1]
180+
self.services["templates"][0]["format"] = builtin_info[2]
178181

179-
# Register new template
180-
template = Template.register(
182+
# Register new template
183+
template = Template.register(
181184
self.apiclient,
182-
v,
185+
self.services["templates"][0],
183186
zoneid=self.zone.id,
184187
account=self.account.name,
185188
domainid=self.account.domainid
186189
)
187-
self.debug(
190+
self.debug(
188191
"Registered a template of format: %s with ID: %s" % (
189-
v["format"],
192+
self.services["templates"][0]["format"],
190193
template.id
191194
))
192-
# Wait for template to download
193-
template.download(self.apiclient)
194-
self.cleanup.append(template)
195-
196-
# Wait for template status to be changed across
197-
time.sleep(self.services["sleep"])
198-
timeout = self.services["timeout"]
199-
while True:
200-
list_template_response = list_templates(
195+
# Wait for template to download
196+
template.download(self.apiclient)
197+
self.cleanup.append(template)
198+
199+
# Wait for template status to be changed across
200+
time.sleep(self.services["sleep"])
201+
timeout = self.services["timeout"]
202+
while True:
203+
list_template_response = list_templates(
201204
self.apiclient,
202-
templatefilter=\
203-
self.services["templatefilter"],
205+
templatefilter='all',
204206
id=template.id,
205207
zoneid=self.zone.id,
206208
account=self.account.name,
207209
domainid=self.account.domainid
208210
)
209-
if isinstance(list_template_response, list):
210-
break
211-
elif timeout == 0:
212-
raise Exception("List template failed!")
213-
214-
time.sleep(5)
215-
timeout = timeout - 1
216-
#Verify template response to check whether template added successfully
217-
self.assertEqual(
211+
if isinstance(list_template_response, list):
212+
break
213+
elif timeout == 0:
214+
raise Exception("List template failed!")
215+
216+
time.sleep(5)
217+
timeout = timeout - 1
218+
#Verify template response to check whether template added successfully
219+
self.assertEqual(
218220
isinstance(list_template_response, list),
219221
True,
220222
"Check for list template response return valid data"
221223
)
222224

223-
self.assertNotEqual(
225+
self.assertNotEqual(
224226
len(list_template_response),
225227
0,
226228
"Check template available in List Templates"
227229
)
228230

229-
template_response = list_template_response[0]
230-
self.assertEqual(
231+
template_response = list_template_response[0]
232+
self.assertEqual(
231233
template_response.isready,
232234
True,
233235
"Check display text of newly created template"
234236
)
235237

236-
# Deploy new virtual machine using template
237-
virtual_machine = VirtualMachine.create(
238+
# Deploy new virtual machine using template
239+
virtual_machine = VirtualMachine.create(
238240
self.apiclient,
239241
self.services["virtual_machine"],
240242
templateid=template.id,
@@ -243,26 +245,26 @@ def test_01_create_template(self):
243245
serviceofferingid=self.service_offering.id,
244246
mode=self.services["mode"]
245247
)
246-
self.debug("creating an instance with template ID: %s" % template.id)
247-
vm_response = list_virtual_machines(
248+
self.debug("creating an instance with template ID: %s" % template.id)
249+
vm_response = list_virtual_machines(
248250
self.apiclient,
249251
id=virtual_machine.id,
250252
account=self.account.name,
251253
domainid=self.account.domainid
252254
)
253-
self.assertEqual(
255+
self.assertEqual(
254256
isinstance(vm_response, list),
255257
True,
256258
"Check for list VMs response after VM deployment"
257259
)
258260
#Verify VM response to check whether VM deployment was successful
259-
self.assertNotEqual(
261+
self.assertNotEqual(
260262
len(vm_response),
261263
0,
262264
"Check VMs available in List VMs response"
263265
)
264-
vm = vm_response[0]
265-
self.assertEqual(
266+
vm = vm_response[0]
267+
self.assertEqual(
266268
vm.state,
267269
'Running',
268270
"Check the state of VM created from Template"

‎tools/marvin/marvin/integration/lib/base.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,17 @@ def register(cls, apiclient, services, zoneid=None,
902902
if isinstance(template, list):
903903
return Template(template[0].__dict__)
904904

905+
@classmethod
906+
def extract(cls, apiclient, id, mode, zoneid=None):
907+
"Extract template "
908+
909+
cmd = extractTemplate.extractTemplateCmd()
910+
cmd.id = id
911+
cmd.mode = mode
912+
cmd.zoneid = zoneid
913+
914+
return apiclient.extractTemplate(cmd)
915+
905916
@classmethod
906917
def create_from_snapshot(cls, apiclient, snapshot, services,
907918
random_name=True):

‎tools/marvin/marvin/integration/lib/common.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,25 @@ def wait_for_ssvms(apiclient, zoneid, podid, interval=60):
265265
break
266266
return
267267

268+
def get_builtin_template_info(apiclient, zoneid):
269+
"""Returns hypervisor specific infor for templates"""
270+
271+
list_template_response = Template.list(
272+
apiclient,
273+
templatefilter='featured',
274+
zoneid=zoneid,
275+
)
276+
277+
for b_template in list_template_response:
278+
if b_template.templatetype == 'BUILTIN':
279+
break
280+
281+
extract_response = Template.extract(apiclient,
282+
b_template.id,
283+
'HTTP_DOWNLOAD',
284+
zoneid)
285+
286+
return extract_response.url, b_template.hypervisor, b_template.format
268287

269288
def download_builtin_templates(apiclient, zoneid, hypervisor, host,
270289
linklocalip, interval=60):

0 commit comments

Comments
 (0)