def test(): test_util.test_dsc('SMP ps remove host and check ps is 0') pss = res_ops.get_resource(res_ops.PRIMARY_STORAGE) #if pss[0].type != "SharedMountPoint": # test_util.test_skip("ps is not smp as expected, therefore, skip!") 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] vm = test_stub.create_vm(vm_name='basic-test-vm', host_uuid=host.uuid) vm.check() host_ops.delete_host(host.uuid) ps_capacity = test_lib.lib_get_storage_capacity(ps_uuids=[ps.uuid]) avail_cap = ps_capacity.availableCapacity avail_phy_cap = ps_capacity.availablePhysicalCapacity avail_total_cap = ps_capacity.totalCapacity avail_total_phy_cap = ps_capacity.totalPhysicalCapacity if avail_cap != 0: test_util.test_fail("avail_cap:%d is not 0 as expected" % (avail_cap)) if avail_phy_cap != 0: test_util.test_fail("avail_phy_cap:%d is not 0 as expected" % (avail_phy_cap)) if avail_total_cap != 0: test_util.test_fail("avail_total_cap:%d is not 0 as expected" % (avail_total_cap)) if avail_total_phy_cap != 0: test_util.test_fail("avail_total_phy_cap:%d is not 0 as expected" % (avail_total_phy_cap)) test_util.test_pass( 'SMP remove host check ps capacity equal 0 test success')
def test(): test_util.test_dsc('SMP ps remove host and check ps is 0') pss = res_ops.get_resource(res_ops.PRIMARY_STORAGE) #if pss[0].type != "SharedMountPoint": # test_util.test_skip("ps is not smp as expected, therefore, skip!") 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] vm = test_stub.create_vm(vm_name = 'basic-test-vm', host_uuid = host.uuid) vm.check() host_ops.delete_host(host.uuid) ps_capacity = test_lib.lib_get_storage_capacity(ps_uuids=[ps.uuid]) avail_cap = ps_capacity.availableCapacity avail_phy_cap = ps_capacity.availablePhysicalCapacity avail_total_cap = ps_capacity.totalCapacity avail_total_phy_cap = ps_capacity.totalPhysicalCapacity if avail_cap != 0: test_util.test_fail("avail_cap:%d is not 0 as expected" %(avail_cap)) if avail_phy_cap != 0: test_util.test_fail("avail_phy_cap:%d is not 0 as expected" %(avail_phy_cap)) if avail_total_cap != 0: test_util.test_fail("avail_total_cap:%d is not 0 as expected" %(avail_total_cap)) if avail_total_phy_cap != 0: test_util.test_fail("avail_total_phy_cap:%d is not 0 as expected" %(avail_total_phy_cap)) test_util.test_pass('SMP remove host check ps capacity equal 0 test success')
def test(): global original_rate test_util.test_dsc('Test change storage over provision rate 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 host = host[0] over_provision_rate1 = 2.5 over_provision_rate2 = 1.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 = test_lib.lib_get_cpu_memory_capacity(host_uuids=[host.uuid]) ps_res = test_lib.lib_get_storage_capacity(zone_uuids=[zone_uuid]) avail_cap = ps_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_rate1) data_volume_size = int(over_provision_rate1 * (avail_cap - kept_disk_size) / target_volume_num) 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) volume_creation_option.set_name('volume-1') volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) #res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid]) #test_util.test_logger('Current available storage size: %d' % res.availableCapacity) volume1.attach(vm) test_lib.lib_set_provision_storage_rate(over_provision_rate2) volume_creation_option.set_name('volume-2') volume2 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume2) #res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid]) #test_util.test_logger('Current available storage size: %d' % res.availableCapacity) volume2.attach(vm) volume1.delete() test_lib.lib_set_provision_storage_rate(over_provision_rate1) volume2.delete() test_lib.lib_set_provision_storage_rate(original_rate) ps_res2 = test_lib.lib_get_storage_capacity(zone_uuids=[zone_uuid]) avail_cap2 = ps_res2.availableCapacity if avail_cap2 != avail_cap: test_util.test_fail( 'Available disk size: %d is different with original size: %d, after creating volume under different over rate.' % (avail_cap2, avail_cap)) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Memory Over Provision Test Pass')
def test(): global vm ova_image_name = 'centos-dhcp' network_pattern1 = os.environ['vcenterDefaultNetwork'] cpuNum = 2 memorySize = 2*1024*1024*1024 cond = res_ops.gen_query_conditions('type', '!=', 'Vcenter') ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond) for i in ps: if (i.type == 'Ceph') or (i.type == 'Sharedblock'): break else: test_util.test_skip('Skip test on non ceph or sharedblock PS') ps_uuid = ps[0].uuid cond = res_ops.gen_query_conditions('primaryStorage.uuid', '=', ps_uuid) cluster_uuid = res_ops.query_resource(res_ops.CLUSTER, cond)[0].uuid cond = res_ops.gen_query_conditions('clusterUuid', '=', cluster_uuid) host = res_ops.query_resource(res_ops.HOST, cond)[0] new_offering = test_lib.lib_create_instance_offering(cpuNum = cpuNum, memorySize = memorySize) vm = test_stub.create_vm_in_vcenter(vm_name = 'v2v-test', image_name = ova_image_name, l3_name = network_pattern1, instance_offering_uuid = new_offering.uuid) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_name('vcenter_volume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) l3_name = os.environ.get('l3VlanNetworkName1') l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid v2v_conversion_host = test_stub.add_v2v_conversion_host('v2v_host', host.uuid, '/tmp/zstack', 'VMWARE') tag_ops.create_system_tag("V2VConversionHostVO", v2v_conversion_host.uuid, "networkInboundBandwidth::167772160") url = 'vmware://%s' % vm.vm.uuid avail_mem = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]).availableMemory avail_cpu = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]).availableCpu avail_cap = test_lib.lib_get_storage_capacity(ps_uuids = [ps_uuid]).availableCapacity migrate_task = test_stub.convert_vm_from_foreign_hypervisor('test', url, cpuNum, memorySize, ps_uuid, [l3_uuid], cluster_uuid, v2v_conversion_host.uuid) for i in range(30): cond = res_ops.gen_query_conditions('uuid', '=', migrate_task.uuid) long_job = res_ops.query_resource(res_ops.LONGJOB, cond)[0] if long_job.state == 'Failed': test_util.test_fail('v2v long job failed.') elif long_job.state == 'Running': time.sleep(60) elif long_job.state == 'Succeeded': test_util.test_logger('v2v long job has been finished.') break avail_mem2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]).availableMemory avail_cpu2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]).availableCpu avail_cap2 = test_lib.lib_get_storage_capacity(ps_uuids = [ps_uuid]).availableCapacity if (avail_mem - memorySize) != avail_mem2: test_util.test_fail('Available memory: %d is different with expected available memory: %d' % (avail_mem2, avail_mem - memorySize)) if (avail_cpu - cpuNum) != avail_cpu2: test_util.test_fail('Available cpuNum: %d is different with expected available cpuNum: %d' % (avail_cpu2, avail_cpu1 - memorySize)) cond = res_ops.gen_query_conditions('type', '=', 'root') cond = res_ops.gen_query_conditions('primaryStorageUuid', '=', ps_uuid, cond) vm_root_volume_size = res_ops.query_resource(res_ops.VOLUME, cond)[0].size if (avail_cap - vm_root_volume_size - disk_offering.diskSize) != avail_cap2: test_util.test_fail('Available storage: %d is different with expected available storage: %d' % (avail_cap2, avail_cap - vm_root_volume_size - disk_offering.diskSize)) actual_qos = (vm_root_volume_size + disk_offering.diskSize) / long_job.executeTime if actual_qos > 167772160: test_util.test_fail('Fail to set qos for converting vm, expect qos:167772160 < actual_qos:%s.' % actual_qos) #cleanup test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass("Migrate vcenter vm to zstack successfully.")
def test(): global original_rate must_ps_list = [inventory.LOCAL_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_if_any_ps_not_deployed(must_ps_list) test_util.test_dsc('Test change storage over provision rate 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 host = host[0] over_provision_rate1 = 2.5 over_provision_rate2 = 1.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) vm.check() test_obj_dict.add_vm(vm) cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 2) if not ps: test_util.test_skip('No Enabled/Connected primary storage was found, skip test.' ) return True ps1 = ps[0].uuid ps1_res = test_lib.lib_get_storage_capacity(ps_uuids=[ps1]) test_util.test_dsc("ps1[uuid:%s]'s available capacity is %s" % (ps1, ps1_res.availableCapacity)) avail_cap = ps1_res.availableCapacity if len(ps) > 1: ps2 = ps[1].uuid ps2_res = test_lib.lib_get_storage_capacity(ps_uuids=[ps2]) test_util.test_dsc("ps2[uuid:%s]'s available capacity is %s" % (ps2, ps2_res.availableCapacity)) avail_cap = ps1_res.availableCapacity + ps2_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_rate1) data_volume_size = int(over_provision_rate1 * (avail_cap - kept_disk_size) / target_volume_num) 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) volume_creation_option.set_name('volume-1') volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) #res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid]) #test_util.test_logger('Current available storage size: %d' % res.availableCapacity) volume1.attach(vm) test_lib.lib_set_provision_storage_rate(over_provision_rate2) volume_creation_option.set_name('volume-2') volume2 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume2) #res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid]) #test_util.test_logger('Current available storage size: %d' % res.availableCapacity) volume2.attach(vm) volume1.delete() volume1.expunge() test_lib.lib_set_provision_storage_rate(over_provision_rate1) volume2.delete() volume2.expunge() test_lib.lib_set_provision_storage_rate(original_rate) time.sleep(10) ps1_res2 = test_lib.lib_get_storage_capacity(ps_uuids=[ps1]) test_util.test_dsc("ps1[uuid:%s]'s available capacity is %s" % (ps1, ps1_res.availableCapacity)) avail_cap2 = ps1_res2.availableCapacity if len(ps) > 1: ps2_res2 = test_lib.lib_get_storage_capacity(ps_uuids=[ps2]) test_util.test_dsc("ps2[uuid:%s]'s available capacity is %s" % (ps2, ps2_res.availableCapacity)) avail_cap2 = ps1_res2.availableCapacity + ps2_res2.availableCapacity if avail_cap2 != avail_cap: test_util.test_fail('Available disk size: %d is different with original size: %d, after creating volume under different over rate.' % (avail_cap2, avail_cap)) 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
def test(): global original_rate test_util.test_dsc('Test change storage over provision rate 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 host = host[0] over_provision_rate1 = 2.5 over_provision_rate2 = 1.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 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host.uuid]) ps_res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid]) avail_cap = ps_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_rate1) data_volume_size = int(over_provision_rate1 * (avail_cap - kept_disk_size) / target_volume_num) 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) volume_creation_option.set_name('volume-1') volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) #res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid]) #test_util.test_logger('Current available storage size: %d' % res.availableCapacity) volume1.attach(vm) test_lib.lib_set_provision_storage_rate(over_provision_rate2) volume_creation_option.set_name('volume-2') volume2 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume2) #res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid]) #test_util.test_logger('Current available storage size: %d' % res.availableCapacity) volume2.attach(vm) volume1.delete() test_lib.lib_set_provision_storage_rate(over_provision_rate1) volume2.delete() test_lib.lib_set_provision_storage_rate(original_rate) ps_res2 = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid]) avail_cap2 = ps_res2.availableCapacity if avail_cap2 != avail_cap: test_util.test_fail('Available disk size: %d is different with original size: %d, after creating volume under different over rate.' % (avail_cap2, avail_cap)) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Memory Over Provision Test Pass')
def test(): global original_rate must_ps_list = [ inventory.LOCAL_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE ] test_lib.skip_test_if_any_ps_not_deployed(must_ps_list) test_util.test_dsc('Test change storage over provision rate 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 host = host[0] over_provision_rate1 = 2.5 over_provision_rate2 = 1.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) vm.check() test_obj_dict.add_vm(vm) cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=2) if not ps: test_util.test_skip( 'No Enabled/Connected primary storage was found, skip test.') return True ps1 = ps[0].uuid ps1_res = test_lib.lib_get_storage_capacity(ps_uuids=[ps1]) test_util.test_dsc("ps1[uuid:%s]'s available capacity is %s" % (ps1, ps1_res.availableCapacity)) avail_cap = ps1_res.availableCapacity if len(ps) > 1: ps2 = ps[1].uuid ps2_res = test_lib.lib_get_storage_capacity(ps_uuids=[ps2]) test_util.test_dsc("ps2[uuid:%s]'s available capacity is %s" % (ps2, ps2_res.availableCapacity)) avail_cap = ps1_res.availableCapacity + ps2_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_rate1) data_volume_size = int(over_provision_rate1 * (avail_cap - kept_disk_size) / target_volume_num) 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) volume_creation_option.set_name('volume-1') volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) #res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid]) #test_util.test_logger('Current available storage size: %d' % res.availableCapacity) volume1.attach(vm) test_lib.lib_set_provision_storage_rate(over_provision_rate2) volume_creation_option.set_name('volume-2') volume2 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume2) #res = test_lib.lib_get_storage_capacity(zone_uuids = [zone_uuid]) #test_util.test_logger('Current available storage size: %d' % res.availableCapacity) volume2.attach(vm) volume1.delete() volume1.expunge() test_lib.lib_set_provision_storage_rate(over_provision_rate1) volume2.delete() volume2.expunge() test_lib.lib_set_provision_storage_rate(original_rate) time.sleep(10) ps1_res2 = test_lib.lib_get_storage_capacity(ps_uuids=[ps1]) test_util.test_dsc("ps1[uuid:%s]'s available capacity is %s" % (ps1, ps1_res.availableCapacity)) avail_cap2 = ps1_res2.availableCapacity if len(ps) > 1: ps2_res2 = test_lib.lib_get_storage_capacity(ps_uuids=[ps2]) test_util.test_dsc("ps2[uuid:%s]'s available capacity is %s" % (ps2, ps2_res.availableCapacity)) avail_cap2 = ps1_res2.availableCapacity + ps2_res2.availableCapacity if avail_cap2 != avail_cap: test_util.test_fail( 'Available disk size: %d is different with original size: %d, after creating volume under different over rate.' % (avail_cap2, avail_cap)) 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