def test(): global session_to global session_mc global session_uuid 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() cond = res_ops.gen_query_conditions('type', '=', 'Data') num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid) if num <= thread_threshold: volumes = res_ops.query_resource(res_ops.VOLUME, cond, session_uuid) delete_volumes(volumes) else: start = 0 limit = thread_threshold - 1 curr_num = start volumes = [] while curr_num < num: volumes_temp = res_ops.query_resource_with_num(res_ops.VOLUME, cond, session_uuid, start, limit) volumes.extend(volumes_temp) start += limit curr_num += limit delete_volumes(volumes) #con_ops.change_global_config('identity', 'session.timeout', session_to) #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc) con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid) con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid) left_num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid) acc_ops.logout(session_uuid) if left_num == 0: test_util.test_pass('Delete Data Volume Success. Delete %d Volumes.' % num) else: test_util.test_fail('Delete Data Volume Fail. %d Volumes are not deleted.' % left_num)
def test(): global session_to global session_mc global session_uuid session_uuid = acc_ops.login_as_admin() 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) cond = res_ops.gen_query_conditions('type', '=', inventory.USER_VM_TYPE) num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid) if num <= thread_threshold: vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond, session_uuid) destroy_vms(vms) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < num: vms_temp = res_ops.query_resource_fields(res_ops.VM_INSTANCE, \ cond, session_uuid, ['uuid'], start, limit) vms.extend(vms_temp) curr_num += limit start += limit destroy_vms(vms) vip_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid) if vip_num <= thread_threshold: vips = res_ops.query_resource(res_ops.VIP, [], session_uuid) destroy_vips(vips) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < vip_num: vips_temp = res_ops.query_resource_fields(res_ops.VIP, \ [], session_uuid, ['uuid'], start, limit) vips.extend(vips_temp) curr_num += limit start += limit destroy_vips(vips) #con_ops.change_global_config('identity', 'session.timeout', session_to) #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc) left_num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid) if left_num == 0: test_util.test_pass('None VR VMs destroy Success. Destroy %d VMs.' % num) else: test_util.test_fail('None VR VMs destroy Fail. %d VMs are not Destroied.' % left_num) left_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid) if left_num == 0: test_util.test_pass('VIP destroy Success. Destroy %d VIP.' % num) else: test_util.test_fail('VIP destroy Fail. %d VIP are not Destroied.' % left_num) 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)
def test(): global session_to global session_mc global session_uuid 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() num = res_ops.query_resource_count(res_ops.SECURITY_GROUP, [], session_uuid) if num <= thread_threshold: sgs = res_ops.query_resource(res_ops.SECURITY_GROUP, [], session_uuid) delete_sgs(sgs) else: start = 0 limit = thread_threshold - 1 curr_num = start sgs = [] while curr_num < num: sgs_tmp = res_ops.query_resource_fields(res_ops.SECURITY_GROUP, [], session_uuid, ["uuid"], start, limit) sgs.extend(sgs_tmp) curr_num += limit start += limit delete_sgs(sgs) # con_ops.change_global_config('identity', 'session.timeout', session_to) # con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc) con_ops.change_global_config("identity", "session.timeout", session_to, session_uuid) con_ops.change_global_config("identity", "session.maxConcurrent", session_mc, session_uuid) left_num = res_ops.query_resource_count(res_ops.SECURITY_GROUP, [], session_uuid) acc_ops.logout(session_uuid) if left_num == 0: test_util.test_pass("Delete SG Success. Delete %d SGs." % num) else: test_util.test_fail("Delete SG Fail. %d SGs are not deleted." % left_num)
def test(): global session_to global session_mc global session_uuid 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() num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid) if num <= thread_threshold: vips = res_ops.query_resource(res_ops.VIP, [], session_uuid) delete_vips(vips) else: start = 0 limit = thread_threshold - 1 curr_num = start vips = [] while curr_num < num: vips_temp = res_ops.query_resource_fields(res_ops.VIP, [], \ session_uuid, ['uuid'], start, limit) vips.extend(vips_temp) curr_num += limit start += limit delete_vips(vips) con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid) con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid) left_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid) acc_ops.logout(session_uuid) if left_num == 0: test_util.test_pass('Delete VIP Success. Delete %d VIPs.' % num) else: test_util.test_fail('Delete VIP Fail. %d VIPs are not deleted.' % left_num)
def test(): global session_to global session_mc global session_uuid 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() num = res_ops.query_resource_count(res_ops.SECURITY_GROUP, [], session_uuid) if num <= thread_threshold: sgs = res_ops.query_resource(res_ops.SECURITY_GROUP, [], session_uuid) delete_sgs(sgs) else: start = 0 limit = thread_threshold - 1 curr_num = start sgs = [] while curr_num < num: sgs_tmp = res_ops.query_resource_fields(res_ops.SECURITY_GROUP, \ [], session_uuid, ['uuid'], start, limit) sgs.extend(sgs_tmp) curr_num += limit start += limit delete_sgs(sgs) #con_ops.change_global_config('identity', 'session.timeout', session_to) #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc) con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid) con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid) left_num = res_ops.query_resource_count(res_ops.SECURITY_GROUP, [], session_uuid) acc_ops.logout(session_uuid) if left_num == 0: test_util.test_pass('Delete SG Success. Delete %d SGs.' % num) else: test_util.test_fail('Delete SG Fail. %d SGs are not deleted.' % left_num)
def test(): global session_to global session_mc global session_uuid session_uuid = acc_ops.login_as_admin() session_to = con_ops.change_global_config('identity', 'session.timeout', '720000') session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000') cond = [] num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond) if num <= thread_threshold: vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond) destroy_vms(vms) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < num: vms_temp = res_ops.query_resource_fields(res_ops.VM_INSTANCE, \ cond, None, ['uuid'], start, limit) vms.extend(vms_temp) curr_num += limit start += limit destroy_vms(vms) vip_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid) if vip_num <= thread_threshold: vips = res_ops.query_resource(res_ops.VIP, [], session_uuid) destroy_vips(vips) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < vip_num: vips_temp = res_ops.query_resource_fields(res_ops.VIP, \ [], session_uuid, ['uuid'], start, limit) vips.extend(vips_temp) curr_num += limit start += limit destroy_vips(vips) test_util.test_pass('vms destroy Success. Destroy %d VMs.' % num) con_ops.change_global_config('identity', 'session.timeout', session_to) con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc) acc_ops.logout(session_uuid)
def check_removalinstance_vmm_number(min_number,expect_number,autoscaling_groupUuid): conf = res_ops.gen_query_conditions('state', '=','Running') vmm_total = res_ops.query_resource_count(res_ops.VM_INSTANCE, conf) test_util.test_logger("%s" %(vmm_total)) vmm_virtualrouter_total = res_ops.query_resource_count(res_ops.VIRTUALROUTER_VM, conf) vmm_total = vmm_total - vmm_virtualrouter_total if vmm_total == expect_number and vmm_total >= min_number: test_util.test_dsc("autoscaling removal instance successfully") elif vmm_total < min_number: autoscaling.delete_autoScaling_group(autoscaling_groupUuid) test_util.test_fail("autoscaling create vm can not LessThan %s" %(min_number)) elif vmm_total != expect_number: autoscaling.delete_autoScaling_group(autoscaling_groupUuid) test_util.test_fail("autoscaling removal instance fail")
def test(): global session_to global session_mc global session_uuid 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() num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT_TREE, [], \ session_uuid) sps_del = [] if num <= thread_threshold: sps = res_ops.query_resource_with_num(res_ops.VOLUME_SNAPSHOT_TREE,\ [], session_uuid, start = 0, limit = num) for sp in sps: sps_del.append(sp.tree.inventory.uuid) else: start = 0 limit = thread_threshold - 1 curr_num = start while curr_num < num: sps_temp = res_ops.query_resource_with_num(\ res_ops.VOLUME_SNAPSHOT_TREE, \ [], session_uuid, start, limit) for sp in sps_temp: sps_del.append(sp.tree.inventory.uuid) start += limit curr_num += limit delete_sps(sps_del) #con_ops.change_global_config('identity', 'session.timeout', session_to) #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc) con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid) con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid) left_num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, [], \ session_uuid) acc_ops.logout(session_uuid) if left_num == 0: test_util.test_pass( 'Delete Volume Snapshot Success. Delete %d Volume Snapshots.' % num) else: test_util.test_fail( 'Delete Data Volume Snapshot Fail. %d Volume Snapshots are not deleted.' % left_num)
def check_deleteautoscaling_vmm_number(): for i in range(10): conf = res_ops.gen_query_conditions('state', '=','Running') mix_vmm_total = res_ops.query_resource_count(res_ops.VM_INSTANCE, conf) test_util.test_logger("%s" %(mix_vmm_total)) vmm_virtualrouter_total = res_ops.query_resource_count(res_ops.VIRTUALROUTER_VM, conf) if mix_vmm_total != vmm_virtualrouter_total: if i < 9: time.sleep(5) continue test_util.test_dsc("autoscaling delete vmm fail") test_util.test_fail("Test AutoScaling Group Failed") else: test_util.test_logger("autoscaling delete vmm sucessfully") break
def destroy_all_vm_and_vips(thread_threshold=1000): session_uuid = acc_ops.login_as_admin() session_to = con_ops.change_global_config('identity', 'session.timeout', '720000') session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000') delete_policy = test_lib.lib_set_delete_policy('vm', 'Direct') expunge_time = test_lib.lib_set_expunge_time('vm', 1) cond = res_ops.gen_query_conditions('state', '!=', 'Destroyed') num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond) if num <= thread_threshold: vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond) do_destroy_vms(vms, thread_threshold) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < num: vms_temp = res_ops.query_resource_fields(res_ops.VM_INSTANCE, \ cond, None, ['uuid'], start, limit) vms.extend(vms_temp) curr_num += limit start += limit do_destroy_vms(vms, thread_threshold) vip_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid) if vip_num <= thread_threshold: vips = res_ops.query_resource(res_ops.VIP, [], session_uuid) do_destroy_vips(vips, thread_threshold) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < vip_num: vips_temp = res_ops.query_resource_fields(res_ops.VIP, \ [], session_uuid, ['uuid'], start, limit) vips.extend(vips_temp) curr_num += limit start += limit do_destroy_vips(vips, thread_threshold) test_lib.lib_set_delete_policy('vm', delete_policy) test_lib.lib_set_expunge_time('vm', expunge_time) test_util.test_logger('vms destroy Success. Destroy %d VMs.' % num)
def test(): global session_to global session_mc global session_uuid session_uuid = acc_ops.login_as_admin() session_to = con_ops.change_global_config('identity', 'session.timeout', '720000') session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000') cond = [] num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond) if num <= thread_threshold: vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond) destroy_vms(vms) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < num: vms_temp = res_ops.query_resource_fields(res_ops.VM_INSTANCE, \ cond, None, ['uuid'], start, limit) vms.extend(vms_temp) curr_num += limit start += limit destroy_vms(vms) vip_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid) if vip_num <= thread_threshold: vips = res_ops.query_resource(res_ops.VIP, [], session_uuid) destroy_vips(vips) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < vip_num: vips_temp = res_ops.query_resource_fields(res_ops.VIP, \ [], session_uuid, ['uuid'], start, limit) vips.extend(vips_temp) curr_num += limit start += limit destroy_vips(vips) test_util.test_pass('vms destroy Success. Destroy %d VMs.' % num) con_ops.change_global_config('identity', 'session.timeout', session_to) con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc) acc_ops.logout(session_uuid)
def delete_all_volumes(thread_threshold = 1000): session_uuid = acc_ops.login_as_admin() session_to = con_ops.change_global_config('identity', 'session.timeout', '720000') session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000') delete_policy = test_lib.lib_set_delete_policy('volume', 'Direct') expunge_time = test_lib.lib_set_expunge_time('volume', 1) cond = res_ops.gen_query_conditions('status', '!=', 'Deleted') num = res_ops.query_resource_count(res_ops.VOLUME, cond) if num <= thread_threshold: volumes = res_ops.query_resource(res_ops.VOLUME, cond) do_delete_volumes(volumes, thread_threshold) else: start = 0 limit = thread_threshold - 1 curr_num = start volumes = [] while curr_num < num: volumes_temp = res_ops.query_resource_fields(res_ops.VOLUME, \ cond, None, ['uuid'], start, limit) volumes.extend(volumes_temp) curr_num += limit start += limit do_delete_volumes(volumes, thread_threshold) test_lib.lib_set_delete_policy('volume', delete_policy) test_lib.lib_set_expunge_time('volume', expunge_time) test_util.test_logger('Volumes destroy Success. Destroy %d Volumes.' % num)
def delete_all_volumes(thread_threshold=1000): session_uuid = acc_ops.login_as_admin() session_to = con_ops.change_global_config("identity", "session.timeout", "720000") session_mc = con_ops.change_global_config("identity", "session.maxConcurrent", "10000") delete_policy = test_lib.lib_set_delete_policy("volume", "Direct") expunge_time = test_lib.lib_set_expunge_time("volume", 1) cond = res_ops.gen_query_conditions("status", "!=", "Deleted") num = res_ops.query_resource_count(res_ops.VOLUME, cond) if num <= thread_threshold: volumes = res_ops.query_resource(res_ops.VOLUME, cond) do_delete_volumes(volumes, thread_threshold) else: start = 0 limit = thread_threshold - 1 curr_num = start volumes = [] while curr_num < num: volumes_temp = res_ops.query_resource_fields(res_ops.VOLUME, cond, None, ["uuid"], start, limit) volumes.extend(volumes_temp) curr_num += limit start += limit do_delete_volumes(volumes, thread_threshold) test_lib.lib_set_delete_policy("volume", delete_policy) test_lib.lib_set_expunge_time("volume", expunge_time) test_util.test_logger("Volumes destroy Success. Destroy %d Volumes." % num)
def test(): global session_uuid global session_to global session_mc vm_num = os.environ.get('ZSTACK_TEST_NUM') if not vm_num: vm_num = 0 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_sim') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanNetworkName1') conditions = res_ops.gen_query_conditions('name', '=', l3_name) l3_uuid = res_ops.query_resource_with_num(res_ops.L3_NETWORK, conditions, \ session_uuid, start = 0, limit = 1)[0].uuid vm_creation_option.set_l3_uuids([l3_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) session_uuid = acc_ops.login_as_admin() #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) vm_creation_option.set_session_uuid(session_uuid) vm = test_vm_header.ZstackTestVm() random_name = random.random() vm_name = 'multihost_sim_vm_%s' % str(random_name) vm_creation_option.set_name(vm_name) while vm_num > 0: check_thread_exception() 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: test_util.test_pass('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 session_to global session_mc session_to = con_ops.change_global_config('identity', 'session.timeout', '720000') session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000') test_util.test_dsc('Create test vm as utility vm') vm = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm) #use root volume to skip add_checking_point test_util.test_dsc('Use root volume for snapshot testing') root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume = zstack_volume_header.ZstackTestVolume() root_volume.set_volume(root_volume_inv) root_volume.set_state(volume_header.ATTACHED) root_volume.set_target_vm(vm) test_obj_dict.add_volume(root_volume) vm.check() snapshots = test_obj_dict.get_volume_snapshot(root_volume.get_volume().uuid) snapshots.set_utility_vm(vm) ori_num = 100 index = 1 while index < 101: thread = threading.Thread(target=create_snapshot, args=(snapshots, index,)) thread.start() index += 1 while threading.activeCount() > 1: time.sleep(0.1) #snapshot.check() doesn't work for root volume #snapshots.check() #check if snapshot exists in install_path ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) if ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE or ps.type == inventory.LOCAL_STORAGE_TYPE: host = test_lib.lib_get_vm_host(vm.get_vm()) for snapshot in snapshots.get_snapshot_list(): snapshot_inv = snapshot.get_snapshot() sp_ps_install_path = snapshot_inv.primaryStorageInstallPath if test_lib.lib_check_file_exist(host, sp_ps_install_path): test_util.test_logger('Check result: snapshot %s is found in host %s in path %s' % (snapshot_inv.name, host.managementIp, sp_ps_install_path)) else: test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_fail('Check result: snapshot %s is not found in host %s in path %s' % (snapshot_inv.name, host.managementIp, sp_ps_install_path)) else: test_util.test_logger('Skip check file install path for %s primary storage' % (ps.type)) cond = res_ops.gen_query_conditions('volumeUuid', '=', root_volume.get_volume().uuid) sps_num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, cond) if sps_num != ori_num: test_util.test_fail('Create %d snapshots, but only %d snapshots were successfully created' % (ori_num, sps_num)) try: test_lib.lib_robot_cleanup(test_obj_dict) except: test_lib.test_logger('Delete VM may timeout') test_util.test_pass('Test create 100 snapshots simultaneously success')
def test(): global session_uuid global session_to global session_mc vm_num = os.environ.get('ZSTACK_TEST_NUM') if not vm_num: vm_num = 0 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('l3VlanNetworkName1') conditions = res_ops.gen_query_conditions('name', '=', l3_name) l3_uuid = res_ops.query_resource_with_num(res_ops.L3_NETWORK, conditions, \ session_uuid, start = 0, limit = 1)[0].uuid vm_creation_option.set_l3_uuids([l3_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) session_uuid = acc_ops.login_as_admin() #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) 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.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: test_util.test_pass('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 Create(vm_name_prefix): global session_uuid global session_to global session_mc session_uuid = None session_to = None session_mc = None vm_num = os.environ.get('ZSTACK_TEST_NUM') if not vm_num: vm_num = 1000 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) 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 cond = res_ops.gen_query_conditions('category', '=', 'Private') l3net_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond, session_uuid)[0].uuid 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() vm_creation_option.set_l3_uuids([l3net_uuid]) while vm_num > 0: check_thread_exception() vm_name = '%s_%s' % (vm_name_prefix, str(vm_num)) vm_creation_option.set_name(vm_name) 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.05) 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)
def check_autoscaling_init_vmm_number(initvm_number,autoscaling_groupUuid): for i in range(10): conf = res_ops.gen_query_conditions('state', '=','Running') mix_vmm_total = res_ops.query_resource_count(res_ops.VM_INSTANCE, conf) test_util.test_logger("%s" %(mix_vmm_total)) vmm_virtualrouter_total = res_ops.query_resource_count(res_ops.VIRTUALROUTER_VM, conf) vmm_total = mix_vmm_total - vmm_virtualrouter_total if vmm_total != initvm_number: if i < 9: time.sleep(5) continue test_util.test_dsc("autoscaling group init vmm fail") autoscaling.delete_autoScaling_group(autoscaling_groupUuid) test_util.test_fail("autoscaling group init vmm fail") else: test_util.test_logger("autoscaling group init vmm sucessfully") break
def test(): global session_uuid global session_to global session_mc vm_num = os.environ.get('ZSTACK_VM_NUM') if not vm_num: vm_num = 0 else: vm_num = int(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') session_uuid = acc_ops.login_as_admin() 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) 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) 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: vm_creation_option.set_l3_uuids([random.choice(l3s).uuid]) vm.set_creation_option(vm_creation_option) vm_num -= 1 thread = threading.Thread(target=vm.create) 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) if vms == org_num: test_util.test_pass('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 session_to global session_mc global session_uuid 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() cond = res_ops.gen_query_conditions('type', '=', 'Data') num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid) if num <= thread_threshold: volumes = res_ops.query_resource(res_ops.VOLUME, cond, session_uuid) delete_volumes(volumes) else: start = 0 limit = thread_threshold - 1 curr_num = start volumes = [] while curr_num < num: volumes_temp = res_ops.query_resource_with_num( res_ops.VOLUME, cond, session_uuid, start, limit) volumes.extend(volumes_temp) start += limit curr_num += limit delete_volumes(volumes) #con_ops.change_global_config('identity', 'session.timeout', session_to) #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc) con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid) con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid) left_num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid) acc_ops.logout(session_uuid) if left_num == 0: test_util.test_pass('Delete Data Volume Success. Delete %d Volumes.' % num) else: test_util.test_fail( 'Delete Data Volume Fail. %d Volumes are not deleted.' % left_num)
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 = 1000 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() vm_creation_option.set_l3_uuids([l3.uuid]) while vm_num > 0: check_thread_exception() vm_name = 'multihost_basic_vm_%s' % str(vm_num) vm_creation_option.set_name(vm_name) 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.05) 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)
def create_snapshot(snapshots, index): snapshot_name = 'create_snapshot%s' % str(index) try: snapshots.create_snapshot(snapshot_name) except: while True: cond = res_ops.gen_query_conditions('name', '=', snapshot_name) sps_num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, cond) if sps_num == 1: break time.sleep(5)
def create_snapshot(snapshots, index): snapshot_name = 'create_snapshot%s' % str(index) try: snapshots.create_snapshot(snapshot_name) except: while True: cond = res_ops.gen_query_conditions('name', '=', snapshot_name) sps_num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, cond) if sps_num == 1: break time.sleep(5)
def test(): global session_to global session_mc global session_uuid session_uuid = acc_ops.login_as_admin() 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) num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid) if num <= thread_threshold: vips = res_ops.query_resource(res_ops.VIP, [], session_uuid) destroy_vips(vips) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < num: vips_temp = res_ops.query_resource_fields(res_ops.VIP, \ [], session_uuid, ['uuid'], start, limit) vips.extend(vips_temp) curr_num += limit start += limit destroy_vips(vips) #con_ops.change_global_config('identity', 'session.timeout', session_to) #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc) con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid) con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid) left_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid) acc_ops.logout(session_uuid) if left_num == 0: test_util.test_pass('VIP destroy Success. Destroy %d VIP.' % num) else: test_util.test_fail('VIP destroy Fail. %d VIP are not Destroied.' % left_num)
def destroy_all_vm_and_vips(thread_threshold=1000): session_uuid = acc_ops.login_as_admin() session_to = con_ops.change_global_config("identity", "session.timeout", "720000") session_mc = con_ops.change_global_config("identity", "session.maxConcurrent", "10000") cond = [] num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond) if num <= thread_threshold: vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond) do_destroy_vms(vms, thread_threshold) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < num: vms_temp = res_ops.query_resource_fields(res_ops.VM_INSTANCE, cond, None, ["uuid"], start, limit) vms.extend(vms_temp) curr_num += limit start += limit do_destroy_vms(vms, thread_threshold) vip_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid) if vip_num <= thread_threshold: vips = res_ops.query_resource(res_ops.VIP, [], session_uuid) do_destroy_vips(vips, thread_threshold) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < vip_num: vips_temp = res_ops.query_resource_fields(res_ops.VIP, [], session_uuid, ["uuid"], start, limit) vips.extend(vips_temp) curr_num += limit start += limit do_destroy_vips(vips, thread_threshold) test_util.test_logger("vms destroy Success. Destroy %d VMs." % num)
def test(): global session_uuid global session_to global session_mc vm_num = os.environ.get('ZSTACK_VM_NUM') if not vm_num: vm_num = 0 else: vm_num = int(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') session_uuid = acc_ops.login_as_admin() 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) 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) 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: vm_creation_option.set_l3_uuids([random.choice(l3s).uuid]) vm.set_creation_option(vm_creation_option) vm_num -= 1 thread = threading.Thread(target=vm.create) 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) if vms == org_num: test_util.test_pass('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 session_to global session_mc global session_uuid 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() num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT_TREE, [], session_uuid) sps_del = [] if num <= thread_threshold: sps = res_ops.query_resource_with_num(res_ops.VOLUME_SNAPSHOT_TREE, [], session_uuid, start=0, limit=num) for sp in sps: sps_del.append(sp.tree.inventory.uuid) else: start = 0 limit = thread_threshold - 1 curr_num = start while curr_num < num: sps_temp = res_ops.query_resource_with_num(res_ops.VOLUME_SNAPSHOT_TREE, [], session_uuid, start, limit) for sp in sps_temp: sps_del.append(sp.tree.inventory.uuid) start += limit curr_num += limit delete_sps(sps_del) # con_ops.change_global_config('identity', 'session.timeout', session_to) # con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc) con_ops.change_global_config("identity", "session.timeout", session_to, session_uuid) con_ops.change_global_config("identity", "session.maxConcurrent", session_mc, session_uuid) left_num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, [], session_uuid) acc_ops.logout(session_uuid) if left_num == 0: test_util.test_pass("Delete Volume Snapshot Success. Delete %d Volume Snapshots." % num) else: test_util.test_fail("Delete Data Volume Snapshot Fail. %d Volume Snapshots are not deleted." % left_num)
def delete_accounts(thread_threshold=1000): def do_delete_accounts(accounts, session_uuid): for account in accounts: thread = threading.Thread(target=acc_ops.delete_account, \ args=(account.uuid, session_uuid)) while threading.active_count() > thread_threshold: time.sleep(0.5) exc = sys.exc_info() if exc[0]: raise info1, None, info2 thread.start() while threading.activeCount() > 1: exc = sys.exc_info() if exc[0]: raise info1, None, info2 time.sleep(0.1) session_uuid = acc_ops.login_as_admin() session_to = con_ops.change_global_config('identity', 'session.timeout', '720000') session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000') cond = [] cond = res_ops.gen_query_conditions('name', '!=', 'admin', cond) num = res_ops.query_resource_count(res_ops.ACCOUNT, cond) if num <= thread_threshold: accounts = res_ops.query_resource(res_ops.ACCOUNT, cond) do_delete_accounts(accounts, session_uuid) else: start = 0 limit = thread_threshold - 1 curr_num = start accs = [] while curr_num < num: acc_tmp= res_ops.query_resource_fields(res_ops.ACCOUNT, \ [], session_uuid, ['uuid'], start, limit) accs.extend(acc_temp) curr_num += limit start += limit do_delete_accounts(accs, thread_threshold)
def delete_accounts(thread_threshold = 1000): def do_delete_accounts(accounts, session_uuid): for account in accounts: thread = threading.Thread(target=acc_ops.delete_account, \ args=(account.uuid, session_uuid)) while threading.active_count() > thread_threshold: time.sleep(0.5) exc = sys.exc_info() if exc[0]: raise info1, None, info2 thread.start() while threading.activeCount() > 1: exc = sys.exc_info() if exc[0]: raise info1, None, info2 time.sleep(0.1) session_uuid = acc_ops.login_as_admin() session_to = con_ops.change_global_config('identity', 'session.timeout', '720000') session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000') cond = [] cond = res_ops.gen_query_conditions('name', '!=', 'admin', cond) num = res_ops.query_resource_count(res_ops.ACCOUNT, cond) if num <= thread_threshold: accounts = res_ops.query_resource(res_ops.ACCOUNT, cond) do_delete_accounts(accounts, session_uuid) else: start = 0 limit = thread_threshold - 1 curr_num = start accs = [] while curr_num < num: acc_tmp= res_ops.query_resource_fields(res_ops.ACCOUNT, \ [], session_uuid, ['uuid'], start, limit) accs.extend(acc_temp) curr_num += limit start += limit do_delete_accounts(accs, thread_threshold)
def query_snapshot_number(volume_uuid): cond = res_ops.gen_query_conditions('volumeUuid', '=', volume_uuid) return res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, cond)
def test(): global session_uuid global session_to global session_mc thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD') if not thread_threshold: thread_threshold = 1000 else: thread_threshold = int(thread_threshold) vip_num = os.environ.get('ZSTACK_TEST_NUM') if not vip_num: vip_num = 0 else: vip_num = int(vip_num) #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() test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold) test_util.test_logger('ZSTACK_TEST_NUM is %d' % vip_num) org_num = vip_num vip_option = test_util.VipOption() l3_name = os.environ.get('l3PublicNetworkName') conditions = res_ops.gen_query_conditions('name', '=', l3_name) l3_uuid = res_ops.query_resource_with_num(res_ops.L3_NETWORK, conditions, \ session_uuid, start = 0, limit = 1)[0].uuid random_name = random.random() vip_name = 'perf_vip_%s' % str(random_name) vip_option.set_name(vip_name) vip_option.set_session_uuid(session_uuid) vip_option.set_l3_uuid(l3_uuid) vm_num = 0 while vip_num > 0: check_thread_exception() vip_num -= 1 vip_option.set_description(org_num - vip_num) if vm_num > (thread_threshold - 1): vm_num = 0 thread = threading.Thread(target=create_vip, args = (vip_option, )) vm_num += 1 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', '=', vip_name) vips_num = res_ops.query_resource_count(res_ops.VIP, 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 vips_num == org_num: test_util.test_pass('Create %d VIPs Test Success' % org_num) else: test_util.test_fail('Create %d VIPs Test Failed. Only find %d VIPs.' % (org_num, vips_num))
def test(): global session_uuid global session_to global session_mc thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD') if not thread_threshold: thread_threshold = 1000 else: thread_threshold = int(thread_threshold) volume_num = os.environ.get('ZSTACK_TEST_NUM') if not volume_num: volume_num = 0 else: volume_num = int(volume_num) #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_num = res_ops.query_resource_count(res_ops.VM_INSTANCE, [], session_uuid) if vm_num < thread_threshold: test_util.test_fail('This test needs: %d VM instances for volume attaching and detaching operations. But there are only %d VMs instances. Please use this case: test_crt_basic_vm_with_max_threads.py to create required VMs.' % (thread_threshold, volume_num)) vms = res_ops.query_resource_with_num(res_ops.VM_INSTANCE, [], \ session_uuid, start = 0, limit = thread_threshold) test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold) test_util.test_logger('ZSTACK_TEST_NUM is %d' % volume_num) org_num = volume_num disk_offering_name = os.environ.get('smallDiskOfferingName') disk_offering_uuid = test_lib.lib_get_disk_offering_by_name(disk_offering_name).uuid volume_option = test_util.VolumeOption() volume_option.set_disk_offering_uuid(disk_offering_uuid) volume_option.set_session_uuid(session_uuid) random_name = random.random() volume_name = 'perf_volume_%s' % str(random_name) volume_option.set_name(volume_name) vm_num = 0 while volume_num > 0: check_thread_exception() volume = test_vol_header.ZstackTestVolume() volume.set_creation_option(volume_option) volume_num -= 1 if vm_num > (thread_threshold - 1): vm_num = 0 thread = threading.Thread(target=create_volume, args = (volume, vms[vm_num].uuid, )) vm_num += 1 while threading.active_count() > thread_threshold: time.sleep(0.) thread.start() while threading.active_count() > 1: time.sleep(0.01) cond = res_ops.gen_query_conditions('name', '=', volume_name) volumes_num = res_ops.query_resource_count(res_ops.VOLUME, 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 volumes_num == org_num: test_util.test_pass('Create %d Volumes Test Success' % org_num) else: test_util.test_fail('Create %d Volumes Test Failed. Only find %d Volumes.' % (org_num, volumes_num))
def test(): global session_uuid global session_to global session_mc thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD') if not thread_threshold: thread_threshold = 1000 else: thread_threshold = int(thread_threshold) eip_num = os.environ.get('ZSTACK_TEST_NUM') if not eip_num: eip_num = 0 else: eip_num = int(eip_num) #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() test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold) test_util.test_logger('ZSTACK_TEST_NUM is %d' % eip_num) org_num = eip_num vip_option = test_util.VipOption() l3_name = os.environ.get('l3PublicNetworkName') conditions = res_ops.gen_query_conditions('name', '=', l3_name) l3_uuid = res_ops.query_resource_with_num(res_ops.L3_NETWORK, conditions, \ session_uuid, start = 0, limit = 1)[0].uuid cond = res_ops.gen_query_conditions('l3NetworkUuid', '!=', l3_uuid) vm_nic_num = res_ops.query_resource_count(res_ops.VM_NIC, cond, \ session_uuid) if vm_nic_num < eip_num: test_util.test_fail( 'This test needs: %d vm nics for pf attaching and detaching operations. But there are only %d vm nics. Please use this case: test_crt_basic_vm_with_max_threads.py to create required VMs.' % (eip_num, vm_nic_num)) nics = [] start_num = 0 while eip_num > 0: vm_nics = res_ops.query_resource_fields(res_ops.VM_NIC, cond, \ session_uuid, ['uuid'], start_num, thread_threshold) for nic in vm_nics: nics.append(nic.uuid) eip_num -= thread_threshold start_num += thread_threshold eip_num = org_num random_name = random.random() vip_name = 'perf_vip_%s' % str(random_name) vip_option.set_name(vip_name) vip_option.set_session_uuid(session_uuid) vip_option.set_l3_uuid(l3_uuid) vic_num = 0 while eip_num > 0: check_thread_exception() eip_num -= 1 vip_option.set_description(org_num - eip_num) thread = threading.Thread(target=create_eip, args=( vip_option, nics[vic_num], )) vic_num += 1 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', '=', 'eip_%s' % vip_name) eips_num = res_ops.query_resource_count(res_ops.EIP, 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 eips_num == org_num: test_util.test_pass('Create %d EIPs Test Success' % org_num) else: test_util.test_fail('Create %d EIPs Test Failed. Only find %d EIPs.' % (org_num, eips_num))
def test(): global session_to global session_mc session_to = con_ops.change_global_config('identity', 'session.timeout', '720000') session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000') test_util.test_dsc('Create test vm as utility vm') vm = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm) #use root volume to skip add_checking_point test_util.test_dsc('Use root volume for snapshot testing') root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume = zstack_volume_header.ZstackTestVolume() root_volume.set_volume(root_volume_inv) root_volume.set_state(volume_header.ATTACHED) root_volume.set_target_vm(vm) test_obj_dict.add_volume(root_volume) vm.check() snapshots = test_obj_dict.get_volume_snapshot( root_volume.get_volume().uuid) snapshots.set_utility_vm(vm) ori_num = 100 index = 1 while index < 101: thread = threading.Thread(target=create_snapshot, args=( snapshots, index, )) thread.start() index += 1 while threading.activeCount() > 1: time.sleep(0.1) #snapshot.check() doesn't work for root volume #snapshots.check() #check if snapshot exists in install_path ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) if ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE or ps.type == inventory.LOCAL_STORAGE_TYPE: host = test_lib.lib_get_vm_host(vm.get_vm()) for snapshot in snapshots.get_snapshot_list(): snapshot_inv = snapshot.get_snapshot() sp_ps_install_path = snapshot_inv.primaryStorageInstallPath if test_lib.lib_check_file_exist(host, sp_ps_install_path): test_util.test_logger( 'Check result: snapshot %s is found in host %s in path %s' % (snapshot_inv.name, host.managementIp, sp_ps_install_path)) else: test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_fail( 'Check result: snapshot %s is not found in host %s in path %s' % (snapshot_inv.name, host.managementIp, sp_ps_install_path)) else: test_util.test_logger( 'Skip check file install path for %s primary storage' % (ps.type)) cond = res_ops.gen_query_conditions('volumeUuid', '=', root_volume.get_volume().uuid) sps_num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, cond) if sps_num != ori_num: test_util.test_fail( 'Create %d snapshots, but only %d snapshots were successfully created' % (ori_num, sps_num)) try: test_lib.lib_robot_cleanup(test_obj_dict) except: test_lib.test_logger('Delete VM may timeout') test_util.test_pass('Test create 100 snapshots simultaneously success')
def test(): global session_to global session_mc global session_uuid session_uuid = acc_ops.login_as_admin() 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) cond = res_ops.gen_query_conditions('type', '=', inventory.USER_VM_TYPE) cond = res_ops.gen_query_conditions('state', '!=', 'Destroyed', cond) num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid) if num <= thread_threshold: vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond, session_uuid) destroy_vms(vms) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < num: vms_temp = res_ops.query_resource_fields(res_ops.VM_INSTANCE, \ cond, session_uuid, ['uuid'], start, limit) vms.extend(vms_temp) curr_num += limit start += limit destroy_vms(vms) vip_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid) if vip_num <= thread_threshold: vips = res_ops.query_resource(res_ops.VIP, [], session_uuid) destroy_vips(vips) else: start = 0 limit = thread_threshold - 1 curr_num = start vms = [] while curr_num < vip_num: vips_temp = res_ops.query_resource_fields(res_ops.VIP, \ [], session_uuid, ['uuid'], start, limit) vips.extend(vips_temp) curr_num += limit start += limit destroy_vips(vips) #con_ops.change_global_config('identity', 'session.timeout', session_to) #con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc) left_num = res_ops.query_resource_count(res_ops.VM_INSTANCE, cond, session_uuid) if left_num == 0: test_util.test_pass('None VR VMs destroy Success. Destroy %d VMs.' % num) else: test_util.test_fail('None VR VMs destroy Fail. %d VMs are not Destroied.' % left_num) left_num = res_ops.query_resource_count(res_ops.VIP, [], session_uuid) if left_num == 0: test_util.test_pass('VIP destroy Success. Destroy %d VIP.' % num) else: test_util.test_fail('VIP destroy Fail. %d VIP are not Destroied.' % left_num) 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)
def test(): global session_uuid global session_to global session_mc thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD') if not thread_threshold: thread_threshold = 1000 else: thread_threshold = int(thread_threshold) volume_num = os.environ.get('ZSTACK_TEST_NUM') if not volume_num: volume_num = 0 else: volume_num = int(volume_num) #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_num = res_ops.query_resource_count(res_ops.VM_INSTANCE, [], session_uuid) if vm_num < thread_threshold: test_util.test_fail( 'This test needs: %d VM instances for volume attaching and detaching operations. But there are only %d VMs instances. Please use this case: test_crt_basic_vm_with_max_threads.py to create required VMs.' % (thread_threshold, volume_num)) vms = res_ops.query_resource_with_num(res_ops.VM_INSTANCE, [], \ session_uuid, start = 0, limit = thread_threshold) test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold) test_util.test_logger('ZSTACK_TEST_NUM is %d' % volume_num) org_num = volume_num disk_offering_name = os.environ.get('smallDiskOfferingName') disk_offering_uuid = test_lib.lib_get_disk_offering_by_name( disk_offering_name).uuid volume_option = test_util.VolumeOption() volume_option.set_disk_offering_uuid(disk_offering_uuid) volume_option.set_session_uuid(session_uuid) random_name = random.random() volume_name = 'perf_volume_%s' % str(random_name) volume_option.set_name(volume_name) vm_num = 0 while volume_num > 0: check_thread_exception() volume = test_vol_header.ZstackTestVolume() volume.set_creation_option(volume_option) volume_num -= 1 if vm_num > (thread_threshold - 1): vm_num = 0 thread = threading.Thread(target=create_volume, args=( volume, vms[vm_num].uuid, )) vm_num += 1 while threading.active_count() > thread_threshold: time.sleep(0.) thread.start() while threading.active_count() > 1: time.sleep(0.01) cond = res_ops.gen_query_conditions('name', '=', volume_name) volumes_num = res_ops.query_resource_count(res_ops.VOLUME, 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 volumes_num == org_num: test_util.test_pass('Create %d Volumes Test Success' % org_num) else: test_util.test_fail( 'Create %d Volumes Test Failed. Only find %d Volumes.' % (org_num, volumes_num))
def test(): global session_uuid global session_to global session_mc thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD') if not thread_threshold: thread_threshold = 1000 else: thread_threshold = int(thread_threshold) vip_num = os.environ.get('ZSTACK_TEST_NUM') if not vip_num: vip_num = 0 else: vip_num = int(vip_num) #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() test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold) test_util.test_logger('ZSTACK_TEST_NUM is %d' % vip_num) org_num = vip_num vip_option = test_util.VipOption() l3_name = os.environ.get('l3PublicNetworkName') conditions = res_ops.gen_query_conditions('name', '=', l3_name) l3_uuid = res_ops.query_resource_with_num(res_ops.L3_NETWORK, conditions, \ session_uuid, start = 0, limit = 1)[0].uuid random_name = random.random() vip_name = 'perf_vip_%s' % str(random_name) vip_option.set_name(vip_name) vip_option.set_session_uuid(session_uuid) vip_option.set_l3_uuid(l3_uuid) vm_num = 0 while vip_num > 0: check_thread_exception() vip_num -= 1 vip_option.set_description(org_num - vip_num) if vm_num > (thread_threshold - 1): vm_num = 0 thread = threading.Thread(target=create_vip, args=(vip_option, )) vm_num += 1 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', '=', vip_name) vips_num = res_ops.query_resource_count(res_ops.VIP, 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 vips_num == org_num: test_util.test_pass('Create %d VIPs Test Success' % org_num) else: test_util.test_fail('Create %d VIPs Test Failed. Only find %d VIPs.' % (org_num, vips_num))
def test(): global session_uuid global session_to global session_mc thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD') if not thread_threshold: thread_threshold = 1000 else: thread_threshold = int(thread_threshold) eip_num = os.environ.get('ZSTACK_TEST_NUM') if not eip_num: eip_num = 0 else: eip_num = int(eip_num) #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() test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold) test_util.test_logger('ZSTACK_TEST_NUM is %d' % eip_num) org_num = eip_num vip_option = test_util.VipOption() l3_name = os.environ.get('l3PublicNetworkName') conditions = res_ops.gen_query_conditions('name', '=', l3_name) l3_uuid = res_ops.query_resource_with_num(res_ops.L3_NETWORK, conditions, \ session_uuid, start = 0, limit = 1)[0].uuid cond = res_ops.gen_query_conditions('l3NetworkUuid', '!=', l3_uuid) vm_nic_num = res_ops.query_resource_count(res_ops.VM_NIC, cond, \ session_uuid) if vm_nic_num < eip_num: test_util.test_fail('This test needs: %d vm nics for pf attaching and detaching operations. But there are only %d vm nics. Please use this case: test_crt_basic_vm_with_max_threads.py to create required VMs.' % (eip_num, vm_nic_num)) nics = [] start_num = 0 while eip_num > 0: vm_nics = res_ops.query_resource_fields(res_ops.VM_NIC, cond, \ session_uuid, ['uuid'], start_num, thread_threshold) for nic in vm_nics: nics.append(nic.uuid) eip_num -= thread_threshold start_num += thread_threshold eip_num = org_num random_name = random.random() vip_name = 'perf_vip_%s' % str(random_name) vip_option.set_name(vip_name) vip_option.set_session_uuid(session_uuid) vip_option.set_l3_uuid(l3_uuid) vic_num = 0 while eip_num > 0: check_thread_exception() eip_num -= 1 vip_option.set_description(org_num - eip_num) thread = threading.Thread(target=create_eip, args = (vip_option, nics[vic_num],)) vic_num += 1 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', '=', 'eip_%s' % vip_name) eips_num = res_ops.query_resource_count(res_ops.EIP, 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 eips_num == org_num: test_util.test_pass('Create %d EIPs Test Success' % org_num) else: test_util.test_fail('Create %d EIPs Test Failed. Only find %d EIPs.' % (org_num, eips_num))
def query_snapshot_number(snapshot_name): cond = res_ops.gen_query_conditions('name', '=', snapshot_name) return res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, cond)
def query_snapshot_number(volume_uuid): cond = res_ops.gen_query_conditions('volumeUuid', '=', volume_uuid) return res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, cond)
def test(): global session_uuid global session_to global session_mc global sp_name thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD') if not thread_threshold: thread_threshold = 1000 else: thread_threshold = int(thread_threshold) sp_num = os.environ.get('ZSTACK_TEST_NUM') if not sp_num: sp_num = 0 else: sp_num = int(sp_num) #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() cond = res_ops.gen_query_conditions('type', '=', 'Root') vol_num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid) if vol_num < thread_threshold: test_util.test_fail('This test needs: %d VM instances for volume attaching and detaching operations. But there are only %d VMs root volumes. Please use this case: test_crt_basic_vm_with_max_threads.py to create required VMs.' % (thread_threshold, vol_num)) vols = res_ops.query_resource_fields(res_ops.VOLUME, cond, session_uuid, \ ['uuid'], start = 0, limit = thread_threshold) test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold) test_util.test_logger('ZSTACK_TEST_NUM is %d' % sp_num) org_num = sp_num random_name = random.random() sp_name = 'perf_sp_%s' % str(random_name) vol_num = 0 while sp_num > 0: check_thread_exception() sp_num -= 1 if vol_num > (thread_threshold - 1): vol_num = 0 thread = threading.Thread(target=create_sp, \ args = (vols[vol_num].uuid, )) vol_num += 1 while threading.active_count() > thread_threshold: time.sleep(0.1) thread.start() while threading.active_count() > 1: time.sleep(0.1) cond = res_ops.gen_query_conditions('name', '=', sp_name) sp_num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, 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 sp_num == org_num: test_util.test_pass('Create %d Volumes Snapshot Perf Test Success' % org_num) else: test_util.test_fail('Create %d Volumes Snapshot Perf Test Failed. Only find %d Volume Snapshots.' % (org_num, sp_num))
def test(): global session_uuid global session_to global session_mc global sp_name thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD') if not thread_threshold: thread_threshold = 1000 else: thread_threshold = int(thread_threshold) sp_num = os.environ.get('ZSTACK_TEST_NUM') if not sp_num: sp_num = 0 else: sp_num = int(sp_num) #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() cond = res_ops.gen_query_conditions('type', '=', 'Root') vol_num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid) if vol_num < thread_threshold: test_util.test_fail( 'This test needs: %d VM instances for volume attaching and detaching operations. But there are only %d VMs root volumes. Please use this case: test_crt_basic_vm_with_max_threads.py to create required VMs.' % (thread_threshold, vol_num)) vols = res_ops.query_resource_fields(res_ops.VOLUME, cond, session_uuid, \ ['uuid'], start = 0, limit = thread_threshold) test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold) test_util.test_logger('ZSTACK_TEST_NUM is %d' % sp_num) org_num = sp_num random_name = random.random() sp_name = 'perf_sp_%s' % str(random_name) vol_num = 0 while sp_num > 0: check_thread_exception() sp_num -= 1 if vol_num > (thread_threshold - 1): vol_num = 0 thread = threading.Thread(target=create_sp, \ args = (vols[vol_num].uuid, )) vol_num += 1 while threading.active_count() > thread_threshold: time.sleep(0.1) thread.start() while threading.active_count() > 1: time.sleep(0.1) cond = res_ops.gen_query_conditions('name', '=', sp_name) sp_num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, 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 sp_num == org_num: test_util.test_pass('Create %d Volumes Snapshot Perf Test Success' % org_num) else: test_util.test_fail( 'Create %d Volumes Snapshot Perf Test Failed. Only find %d Volume Snapshots.' % (org_num, sp_num))
def test(): global session_uuid global session_to global session_mc thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD') if not thread_threshold: thread_threshold = 1000 else: thread_threshold = int(thread_threshold) sg_num = os.environ.get('ZSTACK_TEST_NUM') if not sg_num: sg_num = 0 else: sg_num = int(sg_num) create_1k_rule() #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() test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold) test_util.test_logger('ZSTACK_TEST_NUM is %d' % sg_num) org_num = sg_num sg_option = test_util.SecurityGroupOption() l3_name = os.environ.get('l3VlanNetworkName1') conditions = res_ops.gen_query_conditions('name', '=', l3_name) l3_uuid = res_ops.query_resource_with_num(res_ops.L3_NETWORK, conditions, \ session_uuid, start = 0, limit = 1)[0].uuid cond = res_ops.gen_query_conditions('l3NetworkUuid', '=', l3_uuid) vm_nic_num = res_ops.query_resource_count(res_ops.VM_NIC, cond, \ session_uuid) if vm_nic_num < thread_threshold: test_util.test_fail('This test needs: %d vm nics for pf attaching and detaching operations. But there are only %d vm nics. Please use this case: test_crt_basic_vm_with_max_threads.py to create required VMs.' % (thread_threshold, vm_nic_num)) vm_nics = res_ops.query_resource_fields(res_ops.VM_NIC, cond, \ session_uuid, ['uuid'], 0, thread_threshold) nics = [] for nic in vm_nics: nics.append(nic.uuid) random_name = random.random() sg_name = 'perf_sg_%s' % str(random_name) sg_option.set_name(sg_name) sg_option.set_session_uuid(session_uuid) vm_num = 0 while sg_num > 0: check_thread_exception() sg_num -= 1 sg_option.set_description(org_num - sg_num) if vm_num > (thread_threshold - 1): vm_num = 0 thread = threading.Thread(target=create_sg, args = (sg_option, l3_uuid, nics[vm_num], )) vm_num += 1 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', '=', sg_name) sgs_num = res_ops.query_resource_count(res_ops.SECURITY_GROUP, 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 sgs_num == org_num: test_util.test_pass('Create %d SGs Test Success' % org_num) else: test_util.test_fail('Create %d SGs Test Failed. Only find %d SGs.' % (org_num, sgs_num))
def test(): global session_uuid global session_to global session_mc vm_num = os.environ.get('ZSTACK_TEST_NUM') if not vm_num: vm_num = 0 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 cond = res_ops.gen_query_conditions('networkServiceType', '=', \ 'PortForwarding') service_providers = res_ops.query_resource_fields(res_ops.NETWORK_SERVICE_PROVIDER_L3_REF, cond, session_uuid, ['l3NetworkUuid'], start = 0, limit = 2) l3_name = os.environ.get('l3VlanNetworkName1') conditions = res_ops.gen_query_conditions('name', '=', l3_name) l3_uuids = [res_ops.query_resource_with_num(res_ops.L3_NETWORK, \ conditions, session_uuid, start = 0, limit = 1)[0].uuid] if len(service_providers) < 2: test_util.test_fail('Do not find at least 3 L3 service provider could support port forwarding service') else: for sp in service_providers: l3_uuids.append(sp.l3NetworkUuid) vm_creation_option.set_l3_uuids(l3_uuids) 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) session_uuid = acc_ops.login_as_admin() #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) 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.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: test_util.test_pass('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 session_uuid global session_to global session_mc vm_num = os.environ.get("ZSTACK_TEST_NUM") if not vm_num: vm_num = 0 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") disk_offering_name = os.environ.get("smallDiskOfferingName") disk_offering_uuid = test_lib.lib_get_disk_offering_by_name(disk_offering_name).uuid 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) vm_creation_option.set_data_disk_uuids([disk_offering_uuid]) session_uuid = acc_ops.login_as_admin() # 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) 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: vm_creation_option.set_l3_uuids([random.choice(l3s).uuid]) vm.set_creation_option(vm_creation_option) vm_num -= 1 thread = threading.Thread(target=vm.create) 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: test_util.test_pass("Create %d VMs Test Success" % org_num) else: test_util.test_fail("Create %d VMs Test Failed. Only find %d VMs." % (org_num, vms))