def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) for vr in vrs: if test_lib.lib_is_vm_running(vr) != True: vm_ops.start_vm(vr.uuid) time.sleep(60) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip, conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() test_stub.ensure_host_has_no_vr(host_uuid) #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "OnHostFailure") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') cmd = "ifconfig %s down && sleep 180 && ifconfig %s up" % ( l2_network_interface, l2_network_interface) rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180) if rsp: test_util.test_fail( "host is expected to shutdown after its network down for a while") else: test_util.test_logger("host may have been shutdown") cmd = "date" rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd) if rsp: test_util.test_fail( "host is expected to shutdown after its network down for a while") else: test_util.test_logger("host have been shutdown") try: vm.destroy() except: test_util.test_logger("destroy vm may time out since host is down") test_lib.lib_set_ha_selffencer_maxattempts(max_attempts) test_lib.lib_set_ha_selffencer_storagechecker_timeout( storagechecker_timeout) os.system('bash -ex %s %s' % (os.environ.get('hostRecoverScript'), host_ip)) host_ops.reconnect_host(host_uuid) test_util.test_pass('Test Host Self fence Success')
def test(): global vm global host_uuid global 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 Create(): global session_uuid global session_to global session_mc vm_num = os.environ.get('ZSTACK_TEST_NUM') if not vm_num: vm_num = 700 else: vm_num = int(vm_num) test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold) test_util.test_logger('ZSTACK_TEST_NUM is %d' % vm_num) org_num = vm_num vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3PublicNetworkName') l3 = test_lib.lib_get_l3_by_name(l3_name) l3s = test_lib.lib_get_l3s() 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_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) #change account session timeout. session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid) session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid) session_uuid = acc_ops.login_as_admin() vm_creation_option.set_session_uuid(session_uuid) vm = test_vm_header.ZstackTestVm() random_name = random.random() vm_name = 'multihost_basic_vm_%s' % str(random_name) vm_creation_option.set_name(vm_name) while vm_num > 0: check_thread_exception() vm_creation_option.set_l3_uuids([l3.uuid]) vm.set_creation_option(vm_creation_option) vm_num -= 1 thread = threading.Thread(target=create_vm, args=(vm, )) while threading.active_count() > thread_threshold: time.sleep(1) thread.start() while threading.active_count() > 1: time.sleep(0.01) cond = res_ops.gen_query_conditions('name', '=', vm_name) vms = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid) con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid) con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid) acc_ops.logout(session_uuid) if vms == org_num: print 'Create %d VMs Test Success.' % (org_num) else: test_util.test_fail('Create %d VMs Test Failed. Only find %d VMs.' % (org_num, vms))
def test(): global vms, exec_info, delete_policy1 ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0] if ps.type != inventory.CEPH_PRIMARY_STORAGE_TYPE: test_util.test_skip( 'this test is for moniter expunge vm on ceph, not found ceph, skip test.' ) delete_policy1 = test_lib.lib_set_delete_policy('vm', 'Delay') image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3NoVlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid cpuNum = 1 memorySize = 268435456 name = 'vm-offering-allocator-strategy' new_offering_option = test_util.InstanceOfferingOption() new_offering_option.set_cpuNum(cpuNum) new_offering_option.set_memorySize(memorySize) new_offering_option.set_name(name) new_offering = vm_ops.create_instance_offering(new_offering_option) test_obj_dict.add_instance_offering(new_offering) instance_offering_uuid = new_offering.uuid each_vm_cpu_consume = cpuNum vm_creation_option = test_util.VmOption() 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) #trigger vm create exec_info = [] ts = [] for i in range(vm_num): t = threading.Thread(target=create_vm_wrapper, args=(i, vm_creation_option)) ts.append(t) t.start() for t in ts: t.join() check_exception("created") #trigger vm destroy exec_info = [] ts = [] for i, vm in zip(range(vm_num), vms): t = threading.Thread(target=destroy_vm_wrapper, args=(i, vm.vm.uuid)) ts.append(t) t.start() for t in ts: t.join() check_exception("destroyed") #trigger vm expunge exec_info = [] ts = [] for i, vm in zip(range(vm_num), vms): t = threading.Thread(target=expunge_vm_wrapper, args=(i, vm.vm.uuid)) ts.append(t) t.start() for t in ts: t.join() check_exception("expunged") test_lib.lib_set_delete_policy('vm', delete_policy1) test_util.test_pass('Create VM Test Success')
def __init__(self): super(ZstackTestVm, self).__init__() self.vm_creation_option = test_util.VmOption() self.changed_instance_offering_uuid = None self.delete_policy = test_lib.lib_get_delete_policy('vm') self.delete_delay_time = test_lib.lib_get_expunge_time('vm')
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) 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() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts + mn_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(180, host_ip, host_username, host_password, "zsn1") time.sleep(180) 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() t.join() test_util.test_pass('Test VM ha change to running within 180s Success')
def test(): test_util.test_dsc( '''Will mainly doing random test for all kinds of snapshot operations. VM, Volume and Image operations will also be tested. If reach 1 hour successful running condition, testing will success and quit. SG actions, and VIP actions are removed in this robot test. VM resources: a special Utility vm is required to do volume attach/detach operation. ''') target_running_vm = 4 public_l3 = test_lib.lib_get_l3_by_name( os.environ.get('l3PublicNetworkName')) vm_create_option = test_util.VmOption() #image has to use virtual router image, as it needs to do port checking vm_create_option.set_image_uuid( test_lib.lib_get_image_by_name( img_name=os.environ.get('imageName_net')).uuid) utility_vm_create_option = test_util.VmOption() utility_vm_create_option.set_image_uuid( test_lib.lib_get_image_by_name( img_name=os.environ.get('imageName_net')).uuid) l3_uuid = test_lib.lib_get_l3_by_name( os.environ.get('l3VlanNetworkName1')).uuid utility_vm_create_option.set_l3_uuids([l3_uuid]) priority_actions = test_state.TestAction.snapshot_actions * 4 utility_vm = test_lib.lib_create_vm(utility_vm_create_option) test_dict.add_utility_vm(utility_vm) utility_vm.check() test_util.test_dsc( 'Random Test Begin. Test target: 4 coexisting running VM (not include VR and SG target test VMs.).' ) robot_test_obj = test_util.Robot_Test_Object() robot_test_obj.set_test_dict(test_dict) robot_test_obj.set_vm_creation_option(vm_create_option) priority_action_obj = action_select.ActionPriority() priority_action_obj.add_priority_action_list(priority_actions) robot_test_obj.set_priority_actions(priority_action_obj) robot_test_obj.set_exclusive_actions_list(\ test_state.TestAction.vip_actions + \ test_state.TestAction.image_actions + \ test_state.TestAction.sg_actions) robot_test_obj.set_public_l3(public_l3) robot_test_obj.set_utility_vm(utility_vm) robot_test_obj.set_random_type(action_select.fair_strategy) rounds = 1 current_time = time.time() timeout_time = current_time + 3600 while time.time() <= timeout_time: test_util.test_dsc('New round %s starts: random operation pickup.' % rounds) test_lib.lib_vm_random_operation(robot_test_obj) test_util.test_dsc( '===============Round %s finished. Begin status checking.================' % rounds) rounds += 1 test_lib.lib_robot_status_check(test_dict) test_util.test_dsc('Reach test pass exit criterial: 1 hour.') test_lib.lib_robot_cleanup(test_dict) test_util.test_pass('Snapshots Robot Test Success')
def test(): global disaster_bs_uuid global image_uuid global vm disasterBsUrls = os.environ.get('disasterBsUrls') name = 'disaster_bs' description = 'backup storage for disaster' url = '/zstack_bs' sshport = 22 hostname = disasterBsUrls.split('@')[1] username = disasterBsUrls.split(':')[0] password = disasterBsUrls.split('@')[0].split(':')[1] test_util.test_logger( 'Disaster bs server hostname is %s, username is %s, password is %s' % (hostname, username, password)) #AddDisasterImageStoreBackupStorage disaster_backup_storage = bs_ops.add_disaster_image_store_bs( url, hostname, username, password, sshport, name, description) disaster_bs_uuid = disaster_backup_storage.uuid #AttachBackupStorageToZone zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid bs_ops.attach_backup_storage(disaster_bs_uuid, zone_uuid) #Create vm primary_storage_uuid = res_ops.query_resource( res_ops.PRIMARY_STORAGE)[0].uuid disk_offering_uuid = res_ops.query_resource(res_ops.DISK_OFFERING)[0].uuid host_ip = res_ops.query_resource(res_ops.HOST)[0].managementIp cond = res_ops.gen_query_conditions( 'name', '=', os.environ.get('imageStoreBackupStorageName')) local_bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid cond = res_ops.gen_query_conditions('system', '=', False) l3network_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].uuid cond = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, cond)[0].uuid cond = res_ops.gen_query_conditions('backupStorage.uuid', '=', local_bs_uuid) cond = res_ops.gen_query_conditions('name', '=', 'other', cond) image_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid vm_option = test_util.VmOption() vm_option.set_instance_offering_uuid(instance_offering_uuid) vm_option.set_name('vm_for_data_protect_test') vm_option.set_l3_uuids([l3network_uuid]) vm_option.set_image_uuid(image_uuid) vm = vm_ops.create_vm(vm_option) #CreateRootVolumeTemplateFromRootVolume root_volume_uuid = vm.rootVolumeUuid image_option = test_util.ImageOption() image_option.set_root_volume_uuid(root_volume_uuid) image_option.set_name('create_root_image_to_image_store') image_option.set_backup_storage_uuid_list([disaster_bs_uuid]) image = img_ops.create_root_volume_template(image_option) disaster_bs_image_uuid = image.uuid #Check if the system tag of the image in disaster bs is 'remote' cond = res_ops.gen_query_conditions('resourceUuid', '=', disaster_bs_image_uuid) system_tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)[0] if system_tag.tag != "remote": test_util.test_fail( "Here isn't 'remote' system tag for image in data protect bs") #Check if the image's media_type correct cond = res_ops.gen_query_conditions('uuid', '=', disaster_bs_image_uuid) media_type = res_ops.query_resource(res_ops.IMAGE, cond)[0].mediaType if media_type != 'RootVolumeTemplate': test_util.test_fail( 'Wrong image type, the expect is "RootVolumeTemplate", the real is "%s"' % media_type) #Check recovery root volume recovery_image = img_ops.recovery_image_from_image_store_backup_storage( local_bs_uuid, disaster_bs_uuid, disaster_bs_image_uuid) #Check the process status when recoverying image cond = res_ops.gen_query_conditions('resourceUuid', '=', local_bs_uuid) system_tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)[0].tag status = system_tag.split('::')[7] if status not in ['running', 'success']: test_util.test_fail('Error status for recovery image, status: %s' % status) #Check if recovery root volume success if recovery_image.backupStorageRefs[0].backupStorageUuid != local_bs_uuid: test_util.test_fail('Recovery image failed, image uuid is %s' % recovery_image.uuid) if recovery_image.mediaType != 'RootVolumeTemplate': test_util.test_fail( 'Wrong image type after recovery, the expect is "RootVolumeTemplate", the real is "%s"' % recovery_image.mediaType) image_uuid = recovery_image.uuid try: #Try to recovery the same image again, it's negative test recovery_image = img_ops.recovery_image_from_image_store_backup_storage( local_bs_uuid, disaster_bs_uuid, disaster_bs_image_uuid) img_ops.delete_image(recovery_image.uuid) except Exception, e: if unicode(e).encode("utf-8").find('包含') != -1: test_util.test_pass( 'Try to recovery the same image again and get the error info expectly: %s' % unicode(e).encode("utf-8"))
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() 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() 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)) host_list = test_stub.get_sce_hosts(test_lib.all_scenario_config, test_lib.scenario_file) for host in host_list: if host.ip_ == host_ip: test_host = host break if not test_host: test_util.test_fail('there is no host with ip %s in scenario file.' %(host_ip)) test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold') test_util.test_logger("wait for 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.STOPPED) vm2.set_state(vm_header.STOPPED) vm.check() vm2.check() vm.destroy() vm2.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 testHosts = test_lib.lib_get_all_hosts_from_plan() for host in testHosts: node_ip = host.managementIp_ print str(node_ip) + " is host.managementIp_" break host_username = "******" host_password = "******" vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid 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('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() cmd = "zstack-ctl setenv ZSTACK_HOME=/usr/local/zstacktest/apache-tomcat/webapps/zstack/; zstack-ctl dump_mysql --file-name mysql_dump" rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180) dump_file = rsp.split()[-1] cmd = "mysqldump -uroot -pzstack.mysql.password -A -r /tmp/mysql_before_restore.dump" rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180) vm.check() cmd = "zstack-ctl restore_mysql -f %s --mysql-root-password %s" % ( dump_file, host_password) rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180) cmd = "mysqldump -uroot -pzstack.mysql.password -A -r /tmp/mysql_after_restore.dump" rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180) cmd = "zstack-ctl start" rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180) cmd = "diff /tmp/mysql_before_restore.dump /tmp/mysql_after_restore.dump |wc -l" rsp = test_lib.lib_execute_ssh_cmd(node_ip, host_username, host_password, cmd, 180) #diff mysql dump alway has 4 or 8 line different because the dump time is different. #So we suppose the when the different lines more than 8, Restore mysql db failed. if int(rsp.rstrip()) > 8: test_util.test_fail('Restore Mysql Failed') vm.destroy() test_util.test_pass('Restore Mysql 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', 'AliyunNAS' ] 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() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() test_util.test_logger('vr_hosts = %s' % vr_hosts) test_util.test_logger('mn_hosts = %s' % mn_hosts) test_util.test_logger('nfs_hosts = %s' % nfs_hosts) #test_stub.test_skip('debug') 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.update() #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 360 seconds") # time.sleep(360) test_util.test_logger("wait for 600 seconds") time.sleep(600) vm.update() if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip: test_util.test_fail("VM is expected to start running on another host") vm.set_state(vm_header.RUNNING) vm.check() 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 project_uuid, project_admin_uuid, virtual_id_uuid, project_operator_uuid, plain_user_uuid flavor = case_flavor[os.environ.get('CASE_FLAVOR')] # 1 create project project_name = 'test_project' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid project_linked_account_uuid = project.linkedAccountUuid if flavor['target_role'] == 'project_admin': # 2 create virtual id project_admin_name = 'username' project_admin_password = '******' project_admin_uuid = iam2_ops.create_iam2_virtual_id(project_admin_name, project_admin_password).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid # 3 create project admin iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],project_uuid) attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}] iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes) # login in project by project admin project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(project_admin_name, project_admin_password) project_login_uuid = iam2_ops.login_iam2_project(project_name, session_uuid=project_admin_session_uuid).uuid # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes) elif flavor['target_role'] == 'project_operator': project_operator_name = 'username2' project_operator_password = '******' attributes = [{"name": "__ProjectOperator__", "value": project_uuid}] project_operator_uuid = iam2_ops.create_iam2_virtual_id(project_operator_name,project_operator_password,attributes=attributes).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernamethree','password').uuid # login in project by project operator iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid],project_uuid) project_operator_session_uuid = iam2_ops.login_iam2_virtual_id(project_operator_name,project_operator_password) project_login_uuid = iam2_ops.login_iam2_project(project_name,session_uuid=project_operator_session_uuid).uuid elif flavor['target_role'] == 'project_member': plain_user_name = 'username' plain_user_password = '******' plain_user_uuid = iam2_ops.create_iam2_virtual_id(plain_user_name, plain_user_password, project_uuid=project_uuid).uuid # 3 add virtual id to project iam2_ops.add_iam2_virtual_ids_to_project([plain_user_uuid],project_uuid) # 4 login in project by plain user plain_user_session_uuid = iam2_ops.login_iam2_virtual_id(plain_user_name, plain_user_password) # 4 login in project #project_inv=iam2_ops.get_iam2_projects_of_virtual_id(plain_user_session_uuid) project_login_uuid = iam2_ops.login_iam2_project(project_name, plain_user_session_uuid).uuid # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge if flavor['target_role'] == 'project_member': statements = [{"effect": "Allow", "actions": ["org.zstack.header.volume.**"]}, {"effect": "Allow", "actions": ["org.zstack.header.vm.**"]}] role_uuid = iam2_ops.create_role('test_role', statements).uuid iam2_ops.add_roles_to_iam2_virtual_id([role_uuid], plain_user_uuid) # Volume related ops: Create, Delete, Expunge, Attach, Dettach, Enable, Disable disk_offering_uuid = res_ops.query_resource(res_ops.DISK_OFFERING)[0].uuid acc_ops.share_resources([project_linked_account_uuid], [disk_offering_uuid]) volume_option = test_util.VolumeOption() volume_option.set_disk_offering_uuid(disk_offering_uuid) volume_option.set_name('data_volume_project_management') volume_option.set_session_uuid(project_login_uuid) data_volume = vol_ops.create_volume_from_offering(volume_option) vol_ops.stop_volume(data_volume.uuid, session_uuid=project_login_uuid) vol_ops.start_volume(data_volume.uuid, session_uuid=project_login_uuid) vm_creation_option = test_util.VmOption() l3_net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanNetwork3')).uuid acc_ops.share_resources([project_linked_account_uuid], [l3_net_uuid]) vm_creation_option.set_l3_uuids([l3_net_uuid]) image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm_creation_option.set_image_uuid(image_uuid) acc_ops.share_resources([project_linked_account_uuid], [image_uuid]) instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(os.environ.get('instanceOfferingName_s')).uuid vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) acc_ops.share_resources([project_linked_account_uuid], [instance_offering_uuid]) vm_creation_option.set_name('vm_for_project_management') vm_creation_option.set_session_uuid(project_login_uuid) vm = test_stub.create_vm(image_uuid = image_uuid, session_uuid=project_login_uuid) vm_uuid = vm.get_vm().uuid vol_ops.attach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid) vol_ops.detach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid) vol_ops.delete_volume(data_volume.uuid, session_uuid=project_login_uuid) vol_ops.expunge_volume(data_volume.uuid, session_uuid=project_login_uuid) # 11 delete acc_ops.logout(project_login_uuid) if virtual_id_uuid != None: iam2_ops.delete_iam2_virtual_id(virtual_id_uuid) if project_admin_uuid != None: iam2_ops.delete_iam2_virtual_id(project_admin_uuid) if project_operator_uuid != None: iam2_ops.delete_iam2_virtual_id(project_operator_uuid) if plain_user_uuid != None: iam2_ops.delete_iam2_virtual_id(plain_user_uuid) iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) test_util.test_pass('success test iam2 login in by project admin!')
def test(): test_util.test_dsc(''' Will doing random test Security Group operations, including SG create/delete, rule add/remove, vm nics attach/detach. If reach max 4 coexisting running vm, testing will success and quit. Volume actions and Image actions are removed in this robot test. VM resources: Since SG testing will create target test vm, there might be max 12 running VMs: 4 VR VMs, 4 SG target test VMs and 4 test VMs. ''') target_running_vm = 4 target_l3s = test_lib.lib_get_limited_l3_network(2, 5) vr_num = 0 for target_l3 in target_l3s: vr_l3_uuid = target_l3.uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr_l3_uuid) temp_vm = None if not vrs: #create temp_vm for getting its vr for test pf_vm portforwarding vm_create_option = test_util.VmOption() vm_create_option.set_l3_uuids([vr_l3_uuid]) temp_vm = test_lib.lib_create_vm(vm_create_option) test_dict.add_vm(temp_vm) #we only need temp_vm's VR temp_vm.destroy() test_dict.rm_vm(temp_vm) vr_num += 1 #VIP testing need 3 VRs if vr_num > 2: break vm_create_option = test_util.VmOption() #image has to use network test image, as it needs to do port checking vm_create_option.set_image_uuid( test_lib.lib_get_image_by_name( img_name=os.environ.get('imageName_net')).uuid) priority_actions = [test_state.TestAction.sg_rule_operations] * 2 priority_action_obj = action_select.ActionPriority() priority_action_obj.add_priority_action_list(priority_actions) test_util.test_dsc( 'Random Test Begin. Test target: 4 coexisting running VM (not include VR and SG target test VMs.).' ) robot_test_obj = test_util.Robot_Test_Object() robot_test_obj.set_test_dict(test_dict) robot_test_obj.set_vm_creation_option(vm_create_option) robot_test_obj.set_priority_actions(priority_action_obj) robot_test_obj.set_exclusive_actions_list(\ test_state.TestAction.volume_actions \ + test_state.TestAction.image_actions \ + test_state.TestAction.vip_actions \ + test_state.TestAction.snapshot_actions) rounds = 1 while len(test_dict.get_vm_list(vm_header.RUNNING)) < target_running_vm: test_util.test_dsc('New round %s starts: random operation pickup.' % rounds) test_lib.lib_vm_random_operation(robot_test_obj) test_util.test_dsc( '===============Round %s finished. Begin status checking.================' % rounds) rounds += 1 test_lib.lib_robot_status_check(test_dict) test_util.test_dsc('Reach test pass exit criterial.') test_lib.lib_robot_cleanup(test_dict) test_util.test_pass('Create random VM Test 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(): #This conf should only be put in test(), since test_lib.deploy_config # should be set by woodpecker. global curr_deploy_conf curr_deploy_conf = exp_ops.export_zstack_deployment_config( test_lib.deploy_config) vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #pick up zone1 zone1 = res_ops.get_resource(res_ops.ZONE, name=zone1_name)[0] 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_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multizones_basic_vm') vm_creation_option.set_zone_uuid(zone1.uuid) vm1 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm1) vm2 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm2) vm3 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm3) vm4 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm4) zone_ops.delete_zone(zone1.uuid) test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.DESTROYED) test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.DESTROYED) test_obj_dict.mv_vm(vm3, vm_header.RUNNING, vm_header.DESTROYED) test_obj_dict.mv_vm(vm4, vm_header.RUNNING, vm_header.DESTROYED) vm1.update() vm2.update() vm3.update() vm4.update() test_lib.lib_robot_status_check(test_obj_dict) zone_ops.add_zone_resource(curr_deploy_conf, zone1_name) zone1 = res_ops.get_resource(res_ops.ZONE, name=zone1_name)[0] vm_creation_option.set_zone_uuid(zone1.uuid) vm_creation_option.set_l3_uuids([]) vm1 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm1) vm2 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm2) vm3 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm3) vm4 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm4) test_lib.lib_robot_status_check(test_obj_dict) #time.sleep(5) #vm.check() #vm.destroy() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Delete Zone Test 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=180) 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(): bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None, fields=['uuid']) if not bss: test_util.test_skip("not find available backup storage. Skip test") image_option = test_util.ImageOption() image_option.set_name('test_image_cache_cleanup') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url(os.environ.get('imageUrl_s')) image_option.set_backup_storage_uuid_list([bss[0].uuid]) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid 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) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option = test_util.VmOption() vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(new_image.image.uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('test_image_cache_cleanup_vm1') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() test_obj_dict.add_vm(vm) vm.check() host = test_lib.lib_find_host_by_vm(vm.get_vm()) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) vm.destroy() vm.expunge() conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('uuid', '!=', host.uuid, 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_name('test_image_cache_cleanup_vm2') vm2 = test_vm_header.ZstackTestVm() vm2.set_creation_option(vm_creation_option) vm2.create() host2 = test_lib.lib_find_host_by_vm(vm2.get_vm()) test_obj_dict.add_vm(vm2) disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('smallDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) volume1.attach(vm2) if ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: test_util.test_skip( 'ceph is not directly using image cache, skip test.') image_cache_path = "%s/imagecache/template/%s" % (ps.mountPath, new_image.image.uuid) if not test_lib.lib_check_file_exist(host, image_cache_path): test_util.test_fail('image cache is expected to exist') if bss[0].type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: image_cache_path = "%s/zstore-cache/%s" % (ps.mountPath, new_image.image.uuid) if not test_lib.lib_check_file_exist(host, image_cache_path): test_util.test_fail('image cache is expected to exist') new_image.delete() new_image.expunge() ps_ops.cleanup_imagecache_on_primary_storage(ps.uuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: count = 0 while True: image_cache_path = "%s/imagecache/template/%s/%s.qcow2" % ( ps.mountPath, new_image.image.uuid, new_image.image.uuid) if not test_lib.lib_check_file_exist(host, image_cache_path): break elif count > 5: test_util.test_fail('image cache is expected to be deleted') test_util.test_logger('check %s times: image cache still exist' % (count)) time.sleep(5) count += 1 vm2.destroy() vm2.expunge() ps_ops.cleanup_imagecache_on_primary_storage(ps.uuid) count = 0 while True: image_cache_path = "%s/imagecache/template/%s" % (ps.mountPath, new_image.image.uuid) if not test_lib.lib_check_file_exist(host, image_cache_path): break elif count > 5: test_util.test_fail('image cache is expected to be deleted') test_util.test_logger('check %s times: image cache still exist' % (count)) time.sleep(5) count += 1 count = 0 while True: image_cache_path = "%s/zstore-cache/%s" % (ps.mountPath, new_image.image.uuid) if not test_lib.lib_check_file_exist(host, image_cache_path): break elif count > 5: test_util.test_fail('image cache is expected to be deleted') test_util.test_logger('check %s times: image cache still exist' % (count)) time.sleep(5) count += 1 test_util.test_pass('imagecache cleanup Pass.')
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 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, 180): 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 = 180 for i in range(vm_stop_time, 180): 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 180s.") vm.destroy() test_util.test_pass('Test VM none change to Stopped within 180s Success')
def test(): global curr_deploy_conf curr_deploy_conf = exp_ops.export_zstack_deployment_config( test_lib.deploy_config) vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #pick up l3 l3_1 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name1)[0] l3_2 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name2)[0] 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_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multizones_basic_vm') vm_creation_option.set_l3_uuids([l3_1.uuid, l3_2.uuid]) vm1 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm1) vm2 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm2) test_util.test_dsc('Delete l3_2') net_ops.delete_l3(l3_2.uuid) test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED) test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.STOPPED) vm1.update() vm1.set_state(vm_header.STOPPED) vm2.update() vm2.set_state(vm_header.STOPPED) vm1.check() vm2.check() test_util.test_dsc('start vm again. vm should remove the deleted l3') vm1.start() vm2.start() net_ops.add_l3_resource(curr_deploy_conf, l3_name=l3_2.name) #update l3_2, since it is readded. l3_2 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name2)[0] vm_creation_option.set_l3_uuids([l3_1.uuid, l3_2.uuid]) vm3 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm3) #check vm1 vm2 status. vm1.check() vm2.check() if not len(vm1.get_vm().vmNics) == 1: test_util.test_fail( 'vm1 vmNics still have L3: %s, even if it is deleted' % l3_2.uuid) if not len(vm2.get_vm().vmNics) == 1: test_util.test_fail( 'vm2 vmNics still have L3: %s, even if it is deleted' % l3_2.uuid) #check vm3 status vm3.check() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Delete L3 Test 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) # break 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") # 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 360 && 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, 360) 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 180 seconds") time.sleep(180) 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.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_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) #test_util.test_logger("wait for 300 seconds") #time.sleep(300) 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 == "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 = 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 checking VM ha self-start after host is disconnect and recover 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 deploy_scenario(scenario_config, scenario_file, deploy_config): vm_inv_lst = [] vm_cfg_lst = [] ocfs2smp_shareable_volume_is_created = False zstack_management_ip = scenario_config.basicConfig.zstackManagementIp.text_ root_xml = etree.Element("deployerConfig") vms_xml = etree.SubElement(root_xml, 'vms') for host in xmlobject.safe_list(scenario_config.deployerConfig.hosts.host): for vm in xmlobject.safe_list(host.vms.vm): vm_creation_option = test_util.VmOption() l3_uuid_list = [] default_l3_uuid = None for l3network in xmlobject.safe_list(vm.l3Networks.l3Network): if not default_l3_uuid: default_l3_uuid = l3network.uuid_ l3_uuid_list.append(l3network.uuid_) vm_creation_option.set_instance_offering_uuid( vm.vmInstranceOfferingUuid_) vm_creation_option.set_l3_uuids(l3_uuid_list) vm_creation_option.set_image_uuid(vm.imageUuid_) vm_creation_option.set_name(vm.name_) vm_creation_option.set_host_uuid(host.uuid_) #vm_creation_option.set_data_disk_uuids(disk_offering_uuids) #vm_creation_option.set_default_l3_uuid(default_l3_uuid) #vm_creation_option.set_system_tags(system_tags) #vm_creation_option.set_ps_uuid(ps_uuid) #vm_creation_option.set_session_uuid(session_uuid) vm_inv = create_vm(zstack_management_ip, vm_creation_option) vm_ip = test_lib.lib_get_vm_nic_by_l3(vm_inv, default_l3_uuid).ip test_lib.lib_wait_target_up(vm_ip, '22', 120) vm_xml = etree.SubElement(vms_xml, 'vm') vm_xml.set('name', vm.name_) vm_xml.set('uuid', vm_inv.uuid) vm_xml.set('ip', vm_ip) ips_xml = etree.SubElement(vm_xml, 'ips') for l3_uuid in l3_uuid_list: ip_xml = etree.SubElement(ips_xml, 'ip') ip = test_lib.lib_get_vm_nic_by_l3(vm_inv, l3_uuid).ip ip_xml.set('ip', ip) if xmlobject.has_element(vm, 'nodeRef'): setup_node_vm(vm_inv, vm, deploy_config) if xmlobject.has_element(vm, 'hostRef'): setup_host_vm(vm_inv, vm, deploy_config) vm_inv_lst.append(vm_inv) vm_cfg_lst.append(vm) vm_xml.set('managementIp', vm_ip) if xmlobject.has_element(vm, 'mnHostRef'): setup_mn_host_vm(vm_inv, vm) if xmlobject.has_element(vm, 'backupStorageRef'): volume_option = test_util.VolumeOption() volume_option.set_name(os.environ.get('volumeName')) for bs_ref in xmlobject.safe_list(vm.backupStorageRef): if bs_ref.type_ == 'ceph': disk_offering_uuid = bs_ref.offering_uuid_ volume_option.set_disk_offering_uuid( disk_offering_uuid) volume_inv = create_volume_from_offering( zstack_management_ip, volume_option) attach_volume(zstack_management_ip, volume_inv.uuid, vm_inv.uuid) break if bs_ref.type_ == 'fusionstor': disk_offering_uuid = bs_ref.offering_uuid_ volume_option.set_disk_offering_uuid( disk_offering_uuid) volume_inv = create_volume_from_offering( zstack_management_ip, volume_option) volume_inv1 = create_volume_from_offering( zstack_management_ip, volume_option) volume_inv2 = create_volume_from_offering( zstack_management_ip, volume_option) attach_volume(zstack_management_ip, volume_inv.uuid, vm_inv.uuid) attach_volume(zstack_management_ip, volume_inv1.uuid, vm_inv.uuid) attach_volume(zstack_management_ip, volume_inv2.uuid, vm_inv.uuid) break setup_backupstorage_vm(vm_inv, vm, deploy_config) if xmlobject.has_element(vm, 'primaryStorageRef'): setup_primarystorage_vm(vm_inv, vm, deploy_config) for ps_ref in xmlobject.safe_list(vm.primaryStorageRef): if ps_ref.type_ == 'ocfs2smp': if ocfs2smp_shareable_volume_is_created == False and hasattr( ps_ref, 'disk_offering_uuid_'): ocfs2smp_disk_offering_uuid = ps_ref.disk_offering_uuid_ volume_option.set_disk_offering_uuid( ocfs2smp_disk_offering_uuid) volume_option.set_system_tags([ 'ephemeral::shareable', 'capability::virtio-scsi' ]) share_volume_inv = create_volume_from_offering( zstack_management_ip, volume_option) ocfs2smp_shareable_volume_is_created = True attach_volume(zstack_management_ip, share_volume_inv.uuid, vm_inv.uuid) xml_string = etree.tostring(root_xml, 'utf-8') xml_string = minidom.parseString(xml_string).toprettyxml(indent=" ") open(scenario_file, 'w+').write(xml_string) setup_ceph_storages(scenario_config, scenario_file, deploy_config) setup_ocfs2smp_primary_storages(scenario_config, scenario_file, deploy_config, vm_inv_lst, vm_cfg_lst) setup_fusionstor_storages(scenario_config, scenario_file, deploy_config)
def test(): global vm bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None, fields=['uuid']) if not bss: test_util.test_skip("not find available backup storage. Skip test") image_option = test_util.ImageOption() image_option.set_name('test_image_cache_cleanup') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url(os.environ.get('imageUrl_s')) image_option.set_backup_storage_uuid_list([bss[0].uuid]) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid 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) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option = test_util.VmOption() vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(new_image.image.uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('test_image_cache_cleanup_vm1') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') test_obj_dict.add_vm(vm) vm.check() host = test_lib.lib_find_host_by_vm(vm.get_vm()) target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() new_image.delete() new_image.expunge() ps_ops.cleanup_imagecache_on_primary_storage(ps.uuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: image_cache_path = "%s/imagecache/template/%s" % (ps.mountPath, new_image.image.uuid) if test_lib.lib_check_file_exist(host, image_cache_path): test_util.test_fail('image cache is expected to be deleted') # elif ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE: # elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: # elif ps.type == 'SharedMountPoint': vm.destroy() test_util.test_pass('Migrate VM Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") max_attempts = test_lib.lib_get_ha_selffencer_maxattempts() test_lib.lib_set_ha_selffencer_maxattempts('3') storagechecker_timeout = test_lib.lib_get_ha_selffencer_storagechecker_timeout( ) test_lib.lib_set_ha_selffencer_storagechecker_timeout('5') vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) for vr in vrs: if test_lib.lib_is_vm_running(vr) != True: vm_ops.start_vm(vr.uuid) time.sleep(60) conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '!=', os.environ.get('hostIp'), conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() if not test_lib.lib_check_vm_live_migration_cap(vm.vm): test_util.test_skip('skip ha if live migrate not supported') ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on localstorage') #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') cmd = "ifdown %s && sleep 180 && ifup %s" % (l2_network_interface, l2_network_interface) host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180) if 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") time.sleep(600) vm.update() if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip: test_util.test_fail("VM is expected to start running on another host") vm.set_state(vm_header.RUNNING) vm.check() vm.destroy() test_lib.lib_set_ha_selffencer_maxattempts(max_attempts) test_lib.lib_set_ha_selffencer_storagechecker_timeout( storagechecker_timeout) os.system('bash -ex %s %s' % (os.environ.get('hostRecoverScript'), host_ip)) host_ops.reconnect_host(host_uuid) test_util.test_pass('Test VM ha on host failure Success')
def 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) 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('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") test_stub.stop_ha_vm(vm.get_vm().uuid) vm.set_state(vm_header.STOPPED) vm.check() vm.start() vm.check() 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, 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 ps_uuid global cluster_uuid global tag curr_deploy_conf = exp_ops.export_zstack_deployment_config( test_lib.deploy_config) 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 cluster1_name = os.environ.get('clusterName1') cluster1 = res_ops.get_resource(res_ops.CLUSTER, name=cluster1_name)[0] #pick up primary storage 1 and set system tag for instance offering. zone_name = os.environ.get('zoneName1') zone_uuid = res_ops.get_resource(res_ops.ZONE, name=zone_name)[0].uuid cond = res_ops.gen_query_conditions('zoneUuid', '=', zone_uuid) ps_inv = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0] if ps_inv.type == inventory.NFS_PRIMARY_STORAGE_TYPE: ps_name1 = os.environ.get('nfsPrimaryStorageName1') elif ps_inv.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: ps_name1 = os.environ.get('cephPrimaryStorageName1') ps_inv = res_ops.get_resource(res_ops.PRIMARY_STORAGE, name=ps_name1)[0] ps_uuid = ps_inv.uuid cluster_uuid = cluster1.uuid 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_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multizones_vm_detach_ps') vm_creation_option.set_cluster_uuid(cluster_uuid) tag = tag_ops.create_system_tag('InstanceOfferingVO', \ instance_offering_uuid, \ 'primaryStorage::allocator::uuid::%s' % ps_uuid) l3_name = os.environ.get('l3VlanNetworkName1') l3 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name)[0] vm_creation_option.set_l3_uuids([l3.uuid]) vm1 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm1) vm2 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm2) volume1 = test_stub.create_volume() test_obj_dict.add_volume(volume1) volume1.attach(vm1) test_util.test_dsc("Detach Primary Storage") ps_ops.detach_primary_storage(ps_uuid, cluster_uuid) test_obj_dict.mv_vm(vm1, vm_header.RUNNING, vm_header.STOPPED) test_obj_dict.mv_vm(vm2, vm_header.RUNNING, vm_header.STOPPED) vm1.update() vm1.set_state(vm_header.STOPPED) vm2.update() vm2.set_state(vm_header.STOPPED) vm1.check() vm2.check() test_util.test_dsc("Attach Primary Storage") ps_ops.attach_primary_storage(ps_uuid, cluster_uuid) vm1.start() vm2.start() vm3 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm3) vm1.check() volume1.check() vm2.check() vm3.check() test_util.test_dsc("Delete new added tag") tag_ops.delete_tag(tag.uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Test detaching primary storage Success')
def test(): test_util.test_dsc(''' Will doing random test for VIP operations, including VIP create/delete, PF create/attach/detach/remove, EIP create/attach/detach/remove. VM operations will also be tested. If reach max 4 coexisting running vm, testing will success and quit. SG actions, Volume actions and Image actions are removed in this robot test. VM resources: VIP testing needs at least 3 VRs are running. ''') target_running_vm = 4 target_l3s = test_lib.lib_get_limited_l3_network(2, 5) vr_num = 0 for target_l3 in target_l3s: vr_l3_uuid = target_l3.uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr_l3_uuid) temp_vm = None if not vrs: #create temp_vm for getting its vr for test pf_vm portforwarding vm_create_option = test_util.VmOption() vm_create_option.set_l3_uuids([vr_l3_uuid]) temp_vm = test_lib.lib_create_vm(vm_create_option) test_dict.add_vm(temp_vm) #we only need temp_vm's VR temp_vm.destroy() test_dict.rm_vm(temp_vm) vr_num += 1 #VIP testing need 3 VRs if vr_num > 2: break vrs = test_lib.lib_find_vr_by_l3_uuid(vr_l3_uuid) public_l3 = test_lib.lib_find_vr_pub_nic(vrs[0]).l3NetworkUuid vm_create_option = test_util.VmOption() #image has to use virtual router image, as it needs to do port checking vm_create_option.set_image_uuid( test_lib.lib_get_image_by_name( img_name=os.environ.get('imageName_net')).uuid) priority_actions = test_state.TestAction.vip_actions * 2 + \ [test_state.TestAction.vip_operations] * 2 test_util.test_dsc( 'Random Test Begin. Test target: 4 coexisting running VM (not include VR and SG target test VMs.).' ) robot_test_obj = test_util.Robot_Test_Object() robot_test_obj.set_test_dict(test_dict) robot_test_obj.set_vm_creation_option(vm_create_option) priority_action_obj = action_select.ActionPriority() priority_action_obj.add_priority_action_list(priority_actions) robot_test_obj.set_priority_actions(priority_action_obj) robot_test_obj.set_exclusive_actions_list(\ test_state.TestAction.volume_actions \ + test_state.TestAction.image_actions \ + test_state.TestAction.sg_actions \ + test_state.TestAction.snapshot_actions) robot_test_obj.set_public_l3(public_l3) robot_test_obj.set_random_type(action_select.weight_fair_strategy) rounds = 1 current_time = time.time() timeout_time = current_time + 3600 while time.time() <= timeout_time: test_util.test_dsc('New round %s starts: random operation pickup.' % rounds) test_lib.lib_vm_random_operation(robot_test_obj) test_util.test_dsc( '===============Round %s finished. Begin status checking.================' % rounds) rounds += 1 test_lib.lib_robot_status_check(test_dict) test_util.test_dsc('Reach test pass exit criterial.') test_lib.lib_robot_cleanup(test_dict) test_util.test_pass('Create random VM Test Success')
def test(): global project_uuid, project_admin_uuid, virtual_id_uuid, project_operator_uuid, plain_user_uuid flavor = case_flavor[os.environ.get('CASE_FLAVOR')] # 1 create project project_name = 'test_project' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid project_linked_account_uuid = project.linkedAccountUuid if flavor['target_role'] == 'project_admin': # 2 create virtual id project_admin_name = 'username' project_admin_password = '******' project_admin_uuid = iam2_ops.create_iam2_virtual_id( project_admin_name, project_admin_password).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id( 'usernametwo', 'password').uuid # 3 create project admin iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid], project_uuid) attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}] iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes) # login in project by project admin project_admin_session_uuid = iam2_ops.login_iam2_virtual_id( project_admin_name, project_admin_password) project_login_uuid = iam2_ops.login_iam2_project( project_name, session_uuid=project_admin_session_uuid).uuid # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes) elif flavor['target_role'] == 'project_operator': project_operator_name = 'username2' project_operator_password = '******' attributes = [{"name": "__ProjectOperator__", "value": project_uuid}] project_operator_uuid = iam2_ops.create_iam2_virtual_id( project_operator_name, project_operator_password, attributes=attributes).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id( 'usernamethree', 'password').uuid # login in project by project operator iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid], project_uuid) project_operator_session_uuid = iam2_ops.login_iam2_virtual_id( project_operator_name, project_operator_password) project_login_uuid = iam2_ops.login_iam2_project( project_name, session_uuid=project_operator_session_uuid).uuid elif flavor['target_role'] == 'project_member': plain_user_name = 'username' plain_user_password = '******' plain_user_uuid = iam2_ops.create_iam2_virtual_id( plain_user_name, plain_user_password, project_uuid=project_uuid).uuid # 3 add virtual id to project iam2_ops.add_iam2_virtual_ids_to_project([plain_user_uuid], project_uuid) # 4 login in project by plain user plain_user_session_uuid = iam2_ops.login_iam2_virtual_id( plain_user_name, plain_user_password) # 4 login in project #project_inv=iam2_ops.get_iam2_projects_of_virtual_id(plain_user_session_uuid) project_login_uuid = iam2_ops.login_iam2_project( project_name, plain_user_session_uuid).uuid # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge if flavor['target_role'] == 'project_member': statements = [{ "effect": "Allow", "actions": ["org.zstack.header.vm.**"] }] role_uuid = iam2_ops.create_role('test_role', statements).uuid iam2_ops.add_roles_to_iam2_virtual_id([role_uuid], plain_user_uuid) vm_creation_option = test_util.VmOption() pub_l3_uuid = test_lib.lib_get_l3_by_name( os.environ.get('l3PublicNetworkName')).uuid l3_net_uuid = test_lib.lib_get_l3_by_name( os.environ.get('l3VlanNetworkName3')).uuid acc_ops.share_resources([project_linked_account_uuid], [l3_net_uuid]) vm_creation_option.set_l3_uuids([l3_net_uuid]) image_uuid = test_lib.lib_get_image_by_name( os.environ.get('imageName_net')).uuid vm_creation_option.set_image_uuid(image_uuid) acc_ops.share_resources([project_linked_account_uuid], [image_uuid]) instance_offering_uuid = test_lib.lib_get_instance_offering_by_name( os.environ.get('instanceOfferingName_s')).uuid vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) acc_ops.share_resources([project_linked_account_uuid], [instance_offering_uuid]) vm_creation_option.set_name('vm_for_project_management') vm_creation_option.set_session_uuid(project_login_uuid) vm = test_stub.create_vm(image_uuid=image_uuid, session_uuid=project_login_uuid) vm_uuid = vm.get_vm().uuid vip_option = test_util.VipOption() vip_option.set_name("vip for pm") vip_option.set_session_uuid(project_login_uuid) vip_option.set_l3_uuid(pub_l3_uuid) vm_nic = vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid vip = net_ops.create_vip(vip_option) eip_option = test_util.EipOption() eip_option.set_name('eip for pm') eip_option.set_session_uuid(project_login_uuid) eip_option.set_vip_uuid(vip.uuid) eip_option.set_vm_nic_uuid(vm_nic_uuid) eip = net_ops.create_eip(eip_option) net_ops.detach_eip(eip.uuid, session_uuid=project_login_uuid) net_ops.attach_eip(eip.uuid, vm_nic_uuid, session_uuid=project_login_uuid) net_ops.detach_eip(eip.uuid, session_uuid=project_login_uuid) net_ops.delete_eip(eip.uuid) net_ops.delete_vip(vip.uuid) vm_ops.destroy_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.expunge_vm(vm_uuid, session_uuid=project_login_uuid) # 11 delete acc_ops.logout(project_login_uuid) if virtual_id_uuid != None: iam2_ops.delete_iam2_virtual_id(virtual_id_uuid) if project_admin_uuid != None: iam2_ops.delete_iam2_virtual_id(project_admin_uuid) if project_operator_uuid != None: iam2_ops.delete_iam2_virtual_id(project_operator_uuid) if plain_user_uuid != None: iam2_ops.delete_iam2_virtual_id(plain_user_uuid) iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) test_util.test_pass('success test iam2 login in by project admin!')