def test(): global test_obj_dict ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern1 = os.environ['l3vCenterNoVlanNetworkName'] disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('largeDiskOfferingName')) test_util.test_dsc('Create vm and check') vm = test_stub.create_vm_in_vcenter(vm_name='test_for_instantiated_vm', image_name=ova_image_name, l3_name=network_pattern1) test_obj_dict.add_vm(vm) ps_uuid = vm.vm.allVolumes[0].primaryStorageUuid vm.check() test_util.test_dsc('Create volumes and check') volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_name('vcenter_volume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume_creation_option.set_name('vcenter_volume1') volume_creation_option.set_primary_storage_uuid(ps_uuid) volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) volume1.check() test_util.test_dsc('Attach volumes and check') volume.attach(vm) volume.check() vm.stop() volume1.attach(vm) if volume.volume.installPath == "vcenter://empty" or volume1.volume.installPath != "vcenter://empty": test_util.test_fail("check data volumes fail") vm.start() test_util.test_logger( test_lib.lib_get_volume_by_uuid(volume1.get_volume().uuid)) db_volume1 = test_lib.lib_get_volume_by_uuid(volume1.get_volume().uuid) if db_volume1.installPath == "vcenter://empty": test_util.test_fail("check data volumes fail") #cleanup test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass( "Test data volume will be instantiated at vm startup in vcenter passed." )
def update_volume(self): ''' Called by snapshot actions, since snapshot action will change volume installPath ''' if self.state != volume_header.EXPUNGED: self.set_volume(test_lib.lib_get_volume_by_uuid(self.volume.uuid))
def update(self): if self.state == volume_header.ATTACHED \ and self.get_target_vm() \ and self.get_target_vm().get_state() == vm_header.DESTROYED: if self.get_volume().type != 'Root': self.set_volume( test_lib.lib_get_volume_by_uuid(self.get_volume().uuid)) super(ZstackTestVolume, self).detach() else: super(ZstackTestVolume, self).delete()
def test(): global test_obj_dict ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern1 = os.environ['l3vCenterNoVlanNetworkName'] disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('largeDiskOfferingName')) test_util.test_dsc('Create vm and check') vm = test_stub.create_vm_in_vcenter(vm_name='test_volume_after_sync_vm', image_name=ova_image_name, l3_name=network_pattern1) test_obj_dict.add_vm(vm) vm.check() ps_uuid = vm.vm.allVolumes[0].primaryStorageUuid vc_ps = test_lib.lib_get_primary_storage_by_uuid(ps_uuid) vc_host = test_lib.lib_find_host_by_vm(vm.vm).managementIp test_util.test_dsc('Create volumes and check') volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_name('vcenter_volume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) volume.check() volume_creation_option.set_name('vcenter_volume1') volume_creation_option.set_primary_storage_uuid(ps_uuid) volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) volume1.check() volume.detach() volume.check() volume1.attach(vm) volume1.check() volume1.delete() volume1.check() test_util.test_dsc('Sync vcenter') vc_name = os.environ['vcenter'] vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vc_name).uuid test_util.test_logger(vcenter_uuid) vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) test_util.test_dsc('check volumes after synchronizing vcenter') db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) db_volume1 = test_lib.lib_get_volume_by_uuid(volume1.get_volume().uuid) if db_volume.status != 'Ready' or db_volume1.status != 'Deleted': test_util.test_fail( "check data volumes fail after synchronizing vcenter") #connect vcenter import ssl from pyVmomi import vim import atexit from pyVim import connect import zstackwoodpecker.zstack_test.vcenter_checker.zstack_vcenter_vm_checker as vm_checker vcenter_password = os.environ['vcenterpwd'] vcenter_server = os.environ['vcenter'] vcenter_username = os.environ['vcenteruser'] sslContext = ssl.SSLContext(ssl.PROTOCOL_SSLv23) sslContext.verify_mode = ssl.CERT_NONE SI = connect.SmartConnect(host=vcenter_server, user=vcenter_username, pwd=vcenter_password, port=443, sslContext=sslContext) if not SI: test_util.test_fail("Unable to connect to the vCenter") content = SI.RetrieveContent() volume_installPath = vc_ps.url.split( '//')[1] + db_volume.installPath.split('[' + vc_ps.name + ']')[1].lstrip() test_util.test_logger(volume_installPath) cmd = 'rm -f %s' % volume_installPath vchost_user = os.environ['vchostUser'] vchost_password = os.environ['vchostpwd'] result = test_lib.lib_execute_ssh_cmd(vc_host, vchost_user, vchost_password, cmd, 180) atexit.register(connect.Disconnect, SI) test_util.test_dsc('Sync vcenter') vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) if db_volume: test_util.test_fail( "check data volumes fail after synchronizing vcenter") #cleanup vm.destroy() vm.expunge() volume1.expunge() test_util.test_pass("Test sync volume in vcenter passed.")
def test(): global test_obj_dict ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern1 = os.environ['l3vCenterNoVlanNetworkName'] disk_offering1 = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName')) test_util.test_dsc('Create vm and attach volume') vm = test_stub.create_vm_in_vcenter(vm_name = 'test_for_sync_vcenter_vm', image_name = ova_image_name, l3_name = network_pattern1) test_obj_dict.add_vm(vm) vm.check() volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering1.uuid) volume_creation_option.set_name('vcenter3_volume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) test_util.test_logger(volume.target_vm.state) volume.check() test_util.test_dsc('Destroy vm and its attached data volume both') vm.destroy() volume.delete() vm.check() volume.check() test_util.test_dsc('Check in vcenter after destroying vm and its attached data volume both in zstack') #connect vcenter import ssl from pyVmomi import vim import atexit from pyVim import connect import zstackwoodpecker.zstack_test.vcenter_checker.zstack_vcenter_vm_checker as vm_checker vcenter_password = os.environ['vcenterpwd'] vcenter_server = os.environ['vcenter'] vcenter_username = os.environ['vcenteruser'] sslContext = ssl.SSLContext(ssl.PROTOCOL_SSLv23) sslContext.verify_mode = ssl.CERT_NONE SI = connect.SmartConnect(host=vcenter_server, user=vcenter_username, pwd=vcenter_password, port=443, sslContext=sslContext) if not SI: test_util.test_fail("Unable to connect to the vCenter") content = SI.RetrieveContent() vc_vm = vm_checker.get_obj(content, [vim.VirtualMachine], name='test_for_sync_vcenter_vm') test_util.test_logger(vc_vm.summary.runtime.powerState) if not (vc_vm.summary.runtime.powerState == 'poweredOff'): test_util.test_fail("Vm should stop in vcenter") atexit.register(connect.Disconnect, SI) test_util.test_dsc('Sync vcenter') vc_name = os.environ['vcenter'] vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vc_name).uuid test_util.test_logger(vcenter_uuid) vct_ops.sync_vcenter(vcenter_uuid) #After synchronization, wait for the database update time.sleep(5) test_util.test_dsc('check vm and volumes after synchronizing vcenter') db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) test_util.test_logger(db_volume.status) if db_volume.status != 'Deleted': test_util.test_fail("check data volume fail") db_vm = test_lib.lib_get_vm_by_uuid(vm.vm.uuid) if db_vm.state == 'Destroyed': test_util.test_logger('check vm success') else: test_util.test_fail("check vm fail") vm.recover() vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) db_vm = test_lib.lib_get_vm_by_uuid(vm.vm.uuid) if db_vm.state == 'Stopped' and len(db_vm.allVolumes) == 1 and db_vm.allVolumes[0].type == 'Root' and db_vm.allVolumes[0].status == 'Ready': test_util.test_logger('check vm success') else: test_util.test_fail("check vm fail") vm.destroy() vm.expunge() vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) if test_lib.lib_get_vm_by_uuid(vm.vm.uuid): test_util.test_fail("check vm fail: vm has been expunged") #connect vcenter import ssl from pyVmomi import vim import atexit from pyVim import connect import zstackwoodpecker.zstack_test.vcenter_checker.zstack_vcenter_vm_checker as vm_checker vcenter_password = os.environ['vcenterpwd'] vcenter_server = os.environ['vcenter'] vcenter_username = os.environ['vcenteruser'] sslContext = ssl.SSLContext(ssl.PROTOCOL_SSLv23) sslContext.verify_mode = ssl.CERT_NONE SI = connect.SmartConnect(host=vcenter_server, user=vcenter_username, pwd=vcenter_password, port=443, sslContext=sslContext) if not SI: test_util.test_fail("Unable to connect to the vCenter") content = SI.RetrieveContent() vc_vm = vm_checker.get_obj(content, [vim.VirtualMachine], name='test_for_sync_vcenter_vm') if not isinstance(vc_vm, list): test_util.test_fail("check vm fail: vm has been expunged.") volume.expunge() test_util.test_pass("Sync vcenter test passed after destroying vm and its attached data volume both.")
def test(): global test_obj_dict ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern1 = os.environ['l3vCenterNoVlanNetworkName'] disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('largeDiskOfferingName')) test_util.test_dsc('Create vm and check') vm = test_stub.create_vm_in_vcenter(vm_name='test_volume_after_sync_vm', image_name=ova_image_name, l3_name=network_pattern1) test_obj_dict.add_vm(vm) vm.check() ps_uuid = vm.vm.allVolumes[0].primaryStorageUuid vc_ps = test_lib.lib_get_primary_storage_by_uuid(ps_uuid) vc_host = test_lib.lib_find_host_by_vm(vm.vm).managementIp test_util.test_dsc('Create volumes and check') volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_name('vcenter_volume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) volume.check() volume.detach() volume.check() volume_creation_option.set_name('vcenter_volume1') volume_creation_option.set_primary_storage_uuid(ps_uuid) volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) volume1.check() volume1.attach(vm) volume1.check() volume1.delete() volume1.check() test_util.test_dsc('Sync vcenter') vcenter_uuid = vct_ops.lib_get_vcenter_by_name(os.environ['vcenter']).uuid vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) test_util.test_dsc('check volumes after synchronizing vcenter') db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) db_volume1 = test_lib.lib_get_volume_by_uuid(volume1.get_volume().uuid) if db_volume.status != 'Ready' or db_volume1.status != 'Deleted': test_util.test_fail( "check data volumes fail after synchronizing vcenter") #delete volume file volume_installPath = vc_ps.url.split( '//')[1] + db_volume.installPath.split('[' + vc_ps.name + ']')[1].lstrip() test_util.test_logger(volume_installPath) cmd = 'rm -f %s' % volume_installPath vchost_user = os.environ['vchostUser'] vchost_password = os.environ['vchostpwd'] result = test_lib.lib_execute_ssh_cmd(vc_host, vchost_user, vchost_password, cmd, 180) test_util.test_dsc('Sync vcenter') vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) if db_volume: test_util.test_fail( "check data volumes fail after synchronizing vcenter") #cleanup vm.destroy() vm.expunge() volume1.expunge() test_util.test_pass("Test sync volume in vcenter passed.")
def test(): global test_obj_dict ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern1 = os.environ['l3vCenterNoVlanNetworkName'] disk_offering1 = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName')) test_util.test_dsc('Create vm and attach volume') vm = test_stub.create_vm_in_vcenter(vm_name = 'test_for_sync_vcenter_vm', image_name = ova_image_name, l3_name = network_pattern1) test_obj_dict.add_vm(vm) vm.check() volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering1.uuid) volume_creation_option.set_name('vcenter3_volume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) test_util.test_logger(volume.target_vm.state) volume.check() test_util.test_dsc('Destroy vm and its attached data volume both') vm.destroy() volume.delete() vm.check() volume.check() test_util.test_dsc('Sync vcenter') vc = os.environ.get('vcenter') vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vc).uuid vct_ops.sync_vcenter(vcenter_uuid) #After synchronization, wait for the database update time.sleep(5) test_util.test_dsc('check vm and volumes after synchronizing vcenter') db_volume = test_lib.lib_get_volume_by_uuid(volume.get_volume().uuid) if db_volume.status != 'Deleted': test_util.test_fail("check data volume fail") db_vm = test_lib.lib_get_vm_by_uuid(vm.vm.uuid) if db_vm.state == 'Destroyed': test_util.test_logger('check vm success') else: test_util.test_fail("check vm fail") vm.recover() vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) db_vm = test_lib.lib_get_vm_by_uuid(vm.vm.uuid) if db_vm.state == 'Stopped' and len(db_vm.allVolumes) == 1 and db_vm.allVolumes[0].type == 'Root' and db_vm.allVolumes[0].status == 'Ready': test_util.test_logger('check vm success') else: test_util.test_fail("check vm fail") vm.destroy() vm.expunge() #check in vcenter SI = vct_ops.connect_vcenter(vc) content = SI.RetrieveContent() vc_vm = vct_ops.get_vm(content, name='test_for_sync_vcenter_vm')[0] if vc_vm.name == 'test_for_sync_vcenter_vm' : test_util.test_fail("check vm fail: vm has been expunged.") vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) if test_lib.lib_get_vm_by_uuid(vm.vm.uuid): test_util.test_fail("check vm fail: vm has been expunged") volume.expunge() test_util.test_pass("Sync vcenter test passed after destroying vm and its attached data volume both.")