def test(): global test_obj_dict cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('type', '=', 'LocalStorage', cond) cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond) if len(ps) < 2: test_util.test_skip("Requres at least two local ps") ps1_res = vol_ops.get_local_storage_capacity(None, ps[0].uuid)[0] ps2_res = vol_ops.get_local_storage_capacity(None, ps[1].uuid)[0] if ps1_res.availableCapacity > ps2_res.availableCapacity: data_volume_size = ps2_res.availableCapacity + ( ps1_res.availableCapacity - ps2_res.availableCapacity) / 2 else: data_volume_size = ps1_res.availableCapacity + ( ps2_res.availableCapacity - ps1_res.availableCapacity) / 2 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('2-local-ps-test') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) vm = test_stub.create_vlan_vm( disk_offering_uuids=[data_volume_offering.uuid]) test_obj_dict.add_vm(vm) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('2 Local PS Test Pass') return False
def test(): test_util.test_dsc('Test storage capacity when using expunge vm') if conf_ops.get_global_config_value('vm', 'deletionPolicy') != 'Delay' : test_util.test_skip('vm delete_policy is not Delay, skip test.') return zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid 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 ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1) if not ps: test_util.test_skip('No Enabled/Connected primary storage was found, skip test.' ) return True host = host[0] ps = ps[0] host_res = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap = host_res.availableCapacity vm = test_stub.create_vm(vm_name = 'basic-test-vm', host_uuid = host.uuid) test_obj_dict.add_vm(vm) time.sleep(1) vm.destroy() vm.expunge() host_res2 = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap2 = host_res.availableCapacity if avail_cap != avail_cap2: test_util.test_fail('PS capacity is not same after create/expunge vm on host: %s. Capacity before create vm: %s, after expunge vm: %s ' % (host.uuid, avail_cap, avail_cap2)) test_util.test_pass('Expunge VM Test Success')
def test(): global test_obj_dict cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('type', '=', 'LocalStorage') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond) if len(ps) < 2: test_util.test_skip("Requres at least two local ps") ps1_res = vol_ops.get_local_storage_capacity(None, ps[0].uuid)[0] ps2_res = vol_ops.get_local_storage_capacity(None, ps[1].uuid)[0] if ps1_res.availableCapacity > ps2_res.availableCapacity: data_volume_size = ps2_res.availableCapacity + (ps1_res.availableCapacity - ps2_res.availableCapacity) / 2 else: data_volume_size = ps1_res.availableCapacity + (ps2_res.availableCapacity - ps1_res.availableCapacity) / 2 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('2-local-ps-test') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) vm = test_stub.create_vlan_vm(disk_offering_uuids=[data_volume_offering.uuid]) test_obj_dict.add_vm(vm) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('2 Local PS Test Pass') return False
def test(): global delete_policy1 global delete_policy2 delete_policy1 = test_lib.lib_set_delete_policy('vm', 'Delay') delete_policy2 = test_lib.lib_set_delete_policy('volume', 'Delay') test_util.test_dsc('Test storage capacity when using expunge vm') zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid 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 ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1) if not ps: test_util.test_skip('No Enabled/Connected primary storage was found, skip test.' ) return True host = host[0] ps = ps[0] host_res = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap = host_res.availableCapacity vm = test_stub.create_vm(vm_name = 'basic-test-vm', host_uuid = host.uuid) test_obj_dict.add_vm(vm) data_volume_size = 1024 * 1024 * 10 disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('test-expunge-data-volume') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(data_volume_offering.uuid) volume_creation_option.set_name('volume-1') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.attach(vm) time.sleep(1) vm.destroy() vm.expunge() test_obj_dict.rm_vm(vm) volume.delete() volume.expunge() test_obj_dict.rm_volume(volume) host_res2 = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap2 = host_res.availableCapacity if avail_cap != avail_cap2: test_util.test_fail('PS capacity is not same after create/expunge vm/volume on host: %s. Capacity before create vm: %s, after expunge vm: %s ' % (host.uuid, avail_cap, avail_cap2)) test_lib.lib_set_delete_policy('vm', delete_policy1) test_lib.lib_set_delete_policy('volume', delete_policy2) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Expunge VM Test Success')
def test(): global delete_policy delete_policy = test_lib.lib_set_delete_policy('vm', 'Delay') test_util.test_dsc('Test storage capacity when using expunge vm') zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid 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 ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1) if not ps: test_util.test_skip( 'No Enabled/Connected primary storage was found, skip test.') return True host = host[0] ps = ps[0] host_res = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap = host_res.availableCapacity vm = test_stub.create_vm(vm_name='basic-test-vm', host_uuid=host.uuid) test_obj_dict.add_vm(vm) host_res1 = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap1 = host_res1.availableCapacity if avail_cap == avail_cap1: test_util.test_fail( 'PS capacity is same after create vm on host: %s. Capacity before create vm: %s, after create vm: %s ' % (host.uuid, avail_cap, avail_cap1)) time.sleep(1) vm.destroy() vm.expunge() host_res2 = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap2 = host_res2.availableCapacity if avail_cap != avail_cap2: test_util.test_fail( 'PS capacity is not same after create/expunge vm on host: %s. Capacity before create vm: %s, after expunge vm: %s ' % (host.uuid, avail_cap, avail_cap2)) test_lib.lib_set_delete_policy('vm', delete_policy) test_util.test_pass('Expunge VM Test Success')
def test(): global host flavor = case_flavor[os.environ.get('CASE_FLAVOR')] 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.' ) cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) if flavor['local']: cond = res_ops.gen_query_conditions('type', '=', 'LocalStorage', cond) elif flavor['smp']: cond = res_ops.gen_query_conditions('type', '=', 'SharedMountPoint', cond) elif flavor['nfs']: cond = res_ops.gen_query_conditions('type', '=', 'NFS', cond) elif flavor['ceph']: cond = res_ops.gen_query_conditions('type', '=', 'Ceph', cond) ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1) if not ps: test_util.test_skip('No Enabled/Connected local ps was found, skip test.' ) host_ops.reconnect_host(host[0].uuid) if flavor['local']: saved_res = vol_ops.get_local_storage_capacity(host[0].uuid, ps[0].uuid)[0] elif flavor['smp']: saved_res = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1)[0] elif flavor['nfs']: saved_res = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1)[0] test_stub.setup_fake_df(host[0], '62403200', '22403200') host_ops.reconnect_host(host[0].uuid) if flavor['local']: res = vol_ops.get_local_storage_capacity(host[0].uuid, ps[0].uuid)[0] elif flavor['smp']: res = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1)[0] elif flavor['nfs']: res = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1)[0] if res.totalCapacity != 62403200*1024: test_util.test_fail('totalCapacity %s not updated after reconnect host' % (res.totalCapacity)) if res.totalPhysicalCapacity != 62403200*1024: test_util.test_fail('totalPhysicalCapacity %s not updated after reconnect host' % (res.totalPhysicalCapacity)) if res.availablePhysicalCapacity != 22403200*1024: test_util.test_fail('availablePhysicalCapacity %s not updated after reconnect host' % (res.availablePhysicalCapacity)) if flavor['local']: if res.totalCapacity - saved_res.totalCapacity != res.availableCapacity - saved_res.availableCapacity: test_util.test_fail('availableCapacity %s not updated correctly' % (res.availableCapacity)) test_stub.remove_fake_df(host[0]) host_ops.reconnect_host(host[0].uuid) if flavor['local']: res = vol_ops.get_local_storage_capacity(host[0].uuid, ps[0].uuid)[0] elif flavor['smp']: res = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1)[0] elif flavor['nfs']: res = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1)[0] if res.totalCapacity != saved_res.totalCapacity: test_util.test_fail('totalCapacity %s not updated after reconnect host' % (res.totalCapacity)) if res.totalPhysicalCapacity != saved_res.totalPhysicalCapacity: test_util.test_fail('totalPhysicalCapacity %s not updated after reconnect host' % (res.totalPhysicalCapacity)) if flavor['local']: if res.availablePhysicalCapacity == saved_res.availablePhysicalCapacity: test_util.test_fail('availablePhysicalCapacity %s %s not updated after reconnect host' % (res.availablePhysicalCapacity, saved_res.availablePhysicalCapacity)) if res.availableCapacity != saved_res.availableCapacity: test_util.test_fail('availableCapacity %s not updated after reconnect host' % (res.availableCapacity)) test_util.test_pass('Test backup storage capacity for adding/deleting image pass.')
def test(): global original_rate test_util.test_dsc('Test storage over provision method') zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid 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 ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1) if not ps: test_util.test_skip('No Enabled/Connected primary storage was found, skip test.' ) return True host = host[0] ps = ps[0] over_provision_rate = 2.5 target_volume_num = 12 kept_disk_size = 10 * 1024 * 1024 vm = test_stub.create_vm(vm_name = 'storage_over_prs_vm_1', \ host_uuid = host.uuid) test_obj_dict.add_vm(vm) host_res = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap = host_res.availableCapacity if avail_cap < kept_disk_size: test_util.test_skip('available disk capacity:%d is too small, skip test.' % avail_cap) return True original_rate = test_lib.lib_set_provision_storage_rate(over_provision_rate) data_volume_size = int(over_provision_rate * (avail_cap - kept_disk_size) / target_volume_num) #will change the rate back to check if available capacity is same with original one. This was a bug, that only happened when system create 1 vm. test_lib.lib_set_provision_storage_rate(original_rate) host_res_tmp = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap_tmp = host_res_tmp.availableCapacity if avail_cap != avail_cap_tmp: test_util.test_fail('disk size is not same, between 2 times provision. Before change over rate, 1st cap: %d; 2nd cap: %d' % (avail_cap, avail_cap_tmp)) test_lib.lib_set_provision_storage_rate(over_provision_rate) test_util.test_logger('Will create a serial of volume. Each of them will have %d size.' % data_volume_size) disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('storage-over-ps-test') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(data_volume_offering.uuid) times = 1 while (times <= target_volume_num): try: volume_creation_option.set_name('volume-%d' % times) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) res = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] test_util.test_logger('Current available storage size: %d' % res.availableCapacity) volume.attach(vm) except Exception as e: test_util.test_logger("Unexpected volume Creation Failure in storage over provision test. ") raise e times += 1 host_res2 = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap2 = host_res2.availableCapacity if avail_cap2 > data_volume_size: test_util.test_fail('Available disk size: %d is still bigger than offering disk size: %d , after creating %d volumes.' % (avail_cap2, data_volume_size, target_volume_num)) try: volume_creation_option.set_name('volume-%d' % (times + 1)) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.attach(vm) except: test_util.test_logger("Expected Volume Creation Failure in storage over provision test. ") else: test_util.test_fail("The %dth Volume is still attachable, which is wrong"% (target_volume_num + 1)) test_lib.lib_set_provision_storage_rate(original_rate) 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 global delete_policy 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) hosts = res_ops.query_resource_with_num(res_ops.HOST, cond) if not hosts: test_util.test_skip('No Enabled/Connected host was found, skip test.' ) return True ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1) if not ps: test_util.test_skip('No Enabled/Connected primary storage was found, skip test.' ) return True host = random.choice(hosts) ps = ps[0] over_provision_rate = 1 target_vm_num = 5 host_res = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap = host_res.availableCapacity image_name = os.environ.get('imageName_net') image = test_lib.lib_get_image_by_name(image_name) image_size = image.size original_rate = test_lib.lib_set_provision_storage_rate(over_provision_rate) data_volume_size = int(over_provision_rate * (avail_cap - image_size * target_vm_num) / target_vm_num) if data_volume_size < 0: test_util.test_skip('Do not have enough disk space to do test') return True delete_policy = test_lib.lib_set_delete_policy('vm', 'Direct') delete_policy = test_lib.lib_set_delete_policy('volume', 'Direct') host_res = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap = host_res.availableCapacity disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('vm-parallel-creation-test') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) rounds = 1 while (rounds <= 3): times = 1 test_util.test_logger('test round: %s' % rounds) while (times <= (target_vm_num)): thread = threading.Thread(target = parallelly_create_vm, \ args = ('parallel_vm_creating_%d' % times, \ image_name, \ host.uuid, \ data_volume_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 > 10: test_util.test_fail('creating vm time exceed 10s') times += 1 check_thread_exception() try: vm = test_stub.create_vm(vm_name = 'unexpected vm', \ image_name = image_name, \ host_uuid = host.uuid) test_obj_dict.add_vm(vm) except: test_util.test_logger('expect vm creation failure') else: test_util.test_fail('The extra vm is unexpected to be created up') for vm in test_obj_dict.get_all_vm_list(): try: test_lib.lib_destroy_vm_and_data_volumes_objs_update_test_dict(vm, test_obj_dict) except Exception as e: test_util.test_logger("VM Destroying Failure in vm parallel creation test. :%s " % e) raise e rounds += 1 test_lib.lib_set_provision_storage_rate(original_rate) test_lib.lib_robot_cleanup(test_obj_dict) test_lib.lib_set_delete_policy('vm', delete_policy) test_lib.lib_set_delete_policy('volume', delete_policy) test_util.test_pass('Parallel vm creation Test Pass')
def get_storage_capacity(ps_type, host_uuid, ps_uuid): if ps_type == 'LocalStorage': host_res = vol_ops.get_local_storage_capacity(host_uuid, ps_uuid)[0] else: host_res = test_lib.lib_get_storage_capacity(ps_uuids=[ps_uuid]) return host_res.availableCapacity
def test(): global original_rate global new_offering_uuid global delete_policy 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) hosts = res_ops.query_resource_with_num(res_ops.HOST, cond) if not hosts: test_util.test_skip('No Enabled/Connected host was found, skip test.' ) return True ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1) if not ps: test_util.test_skip('No Enabled/Connected primary storage was found, skip test.' ) return True if ps[0].type == inventory.CEPH_PRIMARY_STORAGE_TYPE or ps[0].type == 'SharedMountPoint': test_util.test_skip('skip test on ceph and smp.' ) return True host = random.choice(hosts) ps = ps[0] over_provision_rate = 1 target_vm_num = 5 host_res = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap = host_res.availableCapacity image_name = os.environ.get('imageName_net') image = test_lib.lib_get_image_by_name(image_name) image_size = image.size original_rate = test_lib.lib_set_provision_storage_rate(over_provision_rate) data_volume_size = int(avail_cap / target_vm_num * over_provision_rate - image_size) if data_volume_size < 0: test_util.test_skip('Do not have enough disk space to do test') return True delete_policy = test_lib.lib_set_delete_policy('vm', 'Direct') delete_policy = test_lib.lib_set_delete_policy('volume', 'Direct') host_res = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap = host_res.availableCapacity disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('vm-parallel-creation-test') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) rounds = 1 while (rounds <= 3): times = 1 test_util.test_logger('test round: %s' % rounds) while (times <= (target_vm_num)): thread = threading.Thread(target = parallelly_create_vm, \ args = ('parallel_vm_creating_%d' % times, \ image_name, \ host.uuid, \ data_volume_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() try: vm = test_stub.create_vm(vm_name = 'unexpected vm', \ image_name = image_name, \ host_uuid = host.uuid) test_obj_dict.add_vm(vm) except: test_util.test_logger('expect vm creation failure') else: test_util.test_fail('The extra vm is unexpected to be created up') for vm in test_obj_dict.get_all_vm_list(): try: test_lib.lib_destroy_vm_and_data_volumes_objs_update_test_dict(vm, test_obj_dict) except Exception as e: test_util.test_logger("VM Destroying Failure in vm parallel creation test. :%s " % e) raise e rounds += 1 test_lib.lib_set_provision_storage_rate(original_rate) test_lib.lib_robot_cleanup(test_obj_dict) test_lib.lib_set_delete_policy('vm', delete_policy) test_lib.lib_set_delete_policy('volume', delete_policy) test_util.test_pass('Parallel vm creation Test Pass')
def test(): global host flavor = case_flavor[os.environ.get('CASE_FLAVOR')] 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.') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) if flavor['local']: cond = res_ops.gen_query_conditions('type', '=', 'LocalStorage', cond) elif flavor['smp']: cond = res_ops.gen_query_conditions('type', '=', 'SharedMountPoint', cond) elif flavor['nfs']: cond = res_ops.gen_query_conditions('type', '=', 'NFS', cond) elif flavor['ceph']: cond = res_ops.gen_query_conditions('type', '=', 'Ceph', cond) ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1) if not ps: test_util.test_skip( 'No Enabled/Connected local ps was found, skip test.') host_ops.reconnect_host(host[0].uuid) if flavor['local']: saved_res = vol_ops.get_local_storage_capacity(host[0].uuid, ps[0].uuid)[0] elif flavor['smp']: saved_res = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1)[0] elif flavor['nfs']: saved_res = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1)[0] test_stub.setup_fake_df(host[0], '62403200', '22403200') host_ops.reconnect_host(host[0].uuid) if flavor['local']: res = vol_ops.get_local_storage_capacity(host[0].uuid, ps[0].uuid)[0] elif flavor['smp']: res = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1)[0] elif flavor['nfs']: res = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1)[0] if res.totalCapacity != 62403200 * 1024: test_util.test_fail( 'totalCapacity %s not updated after reconnect host' % (res.totalCapacity)) if res.totalPhysicalCapacity != 62403200 * 1024: test_util.test_fail( 'totalPhysicalCapacity %s not updated after reconnect host' % (res.totalPhysicalCapacity)) if res.availablePhysicalCapacity != 22403200 * 1024: test_util.test_fail( 'availablePhysicalCapacity %s not updated after reconnect host' % (res.availablePhysicalCapacity)) if flavor['local']: if res.totalCapacity - saved_res.totalCapacity != res.availableCapacity - saved_res.availableCapacity: test_util.test_fail('availableCapacity %s not updated correctly' % (res.availableCapacity)) test_stub.remove_fake_df(host[0]) host_ops.reconnect_host(host[0].uuid) if flavor['local']: res = vol_ops.get_local_storage_capacity(host[0].uuid, ps[0].uuid)[0] elif flavor['smp']: res = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1)[0] elif flavor['nfs']: res = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1)[0] if res.totalCapacity != saved_res.totalCapacity: test_util.test_fail( 'totalCapacity %s not updated after reconnect host' % (res.totalCapacity)) if res.totalPhysicalCapacity != saved_res.totalPhysicalCapacity: test_util.test_fail( 'totalPhysicalCapacity %s not updated after reconnect host' % (res.totalPhysicalCapacity)) if flavor['local']: if res.availablePhysicalCapacity == saved_res.availablePhysicalCapacity: test_util.test_fail( 'availablePhysicalCapacity %s %s not updated after reconnect host' % (res.availablePhysicalCapacity, saved_res.availablePhysicalCapacity)) if res.availableCapacity != saved_res.availableCapacity: test_util.test_fail( 'availableCapacity %s not updated after reconnect host' % (res.availableCapacity)) test_util.test_pass( 'Test backup storage capacity for adding/deleting image pass.')
def test(): global original_rate test_util.test_dsc('Test storage over provision method') zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid 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 ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1) if not ps: test_util.test_skip( 'No Enabled/Connected primary storage was found, skip test.') return True host = host[0] ps = ps[0] over_provision_rate = 2.5 target_volume_num = 12 kept_disk_size = 10 * 1024 * 1024 vm = test_stub.create_vm(vm_name = 'storage_over_prs_vm_1', \ host_uuid = host.uuid) test_obj_dict.add_vm(vm) host_res = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap = host_res.availableCapacity if avail_cap < kept_disk_size: test_util.test_skip( 'available disk capacity:%d is too small, skip test.' % avail_cap) return True original_rate = test_lib.lib_set_provision_storage_rate( over_provision_rate) data_volume_size = int(over_provision_rate * (avail_cap - kept_disk_size) / target_volume_num) #will change the rate back to check if available capacity is same with original one. This was a bug, that only happened when system create 1 vm. test_lib.lib_set_provision_storage_rate(original_rate) host_res_tmp = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap_tmp = host_res_tmp.availableCapacity if avail_cap != avail_cap_tmp: test_util.test_fail( 'disk size is not same, between 2 times provision. Before change over rate, 1st cap: %d; 2nd cap: %d' % (avail_cap, avail_cap_tmp)) test_lib.lib_set_provision_storage_rate(over_provision_rate) test_util.test_logger( 'Will create a serial of volume. Each of them will have %d size.' % data_volume_size) disk_offering_option = test_util.DiskOfferingOption() disk_offering_option.set_name('storage-over-ps-test') disk_offering_option.set_diskSize(data_volume_size) data_volume_offering = vol_ops.create_volume_offering(disk_offering_option) test_obj_dict.add_disk_offering(data_volume_offering) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(data_volume_offering.uuid) times = 1 while (times <= target_volume_num): try: volume_creation_option.set_name('volume-%d' % times) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) res = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] test_util.test_logger('Current available storage size: %d' % res.availableCapacity) volume.attach(vm) except Exception as e: test_util.test_logger( "Unexpected volume Creation Failure in storage over provision test. " ) raise e times += 1 host_res2 = vol_ops.get_local_storage_capacity(host.uuid, ps.uuid)[0] avail_cap2 = host_res2.availableCapacity if avail_cap2 > data_volume_size: test_util.test_fail( 'Available disk size: %d is still bigger than offering disk size: %d , after creating %d volumes.' % (avail_cap2, data_volume_size, target_volume_num)) try: volume_creation_option.set_name('volume-%d' % (times + 1)) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.attach(vm) except: test_util.test_logger( "Expected Volume Creation Failure in storage over provision test. " ) else: test_util.test_fail( "The %dth Volume is still attachable, which is wrong" % (target_volume_num + 1)) test_lib.lib_set_provision_storage_rate(original_rate) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Memory Over Provision Test Pass')
def get_storage_capacity(ps_type, host_uuid, ps_uuid): if ps_type == 'LocalStorage': host_res = vol_ops.get_local_storage_capacity(host_uuid, ps_uuid)[0] else: host_res = test_lib.lib_get_storage_capacity(ps_uuids=[ps_uuid]) return host_res.availableCapacity