def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() vm.destroy() test_util.test_pass('PS maintain mode Test Success')
def test(): global session_uuid session_uuid = acc_ops.login_as_admin() l3_1_name = os.environ.get('l3VlanNetworkName1') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #create VRs. vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid) if not vrs: vm = test_stub.create_vlan_vm(l3_name=l3_1_name) vm.destroy() vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] else: vr1 = vrs[0] vm_ops.stop_vm(vr1.uuid) if test_lib.lib_get_ha_enable() != 'true' or vr1.applianceVmType != "vrouter": vm_ops.start_vm(vr1.uuid) vr1_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr1) if not test_lib.lib_wait_target_up(vr1_mgmt_ip, '7272', 120): test_util.test_fail('vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr1.uuid) timeout = time.time() + 60 while time.time() < timeout: cond = res_ops.gen_query_conditions('uuid', '=', vr1.uuid) vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond) if vms[0].status == 'Connected': test_util.test_pass('Test Reconnect VR VM start VRs success') time.sleep(1) test_util.test_fail('VR VM: %s is not connected within 60 seconds' % vr1.uuid)
def test(): test_util.test_dsc('Test Change VM Image In Multihosts Env') global vm image = test_lib.lib_get_image_by_name("centos") vm = test_stub.create_vm(image_uuid=image.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid last_host_uuid = test_lib.lib_get_vm_last_host(vm.get_vm()).uuid image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_uuid = vm.get_vm().uuid host_ops.change_host_state(host_uuid = last_host_uuid, state = 'disable') vm_ops.stop_vm(vm_uuid) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #Disable vm's host.If ps is shared storage,the vm will be started on another host that meets the conditions and the operation of changing vm image will success. if ps.type != 'LocalStorage': vm_ops.change_vm_image(vm_uuid,image_uuid) vm_ops.start_vm(vm_uuid) #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') vm.destroy() test_util.test_pass('Change Vm Image Test Success In Multihosts Env Success') #Disable vm's host.If ps is local storage,the operation of changing vm image will fail. else: try: vm_ops.change_vm_image(vm_uuid, image_uuid) except: test_util.test_pass('Change Vm Image Test Success In Multihosts Env Success') test_util.test_fail('Test Change VM Image In Multihosts Env Success Failed')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions("status", '=', "Connected") bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) os.system("echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm.vm.uuid) ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() vm.destroy() vm.check() #vm.expunge() #vm.check() test_util.test_pass('PS maintain mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.delete() volume.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() volume.recover() volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() volume.delete() #volume.expunge() volume.check() vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS maintain mode Test Success')
def env_recover(): local_ps, shared_ps = test_stub.PSEnvChecker().get_two_ps() if local_ps.state in ('Disabled', "Maintenance"): ps_ops.change_primary_storage_state(local_ps.uuid, state='enable') if shared_ps.state in ('Disabled', "Maintenance"): ps_ops.change_primary_storage_state(shared_ps.uuid, state='enable') for vr in res_ops.get_resource(res_ops.APPLIANCE_VM): if vr.state != inventory.RUNNING: vm_ops.start_vm(vr.uuid) test_lib.lib_error_cleanup(test_obj_dict)
def check_resource(): hosts = res_ops.query_resource(res_ops.HOST, [], None) for host in hosts: if host.status != "Connected": host_ops.reconnect_host(host.uuid) return False pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, [], None) for ps in pss: if ps.status != "Connected": ps_ops.reconnect_primary_storage(ps.uuid) return False bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, [], None) for bs in bss: if bs.status != "Connected": bs_ops.reconnect_backup_storage(bs.uuid) return False if os.environ.get('WOODPECKER_PARALLEL') != None and os.environ.get('WOODPECKER_PARALLEL') == '0': vms = res_ops.query_resource(res_ops.VM_INSTANCE, [], None) for vm in vms: if vm.type == 'UserVm': try: vm_ops.destroy_vm(vm.uuid) except: test_util.test_logger('ignore exception try to destroy vm') try: vm_ops.expunge_vm(vm.uuid) except: test_util.test_logger('ignore exception try to expunge vm') vrs = res_ops.query_resource(res_ops.APPLIANCE_VM, [], None) for vr in vrs: if vr.status != "Connected" or vr.state != "Running": if vr.applianceVmType != "vrouter": try: vm_ops.stop_vm(vr.uuid, force='cold') vm_ops.start_vm(vr.uuid) except: test_util.test_logger('Exception when reboot vr vm') else: try: vm_ops.stop_vm(vr.uuid, force='cold') except: test_util.test_logger('Exception when reboot vr vm') return False return True
def error_cleanup(): global ps_uuid if ps_uuid != None: ps_ops.change_primary_storage_state(ps_uuid, 'enable') global host_uuid if host_uuid != None: host_ops.reconnect_host(host_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) #global vr_uuid #if vr_uuid != None: # vm_ops.reconnect_vr(vr_uuid) global test_obj_dict test_lib.lib_error_cleanup(test_obj_dict)
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) test_stub.ensure_pss_connected() vrs = test_lib.lib_get_all_vrs() for vr in vrs: vr_cond = res_ops.gen_query_conditions('uuid', '=', vr.uuid) vr_inv = res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0] if vr_inv.state == 'Stopped': vm_ops.start_vm(vr.uuid) else: test_lib.lib_wait_target_up(vr_inv.vmNics[0].ip, '22', 360) for _ in xrange(100): if res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0].state != 'Running': time.sleep(3) else: break vm.start() vm.check() vm.destroy() test_util.test_pass('PS maintain mode Test Success')
def test(): global vcenter_uuid, vm_uuid vcenter1_name = os.environ['vcenter2_name'] vcenter1_domain_name = os.environ['vcenter2_ip'] vcenter1_username = os.environ['vcenter2_domain_name'] vcenter1_password = os.environ['vcenter2_password'] #ova_image_name = os.environ['vcenter2_template_exist'] vm_name = os.environ['vcenter2_no_nic_vm'] network_pattern1 = os.environ['vcenter2_network_pattern1'] zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid) vcenter_uuid = inv.uuid if vcenter_uuid == None: test_util.test_fail("vcenter_uuid is None") #vm = test_stub.create_vm_in_vcenter(vm_name = 'vm-start-stop-test', image_name = ova_image_name, l3_name = network_pattern1) vm_cond = res_ops.gen_query_conditions("name", '=', vm_name) vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("remote woodpecker vm uuid is null") elif vm_uuid and vm_state != "running": print "#%s#" % vm_state vm_ops.start_vm(vm_uuid) if not test_lib.lib_wait_target_up(vm_inv.vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running') vm.stop() if not test_lib.lib_wait_target_down(vm_inv.vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stopped') elif vm_uuid and vm_state == "running": print "#%s#" % vm_state vm.stop() if not test_lib.lib_wait_target_down(vm_inv.vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stopped') vm_ops.start_vm(vm_uuid) if not test_lib.lib_wait_target_up(vm_inv.vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running') vm_ops.destroy_vm(vm_uuid) vm_ops.expunge_vm(vm_uuid) vct_ops.delete_vcenter(vcenter_uuid) test_util.test_pass("vm start and stop of vcenter test passed.")
def test(): session_uuid = acc_ops.login_as_admin() acc_ops.logout(session_uuid) image_name = os.environ.get('imageName3') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid try: vm = test_stub.create_vm(image_uuid = image_uuid, session_uuid=session_uuid) test_util.test_fail('Expect exception after logout while there is none') except: pass vm = test_stub.create_vm(image_uuid = image_uuid) vm_ops.stop_vm(vm.get_vm().uuid) vm_ops.start_vm(vm.get_vm().uuid) try: vm_ops.stop_vm(vm.get_vm().uuid, session_uuid=session_uuid) test_util.test_fail('Expect exception after logout while there is none') except: pass vm.destroy() vm.expunge() test_util.test_pass('Test operations after session logout passed')
def ensure_vr_is_running_connected(l3_uuid): vr_list = test_lib.lib_find_vr_by_l3_uuid(l3_uuid) if not vr_list: return if vr_list[0].applianceVmType == "VirtualRouter": if vr_list[0].state == "Stopped": vm_ops.start_vm(vr_list[0].uuid) elif vr_list[0].applianceVmType == "vrouter": pass else: test_util.test_fail("current vr type not support in ensure_vr_is_connected.") cond = res_ops.gen_query_conditions('uuid', '=', vr_list[0].uuid) for i in range(600): time.sleep(1) vr1 = res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0] if vr1.state == "Running" and vr1.status == "Connected": test_util.test_logger("vr has successfully changed to Running and Connected") break else: test_util.test_fail("vr has not been successfully changed to Running and Connected within 300s: state=%s:status=%s" %(vr1.state, vr1.status))
def ensure_vr_is_running_connected(l3_uuid): vr_list = test_lib.lib_find_vr_by_l3_uuid(l3_uuid) if not vr_list: return if vr_list[0].applianceVmType == "VirtualRouter": if vr_list[0].state == "Stopped": vm_ops.start_vm(vr_list[0].uuid) elif vr_list[0].applianceVmType == "vrouter": pass else: test_util.test_fail("current vr type not support in ensure_vr_is_connected.") cond = res_ops.gen_query_conditions('uuid', '=', vr_list[0].uuid) for i in range(300): time.sleep(1) vr1 = res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0] if vr1.state == "Running" and vr1.status == "Connected": test_util.test_logger("vr has successfully changed to Running and Connected") break else: test_util.test_fail("vr has not been successfully changed to Running and Connected within 300s: state=%s:status=%s" %(vr1.state, vr1.status))
def test(): new_offering = test_lib.lib_create_instance_offering(cpuNum = 1,\ memorySize = 1024 * 1024 * 1024) test_obj_dict.add_instance_offering(new_offering) vm = test_stub.create_vm(vm_name = 'ckvmoffering-c7-64', image_name = "imageName_i_c7", instance_offering_uuid=new_offering.uuid) test_obj_dict.add_vm(vm) vm.check() (available_cpu_before, available_memory_before, vm_outer_cpu_before, vm_outer_mem_before, vm_interal_cpu_before, vm_interal_mem_before) = test_stub.check_cpu_mem(vm, shutdown=True) vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid(vm.get_vm().instanceOfferingUuid) MEMchange = 126*1024*1024 AlignedMemChange = 128*1024*1024 vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum + 1, vm_instance_offering.memorySize + MEMchange) vm.update() time.sleep(10) vm.check() vm_ops.stop_vm(vm.get_vm().uuid) test_stub.wait_for_certain_vm_state(vm, 'stopped') vm_ops.start_vm(vm.get_vm().uuid) test_stub.wait_for_certain_vm_state(vm, 'running') vm.check() (available_cpu_after, available_memory_after, vm_outer_cpu_after, vm_outer_mem_after, vm_interal_cpu_after, vm_internal_mem_after) = test_stub.check_cpu_mem(vm, shutdown=True) assert available_cpu_before == available_cpu_after + 1 assert available_memory_after + AlignedMemChange / int(test_lib.lib_get_provision_memory_rate()) in range(available_memory_before-1, available_memory_before+1) assert vm_outer_cpu_before == vm_outer_cpu_after - 1 assert vm_outer_mem_before == vm_outer_mem_after - AlignedMemChange assert vm_interal_cpu_before == vm_interal_cpu_after - 1 assert vm_interal_mem_before == vm_internal_mem_after - AlignedMemChange/1024/1024 test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('VM online change instance offering Test Pass')
def test(): global session_uuid session_uuid = acc_ops.login_as_admin() l3_1_name = os.environ.get('l3VlanNetworkName1') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #create VRs. vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid) if not vrs: vm = test_stub.create_vlan_vm(l3_name=l3_1_name) vm.destroy() vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] else: vr1 = vrs[0] vm_ops.stop_vm(vr1.uuid) if test_lib.lib_get_ha_enable( ) != 'true' or vr1.applianceVmType != "vrouter": vm_ops.start_vm(vr1.uuid) vr1_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr1) if not test_lib.lib_wait_target_up(vr1_mgmt_ip, '7272', 120): test_util.test_fail( 'vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr1.uuid) timeout = time.time() + 60 while time.time() < timeout: cond = res_ops.gen_query_conditions('uuid', '=', vr1.uuid) vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond) if vms[0].status == 'Connected': test_util.test_pass('Test Reconnect VR VM start VRs success') time.sleep(1) test_util.test_fail('VR VM: %s is not connected within 60 seconds' % vr1.uuid)
def check_resource(): if os.environ.get('WOODPECKER_PARALLEL') != None and os.environ.get('WOODPECKER_PARALLEL') == '0': vms = res_ops.query_resource(res_ops.VM_INSTANCE, [], None) for vm in vms: if vm.type == 'UserVm' and vm.state == 'Running': vm_ops.stop_vm(vm.uuid, force='cold') vrs = res_ops.query_resource(res_ops.APPLIANCE_VM, [], None) for vr in vrs: if vr.status != "Connected" or vr.state != "Running": if vr.applianceVmType != "vrouter": try: vm_ops.stop_vm(vr.uuid, force='cold') vm_ops.start_vm(vr.uuid) except: test_util.test_logger('Exception when reboot vr vm') return False hosts = res_ops.query_resource(res_ops.HOST, [], None) for host in hosts: if host.status != "Connected": host_ops.reconnect_host(host.uuid) return False pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, [], None) for ps in pss: if ps.status != "Connected": ps_ops.reconnect_primary_storage(ps.uuid) return False bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, [], None) for bs in bss: if bs.status != "Connected": bs_ops.reconnect_backup_storage(bs.uuid) return False return True
def test(): ps_env = test_stub.PSEnvChecker() ps1, ps2 = ps_env.get_two_ps() vm_list = [] for root_vol_ps in [ps1, ps2]: for data_vol_ps in [ps1, ps2]: vm = test_stub.create_multi_vms(name_prefix='test_vm', count=1, ps_uuid=root_vol_ps.uuid, data_volume_number=VOLUME_NUMBER, ps_uuid_for_data_vol=data_vol_ps.uuid)[0] test_obj_dict.add_vm(vm) vm_list.append(vm) vm1, vm2, vm3, vm4 = vm_list for vm in vm_list: ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") ps_ops.change_primary_storage_state(state='maintain', primary_storage_uuid=ps2.uuid) maintenance_ps_list.append(ps2) time.sleep(60) vr_vm_list = test_lib.lib_find_vr_by_vm(vm1.get_vm()) vr_vm = None if vr_vm_list: vr_vm = vr_vm_list[0] if vr_vm.allVolumes[0].primaryStorageUuid == ps2.uuid: assert vr_vm.state == inventory.STOPPED else: assert vr_vm.state == inventory.RUNNING vm1.check() else: vm1.check() for vm in vm_list: vm.update() assert vm1.get_vm().state == inventory.RUNNING assert vm2.get_vm().state == inventory.STOPPED assert vm3.get_vm().state == inventory.STOPPED assert vm4.get_vm().state == inventory.STOPPED for vm in [vm2, vm3, vm4]: with test_stub.expected_failure("start vm in maintenance ps", Exception): vm.start() test_util.test_dsc('enable ps2') ps_ops.change_primary_storage_state(state='enable', primary_storage_uuid=ps2.uuid) maintenance_ps_list.remove(ps2) if vr_vm and vr_vm.state == inventory.STOPPED: vm_ops.start_vm(vr_vm.uuid) time.sleep(10) for vm in [vm2, vm3, vm4]: vm.start() for vm in [vm2, vm3, vm4]: vm.update() vm.check() test_util.test_pass('Multi PrimaryStorage Test Pass')
def stopped_vm_operations(vm,bss): vm_uuid = vm.get_vm().uuid ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) vm_ops.stop_vm(vm_uuid) #Change vm's instanceoffering vm_ops.update_vm(vm_uuid,2,2048*1024*1024) #Change vm's status ha_ops.set_vm_instance_ha_level(vm_uuid,'neverstop') vm_ops.stop_vm(vm_uuid) ha_ops.del_vm_instance_ha_level(vm_uuid) vm_ops.stop_vm(vm_uuid) if ps.type != 'LocalStorage': target_host_uuid = test_lib.lib_find_random_host(vm.get_vm()).uuid if target_host_uuid != None: vm_ops.start_vm_with_target_host(vm_uuid,target_host_uuid) #vm_ops.stop_vm(vm_uuid) vm_ops.destroy_vm(vm_uuid) vm_ops.recover_vm(vm_uuid) vm_ops.reinit_vm(vm_uuid) #clone vm_ops.clone_vm(vm_uuid,['vm-1','vm-2','vm-3'],'InstantStart') #migrate vm_ops.start_vm(vm_uuid) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) vm_ops.stop_vm(vm_uuid) migrate_host_uuids = [] if candidate_hosts != None: for host in candidate_hosts.inventories: migrate_host_uuids.append(host.uuid) if ps.type == 'LocalStorage': vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid #vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) vol_ops.migrate_volume(vol_uuid, migrate_host_uuids[0]) test_util.test_logger('migrate vm success') #resize root volume vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024*1024*1024*5 vol_ops.resize_volume(vol_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) test_util.test_logger('resize vm success') #storage migrate #change vm image image_list = vm_ops.get_image_candidates_for_vm_to_change(vm_uuid) image_uuids = [] for image in image_list.inventories: image_uuids.append(image.uuid) vm_ops.change_vm_image(vm_uuid,image_uuids[0]) vm.update() #update vm nic mac nic_uuid = vm.get_vm().vmNics[0].uuid mac = 'fa:4c:ee:9a:76:00' vm_ops.update_vm_nic_mac(nic_uuid,mac) #set/del static ip l3network_uuid = test_lib.lib_get_l3_uuid_by_nic(nic_uuid) vm_ops.change_vm_static_ip(vm_uuid, l3network_uuid, vm.get_vm().vmNics[0].ip) vm_ops.delete_vm_static_ip(vm_uuid, l3network_uuid) #snapshot operations sp_option = test_util.SnapshotOption() vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid sp_option.set_volume_uuid(root_volume_uuid) sp = vol_ops.create_snapshot(sp_option) vol_ops.use_snapshot(sp.uuid) vol_ops.delete_snapshot(sp.uuid) common_operations(vm,bss,'stopped') vm.destroy() vm.expunge()
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout global test_host if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) vr_host_ips = [] for vr in vrs: vr_host_ips.append(test_lib.lib_find_host_by_vr(vr).managementIp) if test_lib.lib_is_vm_running(vr) != True: vm_ops.start_vm(vr.uuid) time.sleep(60) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '=', mn_ip, conditions) #for vr_host_ip in vr_host_ips: # conditions = res_ops.gen_query_conditions('managementIp', '!=', vr_host_ip, conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() if not test_lib.lib_check_vm_live_migration_cap(vm.vm): test_util.test_skip('skip ha if live migrate not supported') ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on localstorage') host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_util.test_logger("host %s is disconnecting" % (host_ip)) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") host_list = test_stub.get_sce_hosts(test_lib.all_scenario_config, test_lib.scenario_file) for host in host_list: if host.ip_ == host_ip: test_host = host break if not test_host: test_util.test_fail('there is no host with ip %s in scenario file.' % (host_ip)) test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold') test_util.test_logger( "wait for 30 seconds to ensure vm disconnected, then just wait 90s for target up." ) time.sleep(30) if test_lib.lib_wait_target_up(vm.vm.vmNics[0].ip, '22', 90): test_util.test_logger("%s can be connected within 120s" % (vm.vm.vmNics[0].ip)) test_stub.start_host(test_host, test_lib.all_scenario_config) vm.destroy() test_util.test_pass('Test VM ha change to running within 120s Success')
def test(): test_util.test_dsc('Test Change VM Image Function') global vm #set overProvisioning.primaryStorage's value as 10 con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10) test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T") l3_uuid = test_lib.lib_get_l3_by_name("l3VlanNetwork1").uuid image_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid] vm = test_stub.create_vm(l3_uuid_list = [l3_uuid],image_uuid = image_uuid,vm_name="test-vm",disk_offering_uuids = disk_offering_uuids) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid vm_ops.stop_vm(vm_uuid) vr = test_lib.lib_find_vr_by_vm(vm.get_vm())[0] vr_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr) #stop vm's vr vm_ops.stop_vm(vr.uuid) #change vm image image_uuid = test_lib.lib_get_image_by_name("windows").uuid vm_ops.change_vm_image(vm_uuid,image_uuid) #check whether vr's status is running if vr.applianceVmType == 'vrouter': if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240): test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid) time.sleep(20) else: vm_ops.start_vm(vr.uuid) vm_ops.reconnect_vr(vr.uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the windows vm is running successfully vm_ip = vm.get_vm().vmNics[0].ip if not test_lib.lib_wait_target_up(vm_ip,'23',1200): test_util.test_fail('vm:%s is not startup in 1200 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') #check whether the linux vm is running successfully vm_ops.stop_vm(vm_uuid) #stop vm's vr vm_ops.stop_vm(vr.uuid) image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_ops.change_vm_image(vm_uuid,image_uuid) #check whether vr's status is running if vr.applianceVmType == 'vrouter': if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240): test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid) time.sleep(20) else: vm_ops.start_vm(vr.uuid) vm_ops.reconnect_vr(vr.uuid) vm_ops.start_vm(vm_uuid) if not test_lib.lib_wait_target_up(vm_ip,'22',120): test_util.test_fail('vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_linux = [] data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_linux: data_volumes_after_uuids_linux.append(data_volume.uuid) if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != l3network_uuid_after_linux: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_linux = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after_linux != primarystorage_uuid_after: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) test_util.test_pass('Change Vm Image Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") max_attempts = test_lib.lib_get_ha_selffencer_maxattempts() test_lib.lib_set_ha_selffencer_maxattempts('12') storagechecker_timeout = test_lib.lib_get_ha_selffencer_storagechecker_timeout() test_lib.lib_set_ha_selffencer_storagechecker_timeout('15') vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) for vr in vrs: if test_lib.lib_is_vm_running(vr) == True: vm_ops.start_vm(vr.uuid) time.sleep(60) conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '!=', os.environ.get('hostIp'), conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') cmd = "ifdown %s && sleep 180 && ifup %s" % (l2_network_interface, l2_network_interface) host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180) if rsp: test_util.test_fail("host is expected to shutdown after its network down for a while") else: test_util.test_logger("host may have been shutdown") test_util.test_logger("wait for 600 seconds") time.sleep(600) vm.update() if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip: test_util.test_fail("VM is expected to start running on another host") vm.set_state(vm_header.RUNNING) vm.check() vm.destroy() test_lib.lib_set_ha_selffencer_maxattempts(max_attempts) test_lib.lib_set_ha_selffencer_storagechecker_timeout(storagechecker_timeout) os.system('bash -ex %s %s' % (os.environ.get('hostRecoverScript'), host_ip)) host_ops.reconnect_host(host_uuid) test_util.test_pass('Test VM ha on host failure Success')
def running_vm_operations(vm, bss): numa = config_ops.get_global_config_value('vm', 'numa') live_migration = config_ops.get_global_config_value( 'localStoragePrimaryStorage', 'liveMigrationWithStorage.allow') ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) vm_uuid = vm.get_vm().uuid #change vm's instanceoffering if numa == 'false': try: vm_ops.update_vm(vm_uuic, 2, 2048 * 1024 * 1024) test_util.test_fail( 'Test Fail.Cannot change instanceoffering of running vm when NUMA is false' ) except: config_ops.change_global_config('vm', 'numa', 'true') vm_ops.reboot_vm(vm_uuid) vm_ops.update_vm(vm_uuid, 2, 2048 * 1024 * 1024) #Change vm's status;set ha level/stop/del ha level/reboot/pause/resume/force stop ha_ops.set_vm_instance_ha_level(vm_uuid, 'neverstop') vm_ops.stop_vm(vm_uuid) ha_ops.del_vm_instance_ha_level(vm_uuid) vm_ops.stop_vm(vm_uuid) vm_ops.start_vm(vm_uuid) vm_ops.reboot_vm(vm_uuid) vm_ops.suspend_vm(vm_uuid) vm_ops.resume_vm(vm_uuid) vm_ops.stop_vm(vm_uuid, 'cold') vm_ops.start_vm(vm_uuid) #clone vms vm_ops.clone_vm(vm_uuid, ['vm-1', 'vm-2', 'vm-3'], 'InstantStart') #migrate candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) migrate_host_uuids = [] if candidate_hosts == None: pass else: for host in candidate_hosts.inventories: migrate_host_uuids.append(host.uuid) if ps.type == 'LocalStorage': if live_migration == 'false': try: vm_ops.migrate_vm(vm_uuid, migrate_host_uuids[0]) test_util.test_fail( 'Test Fail.Cannot migrate localstorage vm when liveMigrationWithStorage is false.' ) except: config_ops.change_global_config( 'localStoragePrimaryStorage', 'liveMigrationWithStorage.allow', 'true') else: vm_ops.migrate_vm(vm_uuid, migrate_host_uuids[0]) test_util.test_logger('migrate vm success') else: vm_ops.migrate_vm(vm_uuid, migrate_host_uuids[0]) test_util.test_logger('migrate vm success') #change vm's password(qga) try: vm_ops.change_vm_password(vm_uuid, 'root', 'testpassword') test_util.test_fail( 'Test Fail.Cannot change vm password when qga is disabled.') except: vm_ops.set_vm_qga_enable(vm_uuid) vm_ops.change_vm_password(vm_uuid, 'root', 'testpassword') vm_ops.set_vm_qga_disable(vm_uuid) #snapshot operations sp_option = test_util.SnapshotOption() vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid test_util.test_logger('rootvolumerunning:%s' % root_volume_uuid) sp_option.set_volume_uuid(root_volume_uuid) sp = vol_ops.create_snapshot(sp_option) vm_ops.stop_vm(vm_uuid) vol_ops.use_snapshot(sp.uuid) vm_ops.start_vm(vm_uuid) vol_ops.delete_snapshot(sp.uuid) common_operations(vm, bss, 'running') vm_ops.destroy_vm(vm_uuid) vm_ops.recover_vm(vm_uuid) vm_ops.start_vm(vm_uuid) vm.destroy() vm.expunge()
def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] ps_env = test_stub.PSEnvChecker() local_ps, shared_ps = ps_env.get_two_ps() vm_list = list( test_stub.generate_local_shared_test_vms(test_obj_dict, vm_ha=flavor['vm_ha'])) (vm_root_local, vm_root_local_data_local, vm_root_local_data_shared, vm_root_local_data_mixed, vm_root_shared, vm_root_shared_data_local, vm_root_shared_data_shared, vm_root_shared_data_mixed) = vm_list if flavor['local_state'] is DISABLED: ps_ops.change_primary_storage_state(local_ps.uuid, state='disable') time.sleep(10) for vm in vm_list: vm.update() assert vm.get_vm().state == inventory.RUNNING if flavor['shared_state'] is DISABLED: ps_ops.change_primary_storage_state(shared_ps.uuid, state='disable') time.sleep(10) for vm in vm_list: vm.update() assert vm.get_vm().state == inventory.RUNNING if flavor['reconnect']: for ps in (local_ps, shared_ps): ps_ops.reconnect_primary_storage(ps.uuid) for vm in vm_list: vm.update() assert vm.get_vm().state == inventory.RUNNING if flavor['local_state'] is MAINTENANCE: ps_ops.change_primary_storage_state(local_ps.uuid, state='maintain') maintain_ps = local_ps if flavor['shared_state'] is MAINTENANCE: ps_ops.change_primary_storage_state(shared_ps.uuid, state='maintain') maintain_ps = shared_ps time.sleep(30) if MAINTENANCE in (flavor['local_state'], flavor['shared_state']): vr_vm_list = test_lib.lib_find_vr_by_vm(vm_list[0].get_vm()) vr_vm = None if vr_vm_list: vr_vm = vr_vm_list[0] if vr_vm.allVolumes[0].primaryStorageUuid == maintain_ps.uuid: assert vr_vm.state == inventory.STOPPED else: assert vr_vm.state == inventory.RUNNING for vm in vm_list: vm.update() if flavor['local_state'] is MAINTENANCE: for vm in (vm_root_local, vm_root_local_data_local, vm_root_local_data_shared, vm_root_local_data_mixed, vm_root_shared_data_mixed, vm_root_shared_data_local): assert vm.get_vm().state == inventory.STOPPED with test_stub.expected_failure("start vm in maintenance ps", Exception): vm.start() for vm in (vm_root_shared, vm_root_shared_data_shared): assert vm.get_vm().state == inventory.RUNNING if flavor['shared_state'] is MAINTENANCE: for vm in (vm_root_shared, vm_root_shared_data_shared, vm_root_shared_data_local, vm_root_shared_data_mixed, vm_root_local_data_mixed, vm_root_local_data_shared): assert vm.get_vm().state == inventory.STOPPED with test_stub.expected_failure("start vm in maintenance ps", Exception): vm.start() for vm in (vm_root_local, vm_root_local_data_local): assert vm.get_vm().state == inventory.RUNNING if flavor['local_state'] is MAINTENANCE: ps_ops.change_primary_storage_state(local_ps.uuid, state='enable') if flavor['shared_state'] is MAINTENANCE: ps_ops.change_primary_storage_state(shared_ps.uuid, state='enable') if MAINTENANCE in (flavor['local_state'], flavor['shared_state']): if vr_vm and vr_vm.state == inventory.STOPPED: vm_ops.start_vm(vr_vm.uuid) for vm in vm_list: if vm.get_vm().state == inventory.STOPPED: vm.start() vm.check()
def test(): global project_uuid, project_admin_uuid, virtual_id_uuid # 1 create project project_name = 'test_project' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid project_linked_account_uuid = project.linkedAccountUuid # 2 create virtual id project_admin_name = 'username' project_admin_password = '******' project_admin_uuid = iam2_ops.create_iam2_virtual_id( project_admin_name, project_admin_password).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid # 3 create project admin iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid], project_uuid) attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}] iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes) # 4 login in project by project admin project_admin_session_uuid = iam2_ops.login_iam2_virtual_id( project_admin_name, project_admin_password) project_login_uuid = iam2_ops.login_iam2_project( project_name, session_uuid=project_admin_session_uuid).uuid # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes) # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] image_option = test_util.ImageOption() image_option.set_name('fake_image') image_option.set_description('fake image') image_option.set_format('raw') image_option.set_mediaType('RootVolumeTemplate') image_option.set_backup_storage_uuid_list([bs.uuid]) image_option.url = "http://fake/fake.raw" image_option.set_session_uuid(project_login_uuid) image_uuid = img_ops.add_image(image_option).uuid img_ops.sync_image_size(image_uuid, session_uuid=project_login_uuid) img_ops.change_image_state(image_uuid, 'disable', session_uuid=project_login_uuid) img_ops.change_image_state(image_uuid, 'enable', session_uuid=project_login_uuid) if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: img_ops.export_image_from_backup_storage( image_uuid, bs.uuid, session_uuid=project_login_uuid) img_ops.delete_exported_image_from_backup_storage( image_uuid, bs.uuid, session_uuid=project_login_uuid) img_ops.set_image_qga_enable(image_uuid, session_uuid=project_login_uuid) img_ops.set_image_qga_disable(image_uuid, session_uuid=project_login_uuid) img_ops.delete_image(image_uuid, session_uuid=project_login_uuid) img_ops.expunge_image(image_uuid, session_uuid=project_login_uuid) # Volume related ops: Create, Delete, Expunge, Attach, Dettach, Enable, Disable disk_offering_uuid = res_ops.query_resource(res_ops.DISK_OFFERING)[0].uuid acc_ops.share_resources([project_linked_account_uuid], [disk_offering_uuid]) volume_option = test_util.VolumeOption() volume_option.set_disk_offering_uuid(disk_offering_uuid) volume_option.set_name('data_volume_project_management') volume_option.set_session_uuid(project_login_uuid) data_volume = vol_ops.create_volume_from_offering(volume_option) vol_ops.stop_volume(data_volume.uuid, session_uuid=project_login_uuid) vol_ops.start_volume(data_volume.uuid, session_uuid=project_login_uuid) vm_creation_option = test_util.VmOption() l3_net_uuid = test_lib.lib_get_l3_by_name( os.environ.get('l3VlanNetwork3')).uuid acc_ops.share_resources([project_linked_account_uuid], [l3_net_uuid]) vm_creation_option.set_l3_uuids([l3_net_uuid]) image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm_creation_option.set_image_uuid(image_uuid) acc_ops.share_resources([project_linked_account_uuid], [image_uuid]) instance_offering_uuid = test_lib.lib_get_instance_offering_by_name( os.environ.get('instanceOfferingName_s')).uuid vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) acc_ops.share_resources([project_linked_account_uuid], [instance_offering_uuid]) vm_creation_option.set_name('vm_for_project_management') vm_creation_option.set_session_uuid(project_login_uuid) vm = test_stub.create_vm(image_uuid=image_uuid, session_uuid=project_login_uuid) vm_uuid = vm.get_vm().uuid vol_ops.attach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid) vol_ops.detach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid) vol_ops.delete_volume(data_volume.uuid, session_uuid=project_login_uuid) vol_ops.expunge_volume(data_volume.uuid, session_uuid=project_login_uuid) # VM related ops: Create, Delete, Expunge, Start, Stop, Suspend, Resume, Migrate vm_ops.stop_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) if candidate_hosts != None and test_lib.lib_check_vm_live_migration_cap( vm.get_vm()): vm_ops.migrate_vm(vm_uuid, candidate_hosts.inventories[0].uuid, session_uuid=project_login_uuid) vm_ops.stop_vm(vm_uuid, force='cold', session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.suspend_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.resume_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.destroy_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.expunge_vm(vm_uuid, session_uuid=project_login_uuid) # L2 related ops: create, delete zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid try: l2 = net_ops.create_l2_novlan('l2_for_pm', 'eth0', zone_uuid, session_uuid=project_login_uuid) test_util.test_fail( "Expect exception: project admin not allowed to create Novlan L2 except vxlan" ) except: pass try: l2 = net_ops.create_l2_vlan('l2_for_pm', 'eth0', zone_uuid, 1234, session_uuid=project_login_uuid) test_util.test_fail( "Expect exception: project admin not allowed to create vlan L2 except vxlan" ) except: pass #net_ops.delete_l2(l2.uuid, session_uuid=project_login_uuid) # L3 related ops: # network service ops: # zwatch ops: # scheduler ops: # certificate # 11 delete acc_ops.logout(project_login_uuid) iam2_ops.delete_iam2_virtual_id(virtual_id_uuid) iam2_ops.delete_iam2_virtual_id(project_admin_uuid) iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) test_util.test_pass('success test iam2 login in by project admin!')
def test(): ps_env = test_stub.PSEnvChecker() ps, another_ps = ps_env.get_two_ps() vm1, vm2 = test_stub.create_multi_vms(name_prefix='test-', count=2, ps_uuid=ps.uuid) for vm in (vm1, vm2): test_obj_dict.add_vm(vm) volume_in_another = test_stub.create_multi_volumes( count=VOLUME_NUMBER, ps=another_ps, host_uuid=test_lib.lib_get_vm_host(vm2.get_vm()).uuid if another_ps.type == inventory.LOCAL_STORAGE_TYPE else None) for volume in volume_in_another: test_obj_dict.add_volume(volume) for volume in volume_in_another: volume.attach(vm2) test_util.test_dsc('set another ps in maintenance mode') ps_ops.change_primary_storage_state(state='maintain', primary_storage_uuid=another_ps.uuid) maintenance_ps_list.append(another_ps) test_stub.wait_until_vm_reach_state(60, inventory.STOPPED, vm2) vm1.update() assert vm1.get_vm().state == inventory.RUNNING vr_vm_list = test_lib.lib_find_vr_by_vm(vm1.get_vm()) vr_vm = None if vr_vm_list: vr_vm = vr_vm_list[0] if vr_vm.allVolumes[0].primaryStorageUuid == another_ps.uuid: assert vr_vm.state == inventory.STOPPED else: assert vr_vm.state == inventory.RUNNING vm1.check() else: vm1.check() with test_stub.expected_failure("Start vm in maintenance ps", Exception): vm2.start() test_util.test_dsc('enable another ps') ps_ops.change_primary_storage_state(state='enable', primary_storage_uuid=another_ps.uuid) maintenance_ps_list.remove(another_ps) if vr_vm and vr_vm.state == inventory.STOPPED: vm_ops.start_vm(vr_vm.uuid) time.sleep(10) vm2.start() vm2.check() for volume in volume_in_another: volume.detach() volume.attach(vm2) test_util.test_pass('Multi PrimaryStorage Test Pass')
def test(): test_util.test_dsc('Test Change VM Image Function') #set overProvisioning.primaryStorage's value as 10 con_ops.change_global_config('mevoco', 'overProvisioning.primaryStorage', 10) global vm bs_cond = res_ops.gen_query_conditions("status", "=", "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid']) if not bss: test_util.test_skip("not find available backup storage.Skip test") test_lib.lib_create_disk_offering(diskSize=1099511627776, name="1T") disk_offering_uuids = [ test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid, test_lib.lib_get_disk_offering_by_name("root-disk").uuid, test_lib.lib_get_disk_offering_by_name("1T").uuid ] #create vm with 3 data volumes vm = test_stub.create_vm(image_name="ttylinux", vm_name="test-vm", disk_offering_uuids=disk_offering_uuids) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid vm_ops.stop_vm(vm_uuid) image_option = test_util.ImageOption() image_option.set_name('windows_for_test') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_platform('windows') image_option.set_url( 'http://172.20.1.16:7480/diskimages/windows-telnet.qcow2') image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(1800 * 1000) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() image_windows_uuid = test_lib.lib_get_image_by_name( "windows_for_test").uuid vm_ops.change_vm_image(vm_uuid, image_windows_uuid) vm_ops.start_vm(vm_uuid) vm.update() vm_ip = vm.get_vm().vmNics[0].ip #check whether the windows vm is running successfully if not test_lib.lib_wait_target_up(vm_ip, '23', 1200): test_util.test_fail( 'vm:%s is not startup in 1200 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail( 'Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail( 'Change VM Image Failed.Primarystorage has changed.') #check whether the linux vm is running successfully image_linux_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_ops.stop_vm(vm_uuid) vm_ops.change_vm_image(vm_uuid, image_linux_uuid) vm_ops.start_vm(vm_uuid) if not test_lib.lib_wait_target_up(vm_ip, '22', 120): test_util.test_fail( 'vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_linux = [] data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_linux: data_volumes_after_uuids_linux.append(data_volume.uuid) if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != l3network_uuid_after_linux: test_util.test_fail( 'Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_linux = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != primarystorage_uuid_after_linux: test_util.test_fail( 'Change VM Image Failed.Primarystorage has changed.') test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) vm.expunge() img_ops.delete_image(image_windows_uuid) img_ops.expunge_image(image_windows_uuid) test_util.test_pass('Change Vm Image Test Success')
def start(self): self.vm = vm_ops.start_vm(self.vm.uuid) super(ZstackTestVm, self).start()
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions("status", '=', "Connected") bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) command = "echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/zstack-repo/7/x86_64/os/test.iso" % os.environ.get('zstackInstallPath') test_lib.lib_execute_ssh_cmd(os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'], 'root', 'password', command) img_option.set_url('http://%s:8080/zstack/static/zstack-repo/7/x86_64/os/test.iso' % (os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'])) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm.vm.uuid) #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) test_stub.ensure_hosts_connected(120) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vr_cond = res_ops.gen_query_conditions('uuid', '=', vr.uuid) vr_inv = res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0] if vr_inv.state == 'Stopped': vm_ops.start_vm(vr.uuid) else: test_lib.lib_wait_target_up(vr_inv.vmNics[0].ip, '22', 360) for _ in xrange(100): if res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0].state != 'Running': time.sleep(3) else: break vm.start() vm.check() vm.destroy() vm.check() #vm.expunge() #vm.check() test_util.test_pass('PS maintain mode Test Success')
def test(): test_util.test_dsc('Test Change VM Image Function') #set overProvisioning.primaryStorage's value as 10 con_ops.change_global_config('mevoco', 'overProvisioning.primaryStorage', 10) global vm test_lib.lib_create_disk_offering(diskSize=1099511627776, name="1T") disk_offering_uuids = [ test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid, test_lib.lib_get_disk_offering_by_name("root-disk").uuid, test_lib.lib_get_disk_offering_by_name("1T").uuid ] vm = test_stub.create_vm(image_name="ttylinux", vm_name="test-vm", disk_offering_uuids=disk_offering_uuids) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid ps = test_lib.lib_get_primary_storage_by_uuid(last_primarystorage_uuid) avail_cap = ps.availableCapacity total_cap = ps.totalCapacity vm_ops.stop_vm(vm_uuid) image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_ops.change_vm_image(vm_uuid, image_uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the vm is running successfully if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 120): test_util.test_fail( 'vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail( 'Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail( 'Change VM Image Failed.Primarystorage has changed.') ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after) avail_cap1 = ps.availableCapacity total_cap1 = ps.totalCapacity if total_cap != total_cap1: test_util.test_fail( 'Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_uuid, total_cap, total_cap1)) if avail_cap <= avail_cap1: test_util.test_fail( 'Primary Storage available capacity is not correct,after changing larger image:%s.The previous value:%s, the current value:%s' % (image_uuid, avail_cap, avail_cap1)) vm_ops.stop_vm(vm_uuid) image_tiny_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid vm_ops.change_vm_image(vm_uuid, image_tiny_uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the vm is running successfully if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 120): test_util.test_fail( 'vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_tiny = [] data_volumes_after_tiny = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_tiny: data_volumes_after_uuids_tiny.append(data_volume.uuid) if set(data_volumes_after_uuids_tiny) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_tiny = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after_tiny != l3network_uuid_after: test_util.test_fail( 'Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_tiny = test_lib.lib_get_root_volume( vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after_tiny != primarystorage_uuid_after: test_util.test_fail( 'Change VM Image Failed.Primarystorage has changed.') ps = test_lib.lib_get_primary_storage_by_uuid( primarystorage_uuid_after_tiny) avail_cap2 = ps.availableCapacity total_cap2 = ps.totalCapacity if total_cap2 != total_cap1: test_util.test_fail( 'Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_uuid, total_cap1, total_cap2)) if avail_cap2 <= avail_cap1: test_util.test_fail( 'Primary Storage available capacity is not correct,after changing smaller image:%s.The previous value:%s, the current value:%s' % (image_uuid, avail_cap1, avail_cap2)) test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) vm.expunge() test_util.test_pass('Change Vm Image Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") max_attempts = test_lib.lib_get_ha_selffencer_maxattempts() test_lib.lib_set_ha_selffencer_maxattempts('12') storagechecker_timeout = test_lib.lib_get_ha_selffencer_storagechecker_timeout( ) test_lib.lib_set_ha_selffencer_storagechecker_timeout('15') vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) for vr in vrs: if test_lib.lib_is_vm_running(vr) == True: vm_ops.start_vm(vr.uuid) time.sleep(60) conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '!=', os.environ.get('hostIp'), conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') cmd = "ifdown %s && sleep 30 && ifup %s" % (l2_network_interface, l2_network_interface) try: rsp = test_lib.lib_execute_sh_cmd_by_agent(host_ip, cmd) test_util.test_logger( "host is not expected to shutdown after its network down just for a little while" ) except: test_util.test_fail( "host may have been shutdown, while it's not expected to shutdown") cmd = "date" try: rsp = test_lib.lib_execute_sh_cmd_by_agent(host_ip, cmd) test_util.test_logger("host is still alive") except: test_util.test_fail( "host is not expected to shutdown after its network down just for a little while" ) vm.destroy() test_lib.lib_set_ha_selffencer_maxattempts(max_attempts) test_lib.lib_set_ha_selffencer_storagechecker_timeout( storagechecker_timeout) time.sleep(60) test_util.test_pass('Test Host Self fence Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, "SharedBlock"] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) test_util.test_dsc('Create test vm and check') bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None) if not bss: test_util.test_skip("not find available backup storage. Skip test") l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() volume.delete() #volume.expunge() volume.check() vm.destroy() test_util.test_pass('Delete volume under PS maintain mode Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") max_attempts = test_lib.lib_get_ha_selffencer_maxattempts() test_lib.lib_set_ha_selffencer_maxattempts('12') storagechecker_timeout = test_lib.lib_get_ha_selffencer_storagechecker_timeout() test_lib.lib_set_ha_selffencer_storagechecker_timeout('15') vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) for vr in vrs: if test_lib.lib_is_vm_running(vr) == True: vm_ops.start_vm(vr.uuid) time.sleep(60) conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '!=', os.environ.get('hostIp'), conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') cmd = "ifdown %s && sleep 180 && ifup %s" % (l2_network_interface, l2_network_interface) host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180) if rsp: test_util.test_logger("host may have been shutdown") else: test_util.test_fail("host is expected to shutdown after its network down for a while") test_util.test_logger("wait for 600 seconds") time.sleep(600) vm.update() if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip: test_util.test_fail("VM is expected to start running on another host") vm.set_state(vm_header.RUNNING) vm.check() vm.destroy() test_lib.lib_set_ha_selffencer_maxattempts(max_attempts) test_lib.lib_set_ha_selffencer_storagechecker_timeout(storagechecker_timeout) os.system('bash -ex %s %s' % (os.environ.get('hostRecoverScript'), host_ip)) host_ops.reconnect_host(host_uuid) test_util.test_pass('Test VM ha on host failure Success')
def stopped_vm_operations(vm, bss): vm_uuid = vm.get_vm().uuid ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) vm_ops.stop_vm(vm_uuid) #Change vm's instanceoffering vm_ops.update_vm(vm_uuid, 2, 2048 * 1024 * 1024) #Change vm's status ha_ops.set_vm_instance_ha_level(vm_uuid, 'neverstop') vm_ops.stop_vm(vm_uuid) ha_ops.del_vm_instance_ha_level(vm_uuid) vm_ops.stop_vm(vm_uuid) if ps.type != 'LocalStorage': target_host_uuid = test_lib.lib_find_random_host(vm.get_vm()).uuid if target_host_uuid != None: vm_ops.start_vm_with_target_host(vm_uuid, target_host_uuid) #vm_ops.stop_vm(vm_uuid) vm_ops.destroy_vm(vm_uuid) vm_ops.recover_vm(vm_uuid) vm_ops.reinit_vm(vm_uuid) #clone vm_ops.clone_vm(vm_uuid, ['vm-1', 'vm-2', 'vm-3'], 'InstantStart') #migrate vm_ops.start_vm(vm_uuid) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) vm_ops.stop_vm(vm_uuid) migrate_host_uuids = [] if candidate_hosts != None: for host in candidate_hosts.inventories: migrate_host_uuids.append(host.uuid) if ps.type == 'LocalStorage': vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid #vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) vol_ops.migrate_volume(vol_uuid, migrate_host_uuids[0]) test_util.test_logger('migrate vm success') #resize root volume vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024 * 1024 * 1024 * 5 vol_ops.resize_volume(vol_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) test_util.test_logger('resize vm success') #storage migrate #change vm image image_list = vm_ops.get_image_candidates_for_vm_to_change(vm_uuid) image_uuids = [] for image in image_list.inventories: image_uuids.append(image.uuid) vm_ops.change_vm_image(vm_uuid, image_uuids[0]) vm.update() #update vm nic mac nic_uuid = vm.get_vm().vmNics[0].uuid mac = 'fa:4c:ee:9a:76:00' vm_ops.update_vm_nic_mac(nic_uuid, mac) #set/del static ip l3network_uuid = test_lib.lib_get_l3_uuid_by_nic(nic_uuid) vm_ops.change_vm_static_ip(vm_uuid, l3network_uuid, vm.get_vm().vmNics[0].ip) vm_ops.delete_vm_static_ip(vm_uuid, l3network_uuid) #snapshot operations sp_option = test_util.SnapshotOption() vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid sp_option.set_volume_uuid(root_volume_uuid) sp = vol_ops.create_snapshot(sp_option) vol_ops.use_snapshot(sp.uuid) vol_ops.delete_snapshot(sp.uuid) common_operations(vm, bss, 'stopped') vm.destroy() vm.expunge()
def start_vm(vm_uuid): try: vm_ops.start_vm(vm_uuid, session_uuid, 200000) except: exc_info.append(sys.exc_info())
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions("status", '=', "Connected") bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) os.system( "echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm.vm.uuid) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() test_util.test_dsc('Detach ISO to VM') img_ops.detach_iso(vm.vm.uuid) #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() vm.destroy() #vm.check() #vm.expunge() vm.check() test_util.test_pass('PS maintain mode Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") max_attempts = test_lib.lib_get_ha_selffencer_maxattempts() test_lib.lib_set_ha_selffencer_maxattempts('12') storagechecker_timeout = test_lib.lib_get_ha_selffencer_storagechecker_timeout() test_lib.lib_set_ha_selffencer_storagechecker_timeout('15') vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) for vr in vrs: if test_lib.lib_is_vm_running(vr) == True: vm_ops.start_vm(vr.uuid) time.sleep(60) conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '!=', os.environ.get('hostIp'), conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') cmd = "ifdown %s && sleep 30 && ifup %s" % (l2_network_interface, l2_network_interface) try: rsp = test_lib.lib_execute_sh_cmd_by_agent(host_ip, cmd) test_util.test_logger("host is not expected to shutdown after its network down just for a little while") except: test_util.test_fail("host may have been shutdown, while it's not expected to shutdown") cmd = "date" try: rsp = test_lib.lib_execute_sh_cmd_by_agent(host_ip, cmd) test_util.test_logger("host is still alive") except: test_util.test_fail("host is not expected to shutdown after its network down just for a little while") vm.destroy() test_lib.lib_set_ha_selffencer_maxattempts(max_attempts) test_lib.lib_set_ha_selffencer_storagechecker_timeout(storagechecker_timeout) time.sleep(60) test_util.test_pass('Test Host Self fence Success')
def test(): test_util.test_dsc('Test Change VM Image Function') #set overProvisioning.primaryStorage's value as 10 con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10) global vm bs_cond = res_ops.gen_query_conditions("status","=","Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid']) if not bss: test_util.test_skip("not find available backup storage.Skip test") test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T") disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid] #create vm with 3 data volumes vm = test_stub.create_vm(image_name = "ttylinux",vm_name="test-vm",disk_offering_uuids = disk_offering_uuids) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid vm_ops.stop_vm(vm_uuid) image_option = test_util.ImageOption() image_option.set_name('windows_for_test') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_platform('windows') #image_option.set_url('http://172.20.1.16:7480/diskimages/windows-telnet.qcow2') image_option.set_url(os.environ.get('windowsImageUrl')) image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(1800*1000) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() image_windows_uuid = test_lib.lib_get_image_by_name("windows_for_test").uuid vm_ops.change_vm_image(vm_uuid,image_windows_uuid) vm_ops.start_vm(vm_uuid) vm.update() vm_ip = vm.get_vm().vmNics[0].ip #check whether the windows vm is running successfully if not test_lib.lib_wait_target_up(vm_ip,'23',1200): test_util.test_fail('vm:%s is not startup in 1200 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') #check whether the linux vm is running successfully image_linux_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_ops.stop_vm(vm_uuid) vm_ops.change_vm_image(vm_uuid,image_linux_uuid) vm_ops.start_vm(vm_uuid) if not test_lib.lib_wait_target_up(vm_ip,'22',180): test_util.test_fail('vm:%s is not startup in 180 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_linux = [] data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_linux: data_volumes_after_uuids_linux.append(data_volume.uuid) if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != l3network_uuid_after_linux: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_linux = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != primarystorage_uuid_after_linux: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) vm.expunge() img_ops.delete_image(image_windows_uuid) img_ops.expunge_image(image_windows_uuid) test_util.test_pass('Change Vm Image Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None) if not bss: test_util.test_skip("not find available backup storage. Skip test") if bss[0].type != inventory.CEPH_BACKUP_STORAGE_TYPE: test_util.test_skip( "not find available imagestore or ceph backup storage. Skip test") l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags( ['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() volume.detach(vm.get_vm().uuid) ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() volume.delete() #volume.expunge() volume.check() vm.destroy() test_util.test_pass('Delete volume under PS maintain mode Test Success')
def test(): global vcenter_uuid1 global vcenter_uuid2 global mevoco1_ip global mevoco2_ip vcenter1_name = os.environ['vcenter2_name'] vcenter1_domain_name = os.environ['vcenter2_ip'] vcenter1_username = os.environ['vcenter2_domain_name'] vcenter1_password = os.environ['vcenter2_password'] vm_name = os.environ['vcenter2_sync_vm_start_stop'] mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['serverIp2'] os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid) vcenter_uuid1 = inv.uuid if vcenter_uuid1 == None: test_util.test_fail("vcenter_uuid is None") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid) vcenter_uuid2 = inv.uuid if vcenter_uuid2 == None: test_util.test_fail("vcenter_uuid is None") #start vm in remote and check test_util.test_logger("start vm for sync test") vm_cond = res_ops.gen_query_conditions("name", '=', vm_name) vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("remote woodpecker vm uuid is null") elif vm_uuid and vm_state != "running": print "#%s#" % vm_state vm_ops.start_vm(vm_uuid) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("local woodpecker vm uuid is null") elif vm_state != "running": test_util.test_fail("vcenter sync vm start failed.") #stop vm in remote and check test_util.test_logger("stop vm for sync test") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("remote woodpecker vm uuid is null") elif vm_uuid and vm_state != "stopped": vm_ops.stop_vm(vm_uuid) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip vm_inv = res_ops.query_resource_fields(res_ops.VM_INSTANCE, vm_cond, None, fields=['uuid', 'state'])[0] vm_uuid = vm_inv.uuid vm_state = vm_inv.state.strip().lower() if not vm_uuid: test_util.test_fail("local woodpecker vm uuid is null") elif vm_state != "stopped": test_util.test_fail("vcenter sync vm stop failed.") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if vcenter_uuid2: vct_ops.delete_vcenter(vcenter_uuid2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if vcenter_uuid1: vct_ops.delete_vcenter(vcenter_uuid1) test_util.test_pass("vcenter sync start and stop vm test passed.")
def start(self, session_uuid = None): self.vm = vm_ops.start_vm(self.vm.uuid, session_uuid) super(ZstackTestVm, self).start()
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) #volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.delete() volume.check() #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() volume.recover() volume.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) test_stub.ensure_pss_connected() vrs = test_lib.lib_get_all_vrs() time.sleep(5) for vr in vrs: vr_cond = res_ops.gen_query_conditions('uuid', '=', vr.uuid) vr_inv = res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0] if vr_inv.state == 'Stopped': vm_ops.start_vm(vr.uuid) else: test_lib.lib_wait_target_up(vr_inv.vmNics[0].ip, '22', 360) for _ in xrange(100): if res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0].state != 'Running': time.sleep(3) else: break vm.start() vm.check() volume.delete() #volume.expunge() volume.check() vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS maintain mode Test Success')
def test(): global project_uuid, project_admin_uuid, virtual_id_uuid, project_operator_uuid, plain_user_uuid flavor = case_flavor[os.environ.get('CASE_FLAVOR')] # 1 create project project_name = 'test_project' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid project_linked_account_uuid = project.linkedAccountUuid if flavor['target_role'] == 'project_admin': # 2 create virtual id project_admin_name = 'username' project_admin_password = '******' project_admin_uuid = iam2_ops.create_iam2_virtual_id(project_admin_name, project_admin_password).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid # 3 create project admin iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],project_uuid) attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}] iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes) # login in project by project admin project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(project_admin_name, project_admin_password) project_login_uuid = iam2_ops.login_iam2_project(project_name, session_uuid=project_admin_session_uuid).uuid # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes) elif flavor['target_role'] == 'project_operator': project_operator_name = 'username2' project_operator_password = '******' attributes = [{"name": "__ProjectOperator__", "value": project_uuid}] project_operator_uuid = iam2_ops.create_iam2_virtual_id(project_operator_name,project_operator_password,attributes=attributes).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernamethree','password').uuid # login in project by project operator iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid],project_uuid) project_operator_session_uuid = iam2_ops.login_iam2_virtual_id(project_operator_name,project_operator_password) project_login_uuid = iam2_ops.login_iam2_project(project_name,session_uuid=project_operator_session_uuid).uuid elif flavor['target_role'] == 'project_member': plain_user_name = 'username' plain_user_password = '******' plain_user_uuid = iam2_ops.create_iam2_virtual_id(plain_user_name, plain_user_password, project_uuid=project_uuid).uuid # 3 add virtual id to project iam2_ops.add_iam2_virtual_ids_to_project([plain_user_uuid],project_uuid) # 4 login in project by plain user plain_user_session_uuid = iam2_ops.login_iam2_virtual_id(plain_user_name, plain_user_password) # 4 login in project #project_inv=iam2_ops.get_iam2_projects_of_virtual_id(plain_user_session_uuid) project_login_uuid = iam2_ops.login_iam2_project(project_name, plain_user_session_uuid).uuid # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge if flavor['target_role'] == 'project_member': statements = [{"effect": "Allow", "actions": ["org.zstack.header.vm.**"]}] role_uuid = iam2_ops.create_role('test_role', statements).uuid iam2_ops.add_roles_to_iam2_virtual_id([role_uuid], plain_user_uuid) vm_creation_option = test_util.VmOption() l3_net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanNetwork3')).uuid acc_ops.share_resources([project_linked_account_uuid], [l3_net_uuid]) vm_creation_option.set_l3_uuids([l3_net_uuid]) image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm_creation_option.set_image_uuid(image_uuid) acc_ops.share_resources([project_linked_account_uuid], [image_uuid]) instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(os.environ.get('instanceOfferingName_s')).uuid vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) acc_ops.share_resources([project_linked_account_uuid], [instance_offering_uuid]) vm_creation_option.set_name('vm_for_project_management') vm_creation_option.set_session_uuid(project_login_uuid) vm = test_stub.create_vm(image_uuid = image_uuid, session_uuid=project_login_uuid) vm_uuid = vm.get_vm().uuid # VM related ops: Create, Delete, Expunge, Start, Stop, Suspend, Resume, Migrate vm_ops.stop_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) if candidate_hosts != None and test_lib.lib_check_vm_live_migration_cap(vm.get_vm()): vm_ops.migrate_vm(vm_uuid, candidate_hosts.inventories[0].uuid, session_uuid=project_login_uuid) vm_ops.stop_vm(vm_uuid, force='cold', session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.suspend_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.resume_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.destroy_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.expunge_vm(vm_uuid, session_uuid=project_login_uuid) # 11 delete acc_ops.logout(project_login_uuid) if virtual_id_uuid != None: iam2_ops.delete_iam2_virtual_id(virtual_id_uuid) if project_admin_uuid != None: iam2_ops.delete_iam2_virtual_id(project_admin_uuid) if project_operator_uuid != None: iam2_ops.delete_iam2_virtual_id(project_operator_uuid) if plain_user_uuid != None: iam2_ops.delete_iam2_virtual_id(plain_user_uuid) iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) test_util.test_pass('success test iam2 login in by project admin!')
def running_vm_operations(vm,bss): numa = config_ops.get_global_config_value('vm', 'numa') live_migration = config_ops.get_global_config_value('localStoragePrimaryStorage','liveMigrationWithStorage.allow') ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) vm_uuid = vm.get_vm().uuid #change vm's instanceoffering if numa == 'false': try: vm_ops.update_vm(vm_uuic,2,2048*1024*1024) test_util.test_fail('Test Fail.Cannot change instanceoffering of running vm when NUMA is false') except: config_ops.change_global_config('vm','numa','true') vm_ops.reboot_vm(vm_uuid) vm_ops.update_vm(vm_uuid,2,2048*1024*1024) #Change vm's status;set ha level/stop/del ha level/reboot/pause/resume/force stop ha_ops.set_vm_instance_ha_level(vm_uuid,'NeverStop') vm_ops.stop_vm(vm_uuid) ha_ops.del_vm_instance_ha_level(vm_uuid) vm_ops.stop_vm(vm_uuid) vm_ops.start_vm(vm_uuid) vm_ops.reboot_vm(vm_uuid) vm_ops.suspend_vm(vm_uuid) vm_ops.resume_vm(vm_uuid) vm_ops.stop_vm(vm_uuid,'cold') vm_ops.start_vm(vm_uuid) #clone vms vm_ops.clone_vm(vm_uuid,['vm-1','vm-2','vm-3'],'InstantStart') #migrate candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) migrate_host_uuids = [] if candidate_hosts == None: pass else: for host in candidate_hosts.inventories: migrate_host_uuids.append(host.uuid) if ps.type == 'LocalStorage': if live_migration == 'false': try: vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) test_util.test_fail('Test Fail.Cannot migrate localstorage vm when liveMigrationWithStorage is false.' ) except: config_ops.change_global_config('localStoragePrimaryStorage','liveMigrationWithStorage.allow','true') else: vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) test_util.test_logger('migrate vm success') else: vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) test_util.test_logger('migrate vm success') #change vm's password(qga) try: vm_ops.change_vm_password(vm_uuid,'root','testpassword') test_util.test_fail('Test Fail.Cannot change vm password when qga is disabled.') except: vm_ops.set_vm_qga_enable(vm_uuid) vm_ops.change_vm_password(vm_uuid,'root','testpassword') vm_ops.set_vm_qga_disable(vm_uuid) #snapshot operations sp_option = test_util.SnapshotOption() vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid test_util.test_logger('rootvolumerunning:%s' % root_volume_uuid) sp_option.set_volume_uuid(root_volume_uuid) sp = vol_ops.create_snapshot(sp_option) vm_ops.stop_vm(vm_uuid) vol_ops.use_snapshot(sp.uuid) vm_ops.start_vm(vm_uuid) vol_ops.delete_snapshot(sp.uuid) common_operations(vm,bss,'running') vm_ops.destroy_vm(vm_uuid) vm_ops.recover_vm(vm_uuid) vm_ops.start_vm(vm_uuid) vm.destroy() vm.expunge()
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) #volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) #volume.attach(vm1) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() volume.delete() #volume.expunge() maintain mode is not support volume expunge volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS maintain mode Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) for vr in vrs: if test_lib.lib_is_vm_running(vr) != True: vm_ops.start_vm(vr.uuid) time.sleep(60) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip, conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() test_stub.ensure_host_has_no_vr(host_uuid) #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') cmd = "ifconfig %s down && sleep 180 && ifconfig %s up" % ( l2_network_interface, l2_network_interface) rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180) if rsp: test_util.test_fail( "host is expected to shutdown after its network down for a while") else: test_util.test_logger("host may have been shutdown") cmd = "date" rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd) if rsp: test_util.test_fail( "host is expected to shutdown after its network down for a while") else: test_util.test_logger("host have been shutdown") try: vm.destroy() except: test_util.test_logger("destroy vm may time out since host is down") test_lib.lib_set_ha_selffencer_maxattempts(max_attempts) test_lib.lib_set_ha_selffencer_storagechecker_timeout( storagechecker_timeout) os.system('bash -ex %s %s' % (os.environ.get('hostRecoverScript'), host_ip)) host_ops.reconnect_host(host_uuid) test_util.test_pass('Test Host Self fence Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedMountPoint'] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) for vr in vrs: if test_lib.lib_is_vm_running(vr) != True: vm_ops.start_vm(vr.uuid) time.sleep(60) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip, conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() test_stub.ensure_host_has_no_vr(host_uuid) #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') cmd = "ifconfig %s down && sleep 30 && ifconfig %s up" % (l2_network_interface, l2_network_interface) try: rsp = test_lib.lib_execute_sh_cmd_by_agent(host_ip, cmd) test_util.test_logger("host is not expected to shutdown after its network down just for a little while") except: test_util.test_fail("host may have been shutdown, while it's not expected to shutdown") cmd = "date" try: rsp = test_lib.lib_execute_sh_cmd_by_agent(host_ip, cmd) test_util.test_logger("host is still alive") except: test_util.test_fail("host is not expected to shutdown after its network down just for a little while") test_stub.exercise_connection(100, 10) vm.destroy() time.sleep(60) test_util.test_pass('Test Host Self fence Success')
def test(): test_util.test_dsc('Test Change VM Image Function') primary_storage_list = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for ps in primary_storage_list: if ps.type == "SharedBlock": test_util.test_skip('SharedBlock primary storage does not support overProvision') global vm #set overProvisioning.primaryStorage's value as 10 con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10) test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T") l3_uuid = test_lib.lib_get_l3_by_name("l3VlanNetwork1").uuid image_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid] #choose the ps which availableCapacity >= 105G cond = res_ops.gen_query_conditions('availableCapacity', '>=', '112742891520') ps_uuid = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0].uuid system_tag = "primaryStorageUuidForDataVolume::%s" % ps_uuid vm = test_stub.create_vm(l3_uuid_list = [l3_uuid],image_uuid = image_uuid,vm_name="test-vm",disk_offering_uuids = disk_offering_uuids,system_tags=[system_tag]) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid vm_ops.stop_vm(vm_uuid) vr = test_lib.lib_find_vr_by_vm(vm.get_vm())[0] vr_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr) #stop vm's vr vm_ops.stop_vm(vr.uuid) #change vm image image_uuid = test_lib.lib_get_image_by_name("windows").uuid vm_ops.change_vm_image(vm_uuid,image_uuid) #check whether vr's status is running if vr.applianceVmType == 'vrouter': if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240): test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid) time.sleep(20) else: vm_ops.start_vm(vr.uuid) vm_ops.reconnect_vr(vr.uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the windows vm is running successfully vm_ip = vm.get_vm().vmNics[0].ip if not test_lib.lib_wait_target_up(vm_ip,'23',1200): test_util.test_fail('vm:%s is not startup in 1200 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != last_l3network_uuid: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') #check whether the linux vm is running successfully vm_ops.stop_vm(vm_uuid) #stop vm's vr vm_ops.stop_vm(vr.uuid) image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_ops.change_vm_image(vm_uuid,image_uuid) #check whether vr's status is running if vr.applianceVmType == 'vrouter': if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240): test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid) time.sleep(20) else: vm_ops.start_vm(vr.uuid) vm_ops.reconnect_vr(vr.uuid) vm_ops.start_vm(vm_uuid) if not test_lib.lib_wait_target_up(vm_ip,'22',180): test_util.test_fail('vm:%s is not startup in 180 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_linux = [] data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_linux: data_volumes_after_uuids_linux.append(data_volume.uuid) if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if l3network_uuid_after != l3network_uuid_after_linux: test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_linux = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after_linux != primarystorage_uuid_after: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) test_util.test_pass('Change Vm Image Test Success')
def test(): ps_env = test_stub.PSEnvChecker() ps, another_ps = ps_env.get_two_ps() if ps_env.is_sb_ceph_env: vm1, vm2 = test_stub.create_multi_vms(name_prefix='test-', count=2, ps_uuid=ps.uuid, timeout=600000, bs_type='ImageStoreBackupStorage') else: vm1, vm2 = test_stub.create_multi_vms(name_prefix='test-', count=2, ps_uuid=ps.uuid, timeout=600000) for vm in (vm1, vm2): test_obj_dict.add_vm(vm) volume_in_another = test_stub.create_multi_volumes(count=VOLUME_NUMBER, ps=another_ps, host_uuid=test_lib.lib_get_vm_host(vm2.get_vm()).uuid if another_ps.type == inventory.LOCAL_STORAGE_TYPE else None) for volume in volume_in_another: test_obj_dict.add_volume(volume) for volume in volume_in_another: volume.attach(vm2) test_util.test_dsc('set another ps in maintenance mode') ps_ops.change_primary_storage_state(state='maintain', primary_storage_uuid=another_ps.uuid) maintenance_ps_list.append(another_ps) test_stub.wait_until_vm_reach_state(60, inventory.STOPPED, vm2) vm1.update() assert vm1.get_vm().state == inventory.RUNNING vr_vm_list = test_lib.lib_find_vr_by_vm(vm1.get_vm()) vr_vm = None if vr_vm_list: vr_vm = vr_vm_list[0] if vr_vm.allVolumes[0].primaryStorageUuid == another_ps.uuid: assert vr_vm.state == inventory.STOPPED or vr_vm.state == inventory.STOPPING else: assert vr_vm.state == inventory.RUNNING vm1.check() else: vm1.check() with test_stub.expected_failure("Start vm in maintenance ps", Exception): vm2.start() test_util.test_dsc('enable another ps') ps_ops.change_primary_storage_state(state='enable', primary_storage_uuid=another_ps.uuid) maintenance_ps_list.remove(another_ps) if vr_vm and vr_vm.state == inventory.STOPPED: vm_ops.start_vm(vr_vm.uuid) time.sleep(10) vm2.start() vm2.check() for volume in volume_in_another: volume.detach() volume.attach(vm2) test_util.test_pass('Multi PrimaryStorage Test Pass')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [ inventory.CEPH_PRIMARY_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedMountPoint' ] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) for vr in vrs: if test_lib.lib_is_vm_running(vr) != True: vm_ops.start_vm(vr.uuid) time.sleep(60) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip, conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() test_stub.ensure_host_has_no_vr(host_uuid) #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') cmd = "ifconfig %s down && sleep 180 && ifconfig %s up" % ( l2_network_interface, l2_network_interface) host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180) if rsp: test_util.test_fail( "host is expected to shutdown after its network down for a while") else: test_util.test_logger("host may have been shutdown") test_util.test_logger("wait for 600 seconds") time.sleep(600) vm.update() if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip: test_util.test_fail("VM is expected to start running on another host") vm.set_state(vm_header.RUNNING) vm.check() vm.destroy() os.system('bash -ex %s %s' % (os.environ.get('hostRecoverScript'), host_ip)) host_ops.reconnect_host(host_uuid) test_util.test_pass('Test VM ha on host failure Success')
def test(): ps_env = test_stub.PSEnvChecker() ps1, ps2 = ps_env.get_two_ps() vm_list = [] for root_vol_ps in [ps1, ps2]: for data_vol_ps in [ps1, ps2]: if root_vol_ps.type == "SharedBlock": bs_type = "ImageStoreBackupStorage" elif root_vol_ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: bs_type = "Ceph" else: bs_type = None vm = test_stub.create_multi_vms(name_prefix='test_vm', count=1, ps_uuid=root_vol_ps.uuid, data_volume_number=VOLUME_NUMBER, ps_uuid_for_data_vol=data_vol_ps.uuid, timeout=1200000, bs_type=bs_type)[0] test_obj_dict.add_vm(vm) vm_list.append(vm) vm1, vm2, vm3, vm4 = vm_list ps_ops.change_primary_storage_state(state='maintain', primary_storage_uuid=ps2.uuid) maintenance_ps_list.append(ps2) time.sleep(60) vr_vm_list = test_lib.lib_find_vr_by_vm(vm1.get_vm()) vr_vm = None if vr_vm_list: vr_vm = vr_vm_list[0] if vr_vm.allVolumes[0].primaryStorageUuid == ps2.uuid: assert vr_vm.state == inventory.STOPPED or vr_vm.state == inventory.STOPPING else: assert vr_vm.state == inventory.RUNNING vm1.check() else: vm1.check() for vm in vm_list: vm.update() assert vm1.get_vm().state == inventory.RUNNING assert vm2.get_vm().state == inventory.STOPPED assert vm3.get_vm().state == inventory.STOPPED assert vm4.get_vm().state == inventory.STOPPED for vm in [vm2, vm3, vm4]: with test_stub.expected_failure("start vm in maintenance ps", Exception): vm.start() test_util.test_dsc('enable ps2') ps_ops.change_primary_storage_state(state='enable', primary_storage_uuid=ps2.uuid) maintenance_ps_list.remove(ps2) if vr_vm and vr_vm.state == inventory.STOPPED: vm_ops.start_vm(vr_vm.uuid) time.sleep(10) for vm in [vm2, vm3, vm4]: vm.start() for vm in [vm2, vm3, vm4]: vm.update() vm.check() test_util.test_pass('Multi PrimaryStorage Test Pass')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") max_attempts = test_lib.lib_get_ha_selffencer_maxattempts() test_lib.lib_set_ha_selffencer_maxattempts('3') storagechecker_timeout = test_lib.lib_get_ha_selffencer_storagechecker_timeout( ) test_lib.lib_set_ha_selffencer_storagechecker_timeout('5') vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) for vr in vrs: if test_lib.lib_is_vm_running(vr) != True: vm_ops.start_vm(vr.uuid) time.sleep(60) conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '!=', os.environ.get('hostIp'), conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() if not test_lib.lib_check_vm_live_migration_cap(vm.vm): test_util.test_skip('skip ha if live migrate not supported') ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on localstorage') #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") test_util.test_logger("force stop host: %s" % (host_ip)) os.system('bash -ex %s %s' % (os.environ.get('hostForceStopScript'), host_ip)) test_util.test_logger("host is expected to shutdown for a while") test_util.test_logger("wait for 500 seconds") time.sleep(500) vm.update() if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip: test_util.test_fail("VM is expected to start running on another host") vm.set_state(vm_header.RUNNING) vm.check() if test_lib.lib_get_vm_last_host(vm.get_vm()).managementIp != host_ip: test_util.test_fail( "Migrated VM's last host is expected to be the last host[ip:%s]" % (host_ip)) vm.destroy() test_lib.lib_set_ha_selffencer_maxattempts(max_attempts) test_lib.lib_set_ha_selffencer_storagechecker_timeout( storagechecker_timeout) os.system('bash -ex %s %s' % (os.environ.get('hostRecoverScript'), host_ip)) host_ops.reconnect_host(host_uuid) test_util.test_pass('Test VM ha on host failure Success')
def test(): test_util.test_dsc('Test Change VM Image Function') #set overProvisioning.primaryStorage's value as 10 primary_storage_list = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for ps in primary_storage_list: if ps.type == "SharedBlock": test_util.test_skip('SharedBlock primary storage does not support overProvision') con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10) global vm test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T") l3_uuid = test_lib.lib_get_l3_by_name("l3VlanNetwork3").uuid image_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid] vm = test_stub.create_vm(l3_uuid_list = [l3_uuid],image_uuid = image_uuid,vm_name="test-nxs",disk_offering_uuids = disk_offering_uuids) test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.get_vm().uuid last_data_volumes_uuids = [] last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in last_data_volumes: last_data_volumes_uuids.append(data_volume.uuid) last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid ps = test_lib.lib_get_primary_storage_by_uuid(last_primarystorage_uuid) avail_cap = ps.availableCapacity total_cap = ps.totalCapacity vm_ops.stop_vm(vm_uuid) vr = test_lib.lib_find_vr_by_vm(vm.get_vm())[0] vr_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr) #stop vm's vr vm_ops.stop_vm(vr.uuid) image_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid vm_ops.change_vm_image(vm_uuid,image_uuid) #check whether vr's status is running if vr.applianceVmType == 'vrouter': if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240): test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid) time.sleep(20) #if vr.state == 'Stopped': else: vm_ops.start_vm(vr.uuid) vm_ops.reconnect_vr(vr.uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the vm is running successfully if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip,'22',120): test_util.test_fail('vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids = [] data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after: data_volumes_after_uuids.append(data_volume.uuid) if set(last_data_volumes_uuids) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if set(l3network_uuid_after) != set(last_l3network_uuid): test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != last_primarystorage_uuid: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after) avail_cap1 = ps.availableCapacity total_cap1 = ps.totalCapacity if total_cap != total_cap1: test_util.test_fail('Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_uuid,total_cap,total_cap1)) if avail_cap <= avail_cap1: test_util.test_fail('Primary Storage available capacity is not correct,after changing larger image:%s.The previous value:%s, the current value:%s' % (image_uuid,avail_cap,avail_cap1)) vm_ops.stop_vm(vm_uuid) #stop vm's vr vm_ops.stop_vm(vr.uuid) image_tiny_uuid = test_lib.lib_get_image_by_name("ttylinux").uuid vm_ops.change_vm_image(vm_uuid,image_tiny_uuid) #check whether vr's status is running if vr.applianceVmType == 'vrouter': if not test_lib.lib_wait_target_up(vr_mgmt_ip,'7272',240): test_util.test_fail('vm:%s is not startup in 240 seconds.Fail to reboot it.' % vr.uuid) time.sleep(20) #if vr.state == 'Stopped': else: vm_ops.start_vm(vr.uuid) vm_ops.reconnect_vr(vr.uuid) vm_ops.start_vm(vm_uuid) vm.update() #check whether the vm is running successfully if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip,'22',120): test_util.test_fail('vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid) #check whether data volumes attached to the vm has changed data_volumes_after_uuids_tiny = [] data_volumes_after_tiny = test_lib.lib_get_data_volumes(vm.get_vm()) for data_volume in data_volumes_after_tiny: data_volumes_after_uuids_tiny.append(data_volume.uuid) if set(data_volumes_after_uuids_tiny) != set(data_volumes_after_uuids): test_util.test_fail('Change Vm Image Failed.Data volumes changed.') #check whether the network config has changed l3network_uuid_after_tiny = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm()) if set(l3network_uuid_after_tiny) != set(l3network_uuid_after_tiny): test_util.test_fail('Change VM Image Failed.The Network config has changed.') #check whether primarystorage has changed primarystorage_uuid_after_tiny = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid if primarystorage_uuid_after != primarystorage_uuid_after_tiny: test_util.test_fail('Change VM Image Failed.Primarystorage has changed.') ps = test_lib.lib_get_primary_storage_by_uuid(primarystorage_uuid_after_tiny) avail_cap2 = ps.availableCapacity total_cap2 = ps.totalCapacity if total_cap2 != total_cap1: test_util.test_fail('Primary Storage total capacity is not same,after changing vm image:%s.The previous value:%s, the current value:%s' % (image_uuid,total_cap1,total_cap2)) if avail_cap2 <= avail_cap1: test_util.test_fail('Primary Storage available capacity is not correct,after changing smaller image:%s.The previous value:%s, the current value:%s' % (image_uuid,avail_cap1,avail_cap2)) test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm()) test_util.test_pass('Change Vm Image Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout global test_host if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) vr_host_ips = [] for vr in vrs: vr_host_ips.append(test_lib.lib_find_host_by_vr(vr).managementIp) if test_lib.lib_is_vm_running(vr) != True: vm_ops.start_vm(vr.uuid) time.sleep(60) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '=', mn_ip, conditions) #for vr_host_ip in vr_host_ips: # conditions = res_ops.gen_query_conditions('managementIp', '!=', vr_host_ip, conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() if not test_lib.lib_check_vm_live_migration_cap(vm.vm): test_util.test_skip('skip ha if live migrate not supported') ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on localstorage') host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_util.test_logger("host %s is disconnecting" %(host_ip)) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") host_list = test_stub.get_sce_hosts(test_lib.all_scenario_config, test_lib.scenario_file) for host in host_list: if host.ip_ == host_ip: test_host = host break if not test_host: test_util.test_fail('there is no host with ip %s in scenario file.' %(host_ip)) test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold') test_util.test_logger("wait for 30 seconds to ensure vm disconnected, then just wait 90s for target up.") time.sleep(30) if test_lib.lib_wait_target_up(vm.vm.vmNics[0].ip, '22', 90): test_util.test_logger("%s can be connected within 120s" %(vm.vm.vmNics[0].ip)) test_stub.start_host(test_host, test_lib.all_scenario_config) vm.destroy() test_util.test_pass('Test VM ha change to running within 120s Success')