def test_03_delete_detached_volume(self): """Delete a Volume unattached to an VM """ # Validate the following # 1. volume should be deleted successfully and listVolume should not # contain the deleted volume details. self.debug("Deleting volume: %s" % self.volume.id) cmd = deleteVolume.deleteVolumeCmd() cmd.id = self.volume.id self.apiclient.deleteVolume(cmd) # Sleep to ensure the current state will reflected in other calls time.sleep(self.services["sleep"]) list_volume_response = Volume.list( self.apiclient, id=self.volume.id, ) self.assertEqual( list_volume_response, None, "Volume %s was not deleted" % self.volume.id ) return
def test_09_delete_detached_volume(self): """Delete a Volume unattached to an VM """ # Validate the following # 1. volume should be deleted successfully and listVolume should not # contain the deleted volume details. # 2. "Delete Volume" menu item not shown under "Actions" menu. # (UI should not allow to delete the volume when it is attached # to instance by hiding the menu Item) self.debug("Delete Volume ID: %s" % self.volume.id) self.volume_1 = Volume.create(self.apiclient, self.services, account=self.account.name, domainid=self.account.domainid) self.virtual_machine.attach_volume(self.apiClient, self.volume_1) self.virtual_machine.detach_volume(self.apiClient, self.volume_1) cmd = deleteVolume.deleteVolumeCmd() cmd.id = self.volume_1.id self.apiClient.deleteVolume(cmd) list_volume_response = Volume.list(self.apiClient, id=self.volume_1.id, type='DATADISK') self.assertEqual(list_volume_response, None, "Check if volume exists in ListVolumes") return
def test_11_delete_detached_volume(self): """ Delete a Volume unattached to an VM """ list_volume_response1 = Volume.list(self.user_api_client, id=self.volume.id) if list_volume_response1[0].virtualmachineid is not None: self.skipTest("Check if volume is detached before deleting") cmd = deleteVolume.deleteVolumeCmd() cmd.id = self.volume.id self.user_api_client.deleteVolume(cmd) # Sleep to ensure the current state will reflected in other calls time.sleep(self.services["sleep"]) list_volume_response = Volume.list( self.user_api_client, id=self.volume.id, ) self.assertEqual(list_volume_response, None, "Volume %s was not deleted" % self.volume.id) return
def test_09_delete_detached_volume(self): """Delete a Volume unattached to an VM """ # Validate the following # 1. volume should be deleted successfully and listVolume should not # contain the deleted volume details. # 2. "Delete Volume" menu item not shown under "Actions" menu. # (UI should not allow to delete the volume when it is attached # to instance by hiding the menu Item) self.debug("Delete Volume ID: %s" % self.volume.id) self.volume_1 = Volume.create( self.apiclient, self.services, account=self.account.name, domainid=self.account.domainid ) self.virtual_machine.attach_volume(self.apiClient, self.volume_1) self.virtual_machine.detach_volume(self.apiClient, self.volume_1) cmd = deleteVolume.deleteVolumeCmd() cmd.id = self.volume_1.id self.apiClient.deleteVolume(cmd) list_volume_response = Volume.list(self.apiClient, id=self.volume_1.id, type="DATADISK") self.assertEqual(list_volume_response, None, "Check if volume exists in ListVolumes") return
def test_11_delete_detached_volume(self): """ Delete a Volume unattached to an VM """ list_volume_response1 = Volume.list( self.user_api_client, id=self.volume.id ) if list_volume_response1[0].virtualmachineid is not None: self.skipTest("Check if volume is detached before deleting") cmd = deleteVolume.deleteVolumeCmd() cmd.id = self.volume.id self.user_api_client.deleteVolume(cmd) # Sleep to ensure the current state will reflected in other calls time.sleep(self.services["sleep"]) list_volume_response = Volume.list( self.user_api_client, id=self.volume.id, ) self.assertEqual( list_volume_response, None, "Volume %s was not deleted" % self.volume.id ) return
def test_03_delete_all_datadisks(self): """Test to delete volumes """ volumes = list_volumes(self.apiclient, listall = True) for s in volumes: try: if s.virtualmachineid is None: cmd = deleteVolume.deleteVolumeCmd() cmd.id = s.id self.apiclient.deleteVolume(cmd) except Exception as e: continue
def test_04_delete_attached_volume(self): """Delete a Volume attached to a VM """ # Validate the following # 1. delete volume will fail with proper error message # "Failed - Invalid state of the volume with ID: # It should be either detached or the VM should be in stopped state self.debug("Trying to delete attached Volume ID: %s" % self.volume.id) self.virtual_machine.attach_volume(self.apiClient, self.volume) self.attached = True cmd = deleteVolume.deleteVolumeCmd() cmd.id = self.volume.id # Proper exception should be raised; deleting attach VM is not allowed # with self.assertRaises(Exception): with self.assertRaises(Exception): self.apiClient.deleteVolume(cmd)
def test_05_extract_root_volume_and_destroy_vm(self): """Create VM, extract root volume, then destroy vm and volume Steps: # 1. create vm without data disk, resource count increases. # 2. stop vm # 3. extract root volume # 4. expunge vm, root volume in Expunged state. resource count decreased with size of root disk. # 5. destroy volume (expunge = false), Exception happened. resource count no changes # 6. destroy volume (expunge = true). volume is not found. resource count no changes. """ # Create vm try: virtual_machine_4 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, templateid=self.template.id, zoneid=self.zone.id) self.cleanup.append(virtual_machine_4) except Exception as e: self.fail("Exception while deploying virtual machine: %s" % e) self.expectedCount = self.expectedCount + self.templatesize self.volumeTotal = self.volumeTotal + 1 self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal) # Get id of root disk root_volumes_list = Volume.list(self.apiclient, virtualmachineid=virtual_machine_4.id, type='ROOT', listall=True) status = validateList(root_volumes_list) self.assertEqual(status[0], PASS, "ROOT Volume List Validation Failed") root_volume_id = root_volumes_list[0].id # Stop vm virtual_machine_4.stop(self.apiclient) # extract root volume cmd = extractVolume.extractVolumeCmd() cmd.id = root_volume_id cmd.mode = "HTTP_DOWNLOAD" cmd.zoneid = self.zone.id self.apiclient.extractVolume(cmd) # Destroy VM (expunge=True) virtual_machine_4.delete(self.apiclient, expunge=True) self.cleanup.remove(virtual_machine_4) self.expectedCount = self.expectedCount - self.templatesize self.volumeTotal = self.volumeTotal - 1 self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal) # check root disk state root_volumes_list = Volume.list(self.apiclient, id=root_volume_id, listall=True) status = validateList(root_volumes_list) self.assertEqual(status[0], PASS, "ROOT Volume List Validation Failed") root_volume = root_volumes_list[0] self.assertEqual(root_volume['state'], 'Expunged', "ROOT volume should be Destroy after restorevm") # delete root disk cmd = deleteVolume.deleteVolumeCmd() cmd.id = root_volume.id self.apiclient.deleteVolume(cmd) self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal)
def test_04_recover_root_volume_after_restorevm(self): """Restore VM, recover/delete old root disk Steps: # 1. create vm without data disk, resource count increases. # 2. restore vm. resource count no changes. # 3. check old root disk , should be Destroy state # 4. recover old root disk. resource count increases. # 5. delete old root disk . resource count decreases. # 6. destroy vm (expunge=True). resource count decreased with size of root disk """ # Create vm try: virtual_machine_3 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, templateid=self.template.id, zoneid=self.zone.id) self.cleanup.append(virtual_machine_3) except Exception as e: self.fail("Exception while deploying virtual machine: %s" % e) self.expectedCount = self.expectedCount + self.templatesize self.volumeTotal = self.volumeTotal + 1 self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal) # Get id of root disk root_volumes_list = Volume.list(self.apiclient, virtualmachineid=virtual_machine_3.id, type='ROOT', listall=True) status = validateList(root_volumes_list) self.assertEqual(status[0], PASS, "ROOT Volume List Validation Failed") root_volume_id = root_volumes_list[0].id # restore vm virtual_machine_3.restore(self.apiclient) self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal) # check old root disk state root_volumes_list = Volume.list(self.apiclient, id=root_volume_id, listall=True) status = validateList(root_volumes_list) self.assertEqual(status[0], PASS, "ROOT Volume List Validation Failed") root_volume = root_volumes_list[0] self.assertEqual(root_volume['state'], 'Destroy', "ROOT volume should be Destroy after restorevm") # recover old root disk cmd = recoverVolume.recoverVolumeCmd() cmd.id = root_volume.id self.apiclient.recoverVolume(cmd) self.expectedCount = self.expectedCount + self.templatesize self.volumeTotal = self.volumeTotal + 1 self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal) # delete old root disk cmd = deleteVolume.deleteVolumeCmd() cmd.id = root_volume.id self.apiclient.deleteVolume(cmd) self.expectedCount = self.expectedCount - self.templatesize self.volumeTotal = self.volumeTotal - 1 self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal) # Destroy VM (expunge=True) virtual_machine_3.delete(self.apiclient, expunge=True) self.cleanup.remove(virtual_machine_3) self.expectedCount = self.expectedCount - self.templatesize self.volumeTotal = self.volumeTotal - 1 self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal)
def test_01_create_vm_with_data_disk(self): """Create VM with DATA disk, then destroy it (expunge=False) and expunge it Steps: # 1. create vm with root disk and data disk # 2. destroy vm, resource count of primary storage is not changed # 3. expunge vm, resource count of primary storage decreased with size of root disk. # 4. delete volume (data disk), resource count of primary storage decreased with size of data disk """ try: virtual_machine_1 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.service_offering.id, diskofferingid=self.disk_offering.id, templateid=self.template.id, zoneid=self.zone.id) self.cleanup.append(virtual_machine_1) except Exception as e: self.fail("Exception while deploying virtual machine: %s" % e) self.expectedCount = self.expectedCount + self.templatesize + self.disk_offering.disksize self.volumeTotal = self.volumeTotal + 2 self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal) root_volumes_list = Volume.list(self.apiclient, virtualmachineid=virtual_machine_1.id, type='ROOT', listall=True) status = validateList(root_volumes_list) self.assertEqual(status[0], PASS, "ROOT Volume List Validation Failed") root_volume_id = root_volumes_list[0].id data_volumes_list = Volume.list(self.apiclient, virtualmachineid=virtual_machine_1.id, type='DATADISK', listall=True) status = validateList(data_volumes_list) self.assertEqual(status[0], PASS, "DATADISK Volume List Validation Failed") data_volume_id = data_volumes_list[0].id # destroy vm virtual_machine_1.delete(self.apiclient, expunge=False) self.cleanup.remove(virtual_machine_1) self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal) # expunge vm virtual_machine_1.expunge(self.apiclient) self.expectedCount = self.expectedCount - self.templatesize self.volumeTotal = self.volumeTotal - 1 self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal) # delete datadisk cmd = deleteVolume.deleteVolumeCmd() cmd.id = data_volume_id self.apiclient.deleteVolume(cmd) self.expectedCount = self.expectedCount - self.disk_offering.disksize self.volumeTotal = self.volumeTotal - 1 self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal)