def test(): #If test execution machine is not the same one as Host machine, deploy work is needed to separated to 2 steps(deploy_test_agent, execute_plan_without_deploy_test_agent). And it can not directly call SetupAction.run() mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['serverIp2'] os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_lib.setup_plan.deploy_test_agent() test_lib.setup_plan.execute_plan_without_deploy_test_agent() deploy_operations.deploy_initial_database(test_lib.deploy_config) if os.path.exists(EXTRA_SUITE_SETUP_SCRIPT): os.system("bash %s" % EXTRA_SUITE_SETUP_SCRIPT) if test_lib.lib_get_ha_selffencer_maxattempts() != None: test_lib.lib_set_ha_selffencer_maxattempts('60') test_lib.lib_set_ha_selffencer_storagechecker_timeout('60') test_lib.lib_set_primary_storage_imagecache_gc_interval(1) test_lib.lib_set_provision_storage_rate(6) test_lib.lib_set_provision_memory_rate(3) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_lib.setup_plan.deploy_test_agent() #test_lib.setup_plan.execute_plan_without_deploy_test_agent() #deploy_operations.deploy_initial_database(test_lib.deploy_config) if os.path.exists(EXTRA_SUITE_SETUP_SCRIPT): os.system("bash %s" % EXTRA_SUITE_SETUP_SCRIPT) if test_lib.lib_get_ha_selffencer_maxattempts() != None: test_lib.lib_set_ha_selffencer_maxattempts('60') test_lib.lib_set_ha_selffencer_storagechecker_timeout('60') test_lib.lib_set_primary_storage_imagecache_gc_interval(1) test_lib.lib_set_provision_storage_rate(6) test_lib.lib_set_provision_memory_rate(3) test_util.test_pass('Suite Setup Success')
def test(): os.environ['ZSTACK_THREAD_THRESHOLD'] = '1000' os.environ['ZSTACK_TEST_NUM'] = '1000' test_lib.lib_set_provision_memory_rate(20) test_lib.lib_set_provision_storage_rate(20) lib_set_provision_cpu_rate(20) Create() time.sleep(180) create_vm_begin_time = get_begin_time() create_vm_end_time = get_end_time() print("begin time = %s") % create_vm_begin_time print("end time = %s") % create_vm_end_time if create_vm_end_time != 0 and create_vm_begin_time != 0: create_1000_vm_time = create_vm_end_time - create_vm_begin_time test_util.test_dsc("create_vm_time is " + str(create_1000_vm_time)) Destroy_VM() time.sleep(180) Expunge_VM() time.sleep(180) zone_name = os.environ.get('zoneName') zone = res_ops.get_resource(res_ops.ZONE, name=zone_name)[0] zone_ops.delete_zone(zone.uuid) test_util.test_pass('Create 1000 vms success,takes %s time' % create_1000_vm_time)
def test(): os.environ['ZSTACK_THREAD_THRESHOLD']='1000' os.environ['ZSTACK_TEST_NUM']='1000' test_lib.lib_set_provision_memory_rate(20) test_lib.lib_set_provision_storage_rate(20) lib_set_provision_cpu_rate(20) Create() time.sleep(180) create_vm_begin_time = get_begin_time() create_vm_end_time = get_end_time() print ("begin time = %s") % create_vm_begin_time print ("end time = %s") % create_vm_end_time if create_vm_end_time != 0 and create_vm_begin_time != 0: create_1000_vm_time = create_vm_end_time - create_vm_begin_time test_util.test_dsc("create_vm_time is "+str(create_1000_vm_time)) Destroy_VM() time.sleep(180) Expunge_VM() time.sleep(180) zone_name = os.environ.get('zoneName') zone = res_ops.get_resource(res_ops.ZONE, name = zone_name)[0] zone_ops.delete_zone(zone.uuid) test_util.test_pass('Create 1000 vms success,takes %s time' % create_1000_vm_time)
def test(): global original_rate test_util.test_dsc('Change Test memory over provision method') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit=1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.') return True host = host[0] over_provision_rate1 = 2 over_provision_rate2 = 1.5 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid]) avail_mem = host_res.availableMemory if avail_mem <= 1024 * 1024 * 1024: test_util.test_skip('Available memory is less than 512MB, skip test.') return True original_rate = test_lib.lib_set_provision_memory_rate( over_provision_rate1) vm = test_stub.create_vm(vm_name='mem_over_prs_vm_1') test_obj_dict.add_vm(vm) test_lib.lib_set_provision_memory_rate(over_provision_rate2) vm.destroy() vm = test_stub.create_vm(vm_name='mem_over_prs_vm_2') test_obj_dict.add_vm(vm) test_lib.lib_set_provision_memory_rate(original_rate) vm.destroy() host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 != avail_mem: test_util.test_fail( 'Available memory: %d is different with original available memory: %d' % (avail_mem2, avail_mem)) else: test_util.test_logger( 'Available memory: %d is same with original available memory.' % avail_mem2) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Change Memory Over Provision Test Pass')
def test(): os.environ['ZSTACK_THREAD_THRESHOLD']='1000' os.environ['ZSTACK_TEST_NUM']='1000' test_lib.lib_set_provision_memory_rate(20) test_lib.lib_set_provision_storage_rate(20) lib_set_provision_cpu_rate(20) while True: Create() time.sleep(180) Stop_VM() time.sleep(180) Start_VM() time.sleep(180) Reboot_VM() time.sleep(360) Ha_NeverStop_VM() time.sleep(30) Stop_VM_Simple_Scheduler() time.sleep(180) Cancel_Ha_VM() time.sleep(30) Stop_VM_Simple_Scheduler() time.sleep(180) Start_VM_Simple_Scheduler() time.sleep(180) Reboot_VM_Simple_Scheduler() time.sleep(180) Snapshot_VM_Simple_Scheduler() time.sleep(30) Force_Stop_VM() time.sleep(180) Destroy_VM() time.sleep(180) Recover_VM() time.sleep(180) Start_VM() time.sleep(180) Destroy_VM() time.sleep(180) Expunge_VM() time.sleep(180) while True: time.sleep(3600)
def test(): global original_rate test_util.test_dsc('Change Test memory over provision method') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.' ) return True host = host[0] over_provision_rate1 = 2 over_provision_rate2 = 1.5 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem = host_res.availableMemory if avail_mem <= 1024*1024*1024: test_util.test_skip('Available memory is less than 512MB, skip test.') return True original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate1) vm = test_stub.create_vm(vm_name = 'mem_over_prs_vm_1') test_obj_dict.add_vm(vm) test_lib.lib_set_provision_memory_rate(over_provision_rate2) vm.destroy() vm = test_stub.create_vm(vm_name = 'mem_over_prs_vm_2') test_obj_dict.add_vm(vm) test_lib.lib_set_provision_memory_rate(original_rate) vm.destroy() host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 != avail_mem: test_util.test_fail('Available memory: %d is different with original available memory: %d' % (avail_mem2, avail_mem)) else: test_util.test_logger('Available memory: %d is same with original available memory.' % avail_mem2) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Change Memory Over Provision Test Pass')
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) if original_rate: test_lib.lib_set_provision_memory_rate(original_rate) if new_offering_uuid: vm_ops.delete_instance_offering(new_offering_uuid)
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) if original_rate: test_lib.lib_set_provision_memory_rate(original_rate)
def test(): global original_rate global new_offering_uuid test_util.test_dsc('Test memory allocation and reclaiming.') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.' ) return True host = host[0] over_provision_rate = 1 target_vm_num = 5 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) #avail_mem = host_res.availableMemory * over_provision_rate avail_mem = host_res.availableMemory if avail_mem <= 1024*1024*1024: test_util.test_skip('Available memory is less than 1024MB, skip test.') return True original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate) host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem = host_res.availableMemory test_mem = avail_mem / target_vm_num new_offering_mem = test_mem new_offering = test_lib.lib_create_instance_offering(memorySize = new_offering_mem) new_offering_uuid = new_offering.uuid rounds = 0 while (rounds < 3): times = 1 while (times <= (target_vm_num+3)): try: vm = test_stub.create_vm(vm_name = 'mem_reclaim_vm_%d' % times, \ host_uuid = host.uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) except Exception as e: test_util.test_logger("VM Creation Failure in memory reclaiming test. :%s " % e) pass times += 1 for vm in test_obj_dict.get_all_vm_list(): try: vm.destroy() test_obj_dict.rm_vm(vm) except Exception as e: test_util.test_logger("VM Destroying Failure in memory reclaiming test. :%s " % e) pass host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 != avail_mem: test_util.test_fail('Available memory reclaiming is not correct. Current available memory : %d, original available memory: %d , after creating and destroying %d vms. in round: %d' % (avail_mem2, avail_mem, target_vm_num, rounds)) rounds += 1 test_lib.lib_set_provision_memory_rate(original_rate) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Memory Over Provision Test Pass')
def test(): total_create_vms_time = 0 total_destroy_vms_time = 0 total_expunge_vms_time = 0 create_vms_time = [] destroy_vms_time = [] expunge_vms_time = [] test_lib.lib_set_provision_memory_rate(20) test_lib.lib_set_provision_storage_rate(20) lib_set_provision_cpu_rate(20) for i in range(0, perf_loop): test_util.test_dsc("start the %d interation" % i) vm_name_prefix = 'multi_vms_%s' % str(get_random_name(4)) Create(vm_name_prefix) time.sleep(time_interval) create_vm_begin_time = get_begin_time(vm_name_prefix, 'create') create_vm_end_time = get_end_time(vm_name_prefix, 'create') print ("vm creation begin time = %s") % create_vm_begin_time print ("vm creation end time = %s") % create_vm_end_time if create_vm_end_time != 0 and create_vm_begin_time != 0: create_vms_time.append(create_vm_end_time - create_vm_begin_time) test_util.test_dsc("create_vm_time is "+str(create_vms_time[i])) Destroy_VM() time.sleep(180) destroy_vm_begin_time = get_begin_time(vm_name_prefix, 'destroy') destroy_vm_end_time = get_end_time(vm_name_prefix, 'destroy') print ("vm destroy begin time = %s") % destroy_vm_begin_time print ("vm destroy end time = %s") % destroy_vm_end_time if destroy_vm_end_time != 0 and destroy_vm_begin_time != 0: destroy_vms_time.append(destroy_vm_end_time - destroy_vm_begin_time) test_util.test_dsc("destroy_vm_time is "+str(destroy_vms_time[i])) Expunge_VM() time.sleep(180) expunge_vm_begin_time = get_begin_time(vm_name_prefix, 'expunge') expunge_vm_end_time = get_end_time(vm_name_prefix, 'expunge') print ("vm expunge begin time = %s") % expunge_vm_begin_time print ("vm expunge end time = %s") % expunge_vm_end_time if expunge_vm_end_time != 0 and expunge_vm_begin_time != 0: expunge_vms_time.append(expunge_vm_end_time - expunge_vm_begin_time) test_util.test_dsc("expunge_vm_time is "+str(expunge_vms_time[i])) print ("totally %d iterations executed") % perf_loop print "\t\tCre\tDes\tExp" for i in range(0, perf_loop): print "Iteration%d\t%d\t%d\t%d" % (i, create_vms_time[i], destroy_vms_time[i], expunge_vms_time[i]) total_create_vms_time = total_create_vms_time + create_vms_time[i] total_destroy_vms_time = total_destroy_vms_time + destroy_vms_time[i] total_expunge_vms_time = total_expunge_vms_time + expunge_vms_time[i] print "Average\t\t%d\t%d\t%d" % (int(total_create_vms_time/perf_loop), int(total_destroy_vms_time/perf_loop), int(total_expunge_vms_time/perf_loop))
def test(): global original_rate global new_offering_uuid test_util.test_dsc('Test memory over provision method') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit=1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.') return True host = host[0] over_provision_rate = 2 target_vm_num = 4 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid]) real_availableMemory = host_res.availableMemory - \ sizeunit.get_size(test_lib.lib_get_reserved_memory()) avail_mem = real_availableMemory * over_provision_rate if avail_mem <= 1024 * 1024 * 1024: test_util.test_skip('Available memory is less than 512MB, skip test.') return True test_util.test_logger('host available memory is: %s' % host_res.availableMemory) original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate) new_offering_mem = avail_mem / target_vm_num new_offering = test_lib.lib_create_instance_offering( memorySize=new_offering_mem) new_offering_uuid = new_offering.uuid times = 1 while (times <= target_vm_num): try: vm_name = 'mem_over_prs_vm_%d' % times vm = test_stub.create_vm(vm_name = vm_name, \ host_uuid = host.uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) host_res_new = test_lib.lib_get_cpu_memory_capacity( host_uuids=[host.uuid]) test_util.test_logger( 'After create vm: %s, host available memory is: %s' % (vm_name, host_res_new.availableMemory)) except Exception as e: test_util.test_logger( "Unexpected VM Creation Failure in memory over provision test. Previous available memory is %s" % host_res_new.availableMemory) raise e times += 1 host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 > new_offering_mem: test_util.test_fail( 'Available memory: %d is still bigger than offering memory: %d , after creating 4 vms.' % (avail_mem2, new_offering_mem)) try: vm = test_stub.create_vm(vm_name = 'mem_over_prs_vm_bad', \ host_uuid = host.uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) except: test_util.test_logger( "Expected VM Creation Failure in memory over provision test. ") else: test_util.test_fail("The 5th VM is still created up, which is wrong") test_lib.lib_set_provision_memory_rate(original_rate) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Memory Over Provision Test Pass')
def test(): global original_rate global new_offering_uuid test_util.test_dsc('Test memory over provision method') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.' ) return True host = host[0] over_provision_rate = 2 target_vm_num = 4 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) real_availableMemory = host_res.availableMemory avail_mem = real_availableMemory * over_provision_rate if avail_mem <= 1024*1024*1024: test_util.test_skip('Available memory is less than 512MB, skip test.') return True test_util.test_logger('host available memory is: %s' % host_res.availableMemory) original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate) new_offering_mem = int((avail_mem - 1) / target_vm_num) if (new_offering_mem % 2) != 0 : new_offering_mem = new_offering_mem - 1 new_offering = test_lib.lib_create_instance_offering(memorySize = new_offering_mem) new_offering_uuid = new_offering.uuid times = 1 while (times <= target_vm_num): try: vm_name = 'mem_over_prs_vm_%d' % times vm = test_stub.create_vm(vm_name = vm_name, \ host_uuid = host.uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) host_res_new = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) test_util.test_logger('After create vm: %s, host available memory is: %s' % (vm_name, host_res_new.availableMemory)) except Exception as e: test_util.test_logger("Unexpected VM Creation Failure in memory over provision test. Previous available memory is %s" % host_res_new.availableMemory) raise e times += 1 host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 > new_offering_mem: test_util.test_fail('Available memory: %d is still bigger than offering memory: %d , after creating 4 vms.' % (avail_mem2, new_offering_mem)) try: vm = test_stub.create_vm(vm_name = 'mem_over_prs_vm_bad', \ host_uuid = host.uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) except: test_util.test_logger("Expected VM Creation Failure in memory over provision test. ") else: test_util.test_fail("The 5th VM is still created up, which is wrong") test_lib.lib_set_provision_memory_rate(original_rate) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Memory Over Provision Test Pass')
def test(): global original_rate global new_offering_uuid test_util.test_dsc('Test memory allocation and reclaiming.') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.' ) return True host = host[0] over_provision_rate = 1 target_vm_num = 5 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) #avail_mem = host_res.availableMemory * over_provision_rate avail_mem = host_res.availableMemory if avail_mem <= 1024*1024*1024: test_util.test_skip('Available memory is less than 1024MB, skip test.') return True original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate) host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem = host_res.availableMemory test_mem = avail_mem / target_vm_num new_offering_mem = test_mem new_offering = test_lib.lib_create_instance_offering(memorySize = new_offering_mem) new_offering_uuid = new_offering.uuid rounds = 0 while (rounds < 3): times = 1 while (times <= (target_vm_num)): thread = threading.Thread(target = parallelly_create_vm, \ args = ('parallel_vm_creating_%d' % times, \ host.uuid, \ new_offering.uuid, )) thread.start() times += 1 times = 1 print 'Running VM: %s ' % len(test_obj_dict.get_vm_list()) while threading.active_count() > 1: check_thread_exception() time.sleep(1) if times > 30: test_util.test_fail('creating vm time exceed 30s') times += 1 check_thread_exception() for vm in test_obj_dict.get_all_vm_list(): try: vm.destroy() test_obj_dict.rm_vm(vm) except Exception as e: test_util.test_logger("VM Destroying Failure in memory reclaiming test. :%s " % e) raise e host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 != avail_mem: test_util.test_fail('Available memory reclaiming is not correct. Current available memory : %d, original available memory: %d , after creating and destroying %d vms. in round: %d' % (avail_mem2, avail_mem, target_vm_num, rounds)) rounds += 1 test_lib.lib_set_provision_memory_rate(original_rate) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Parallel vm creation Test Pass')
def test(): global original_rate global new_offering_uuid test_util.test_dsc('Test memory allocation and reclaiming.') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit = 1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.' ) return True host = host[0] over_provision_rate = 1 target_vm_num = 5 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) #avail_mem = host_res.availableMemory * over_provision_rate avail_mem = host_res.availableMemory if avail_mem <= 1024*1024*1024: test_util.test_skip('Available memory is less than 1024MB, skip test.') return True original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate) host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem = host_res.availableMemory test_mem = avail_mem / target_vm_num new_offering_mem = test_mem new_offering = test_lib.lib_create_instance_offering(memorySize = new_offering_mem) new_offering_uuid = new_offering.uuid rounds = 0 while (rounds < 3): times = 1 while (times <= (target_vm_num)): thread = threading.Thread(target = parallelly_create_vm, \ args = ('parallel_vm_creating_%d' % times, \ host.uuid, \ new_offering.uuid, )) thread.start() times += 1 times = 1 print 'Running VM: %s ' % len(test_obj_dict.get_vm_list()) while threading.active_count() > 1: check_thread_exception() time.sleep(1) if times > 5: test_util.test_fail('creating vm time exceed 5s') times += 1 check_thread_exception() for vm in test_obj_dict.get_all_vm_list(): try: vm.destroy() test_obj_dict.rm_vm(vm) except Exception as e: test_util.test_logger("VM Destroying Failure in memory reclaiming test. :%s " % e) raise e host_res2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 != avail_mem: test_util.test_fail('Available memory reclaiming is not correct. Current available memory : %d, original available memory: %d , after creating and destroying %d vms. in round: %d' % (avail_mem2, avail_mem, target_vm_num, rounds)) rounds += 1 test_lib.lib_set_provision_memory_rate(original_rate) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Parallel vm creation Test Pass')
def test(): global original_rate global new_offering_uuid test_util.test_dsc('Test memory allocation and reclaiming.') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) host = res_ops.query_resource_with_num(res_ops.HOST, cond, limit=1) if not host: test_util.test_skip('No Enabled/Connected host was found, skip test.') return True host = host[0] over_provision_rate = 1 target_vm_num = 5 host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid]) #avail_mem = host_res.availableMemory * over_provision_rate avail_mem = host_res.availableMemory if avail_mem <= 1024 * 1024 * 1024: test_util.test_skip('Available memory is less than 1024MB, skip test.') return True original_rate = test_lib.lib_set_provision_memory_rate(over_provision_rate) host_res = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid]) avail_mem = host_res.availableMemory test_mem = avail_mem / target_vm_num new_offering_mem = test_mem new_offering = test_lib.lib_create_instance_offering( memorySize=new_offering_mem) new_offering_uuid = new_offering.uuid rounds = 0 while (rounds < 3): times = 1 while (times <= (target_vm_num + 3)): try: vm = test_stub.create_vm(vm_name = 'mem_reclaim_vm_%d' % times, \ host_uuid = host.uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) except Exception as e: test_util.test_logger( "VM Creation Failure in memory reclaiming test. :%s " % e) pass times += 1 for vm in test_obj_dict.get_all_vm_list(): try: vm.destroy() test_obj_dict.rm_vm(vm) except Exception as e: test_util.test_logger( "VM Destroying Failure in memory reclaiming test. :%s " % e) pass host_res2 = test_lib.lib_get_cpu_memory_capacity( host_uuids=[host.uuid]) avail_mem2 = host_res2.availableMemory if avail_mem2 != avail_mem: test_util.test_fail( 'Available memory reclaiming is not correct. Current available memory : %d, original available memory: %d , after creating and destroying %d vms. in round: %d' % (avail_mem2, avail_mem, target_vm_num, rounds)) rounds += 1 test_lib.lib_set_provision_memory_rate(original_rate) vm_ops.delete_instance_offering(new_offering_uuid) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Memory Over Provision Test Pass')