def test_16_template_from_volume_with_uuid(self): list = list_volumes(self.apiclient, virtualmachineid = self.virtual_machine.id, type = "ROOT") self.helper.storpool_volume_globalid(list[0]) self.virtual_machine.stop(self.apiclient, forced = True) template = self.helper.create_template_from_snapshot_or_volume(services = self.services, volumeid = list[0].id) self.helper.create_vm_from_template(template, False) Template.delete(template, self.apiclient, zoneid = self.zone.id)
def test_01_list_templates_pagination(self): """ @Desc: Test to List Templates pagination @steps: Step1: Listing all the Templates for a user Step2: Verifying that no Templates are listed Step3: Creating (page size + 1) number of Templates Step4: Listing all the Templates again for a user Step5: Verifying that list size is (page size + 1) Step6: Listing all the Templates in page1 Step7: Verifying that list size is (page size) Step8: Listing all the Templates in page2 Step9: Verifying that list size is 1 Step10: Listing the template by Id Step11: Verifying if the template is downloaded and ready. If yes the continuing If not waiting and checking for template to be ready till timeout Step12: Deleting the Template present in page 2 Step13: Listing all the Templates in page2 Step14: Verifying that no Templates are listed """ # 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"] # Creating pagesize + 1 number of Templates for i in range(0, (self.services["pagesize"] + 1)): 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 pagesize + 1 self.assertEquals( self.services["pagesize"] + 1, len(list_templates_after), "Failed to create pagesize + 1 number of Templates" ) # Listing all the Templates in page 1 list_templates_page1 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], page=1, pagesize=self.services["pagesize"] ) status = validateList(list_templates_page1) self.assertEquals( PASS, status[0], "Failed to list Templates in page 1" ) # Verifying the list size to be equal to pagesize self.assertEquals( self.services["pagesize"], len(list_templates_page1), "Size of Templates in page 1 is not matching" ) # Listing all the Templates in page 2 list_templates_page2 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], page=2, pagesize=self.services["pagesize"] ) status = validateList(list_templates_page2) self.assertEquals( PASS, status[0], "Failed to list Templates in page 2" ) # Verifying the list size to be equal to 1 self.assertEquals( 1, len(list_templates_page2), "Size of Templates in page 2 is not matching" ) # Verifying the state of the template to be ready. If not waiting for # state to become ready 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 # Deleting the Template present in page 2 Template.delete( template_created, self.userapiclient ) # Listing all the Templates in page 2 again list_templates_page2 = Template.list( self.userapiclient, listall=self.services["listall"], templatefilter=self.services["templatefilter"], page=2, pagesize=self.services["pagesize"] ) # Verifying that there are no Templates listed self.assertIsNone( list_templates_page2, "Templates not deleted from page 2" ) del self.services["privatetemplate"]["ostype"] return
def test_08_delete_snapshot_of_deleted_volume(self): ''' Delete snapshot and template if volume is already deleted, bypassing secondary ''' Configurations.update(self.apiclient, name = "sp.bypass.secondary.storage", value = "true") volume = Volume.create( self.apiclient, {"diskname":"StorPoolDisk-Delete" }, zoneid = self.zone.id, diskofferingid = self.disk_offerings.id, account=self.account.name, domainid=self.account.domainid, ) delete = volume self.virtual_machine2.attach_volume( self.apiclient, volume ) self.virtual_machine2.detach_volume( self.apiclient, volume ) volume = list_volumes(self.apiclient, id = volume.id, listall = True,) name = volume[0].path.split("/")[3] try: spvolume = self.spapi.volumeList(volumeName="~" + name) except spapi.ApiError as err: raise Exception(err) snapshot = Snapshot.create( self.apiclient, volume_id = volume[0].id ) try: cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd() cmd.snapshotid = snapshot.id snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd) if snapshot_details is not None: flag = False for s in snapshot_details: if s["snapshotDetailsName"] == snapshot.id: name = s["snapshotDetailsValue"].split("/")[3] try: sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + name) self.debug('################ %s' % sp_snapshot) flag = True except spapi.ApiError as err: raise Exception(err) if flag == False: raise Exception("Could not find snapshot in snapshot details") except Exception as err: raise Exception(err) template = self.helper.create_template_from_snapshot(self.apiclient, self.services, snapshotid = snapshot.id) Volume.delete(delete, self.apiclient, ) Snapshot.delete(snapshot, self.apiclient) flag = False try: cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd() cmd.snapshotid = snapshot.id snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd) if snapshot_details is not None: try: for s in snapshot_details: if s["snapshotDetailsName"] == snapshot.id: name = s["snapshotDetailsValue"].split("/")[3] sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + name) self.debug('################ The snapshot had to be deleted %s' % sp_snapshot) flag = True except spapi.ApiError as err: flag = False if flag is True: raise Exception("Snapshot was not deleted") except Exception as err: self.debug('Snapshot was deleted %s' % err) Template.delete(template, self.apiclient, zoneid = self.zone.id)
def test_06_template_from_snapshot(self): ''' Test create template bypassing secondary from snapshot which is backed up on secondary storage ''' ##cls.virtual_machine volume = list_volumes( self.apiclient, virtualmachineid = self.virtual_machine.id, type = "ROOT", listall = True, ) try: name = volume[0].path.split("/")[3] sp_volume = self.spapi.volumeList(volumeName = "~" + name) self.debug('################ %s' % sp_volume) except spapi.ApiError as err: raise Exception(err) Configurations.update(self.apiclient, name = "sp.bypass.secondary.storage", value = "false") snapshot = Snapshot.create( self.apiclient, volume_id = volume[0].id, account=self.account.name, domainid=self.account.domainid, ) try: cmd = getVolumeSnapshotDetails.getVolumeSnapshotDetailsCmd() cmd.snapshotid = snapshot.id snapshot_details = self.apiclient.getVolumeSnapshotDetails(cmd) flag = False for s in snapshot_details: if s["snapshotDetailsName"] == snapshot.id: name = s["snapshotDetailsValue"].split("/")[3] sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + name) flag = True self.debug('################ %s' % sp_snapshot) if flag == False: raise Exception("Could not find snapshot in snapshot details") except spapi.ApiError as err: raise Exception(err) self.assertIsNotNone(snapshot, "Could not create snapshot") self.assertIsInstance(snapshot, Snapshot, "Snapshot is not an instance of Snapshot") Configurations.update(self.apiclient, name = "sp.bypass.secondary.storage", value = "true") template = self.helper.create_template_from_snapshot( self.apiclient, self.services, snapshotid = snapshot.id ) flag = False globalId = None sp_snapshots = self.spapi.snapshotsList() for snap in sp_snapshots: tags = snap.tags for t in tags: if tags[t] == template.id: flag = True globalId = snap.globalId break else: continue break if flag is False: raise Exception("Template does not exists in Storpool") self.assertIsNotNone(template, "Template is None") self.assertIsInstance(template, Template, "Template is instance of template") temp = Template.delete(template, self.apiclient, self.zone.id) self.assertIsNone(temp, "Template was not deleted") if globalId is not None: try: sp_snapshot = self.spapi.snapshotList(snapshotName = "~" + globalId) if sp_snapshot is not None: raise Exception("Snapshot does not exists on Storpool name" + globalId) except spapi.ApiError as err: self.debug("Do nothing the template has to be deleted") else: flag = False sp_snapshots = self.spapi.snapshotsList() for snap in sp_snapshots: tags = snap.tags for t in tags: if tags[t] == template.id: flag = True break else: continue break if flag is True: raise Exception("Template should not exists in Storpool")
def test_04_try_delete_primary_with_template(self): virtual_machine = VirtualMachine.create( self.apiclient, {"name": "StorPool-%s" % uuid.uuid4()}, zoneid=self.zone.id, templateid=self.template.id, serviceofferingid=self.serviceOfferings.id, hypervisor=self.hypervisor, rootdisksize=10) volume = list_volumes(self.apiclient, virtualmachineid=virtual_machine.id, type="ROOT", listall=True) volume = volume[0] name = volume.path.split("/")[3] try: spvolume = self.spapi.volumeList(volumeName="~" + name) if spvolume[0].templateName != self.template_name: raise Exception( "Storpool volume's template %s is not with the same template %s" % (spvolume[0].templateName, self.template_name)) except spapi.ApiError as err: raise Exception(err) backup_config = list_configurations(self.apiclient, name="sp.bypass.secondary.storage") if (backup_config[0].value == "false"): backup_config = Configurations.update( self.apiclient, name="sp.bypass.secondary.storage", value="true") snapshot = Snapshot.create( self.apiclient, volume_id=volume.id, ) self.debug("###################### %s" % snapshot) id = self.helper.get_snapshot_template_id(self.apiclient, snapshot, self.storage_pool_id) if id is None: raise Exception("There isn't primary storgae id") virtual_machine.delete(self.apiclient, expunge=True) pool = list_storage_pools(self.apiclient, id=id) services = { "displaytext": "Template-1", "name": "Template-1-name", "ostypeid": self.template.ostypeid, "ispublic": "true" } template = Template.create_from_snapshot(self.apiclient, snapshot=snapshot, services=services) Snapshot.delete(snapshot, self.apiclient) try: StoragePool.delete(self.sp_primary_storage, self.apiclient) except Exception as err: StoragePool.cancelMaintenance(self.apiclient, id=self.sp_primary_storage.id) self.debug("Storge pool could not be delete due to %s" % err) Template.delete(template, self.apiclient)