def test(): global vm global test_host global ps_uuid global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.LOCAL_STORAGE_TYPE] 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].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('ls_vm_ha_self_start') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") 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') for i in range(0, 300): if res_ops.query_resource(res_ops.VM_INSTANCE, conditions)[0].state == "Running": break time.sleep(1) else: test_util.test_fail( "vm has not been changed to running as expected within 300s.") vm.destroy() test_util.test_pass( 'Test checking VM ha and none status when force stop vm Success.')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) test_stub.skip_if_not_storage_network_separate(test_lib.all_scenario_config) 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() 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() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts): test_util.test_fail("Not find out a suitable host") #vm.check() 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") #test_stub.down_host_network(host_ip, test_lib.all_scenario_config) host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') t = test_stub.async_exec_ifconfig_nic_down_up(1200, host_ip, host_username, host_password, "zsn1") vm.destroy() test_util.test_pass('Test VM ha change to running within 300s Success')
def test(): global vm global test_host global ps_uuid global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.LOCAL_STORAGE_TYPE] 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].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('ls_vm_ha_self_start') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") 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') for i in range(0, 300): if res_ops.query_resource(res_ops.VM_INSTANCE, conditions)[0].state == "Running": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within 300s.") vm.destroy() test_util.test_pass('Test checking VM ha and none status when force stop vm Success.')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout must_ps_list = ['MiniStorage'] test_lib.skip_test_if_any_ps_not_deployed(must_ps_list) test_stub.skip_if_not_storage_network_separate(test_lib.all_scenario_config) 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("ttylinux").uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() 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() #vm.check() 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") test_stub.down_host_network(host_ip, test_lib.all_scenario_config, "managment_net") if test_stub.check_vm_running_on_host(vm.vm.uuid, 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_stub.up_host_network(host_ip, test_lib.all_scenario_config, "managment_net") test_util.test_pass('Test Success')
def test(): global vm, vm2 test_stub.skip_if_scenario_is_multiple_networks(mul_nets_sce_list=["scenario-config-ceph-sep-man.xml", "scenario-config-ceph-sep-pub.xml"]) test_stub.skip_if_vr_not_vyos("vr") test_lib.clean_up_all_vr() vm = test_stub.create_basic_vm() vm.check() vr_vm = test_lib.lib_find_vr_by_vm(vm.vm)[0] vm.destroy() t = threading.Thread(target=async_exec_reboot_vr, args=(vr_vm.uuid,)) t.start() vm2 = test_stub.create_basic_vm(wait_vr_running=False) vm2.check() vm2.destroy() test_util.test_pass('Create VM when vyos is rebooting Test Success')
def test(): global vm, vm2 test_stub.skip_if_scenario_is_multiple_networks(mul_nets_sce_list=[ "scenario-config-ceph-sep-man.xml", "scenario-config-ceph-sep-pub.xml" ]) test_stub.skip_if_vr_not_vyos("vr") test_lib.clean_up_all_vr() vm = test_stub.create_basic_vm() vm.check() vr_vm = test_lib.lib_find_vr_by_vm(vm.vm)[0] vm.destroy() t = threading.Thread(target=async_exec_reboot_vr, args=(vr_vm.uuid, )) t.start() vm2 = test_stub.create_basic_vm(wait_vr_running=False) vm2.check() vm2.destroy() test_util.test_pass('Create VM when vyos is rebooting Test Success')
def test(): global vm global host_uuid global test_host global host_ip global max_attempts global storagechecker_timeout test_lib.lib_skip_if_ps_num_is_not_eq_number(1) allow_ps_list = [inventory.LOCAL_STORAGE_TYPE] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) test_lib.lib_cur_env_is_not_scenario() 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() 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('ls_vm_ha_self_start') 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 test_util.test_logger("host %s is disconnecting" %(host_ip)) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") for i in range(10): test_stub.stop_ha_vm(vm.get_vm().uuid) vm.set_state(vm_header.STOPPED) vm.check() vm.start() vm.check() #The following logical are belong to vm ha nature feature. 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 or host.managementIp_ == 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') vm_stop_time = None cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_ha_self_start') cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond) for i in range(0, 180): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped": vm_stop_time = i test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) break time.sleep(1) if vm_stop_time is None: vm_stop_time = 180 for i in range(vm_stop_time, 180): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Starting": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within 180s.") vm.destroy() test_util.test_pass('Test checking VM ha and none status when force stop vm 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] 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") set_quick_ha_properties() set_quick_ha_params() 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() #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() test_stub.ensure_host_has_no_vr(host_uuid) #vm.check() 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") test_stub.down_host_network(host_ip, test_lib.all_scenario_config) #test_util.test_logger("wait for 180 seconds") #time.sleep(180) vm_stop_time = None cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) for i in range(0, max_time): vm_stop_time = i if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Unknown": test_stub.up_host_network(host_ip, test_lib.all_scenario_config) break time.sleep(1) if vm_stop_time is None: vm_stop_time = max_time for i in range(vm_stop_time, max_time): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within %s s." %(max_time)) vm.destroy() test_util.test_pass('Test VM ha change to running within 120s Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.LOCAL_STORAGE_TYPE] 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") test_lib.lib_skip_if_ps_num_is_not_eq_number(2) 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() 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('ls_vm_ha_self_start') 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 test_util.test_logger("host %s is disconnecting" % (host_ip)) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") test_stub.down_host_network(host_ip, test_lib.all_scenario_config) vm_stop_time = None cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_ha_self_start') cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond) for i in range(0, max_time): vm_stop_time = i if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Unknown": test_stub.up_host_network(host_ip, test_lib.all_scenario_config) break time.sleep(1) if vm_stop_time is None: vm_stop_time = max_time for i in range(vm_stop_time, max_time): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running": break time.sleep(1) else: test_util.test_fail( "vm has not been changed to running as expected within %s s." % (max_time)) vm.destroy() test_util.test_pass('Test VM ha change to running within %s s Success' % (max_time))
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 test_lib.clean_up_all_vr() #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName #vr_host_ips = [] #for vr in vrs: # vr_ip = test_lib.lib_find_host_by_vr(vr).managementIp # #ensure mn host has no vr # if vr_ip == mn_ip: # conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip) # host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid # vm_ops.migrate_vm(vr.uuid, host_uuid) # vr_host_ips.append(vr_ip) # 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', '=', 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() vm.check() test_stub.ensure_host_has_no_vr(host_uuid) if not test_lib.lib_check_vm_live_migration_cap(vm.vm): vm.destroy() 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: vm.destroy() test_util.test_skip('Skip test on localstorage') host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" % (host_ip)) 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.down_host_network(host_ip, test_lib.all_scenario_config) test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold') time.sleep(30) #test_stub.up_host_network(host_ip, test_lib.all_scenario_config) test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) time.sleep(120) cmd = "nohup zstack-ctl start &" host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') if not test_lib.lib_execute_ssh_cmd( mn_ip, host_username, host_password, cmd, timeout=300): test_util.test_fail("CMD:%s execute failed on %s" % (cmd, mn_ip)) #test_util.test_logger("wait for 480 seconds") #time.sleep(480) time.sleep(120) cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) if not res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped": test_util.test_fail("vm is not stopped as expected.") vm.destroy() #this is used to design to check mn works normally time.sleep(20) vm.create() vm.check() vm.destroy() #host_ops.reconnect_host(host_uuid) test_util.test_pass( 'Test checking vm status after force stop and start success')
def test(): global vm global host_uuid global test_host global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.LOCAL_STORAGE_TYPE] 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() #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('ls_vm_none_status') vm2 = test_vm_header.ZstackTestVm() vm2.set_creation_option(vm_creation_option) vm2.create() test_stub.ensure_host_has_no_vr(host_uuid) #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm2.get_vm()).managementIp test_util.test_logger("host %s is disconnecting" %(host_ip)) 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') cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_none_status') cond = res_ops.gen_query_conditions('uuid', '=', vm2.vm.uuid, cond) vm_stop_time = None for i in range(0, 300): vm_stop_time = i if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Unknown": test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) break time.sleep(1) if vm_stop_time is None: vm_stop_time = 300 for i in range(vm_stop_time, 300): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped": break time.sleep(1) else: test_util.test_fail("vm none is not change to Stopped as expected within 300s.") test_util.test_pass('Test checking vm none status when host has been force stop 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 l3_name2 = os.environ.get('l3VlanNetwork2') l3_net_uuid2 = test_lib.lib_get_l3_by_name(l3_name2).uuid test_lib.clean_up_all_vr() #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, l3_net_uuid2]) vm_creation_option.set_default_l3_uuid(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_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" % (host_ip)) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") test_stub.down_host_network(host_ip, test_lib.all_scenario_config) test_util.test_logger("wait for 240 seconds") time.sleep(240) test_stub.up_host_network(host_ip, test_lib.all_scenario_config) #vm.update() #bug for host uuid is not updated cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) vm_inv = res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0] vm_host_ip = test_lib.lib_find_host_by_vm(vm_inv).managementIp for i in range(0, max_time): test_util.test_logger("vm_host_ip:%s; host_ip:%s" % (vm_host_ip, host_ip)) time.sleep(1) vm_inv = res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0] vm_host_ip = test_lib.lib_find_host_by_vm(vm_inv).managementIp if vm_host_ip != host_ip: break else: test_util.test_fail("VM is expected to start running on another host") test_lib.lib_set_vm_host_l2_ip(vm_inv) #vm.check() #bug when multi-networks #if test_lib.lib_wait_target_up(vm_inv.vmNics[0].ip, '22', 120): # test_util.test_logger("%s can be connected within 120s" %(vm_inv.vmNics[0].ip)) #elif test_lib.lib_wait_target_up(vm_inv.vmNics[1].ip, '22', 120): # test_util.test_logger("%s can be connected within 120s" %(vm_inv.vmNics[1].ip)) #else: # test_util.test_fail("Both %s and %s can't be connected." %(vm_inv.vmNics[0].ip, vm_inv.vmNics[1].ip)) ssh_timeout = test_lib.SSH_TIMEOUT test_lib.SSH_TIMEOUT = 120 if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry( vm_host_ip, vm_inv.vmNics[0].ip, 'root', 'password', "pwd"): test_lib.SSH_TIMEOUT = ssh_timeout test_util.test_fail("vm can't be access by %s." % (vm_inv.vmNics[0].ip)) if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry( vm_host_ip, vm_inv.vmNics[1].ip, 'root', 'password', "pwd"): test_lib.SSH_TIMEOUT = ssh_timeout test_util.test_fail("vm can't be access by %s." % (vm_inv.vmNics[1].ip)) test_lib.SSH_TIMEOUT = ssh_timeout vm.destroy() test_util.test_pass( 'Test VM ha with multiple networks disconnect host Success')
def test(): global vm global host_uuid global test_host global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.LOCAL_STORAGE_TYPE] 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 l3_name2 = os.environ.get('l3VlanNetwork2') l3_net_uuid2 = test_lib.lib_get_l3_by_name(l3_name2).uuid test_lib.clean_up_all_vr() #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, l3_net_uuid2]) vm_creation_option.set_default_l3_uuid(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_port = test_lib.lib_get_host_port(host_ip) 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)) cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) vm_inv = res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0] test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold') test_util.test_logger("wait for 120 seconds") time.sleep(120) test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) for i in range(0, 120): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within %s s." %(240)) vm.destroy() test_util.test_pass('Test VM ha with multiple networks disconnect host Success')
def test(): global vm global host_uuid global test_host global host_ip global max_attempts global storagechecker_timeout must_ps_list = [inventory.LOCAL_STORAGE_TYPE, 'SharedMountPoint'] test_lib.skip_test_if_any_ps_not_deployed(must_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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() 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) cond = res_ops.gen_query_conditions('type', '=', "SharedMountPoint") vm_creation_option.set_ps_uuid(res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0].uuid) vm_creation_option.set_name('vm-smp') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vm.check() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts): test_util.test_fail("Not find out a suitable host") 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') 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") cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) for i in range(0, 300): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within 300s.") vm.set_state(vm_header.RUNNING) vm.check() vm.destroy() test_util.test_pass('Test checking vm status after graceful stop and start success')
def test(): global vm global host_uuid global host_ip must_ps_list = ['MiniStorage'] test_lib.skip_test_if_any_ps_not_deployed(must_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("ttylinux").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 test_lib.clean_up_all_vr() 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() #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" %(host_ip)) 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_host = None 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') vm_stop_time = None cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) for i in range(0, 300): vm_stop_time = i if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Unknown": test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) break time.sleep(1) if vm_stop_time is None: vm_stop_time = 300 for i in range(vm_stop_time, 300): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Starting": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within 300s.") vm.destroy() test_util.test_pass('Test VM ha on host failure Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout must_ps_list = [inventory.LOCAL_STORAGE_TYPE, 'SharedMountPoint'] test_lib.skip_test_if_any_ps_not_deployed(must_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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() #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('ls_vm_none_status') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts): test_util.test_fail("Not find out a suitable host") #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_util.test_logger("host %s is disconnecting" %(host_ip)) test_stub.down_host_network(host_ip, test_lib.all_scenario_config) cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_none_status') cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond) for i in range(0, 300): vm_stop_time = i if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Unknown": test_stub.up_host_network(host_ip, test_lib.all_scenario_config) time.sleep(1) test_stub.recover_smp_nfs_server(host_ip) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid) break time.sleep(1) if vm_stop_time is None: vm_stop_time = 300 for i in range(vm_stop_time, 300): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within 300s.") vm.destroy() test_util.test_pass('Test VM none change to Stopped within 300s Success')
def test(): global vm global host_uuid global test_host global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.LOCAL_STORAGE_TYPE] 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() #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('ls_vm_none_status') vm2 = test_vm_header.ZstackTestVm() vm2.set_creation_option(vm_creation_option) vm2.create() test_stub.ensure_host_has_no_vr(host_uuid) #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm2.get_vm()).managementIp test_util.test_logger("host %s is disconnecting" % (host_ip)) 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') cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_none_status') cond = res_ops.gen_query_conditions('uuid', '=', vm2.vm.uuid, cond) vm_stop_time = None for i in range(0, 180): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Unknown": vm_stop_time = i test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) break time.sleep(1) if not vm_stop_time: vm_stop_time = 180 for i in range(vm_stop_time, 180): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped": break time.sleep(1) else: test_util.test_fail( "vm none is not change to Stopped as expected within 180s.") test_util.test_pass( 'Test checking vm none status when host has been force stop 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) test_lib.clean_up_all_vr() mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName #vr_host_ips = [] #for vr in vrs: # vr_ip = test_lib.lib_find_host_by_vr(vr).managementIp # #ensure mn host has no vr # if vr_ip == mn_ip: # conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip) # host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid # vm_ops.migrate_vm(vr.uuid, host_uuid) # vr_host_ips.append(vr_ip) # 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', '=', 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_status_runnning') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vm.check() 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_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" % (host_ip)) test_stub.down_host_network(host_ip, test_lib.all_scenario_config) test_util.test_logger("wait for 30 seconds") time.sleep(30) test_stub.up_host_network(host_ip, test_lib.all_scenario_config) time.sleep(120) cmd = "nohup zstack-ctl start &" host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') if not test_lib.lib_execute_ssh_cmd( mn_ip, host_username, host_password, cmd, timeout=300): test_util.test_fail("CMD:%s execute failed on %s" % (cmd, mn_ip)) time.sleep(120) cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) if not res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running": test_util.test_fail("vm is not stopped as expected.") vm.destroy() #check mn service works normally time.sleep(20) vm.create() vm.check() vm.destroy() test_util.test_pass( 'Test vm checking status after network disconnect and connect 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 l3_name2 = os.environ.get('l3VlanNetwork2') l3_net_uuid2 = test_lib.lib_get_l3_by_name(l3_name2).uuid test_lib.clean_up_all_vr() #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, l3_net_uuid2]) vm_creation_option.set_default_l3_uuid(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_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" %(host_ip)) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") test_stub.down_host_network(host_ip, test_lib.all_scenario_config) test_util.test_logger("wait for 240 seconds") time.sleep(240) test_stub.up_host_network(host_ip, test_lib.all_scenario_config) #vm.update() #bug for host uuid is not updated cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) vm_inv = res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0] vm_host_ip = test_lib.lib_find_host_by_vm(vm_inv).managementIp for i in range(0, max_time): test_util.test_logger("vm_host_ip:%s; host_ip:%s" %(vm_host_ip, host_ip)) time.sleep(1) vm_inv = res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0] vm_host_ip = test_lib.lib_find_host_by_vm(vm_inv).managementIp if vm_host_ip != host_ip: break else: test_util.test_fail("VM is expected to start running on another host") test_lib.lib_set_vm_host_l2_ip(vm_inv) #vm.check() #bug when multi-networks #if test_lib.lib_wait_target_up(vm_inv.vmNics[0].ip, '22', 120): # test_util.test_logger("%s can be connected within 120s" %(vm_inv.vmNics[0].ip)) #elif test_lib.lib_wait_target_up(vm_inv.vmNics[1].ip, '22', 120): # test_util.test_logger("%s can be connected within 120s" %(vm_inv.vmNics[1].ip)) #else: # test_util.test_fail("Both %s and %s can't be connected." %(vm_inv.vmNics[0].ip, vm_inv.vmNics[1].ip)) ssh_timeout = test_lib.SSH_TIMEOUT test_lib.SSH_TIMEOUT = 120 if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(vm_host_ip, vm_inv.vmNics[0].ip, 'root', 'password', "pwd"): test_lib.SSH_TIMEOUT = ssh_timeout test_util.test_fail("vm can't be access by %s." %(vm_inv.vmNics[0].ip)) if not test_lib.lib_ssh_vm_cmd_by_agent_with_retry(vm_host_ip, vm_inv.vmNics[1].ip, 'root', 'password', "pwd"): test_lib.SSH_TIMEOUT = ssh_timeout test_util.test_fail("vm can't be access by %s." %(vm_inv.vmNics[1].ip)) test_lib.SSH_TIMEOUT = ssh_timeout vm.destroy() test_util.test_pass('Test VM ha with multiple networks disconnect host Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout must_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_if_any_ps_not_deployed(must_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 test_lib.clean_up_all_vr() #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() vm_creation_option.set_name('multihost_basic_vm2') vm2 = test_vm_header.ZstackTestVm() vm2.set_creation_option(vm_creation_option) vm2.create() vm_creation_option.set_name('multihost_basic_vm3') vm3 = test_vm_header.ZstackTestVm() vm3.set_creation_option(vm_creation_option) vm3.create() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts + mn_hosts + nfs_hosts): test_util.test_fail("Not find out a suitable host") #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" % (host_ip)) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") ha_ops.set_vm_instance_ha_level(vm2.get_vm().uuid, "NeverStop") ha_ops.set_vm_instance_ha_level(vm3.get_vm().uuid, "NeverStop") test_stub.down_host_network(host_ip, test_lib.all_scenario_config) #Here we wait for 180 seconds for all vms have been killed, but test result show: #no need to wait, the reaction of killing the vm is very quickly. test_util.test_logger("wait for 30 seconds") time.sleep(30) if test_stub.check_vm_running_on_host(vm.vm.uuid, host_ip): test_util.test_fail("VM1 is expected to start running on another host") if test_stub.check_vm_running_on_host(vm2.vm.uuid, host_ip): test_util.test_fail("VM2 is expected to start running on another host") if test_stub.check_vm_running_on_host(vm3.vm.uuid, host_ip): test_util.test_fail("VM3 is expected to start running on another host") test_stub.up_host_network(host_ip, test_lib.all_scenario_config) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid) vm.set_state(vm_header.RUNNING) vm2.set_state(vm_header.RUNNING) vm3.set_state(vm_header.RUNNING) time.sleep(60) vm.check() vm2.check() vm3.check() vm.destroy() vm2.destroy() vm3.destroy() test_util.test_pass('Test VM ha on host failure Success')
def test(): global vm global host_uuid global test_host global host_ip global max_attempts global storagechecker_timeout must_ps_list = [inventory.LOCAL_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_if_any_ps_not_deployed(must_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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() 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('ls_vm_ha_self_start') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts): test_util.test_fail("Not find out a suitable host") #vm.check() 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) vm_stop_time = None cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_ha_self_start') cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond) for i in range(0, 300): vm_stop_time = i if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped": test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid) break time.sleep(1) if vm_stop_time is None: vm_stop_time = 300 for i in range(vm_stop_time, 300): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Starting": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within 300s.") vm.destroy() test_util.test_pass('Test checking VM ha and none status when force stop vm Success.')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout must_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_if_any_ps_not_deployed(must_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 test_lib.clean_up_all_vr() #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() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts): test_util.test_fail("Not find out a suitable host") #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" %(host_ip)) 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') #l2interface = test_lib.lib_get_l2s_by_vm(vm.get_vm())[0].physicalInterface l2_network_interface = test_stub.get_host_l2_nic_name("br_eth0") cmd = "ifconfig %s down && sleep 300 && 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, 240) if not rsp: test_util.test_logger("host is expected to shutdown after its network down for a while") #test_util.test_logger("wait for 600 seconds") test_util.test_logger("wait for 300 seconds") time.sleep(300) 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() cmd = 'PORT=%s bash -ex %s %s' % (host_port, os.environ.get('hostRecoverScript'), host_ip) test_util.test_logger(cmd) os.system(cmd) host_ops.reconnect_host(host_uuid) test_util.test_pass('Test VM ha on host failure 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 test_lib.clean_up_all_vr() #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() test_stub.ensure_host_has_no_vr(host_uuid) #vm.check() 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") test_stub.down_host_network(host_ip, test_lib.all_scenario_config) #Here we wait for 180 seconds for all vms have been killed, but test result show: #no need to wait, the reaction of killing the vm is very quickly. #test_util.test_logger("wait for 180 seconds") #time.sleep(180) vm_stop_time = None cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) for i in range(0, max_time): vm_stop_time = i if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Unknown": test_stub.up_host_network(host_ip, test_lib.all_scenario_config) break time.sleep(1) if vm_stop_time is None: vm_stop_time = max_time for i in range(vm_stop_time, max_time): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running": break time.sleep(1) else: test_util.test_fail( "vm has not been changed to running as expected within %s s." % (max_time)) vm.destroy() test_util.test_pass('Test VM ha change to running within 120s Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout must_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_if_any_ps_not_deployed(must_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 test_lib.clean_up_all_vr() #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() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts + mn_hosts + nfs_hosts): test_util.test_fail("Not find out a suitable host") host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid test_stub.ensure_all_vrs_on_host(host_uuid) #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) #target_host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid #for vr in vrs: # if test_lib.lib_find_host_by_vr(vr).managementIp != test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp: # vm_ops.migrate_vm(vr.uuid, target_host_uuid) #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" % (host_ip)) 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 300 seconds") time.sleep(300) 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() 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(): 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 test_lib.clean_up_all_vr() #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName #vr_host_ips = [] #for vr in vrs: # vr_ip = test_lib.lib_find_host_by_vr(vr).managementIp # #ensure mn host has no vr # if vr_ip == mn_ip: # conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip) # host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid # vm_ops.migrate_vm(vr.uuid, host_uuid) # vr_host_ips.append(vr_ip) # 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', '=', 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() vm.check() test_stub.ensure_host_has_no_vr(host_uuid) if not test_lib.lib_check_vm_live_migration_cap(vm.vm): vm.destroy() 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: vm.destroy() test_util.test_skip('Skip test on localstorage') host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" %(host_ip)) 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.down_host_network(host_ip, test_lib.all_scenario_config) test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold') time.sleep(30) #test_stub.up_host_network(host_ip, test_lib.all_scenario_config) test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) time.sleep(120) cmd = "nohup zstack-ctl start &" host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') if not test_lib.lib_execute_ssh_cmd(mn_ip, host_username, host_password, cmd, timeout = 300): test_util.test_fail("CMD:%s execute failed on %s" %(cmd, mn_ip)) #test_util.test_logger("wait for 480 seconds") #time.sleep(480) time.sleep(120) cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) if not res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped": test_util.test_fail("vm is not stopped as expected.") vm.destroy() #this is used to design to check mn works normally time.sleep(20) vm.create() vm.check() vm.destroy() #host_ops.reconnect_host(host_uuid) test_util.test_pass('Test checking vm status after force stop and start 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 test_lib.clean_up_all_vr() #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_status_runnning') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vm.check() test_stub.ensure_host_has_no_vr(host_uuid) vm_creation_option.set_name('multihost_basic_vm_status_stopped') vm2 = test_vm_header.ZstackTestVm() vm2.set_creation_option(vm_creation_option) vm2.create() vm2.stop() vm2.check() #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" %(host_ip)) test_stub.down_host_network(host_ip, test_lib.all_scenario_config) test_util.test_logger("wait for 180 seconds") time.sleep(180) test_stub.up_host_network(host_ip, test_lib.all_scenario_config) vm.set_state(vm_header.STOPPED) vm2.set_state(vm_header.STOPPED) vm.check() vm2.check() vm.destroy() vm2.destroy() test_util.test_pass('Test vm checking status after network disconnect and connect success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout config_ops.change_global_config('localStoragePrimaryStorage', 'liveMigrationWithStorage.allow', 'true') allow_ps_list = [inventory.LOCAL_STORAGE_TYPE] 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") test_lib.lib_skip_if_ps_num_is_not_eq_number(2) 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() 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('ls_vm_ha_self_start') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() test_stub.ensure_all_vrs_on_host(host_uuid) #vm.check() 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") test_stub.down_host_network(host_ip, test_lib.all_scenario_config) vm_stop_time = None cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_ha_self_start') cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond) for i in range(0, max_time): vm_stop_time = i if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Unknown": test_stub.up_host_network(host_ip, test_lib.all_scenario_config) break time.sleep(1) if vm_stop_time is None: vm_stop_time = max_time for i in range(vm_stop_time, max_time): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within %s s." %(max_time)) vm.destroy() test_util.test_pass('Test VM ha change to running within %s s Success' %(max_time))
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE] 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") set_quick_ha_properties() set_quick_ha_params() 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() #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() vm.check() test_stub.ensure_host_has_no_vr(host_uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) 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) test_util.test_logger("wait for 120 seconds") time.sleep(120) test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) vm.set_state(vm_header.RUNNING) vm.check() 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.destroy() test_util.test_pass('Test checking vm status after graceful stop and start success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout must_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_if_any_ps_not_deployed(must_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 test_lib.clean_up_all_vr() #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() vm_creation_option.set_name('multihost_basic_vm2') vm2 = test_vm_header.ZstackTestVm() vm2.set_creation_option(vm_creation_option) vm2.create() vm_creation_option.set_name('multihost_basic_vm3') vm3 = test_vm_header.ZstackTestVm() vm3.set_creation_option(vm_creation_option) vm3.create() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts): test_util.test_fail("Not find out a suitable host") host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid test_stub.ensure_all_vrs_on_host(host_uuid) #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) #target_host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid #for vr in vrs: # if test_lib.lib_find_host_by_vr(vr).managementIp != test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp: # vm_ops.migrate_vm(vr.uuid, target_host_uuid) #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" %(host_ip)) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") ha_ops.set_vm_instance_ha_level(vm2.get_vm().uuid, "NeverStop") ha_ops.set_vm_instance_ha_level(vm3.get_vm().uuid, "NeverStop") test_stub.down_host_network(host_ip, test_lib.all_scenario_config) #Here we wait for 180 seconds for all vms have been killed, but test result show: #no need to wait, the reaction of killing the vm is very quickly. test_util.test_logger("wait for 30 seconds") time.sleep(30) if test_stub.check_vm_running_on_host(vm.vm.uuid, host_ip): test_util.test_fail("VM1 is expected to start running on another host") if test_stub.check_vm_running_on_host(vm2.vm.uuid, host_ip): test_util.test_fail("VM2 is expected to start running on another host") if test_stub.check_vm_running_on_host(vm3.vm.uuid, host_ip): test_util.test_fail("VM3 is expected to start running on another host") test_stub.up_host_network(host_ip, test_lib.all_scenario_config) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid) vm.set_state(vm_header.RUNNING) vm2.set_state(vm_header.RUNNING) vm3.set_state(vm_header.RUNNING) time.sleep(60) vm.check() vm2.check() vm3.check() vm.destroy() vm2.destroy() vm3.destroy() test_util.test_pass('Test VM ha on host failure Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout test_lib.lib_skip_if_ps_num_is_not_eq_number(1) allow_ps_list = [ inventory.CEPH_PRIMARY_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedMountPoint', inventory.FUSIONSTOR_PRIMARY_STORAGE_TYPE ] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) test_lib.lib_cur_env_is_not_scenario() 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() 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() vm.check() test_stub.ensure_host_has_no_vr(host_uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" % (host_ip)) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") for i in range(10): test_stub.stop_ha_vm(vm.get_vm().uuid) vm.set_state(vm_header.STOPPED) vm.check() vm.start() vm.check() #vm ha natural feature: 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 or host.managementIp_ == 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) #test_util.test_logger("wait for 60 seconds") #time.sleep(60) test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) vm.set_state(vm_header.RUNNING) vm.check() 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.destroy() test_util.test_pass( 'Test checking vm status after graceful stop and start 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 test_lib.clean_up_all_vr() #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_status_runnning') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vm.check() test_stub.ensure_host_has_no_vr(host_uuid) vm_creation_option.set_name('multihost_basic_vm_status_stopped') vm2 = test_vm_header.ZstackTestVm() vm2.set_creation_option(vm_creation_option) vm2.create() vm2.stop() vm2.check() #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" %(host_ip)) test_stub.down_host_network(host_ip, test_lib.all_scenario_config) test_util.test_logger("wait for 300 seconds") time.sleep(300) test_stub.up_host_network(host_ip, test_lib.all_scenario_config) vm.set_state(vm_header.STOPPED) vm2.set_state(vm_header.STOPPED) vm.check() vm2.check() vm.destroy() vm2.destroy() test_util.test_pass('Test vm checking status after network disconnect and connect success')
def test(): global vm global host_uuid global test_host global host_ip global max_attempts global storagechecker_timeout must_ps_list = [inventory.LOCAL_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_if_any_ps_not_deployed(must_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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() #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('ls_vm_ha_self_start') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts): test_util.test_fail("Not find out a suitable host") host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid test_stub.ensure_all_vrs_on_host(host_uuid) #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) #target_host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid #for vr in vrs: # if test_lib.lib_find_host_by_vr(vr).managementIp != test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp: # vm_ops.migrate_vm(vr.uuid, target_host_uuid) #vm.check() 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') vm_stop_time = None cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_ha_self_start') cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond) for i in range(0, 180): vm_stop_time = i if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped": test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid) break time.sleep(1) if vm_stop_time is None: vm_stop_time = 180 for i in range(vm_stop_time, 180): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Starting": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within 180s.") vm.destroy() test_util.test_pass('Test checking VM ha and none status when force stop vm Success.')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout must_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_if_any_ps_not_deployed(must_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 test_lib.clean_up_all_vr() #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() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts): test_util.test_fail("Not find out a suitable host") host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid test_stub.ensure_all_vrs_on_host(host_uuid) #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) #target_host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid #for vr in vrs: # if test_lib.lib_find_host_by_vr(vr).managementIp != test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp: # vm_ops.migrate_vm(vr.uuid, target_host_uuid) #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" %(host_ip)) 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 300 seconds") time.sleep(300) 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() 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(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) test_stub.skip_if_not_storage_network_separate(test_lib.all_scenario_config) 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() 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() vm.check() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts): test_util.test_fail("Not find out a suitable host") host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid test_stub.ensure_all_vrs_on_host(host_uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) 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) test_stub.check_if_vm_starting_incorrectly_on_original_host(vm.get_vm().uuid, host_uuid, max_count=300) test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid) vm.set_state(vm_header.RUNNING) vm.check() 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.destroy() test_util.test_pass('Test checking vm status after graceful stop and start success')
def test(): global vm global host_uuid global test_host global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE] 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") test_lib.lib_skip_if_ps_num_is_not_eq_number(2) 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() 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(vm_name) vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts + mn_hosts + nfs_hosts): test_util.test_fail("Not find out a suitable host") 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) test_stub.check_if_vm_starting_incorrectly_on_original_host( vm.get_vm().uuid, host_uuid, max_count=180) vm_stop_time = None cond = res_ops.gen_query_conditions('name', '=', vm_name) cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond) for i in range(0, 120): vm_stop_time = i if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped": test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid) break time.sleep(1) for i in range(vm_stop_time, 120): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running": break time.sleep(1) else: test_util.test_fail( "vm has not been changed to running as expected within 300s.") 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.destroy() test_util.test_pass( 'Test checking 2nfs vm ha running on other host Success.')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout test_lib.lib_skip_if_ps_num_is_not_eq_number(1) allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedMountPoint', 'AliyunNAS', inventory.FUSIONSTOR_PRIMARY_STORAGE_TYPE] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) test_lib.lib_cur_env_is_not_scenario() 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() 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() vm.check() test_stub.ensure_host_has_no_vr(host_uuid) host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" %(host_ip)) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") for i in range(10): test_stub.stop_ha_vm(vm.get_vm().uuid) vm.set_state(vm_header.STOPPED) vm.check() vm.start() vm.check() #vm ha natural feature: 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 or hasattr(host, 'managementIp_') and host.managementIp_ == 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) #test_util.test_logger("wait for 60 seconds") #time.sleep(60) test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) vm.set_state(vm_header.RUNNING) vm.check() 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.destroy() test_util.test_pass('Test checking vm status after graceful stop and start 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) test_lib.clean_up_all_vr() mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName #vr_host_ips = [] #for vr in vrs: # vr_ip = test_lib.lib_find_host_by_vr(vr).managementIp # #ensure mn host has no vr # if vr_ip == mn_ip: # conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip) # host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid # vm_ops.migrate_vm(vr.uuid, host_uuid) # vr_host_ips.append(vr_ip) # 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', '=', 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_status_runnning') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vm.check() 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_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" %(host_ip)) test_stub.down_host_network(host_ip, test_lib.all_scenario_config) test_util.test_logger("wait for 30 seconds") time.sleep(30) test_stub.up_host_network(host_ip, test_lib.all_scenario_config) time.sleep(120) cmd = "nohup zstack-ctl start &" host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') if not test_lib.lib_execute_ssh_cmd(mn_ip, host_username, host_password, cmd, timeout = 300): test_util.test_fail("CMD:%s execute failed on %s" %(cmd, mn_ip)) time.sleep(120) cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) if not res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running": test_util.test_fail("vm is not stopped as expected.") vm.destroy() #check mn service works normally time.sleep(20) vm.create() vm.check() vm.destroy() test_util.test_pass('Test vm checking status after network disconnect and connect success')