mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
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)
This commit is contained in:
parent
1058654cb4
commit
c6f0d46911
@ -174,67 +174,69 @@ class TestCreateTemplate(cloudstackTestCase):
|
||||
# tar bzip template.
|
||||
# 6. Verify VMs & Templates is up and in ready state
|
||||
|
||||
for k, v in self.services["templates"].items():
|
||||
builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
|
||||
self.services["templates"][0]["url"] = builtin_info[0]
|
||||
self.services["templates"][0]["hypervisor"] = builtin_info[1]
|
||||
self.services["templates"][0]["format"] = builtin_info[2]
|
||||
|
||||
# Register new template
|
||||
template = Template.register(
|
||||
# Register new template
|
||||
template = Template.register(
|
||||
self.apiclient,
|
||||
v,
|
||||
self.services["templates"][0],
|
||||
zoneid=self.zone.id,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
self.debug(
|
||||
self.debug(
|
||||
"Registered a template of format: %s with ID: %s" % (
|
||||
v["format"],
|
||||
self.services["templates"][0]["format"],
|
||||
template.id
|
||||
))
|
||||
# Wait for template to download
|
||||
template.download(self.apiclient)
|
||||
self.cleanup.append(template)
|
||||
# Wait for template to download
|
||||
template.download(self.apiclient)
|
||||
self.cleanup.append(template)
|
||||
|
||||
# Wait for template status to be changed across
|
||||
time.sleep(self.services["sleep"])
|
||||
timeout = self.services["timeout"]
|
||||
while True:
|
||||
list_template_response = list_templates(
|
||||
# Wait for template status to be changed across
|
||||
time.sleep(self.services["sleep"])
|
||||
timeout = self.services["timeout"]
|
||||
while True:
|
||||
list_template_response = list_templates(
|
||||
self.apiclient,
|
||||
templatefilter=\
|
||||
self.services["templatefilter"],
|
||||
templatefilter='all',
|
||||
id=template.id,
|
||||
zoneid=self.zone.id,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
if isinstance(list_template_response, list):
|
||||
break
|
||||
elif timeout == 0:
|
||||
raise Exception("List template failed!")
|
||||
if isinstance(list_template_response, list):
|
||||
break
|
||||
elif timeout == 0:
|
||||
raise Exception("List template failed!")
|
||||
|
||||
time.sleep(5)
|
||||
timeout = timeout - 1
|
||||
#Verify template response to check whether template added successfully
|
||||
self.assertEqual(
|
||||
time.sleep(5)
|
||||
timeout = timeout - 1
|
||||
#Verify template response to check whether template added successfully
|
||||
self.assertEqual(
|
||||
isinstance(list_template_response, list),
|
||||
True,
|
||||
"Check for list template response return valid data"
|
||||
)
|
||||
|
||||
self.assertNotEqual(
|
||||
self.assertNotEqual(
|
||||
len(list_template_response),
|
||||
0,
|
||||
"Check template available in List Templates"
|
||||
)
|
||||
|
||||
template_response = list_template_response[0]
|
||||
self.assertEqual(
|
||||
template_response = list_template_response[0]
|
||||
self.assertEqual(
|
||||
template_response.isready,
|
||||
True,
|
||||
"Check display text of newly created template"
|
||||
)
|
||||
|
||||
# Deploy new virtual machine using template
|
||||
virtual_machine = VirtualMachine.create(
|
||||
# Deploy new virtual machine using template
|
||||
virtual_machine = VirtualMachine.create(
|
||||
self.apiclient,
|
||||
self.services["virtual_machine"],
|
||||
templateid=template.id,
|
||||
@ -243,26 +245,26 @@ class TestCreateTemplate(cloudstackTestCase):
|
||||
serviceofferingid=self.service_offering.id,
|
||||
mode=self.services["mode"]
|
||||
)
|
||||
self.debug("creating an instance with template ID: %s" % template.id)
|
||||
vm_response = list_virtual_machines(
|
||||
self.debug("creating an instance with template ID: %s" % template.id)
|
||||
vm_response = list_virtual_machines(
|
||||
self.apiclient,
|
||||
id=virtual_machine.id,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
self.assertEqual(
|
||||
self.assertEqual(
|
||||
isinstance(vm_response, list),
|
||||
True,
|
||||
"Check for list VMs response after VM deployment"
|
||||
)
|
||||
#Verify VM response to check whether VM deployment was successful
|
||||
self.assertNotEqual(
|
||||
self.assertNotEqual(
|
||||
len(vm_response),
|
||||
0,
|
||||
"Check VMs available in List VMs response"
|
||||
)
|
||||
vm = vm_response[0]
|
||||
self.assertEqual(
|
||||
vm = vm_response[0]
|
||||
self.assertEqual(
|
||||
vm.state,
|
||||
'Running',
|
||||
"Check the state of VM created from Template"
|
||||
|
||||
@ -902,6 +902,17 @@ class Template:
|
||||
if isinstance(template, list):
|
||||
return Template(template[0].__dict__)
|
||||
|
||||
@classmethod
|
||||
def extract(cls, apiclient, id, mode, zoneid=None):
|
||||
"Extract template "
|
||||
|
||||
cmd = extractTemplate.extractTemplateCmd()
|
||||
cmd.id = id
|
||||
cmd.mode = mode
|
||||
cmd.zoneid = zoneid
|
||||
|
||||
return apiclient.extractTemplate(cmd)
|
||||
|
||||
@classmethod
|
||||
def create_from_snapshot(cls, apiclient, snapshot, services,
|
||||
random_name=True):
|
||||
|
||||
@ -265,6 +265,25 @@ def wait_for_ssvms(apiclient, zoneid, podid, interval=60):
|
||||
break
|
||||
return
|
||||
|
||||
def get_builtin_template_info(apiclient, zoneid):
|
||||
"""Returns hypervisor specific infor for templates"""
|
||||
|
||||
list_template_response = Template.list(
|
||||
apiclient,
|
||||
templatefilter='featured',
|
||||
zoneid=zoneid,
|
||||
)
|
||||
|
||||
for b_template in list_template_response:
|
||||
if b_template.templatetype == 'BUILTIN':
|
||||
break
|
||||
|
||||
extract_response = Template.extract(apiclient,
|
||||
b_template.id,
|
||||
'HTTP_DOWNLOAD',
|
||||
zoneid)
|
||||
|
||||
return extract_response.url, b_template.hypervisor, b_template.format
|
||||
|
||||
def download_builtin_templates(apiclient, zoneid, hypervisor, host,
|
||||
linklocalip, interval=60):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user