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 test_04_extract_template(self): "Test for extract template" # Validate the following # 1. Admin should able extract and download the templates # 2. ListTemplates should display all the public templates # for all kind of users # 3 .ListTemplates should not display the system templates self.debug("Extracting template with ID: %s" % self.template_2.id) list_extract_response = Template.extract(self.apiclient, id=self.template_2.id, mode= self.services["template_2"]["mode"], zoneid=self.zone.id) try: # Format URL to ASCII to retrieve response code formatted_url = urllib.unquote_plus(list_extract_response.url) url_response = urllib.urlopen(formatted_url) response_code = url_response.getcode() except Exception: self.fail( "Extract Template Failed with invalid URL %s (template id: %s)" \ % (formatted_url, self.template_2.id) ) self.assertEqual( list_extract_response.id, self.template_2.id, "Check ID of the extracted template" ) self.assertEqual( list_extract_response.extractMode, self.services["template_2"]["mode"], "Check mode of extraction" ) self.assertEqual( list_extract_response.zoneid, self.services["template_2"]["zoneid"], "Check zone ID of extraction" ) self.assertEqual( response_code, 200, "Check for a valid response download URL" ) 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 test_02_download_template(self): """ @Desc: Test to Download Template @steps: Step1: Listing all the Templates for a user Step2: Verifying that no Templates are listed Step3: Creating a Templates Step4: Listing all the Templates again for a user Step5: Verifying that list size is 1 Step6: Verifying if the template is in ready state. If yes the continuing If not waiting and checking for template to be ready till timeout Step7: Downloading the template (Extract) Step8: Verifying that Template is downloaded """ # Listing all the Templates for a User list_templates_before = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"] ) # Verifying that no Templates are listed self.assertIsNone( list_templates_before, "Templates listed for newly created User" ) self.services["privatetemplate"]["ostype"] = self.services["ostype"] self.services["privatetemplate"]["isextractable"] = True # Creating aTemplate template_created = Template.register( self.userapiclient, self.services["privatetemplate"], self.zone.id, hypervisor=self.hypervisor ) self.assertIsNotNone( template_created, "Template creation failed" ) # Listing all the Templates for a User list_templates_after = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"] ) status = validateList(list_templates_after) self.assertEquals( PASS, status[0], "Templates creation failed" ) # Verifying that list size is 1 self.assertEquals( 1, len(list_templates_after), "Failed to create a Template" ) # Verifying the state of the template to be ready. If not waiting for # state to become ready till time out template_ready = False count = 0 while template_ready is False: list_template = Template.list( self.userapiclient, id=template_created.id, listall=self.services["listall"], templatefilter=self.services["templatefilter"], ) status = validateList(list_template) self.assertEquals( PASS, status[0], "Failed to list Templates by Id" ) if list_template[0].isready is True: template_ready = True elif (str(list_template[0].status) == "Error"): self.fail("Created Template is in Errored state") break elif count > 10: self.fail("Timed out before Template came into ready state") break else: time.sleep(self.services["sleep"]) count = count + 1 # Downloading the Template name download_template = Template.extract( self.userapiclient, template_created.id, mode="HTTP_DOWNLOAD", zoneid=self.zone.id ) self.assertIsNotNone( download_template, "Download Template failed" ) # Verifying the details of downloaded template self.assertEquals( "DOWNLOAD_URL_CREATED", download_template.state, "Download URL not created for Template" ) self.assertIsNotNone( download_template.url, "Download URL not created for Template" ) self.assertEquals( template_created.id, download_template.id, "Download Template details are not same as Template created" ) del self.services["privatetemplate"]["ostype"] del self.services["privatetemplate"]["isextractable"] return
def test01_template_download_URL_expire(self): """ @Desc:Template files are deleted from secondary storage after download URL expires Step1:Deploy vm with default cent os template Step2:Stop the vm Step3:Create template from the vm's root volume Step4:Extract Template and wait for the download url to expire Step5:Deploy another vm with the template created at Step3 Step6:Verify that vm deployment succeeds """ params = [ 'extract.url.expiration.interval', 'extract.url.cleanup.interval' ] wait_time = 0 for param in params: config = Configurations.list( self.apiClient, name=param, ) self.assertEqual( validateList(config)[0], PASS, "Config list returned invalid response") wait_time = wait_time + int(config[0].value) self.debug("Total wait time for url expiry: %s" % wait_time) # Creating Virtual Machine self.virtual_machine = VirtualMachine.create( self.userapiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, ) self.assertIsNotNone(self.virtual_machine, "Virtual Machine creation failed") self.cleanup.append(self.virtual_machine) #Stop virtual machine self.virtual_machine.stop(self.userapiclient) list_volume = Volume.list(self.userapiclient, virtualmachineid=self.virtual_machine.id, type='ROOT', listall=True) self.assertEqual( validateList(list_volume)[0], PASS, "list volumes with type ROOT returned invalid list") self.volume = list_volume[0] self.create_template = Template.create(self.userapiclient, self.services["template"], volumeid=self.volume.id, account=self.account.name, domainid=self.account.domainid) self.assertIsNotNone(self.create_template, "Failed to create template from root volume") self.cleanup.append(self.create_template) """ Extract template """ try: Template.extract(self.userapiclient, self.create_template.id, 'HTTP_DOWNLOAD', self.zone.id) except Exception as e: self.fail("Extract template failed with error %s" % e) self.debug("Waiting for %s seconds for url to expire" % repr(wait_time + 20)) time.sleep(wait_time + 20) self.debug("Waited for %s seconds for url to expire" % repr(wait_time + 20)) """ Deploy vm with the template created from the volume. After url expiration interval only url should be deleted not the template. To validate this deploy vm with the template """ try: self.vm = VirtualMachine.create( self.userapiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, templateid=self.create_template.id) self.cleanup.append(self.vm) except Exception as e: self.fail("Template is automatically deleted after URL expired.\ So vm deployment failed with error: %s" % e) return
def test01_template_download_URL_expire(self): """ @Desc:Template files are deleted from secondary storage after download URL expires Step1:Deploy vm with default cent os template Step2:Stop the vm Step3:Create template from the vm's root volume Step4:Extract Template and wait for the download url to expire Step5:Deploy another vm with the template created at Step3 Step6:Verify that vm deployment succeeds """ params = ["extract.url.expiration.interval", "extract.url.cleanup.interval"] wait_time = 0 for param in params: config = Configurations.list(self.apiClient, name=param) self.assertEqual(validateList(config)[0], PASS, "Config list returned invalid response") wait_time = wait_time + int(config[0].value) self.debug("Total wait time for url expiry: %s" % wait_time) # Creating Virtual Machine self.virtual_machine = VirtualMachine.create( self.userapiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, ) self.assertIsNotNone(self.virtual_machine, "Virtual Machine creation failed") self.cleanup.append(self.virtual_machine) # Stop virtual machine self.virtual_machine.stop(self.userapiclient) list_volume = Volume.list( self.userapiclient, virtualmachineid=self.virtual_machine.id, type="ROOT", listall=True ) self.assertEqual(validateList(list_volume)[0], PASS, "list volumes with type ROOT returned invalid list") self.volume = list_volume[0] self.create_template = Template.create( self.userapiclient, self.services["template"], volumeid=self.volume.id, account=self.account.name, domainid=self.account.domainid, ) self.assertIsNotNone(self.create_template, "Failed to create template from root volume") self.cleanup.append(self.create_template) """ Extract template """ try: Template.extract(self.userapiclient, self.create_template.id, "HTTP_DOWNLOAD", self.zone.id) except Exception as e: self.fail("Extract template failed with error %s" % e) self.debug("Waiting for %s seconds for url to expire" % repr(wait_time + 20)) time.sleep(wait_time + 20) self.debug("Waited for %s seconds for url to expire" % repr(wait_time + 20)) """ Deploy vm with the template created from the volume. After url expiration interval only url should be deleted not the template. To validate this deploy vm with the template """ try: self.vm = VirtualMachine.create( self.userapiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, templateid=self.create_template.id, ) self.cleanup.append(self.vm) except Exception as e: self.fail( "Template is automatically deleted after URL expired.\ So vm deployment failed with error: %s" % e ) return
def test_02_download_template(self): """ @Desc: Test to Download Template @steps: Step1: Listing all the Templates for a user Step2: Verifying that no Templates are listed Step3: Creating a Templates Step4: Listing all the Templates again for a user Step5: Verifying that list size is 1 Step6: Verifying if the template is in ready state. If yes the continuing If not waiting and checking for template to be ready till timeout Step7: Downloading the template (Extract) Step8: Verifying that Template is downloaded """ # Listing all the Templates for a User list_templates_before = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"]) # Verifying that no Templates are listed self.assertIsNone(list_templates_before, "Templates listed for newly created User") self.services["privatetemplate"]["ostype"] = self.services["ostype"] self.services["privatetemplate"]["isextractable"] = True # Creating aTemplate template_created = Template.register(self.userapiclient, self.services["privatetemplate"], self.zone.id, hypervisor=self.hypervisor) self.assertIsNotNone(template_created, "Template creation failed") # Listing all the Templates for a User list_templates_after = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"]) status = validateList(list_templates_after) self.assertEqual(PASS, status[0], "Templates creation failed") # Verifying that list size is 1 self.assertEqual(1, len(list_templates_after), "Failed to create a Template") # Verifying the state of the template to be ready. If not waiting for # state to become ready till time out self.download(self.apiClient, template_created.id) # Downloading the Template name download_template = Template.extract(self.userapiclient, template_created.id, mode="HTTP_DOWNLOAD", zoneid=self.zone.id) self.assertIsNotNone(download_template, "Download Template failed") # Verifying the details of downloaded template self.assertEqual("DOWNLOAD_URL_CREATED", download_template.state, "Download URL not created for Template") self.assertIsNotNone(download_template.url, "Download URL not created for Template") self.assertEqual( template_created.id, download_template.id, "Download Template details are not same as Template created") del self.services["privatetemplate"]["ostype"] del self.services["privatetemplate"]["isextractable"] return