def operate_vm_parall(self, vm_uuid): try: vm_ops.reboot_vm(vm_uuid, self.session_uuid) v1 = test_lib.lib_get_vm_by_uuid(vm_uuid) if v1.state == "Rebooting": test_util.test_fail('Fail to reboot VM %s.' % v1.uuid) except: self.exc_info.append(sys.exc_info())
def stop(self, session_uuid = None): self.vm = vm_ops.stop_vm(self.vm.uuid, None, session_uuid) super(ZstackTestVm, self).stop() if ha_ops.get_vm_instance_ha_level(self.vm.uuid): status = self.vm.state while status != 'Running': vm_inv = test_lib.lib_get_vm_by_uuid(self.vm.uuid) status = vm_inv.state self.set_state(vm_header.RUNNING)
def check(self): super(zstack_kvm_virtioscsi_shareable_checker, self).check() volume = self.test_obj.volume has_volume = False shareable = False check_result = False #sv_cond = res_ops.gen_query_conditions("volumeUuid", '=', volume.uuid) #share_volume_vm_uuids = res_ops.query_resource_fields(res_ops.SHARE_VOLUME, sv_cond, None, fields=['vmInstanceUuid']) #test_util.test_logger('share_volume_vm_uuids is %s' %share_volume_vm_uuids) print "volume_uuid= %s" % (volume.uuid) sv_cond = res_ops.gen_query_conditions("volumeUuid", '=', volume.uuid) volume_vmInstanceUuid = res_ops.query_resource_fields( res_ops.SHARE_VOLUME, sv_cond, None, fields=['vmInstanceUuid'])[0].vmInstanceUuid pv_cond = res_ops.gen_query_conditions("volume.uuid", '=', volume.uuid) volume_ps_type = res_ops.query_resource_fields(res_ops.PRIMARY_STORAGE, pv_cond, None, fields=['type'])[0].type host = test_lib.lib_get_vm_host( test_lib.lib_get_vm_by_uuid(volume_vmInstanceUuid)) test_util.test_logger('vmInstanceUuid_host.ip is %s' % host.managementIp) test_util.test_logger('vmInstanceUuid is %s' % volume_vmInstanceUuid) #xml = os.popen('virsh dumpxml %s' % volume.vmInstanceUuid) xml = os.popen( 'sshpass -p password ssh root@%s -p %s "virsh dumpxml %s"' % (host.managementIp, host.sshPort, volume_vmInstanceUuid)) tree = ET.parse(xml) root = tree.getroot() for domain in root: if domain.tag == "devices": for device in domain: if device.tag == "disk": for disk in device: if disk.tag == "source": if volume_ps_type == "Ceph": if disk.get("name").find(volume.uuid) > 0: has_volume = True if volume_ps_type == "SharedBlock": if disk.get("file").find(volume.uuid) > 0: has_volume = True if disk.tag == "shareable": shareable = True if has_volume and shareable: check_result = True break test_util.test_logger( 'Check result: The result of check VirtioSCSI shareable label is %s' % check_result) return self.judge(check_result)
def operate_vm_parall(self, vm_uuid): try: #test_lib.lib_get_root_volume_uuid(rebootvms.vms[0]) vm=test_lib.lib_get_vm_by_uuid(vm_uuid) root_volume_uuid=test_lib.lib_get_root_volume_uuid(vm) sp_option = test_util.SnapshotOption() sp_option.set_name('simple_schduler_snapshot') sp_option.set_volume_uuid(root_volume_uuid) schd = vol_ops.create_snapshot_scheduler(sp_option, 'simple', 'simple_create_snapshot_scheduler', 0, 1, 1) except: self.exc_info.append(sys.exc_info())
def check_operation_result(self): for x in range(30): start_msg_mismatch=1 time.sleep(10) for i in range(0, self.i): vm_stat_flag=0 v1 = test_lib.lib_get_vm_by_uuid(self.vms[i].uuid) if v1.state != "Running": start_msg_mismatch += 1 vm_stat_flag=1 if vm_stat_flag == 0: break if start_msg_mismatch > 30: test_util.test_fail('StartVmInstance scheduler doesn\'t work as expected')
def check_operation_result(self): for x in range(30): start_msg_mismatch=1 time.sleep(10) for i in range(0, self.i): vm_stat_flag=0 v1 = test_lib.lib_get_vm_by_uuid(self.vms[i].uuid) if v1.state != "Stopped": start_msg_mismatch += 1 vm_stat_flag=1 if vm_stat_flag == 0: break if start_msg_mismatch > 30: test_util.test_fail('StopVmInstance scheduler doesn\'t work as expected')
def check_operation_result(self): time.sleep(30) start_msg_mismatch = 1 for k in range(0, 1000): for i in range(0, self.i): vm_stat_flag=0 vm=test_lib.lib_get_vm_by_uuid(self.vms[i].uuid) root_volume_uuid=test_lib.lib_get_root_volume_uuid(vm) if not test_lib.lib_find_in_local_management_server_log(self.date+k, '[msg send]: {"org.zstack.header.volume.CreateVolumeSnapshotMsg', self.vms[i].uuid): test_util.test_warn('CreateVolumeSnapshotMsg is expected to execute at %s' % (self.date+k)) vm_stat_flag=1 start_msg_mismatch += 1 if vm_stat_flag == 0: break if start_msg_mismatch > 1000: test_util.test_fail('%s of 1000 CreateVolumeSnapshotMsg not executed at expected timestamp' % (start_msg_mismatch))
def update(self): ''' If vm's status was changed by none vm operations, it needs to call vm.update() to update vm's infromation. The none vm operations: host.maintain() host.delete(), zone.delete() cluster.delete() ''' super(ZstackTestVm, self).update() if self.get_state != vm_header.EXPUNGED: updated_vm = test_lib.lib_get_vm_by_uuid(self.vm.uuid) if updated_vm: self.vm = updated_vm #vm state need to chenage to stopped, if host is deleted host = test_lib.lib_find_host_by_vm(updated_vm) if not host and self.vm.state != vm_header.STOPPED: self.set_state(vm_header.STOPPED) else: self.set_state(vm_header.EXPUNGED) return self.vm
def check_operation_result(self): for i in range(0, self.i): v1 = test_lib.lib_get_vm_by_uuid(self.vms[i].uuid) if v1 is not None: test_util.test_fail('Fail to expunge VM %s.' % v1.uuid)
def create_from(self, uuid): self.vm = test_lib.lib_get_vm_by_uuid(uuid) self.set_state(self.vm.state) self.update()
def check_operation_result(self): #should be defined by case for i in range(0, self.i): v1 = test_lib.lib_get_vm_by_uuid(self.vms[i].uuid) if v1.state == self.justify_con: test_util.test_fail('Fail to operate VM %s.' % v1.uuid)
def check_operation_result(self): for i in range(0, self.i): v1 = test_lib.lib_get_vm_by_uuid(self.vms[i].uuid) if v1.state != "Destroyed": test_util.test_fail('Fail to destroy VM %s.' % v1.uuid)
def check_operation_result(self): for i in range(0, self.i): vi = test_lib.lib_get_vm_by_uuid(self.vms[i].uuid) if v1.state == "Stopped": test_util.test_fail('Fail to start VM %s.' % v1.uuid)
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_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.")