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 <[email protected]> (cherry picked from commit 20256706b376551fe8993ee2e73c61df31dcb6de) Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c6f0d469 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c6f0d469 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c6f0d469 Branch: refs/heads/ldapplugin Commit: c6f0d46911143ef79bec86d4b989d9256f15b29e Parents: 1058654 Author: Girish Shilamkar <[email protected]> Authored: Mon Aug 26 18:27:53 2013 +0530 Committer: Prasanna Santhanam <[email protected]> Committed: Thu Aug 29 14:10:54 2013 +0530 ---------------------------------------------------------------------- test/integration/component/test_templates.py | 76 +++++++++++----------- tools/marvin/marvin/integration/lib/base.py | 11 ++++ tools/marvin/marvin/integration/lib/common.py | 19 ++++++ 3 files changed, 69 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6f0d469/test/integration/component/test_templates.py ---------------------------------------------------------------------- diff --git a/test/integration/component/test_templates.py b/test/integration/component/test_templates.py index e4599d4..ea4b277 100644 --- a/test/integration/component/test_templates.py +++ b/test/integration/component/test_templates.py @@ -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 status to be changed across - time.sleep(self.services["sleep"]) - timeout = self.services["timeout"] - while True: - list_template_response = list_templates( + # 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( 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!") - - time.sleep(5) - timeout = timeout - 1 - #Verify template response to check whether template added successfully - self.assertEqual( + 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( 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" http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6f0d469/tools/marvin/marvin/integration/lib/base.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/integration/lib/base.py b/tools/marvin/marvin/integration/lib/base.py index c528cea..2152637 100755 --- a/tools/marvin/marvin/integration/lib/base.py +++ b/tools/marvin/marvin/integration/lib/base.py @@ -903,6 +903,17 @@ class Template: 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): """Create Template from snapshot""" http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6f0d469/tools/marvin/marvin/integration/lib/common.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/integration/lib/common.py b/tools/marvin/marvin/integration/lib/common.py index f27e87d..478aa31 100644 --- a/tools/marvin/marvin/integration/lib/common.py +++ b/tools/marvin/marvin/integration/lib/common.py @@ -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):
