def test_add_remove_host_with_solidfire_plugin_1(self): primarystorage = self.testdata[TestData.primaryStorage] primary_storage = StoragePool.create( self.apiClient, primarystorage, scope=primarystorage[TestData.scope], zoneid=self.zone.id, provider=primarystorage[TestData.provider], tags=primarystorage[TestData.tags], capacityiops=primarystorage[TestData.capacityIops], capacitybytes=primarystorage[TestData.capacityBytes], hypervisor=primarystorage[TestData.hypervisor]) self.cleanup.append(primary_storage) self.virtual_machine = VirtualMachine.create( self.apiClient, self.testdata[TestData.virtualMachine], accountid=self.account.name, zoneid=self.zone.id, serviceofferingid=self.compute_offering.id, templateid=self.template.id, domainid=self.domain.id, startvm=True) root_volume = self._get_root_volume(self.virtual_machine) sf_iscsi_name = sf_util.get_iqn(self.cs_api, root_volume, self) self._perform_add_remove_host(primary_storage.id, sf_iscsi_name)
def test_01_attach_new_volume_to_stopped_VM(self): """Attach a volume to a stopped virtual machine, then start VM""" self.virtual_machine.stop(self.apiClient) new_volume = Volume.create( self.apiClient, self.testdata[TestData.volume_2], account=self.account.name, domainid=self.domain.id, zoneid=self.zone.id, diskofferingid=self.disk_offering.id, ) self.cleanup.append(new_volume) self._check_and_get_cs_volume(new_volume.id, self.testdata[TestData.volume_2][TestData.diskName]) new_volume = self.virtual_machine.attach_volume(self.apiClient, new_volume) newvolume = self._check_and_get_cs_volume(new_volume.id, self.testdata[TestData.volume_2][TestData.diskName]) self.virtual_machine.start(self.apiClient) vm = self._get_vm(self.virtual_machine.id) self.assertEqual(newvolume.virtualmachineid, vm.id, TestVolumes._volume_vm_id_and_vm_id_do_not_match_err_msg) self.assertEqual(vm.state.lower(), "running", TestVolumes._vm_not_in_running_state_err_msg) sf_account_id = sf_util.get_sf_account_id( self.cs_api, self.account.id, self.primary_storage.id, self, TestVolumes._sf_account_id_should_be_non_zero_int_err_msg, ) sf_volume_size = sf_util.get_volume_size_with_hsr(self.cs_api, new_volume, self) self._verify_hsr(self.disk_offering.disksize, self.disk_offering.hypervisorsnapshotreserve, sf_volume_size) sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id, self.primary_storage.id, self) sf_iscsi_name = sf_util.get_iqn(self.cs_api, new_volume, self) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, newvolume.name, self) sf_util.check_size_and_iops(sf_volume, newvolume, sf_volume_size, self) sf_util.check_vag(sf_volume, sf_vag_id, self) self._check_xen_sr(sf_iscsi_name) # Detach volume new_volume = self.virtual_machine.detach_volume(self.apiClient, new_volume)
def test_add_remove_host_with_solidfire_plugin_3(self): if TestData.hypervisor_type != TestData.xenServer: return primarystorage = self.testdata[TestData.primaryStorage] primary_storage = StoragePool.create( self.apiClient, primarystorage, scope=primarystorage[TestData.scope], zoneid=self.zone.id, provider=primarystorage[TestData.provider], tags=primarystorage[TestData.tags], capacityiops=primarystorage[TestData.capacityIops], capacitybytes=primarystorage[TestData.capacityBytes], hypervisor=primarystorage[TestData.hypervisor] ) self.cleanup.append(primary_storage) self.virtual_machine = VirtualMachine.create( self.apiClient, self.testdata[TestData.virtualMachine], accountid=self.account.name, zoneid=self.zone.id, serviceofferingid=self.compute_offering.id, templateid=self.template.id, domainid=self.domain.id, startvm=True ) root_volume = self._get_root_volume(self.virtual_machine) sf_iscsi_name = sf_util.get_iqn(self.cs_api, root_volume, self) primarystorage2 = self.testdata[TestData.primaryStorage2] primary_storage_2 = StoragePool.create( self.apiClient, primarystorage2, scope=primarystorage2[TestData.scope], zoneid=self.zone.id, clusterid=self.cluster.id, provider=primarystorage2[TestData.provider], tags=primarystorage2[TestData.tags], capacityiops=primarystorage2[TestData.capacityIops], capacitybytes=primarystorage2[TestData.capacityBytes], hypervisor=primarystorage2[TestData.hypervisor] ) self.cleanup.append(primary_storage_2) self._perform_add_remove_xenserver_host(primary_storage.id, sf_iscsi_name)
def test_08_delete_volume_was_attached(self): """Delete volume that was attached to a VM and is detached now""" self.virtual_machine.start(self.apiClient) ####################################### ####################################### # STEP 1: Create vol and attach to VM # ####################################### ####################################### new_volume = Volume.create( self.apiClient, self.testdata[TestData.volume_2], account=self.account.name, domainid=self.domain.id, zoneid=self.zone.id, diskofferingid=self.disk_offering.id, ) volume_to_delete_later = new_volume self._check_and_get_cs_volume(new_volume.id, self.testdata[TestData.volume_2][TestData.diskName]) new_volume = self.virtual_machine.attach_volume(self.apiClient, new_volume) vol = self._check_and_get_cs_volume(new_volume.id, self.testdata[TestData.volume_2][TestData.diskName]) vm = self._get_vm(self.virtual_machine.id) self.assertEqual(vol.virtualmachineid, vm.id, "Check if attached to virtual machine") self.assertEqual(vm.state.lower(), "running", str(vm.state)) sf_account_id = sf_util.get_sf_account_id( self.cs_api, self.account.id, self.primary_storage.id, self, TestVolumes._sf_account_id_should_be_non_zero_int_err_msg, ) sf_volume_size = sf_util.get_volume_size_with_hsr(self.cs_api, new_volume, self) self._verify_hsr(self.disk_offering.disksize, self.disk_offering.hypervisorsnapshotreserve, sf_volume_size) sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id, self.primary_storage.id, self) sf_iscsi_name = sf_util.get_iqn(self.cs_api, new_volume, self) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) sf_util.check_size_and_iops(sf_volume, vol, sf_volume_size, self) sf_util.check_vag(sf_volume, sf_vag_id, self) self._check_xen_sr(sf_iscsi_name) ####################################### ####################################### # STEP 2: Detach and delete volume # ####################################### ####################################### new_volume = self.virtual_machine.detach_volume(self.apiClient, new_volume) vol = self._check_and_get_cs_volume(new_volume.id, self.testdata[TestData.volume_2][TestData.diskName]) vm = self._get_vm(self.virtual_machine.id) self.assertEqual(vol.virtualmachineid, None, "Check if attached to virtual machine") self.assertEqual(vm.state.lower(), "running", str(vm.state)) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) sf_util.check_size_and_iops(sf_volume, vol, sf_volume_size, self) self.assertEqual(len(sf_volume["volumeAccessGroups"]), 0, TestVolumes._volume_should_not_be_in_a_vag) self._check_xen_sr(sf_iscsi_name, False) volume_to_delete_later.delete(self.apiClient) list_volumes_response = list_volumes(self.apiClient, id=new_volume.id) self.assertEqual(list_volumes_response, None, "Check volume was deleted") sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self, False)
def test_07_destroy_expunge_VM_with_volume(self): """Destroy and expunge VM with attached volume""" ####################################### ####################################### # STEP 1: Create VM and attach volume # ####################################### ####################################### test_virtual_machine = VirtualMachine.create( self.apiClient, self.testdata[TestData.virtualMachine2], accountid=self.account.name, zoneid=self.zone.id, serviceofferingid=self.compute_offering.id, templateid=self.template.id, domainid=self.domain.id, startvm=True, ) self.volume = test_virtual_machine.attach_volume(self.apiClient, self.volume) self.attached = True vol = self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) vm = self._get_vm(test_virtual_machine.id) self.assertEqual(vol.virtualmachineid, vm.id, TestVolumes._volume_vm_id_and_vm_id_do_not_match_err_msg) self.assertEqual(vm.state.lower(), "running", TestVolumes._vm_not_in_running_state_err_msg) sf_account_id = sf_util.get_sf_account_id( self.cs_api, self.account.id, self.primary_storage.id, self, TestVolumes._sf_account_id_should_be_non_zero_int_err_msg, ) sf_volume_size = sf_util.get_volume_size_with_hsr(self.cs_api, self.volume, self) self._verify_hsr(self.disk_offering.disksize, self.disk_offering.hypervisorsnapshotreserve, sf_volume_size) sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id, self.primary_storage.id, self) sf_iscsi_name = sf_util.get_iqn(self.cs_api, self.volume, self) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) sf_util.check_size_and_iops(sf_volume, vol, sf_volume_size, self) sf_util.check_vag(sf_volume, sf_vag_id, self) self._check_xen_sr(sf_iscsi_name) ####################################### ####################################### # STEP 2: Destroy and Expunge VM # ####################################### ####################################### test_virtual_machine.delete(self.apiClient, True) self.attached = False vol = self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) self.assertEqual(vol.virtualmachineid, None, "Check if attached to virtual machine") self.assertEqual(vol.vmname, None, "Check if VM was expunged") list_virtual_machine_response = list_virtual_machines(self.apiClient, id=test_virtual_machine.id) self.assertEqual(list_virtual_machine_response, None, "Check if VM was actually expunged") sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) sf_util.check_size_and_iops(sf_volume, vol, sf_volume_size, self) self.assertEqual(len(sf_volume["volumeAccessGroups"]), 0, TestVolumes._volume_should_not_be_in_a_vag) self._check_xen_sr(sf_iscsi_name, False)
def test_06_attach_volume_to_stopped_VM(self): """Attach a volume to a stopped virtual machine, then start VM""" self.virtual_machine.stop(self.apiClient) sf_account_id = sf_util.get_sf_account_id( self.cs_api, self.account.id, self.primary_storage.id, self, TestVolumes._sf_account_id_should_be_non_zero_int_err_msg, ) sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id, self.primary_storage.id, self) self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) ####################################### ####################################### # STEP 1: Attach volume to stopped VM # ####################################### ####################################### self.volume = self.virtual_machine.attach_volume(self.apiClient, self.volume) self.attached = True vol = self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) vm = self._get_vm(self.virtual_machine.id) self.assertEqual(vol.virtualmachineid, vm.id, TestVolumes._volume_vm_id_and_vm_id_do_not_match_err_msg) self.assertEqual(vm.state.lower(), "stopped", TestVolumes._vm_not_in_stopped_state_err_msg) sf_iscsi_name = sf_util.get_iqn(self.cs_api, self.volume, self) sf_volume_size = sf_util.get_volume_size_with_hsr(self.cs_api, self.volume, self) self._verify_hsr(self.disk_offering.disksize, self.disk_offering.hypervisorsnapshotreserve, sf_volume_size) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) sf_util.check_size_and_iops(sf_volume, vol, sf_volume_size, self) sf_util.check_vag(sf_volume, sf_vag_id, self) self._check_xen_sr(sf_iscsi_name) self.virtual_machine.start(self.apiClient) vol = self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) vm = self._get_vm(self.virtual_machine.id) self.assertEqual(vol.virtualmachineid, vm.id, TestVolumes._volume_vm_id_and_vm_id_do_not_match_err_msg) self.assertEqual(vm.state.lower(), "running", TestVolumes._vm_not_in_running_state_err_msg) sf_iscsi_name = sf_util.get_iqn(self.cs_api, self.volume, self) sf_volume_size = sf_util.get_volume_size_with_hsr(self.cs_api, self.volume, self) self._verify_hsr(self.disk_offering.disksize, self.disk_offering.hypervisorsnapshotreserve, sf_volume_size) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) sf_util.check_size_and_iops(sf_volume, vol, sf_volume_size, self) sf_util.check_vag(sf_volume, sf_vag_id, self) self._check_xen_sr(sf_iscsi_name)
def test_05_detach_vol_stopped_VM_start(self): """Detach volume from a stopped VM, then start.""" self.virtual_machine.start(self.apiClient) sf_account_id = sf_util.get_sf_account_id( self.cs_api, self.account.id, self.primary_storage.id, self, TestVolumes._sf_account_id_should_be_non_zero_int_err_msg, ) sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id, self.primary_storage.id, self) self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) ####################################### ####################################### # STEP 1: Attach volume to running VM # ####################################### ####################################### self.volume = self.virtual_machine.attach_volume(self.apiClient, self.volume) self.attached = True vol = self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) vm = self._get_vm(self.virtual_machine.id) self.assertEqual(vol.virtualmachineid, vm.id, TestVolumes._volume_vm_id_and_vm_id_do_not_match_err_msg) self.assertEqual(vm.state.lower(), "running", TestVolumes._vm_not_in_running_state_err_msg) sf_iscsi_name = sf_util.get_iqn(self.cs_api, self.volume, self) sf_volume_size = sf_util.get_volume_size_with_hsr(self.cs_api, self.volume, self) self._verify_hsr(self.disk_offering.disksize, self.disk_offering.hypervisorsnapshotreserve, sf_volume_size) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) sf_util.check_size_and_iops(sf_volume, vol, sf_volume_size, self) sf_util.check_vag(sf_volume, sf_vag_id, self) self._check_xen_sr(sf_iscsi_name) ######################################### ######################################### # STEP 2: Detach volume from stopped VM # ######################################### ######################################### self.virtual_machine.stop(self.apiClient) self.volume = self.virtual_machine.detach_volume(self.apiClient, self.volume) self.attached = False vol = self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) vm = self._get_vm(self.virtual_machine.id) self.assertEqual(vol.virtualmachineid, None, "The volume should not be attached to a VM.") self.assertEqual(vm.state.lower(), "stopped", TestVolumes._vm_not_in_stopped_state_err_msg) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) self.assertEqual(len(sf_volume["volumeAccessGroups"]), 0, TestVolumes._volume_should_not_be_in_a_vag) self._check_xen_sr(sf_iscsi_name, False) ####################################### ####################################### # STEP 3: Start VM with detached vol # ####################################### ####################################### self.virtual_machine.start(self.apiClient) vol = self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) vm = self._get_vm(self.virtual_machine.id) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) self.assertEqual(len(sf_volume["volumeAccessGroups"]), 0, TestVolumes._volume_should_not_be_in_a_vag) self._check_xen_sr(sf_iscsi_name, False)
def test_10_attach_more_than_one_disk_to_VM(self): """Attach more than one disk to a VM""" self.virtual_machine.start(self.apiClient) volume_2 = Volume.create( self.apiClient, self.testdata[TestData.volume_2], zoneid=self.zone.id, account=self.account.name, domainid=self.domain.id, diskofferingid=self.disk_offering.id, ) self.cleanup.append(volume_2) self._check_and_get_cs_volume(volume_2.id, self.testdata[TestData.volume_2][TestData.diskName]) ####################################### ####################################### # Step 1: Attach volumes to VM # ####################################### ####################################### self.virtual_machine.attach_volume(self.apiClient, self.volume) self.attached = True vol = self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) self.virtual_machine.attach_volume(self.apiClient, volume_2) vol_2 = self._check_and_get_cs_volume(volume_2.id, self.testdata[TestData.volume_2][TestData.diskName]) sf_account_id = sf_util.get_sf_account_id( self.cs_api, self.account.id, self.primary_storage.id, self, TestVolumes._sf_account_id_should_be_non_zero_int_err_msg, ) sf_volume_size = sf_util.get_volume_size_with_hsr(self.cs_api, self.volume, self) self._verify_hsr(self.disk_offering.disksize, self.disk_offering.hypervisorsnapshotreserve, sf_volume_size) sf_volume_2_size = sf_util.get_volume_size_with_hsr(self.cs_api, volume_2, self) self._verify_hsr(self.disk_offering.disksize, self.disk_offering.hypervisorsnapshotreserve, sf_volume_2_size) sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id, self.primary_storage.id, self) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) sf_util.check_size_and_iops(sf_volume, vol, sf_volume_size, self) sf_iscsi_name = sf_util.get_iqn(self.cs_api, self.volume, self) self._check_xen_sr(sf_iscsi_name) sf_util.check_vag(sf_volume, sf_vag_id, self) sf_volume_2 = sf_util.check_and_get_sf_volume(sf_volumes, vol_2.name, self) sf_util.check_size_and_iops(sf_volume_2, vol_2, sf_volume_2_size, self) sf_iscsi_name_2 = sf_util.get_iqn(self.cs_api, volume_2, self) self._check_xen_sr(sf_iscsi_name_2) sf_util.check_vag(sf_volume_2, sf_vag_id, self) self.virtual_machine.detach_volume(self.apiClient, volume_2)
def test_09_attach_volumes_multiple_accounts(self): """Attach a data disk to a VM in one account and attach another data disk to a VM in another account""" self.virtual_machine.start(self.apiClient) ####################################### ####################################### # STEP 1: Create account, VM, and vol # ####################################### ####################################### test_account = Account.create(self.apiClient, self.testdata[TestData.testAccount], admin=1) self.cleanup.append(test_account) test_virtual_machine = VirtualMachine.create( self.apiClient, self.testdata[TestData.virtualMachine2], accountid=test_account.name, zoneid=self.zone.id, serviceofferingid=self.compute_offering.id, templateid=self.template.id, domainid=self.domain.id, startvm=True, ) test_volume = Volume.create( self.apiClient, self.testdata[TestData.volume_2], zoneid=self.zone.id, account=test_account.name, domainid=self.domain.id, diskofferingid=self.disk_offering.id, ) self._check_and_get_cs_volume(test_volume.id, self.testdata[TestData.volume_2][TestData.diskName]) ####################################### ####################################### # STEP 2: Attach volumes to VMs # ####################################### ####################################### self.volume = self.virtual_machine.attach_volume(self.apiClient, self.volume) self.attached = True vol = self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) vm = self._get_vm(self.virtual_machine.id) self.assertEqual(vol.virtualmachineid, vm.id, "Check if attached to virtual machine") self.assertEqual(vm.state.lower(), "running", str(vm.state)) test_volume = test_virtual_machine.attach_volume(self.apiClient, test_volume) test_vol = self._check_and_get_cs_volume(test_volume.id, self.testdata[TestData.volume_2][TestData.diskName]) test_vm = self._get_vm(test_virtual_machine.id) self.assertEqual(test_vol.virtualmachineid, test_vm.id, "Check if attached to virtual machine of other acct") self.assertEqual(test_vm.state.lower(), "running", str(test_vm.state)) sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id, self.primary_storage.id, self) sf_account_id = sf_util.get_sf_account_id( self.cs_api, self.account.id, self.primary_storage.id, self, TestVolumes._sf_account_id_should_be_non_zero_int_err_msg, ) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) sf_volume_size = sf_util.get_volume_size_with_hsr(self.cs_api, vol, self) self._verify_hsr(self.disk_offering.disksize, self.disk_offering.hypervisorsnapshotreserve, sf_volume_size) sf_util.check_size_and_iops(sf_volume, vol, sf_volume_size, self) sf_iscsi_name = sf_util.get_iqn(self.cs_api, self.volume, self) self._check_xen_sr(sf_iscsi_name) sf_util.check_vag(sf_volume, sf_vag_id, self) sf_test_account_id = sf_util.get_sf_account_id( self.cs_api, test_account.id, self.primary_storage.id, self, TestVolumes._sf_account_id_should_be_non_zero_int_err_msg, ) sf_test_volumes = self._get_active_sf_volumes(sf_test_account_id) sf_test_volume = sf_util.check_and_get_sf_volume(sf_test_volumes, test_vol.name, self) sf_test_volume_size = sf_util.get_volume_size_with_hsr(self.cs_api, test_vol, self) self._verify_hsr(self.disk_offering.disksize, self.disk_offering.hypervisorsnapshotreserve, sf_test_volume_size) sf_util.check_size_and_iops(sf_test_volume, test_vol, sf_test_volume_size, self) sf_test_iscsi_name = sf_util.get_iqn(self.cs_api, test_volume, self) self._check_xen_sr(sf_test_iscsi_name) sf_util.check_vag(sf_test_volume, sf_vag_id, self)
def test_02_attach_detach_attach_volume(self): '''Attach, detach, and attach volume to a running VM''' self.virtual_machine.start(self.apiClient) sf_account_id = sf_util.get_sf_account_id(self.cs_api, self.account.id, self.primary_storage.id, self, TestVolumes._sf_account_id_should_be_non_zero_int_err_msg) sf_vag_id = sf_util.get_vag_id(self.cs_api, self.cluster.id, self.primary_storage.id, self) self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) ####################################### ####################################### # STEP 1: Attach volume to running VM # ####################################### ####################################### self.volume = self.virtual_machine.attach_volume( self.apiClient, self.volume ) self.attached = True vol = self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) vm = self._get_vm(self.virtual_machine.id) self.assertEqual( vol.virtualmachineid, vm.id, TestVolumes._volume_vm_id_and_vm_id_do_not_match_err_msg ) self.assertEqual( vm.state.lower(), 'running', TestVolumes._vm_not_in_running_state_err_msg ) sf_iscsi_name = sf_util.get_iqn(self.cs_api, self.volume, self) sf_volume_size = sf_util.get_volume_size_with_hsr(self.cs_api, self.volume, self) self._verify_hsr(self.disk_offering.disksize, self.disk_offering.hypervisorsnapshotreserve, sf_volume_size) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) sf_util.check_size_and_iops(sf_volume, vol, sf_volume_size, self) sf_util.check_vag(sf_volume, sf_vag_id, self) self._check_xen_sr(sf_iscsi_name) ######################################### ######################################### # STEP 2: Detach volume from running VM # ######################################### ######################################### self.volume = self.virtual_machine.detach_volume( self.apiClient, self.volume ) self.attached = False vol = self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) vm = self._get_vm(self.virtual_machine.id) self.assertEqual( vol.virtualmachineid, None, "The volume should not be attached to a VM." ) self.assertEqual( vm.state.lower(), 'running', str(vm.state) ) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) self.assertEqual( len(sf_volume.volume_access_groups), 0, "The volume should not be in a VAG." ) self._check_xen_sr(sf_iscsi_name, False) ####################################### ####################################### # STEP 3: Attach volume to running VM # ####################################### ####################################### self.volume = self.virtual_machine.attach_volume( self.apiClient, self.volume ) self.attached = True vol = self._check_and_get_cs_volume(self.volume.id, self.testdata[TestData.volume_1][TestData.diskName]) vm = self._get_vm(self.virtual_machine.id) self.assertEqual( vol.virtualmachineid, vm.id, TestVolumes._volume_vm_id_and_vm_id_do_not_match_err_msg ) self.assertEqual( vm.state.lower(), 'running', TestVolumes._vm_not_in_running_state_err_msg ) sf_volumes = self._get_active_sf_volumes(sf_account_id) sf_volume = sf_util.check_and_get_sf_volume(sf_volumes, vol.name, self) sf_util.check_vag(sf_volume, sf_vag_id, self) self._check_xen_sr(sf_iscsi_name)