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 ps 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) if 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 ps was found, skip test.' ) ps_ops.reconnect_primary_storage(ps[0].uuid) saved_ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1) if flavor['ceph']: ps[0].managementIp = ps[0].mons[0].hostname else: ps[0].managementIp = ps[0].hostname if flavor['ceph']: test_stub.setup_fake_ceph(ps[0], 631242663936, 428968118272) fake_total = 631242663936 fake_available = 428968118272 else: test_stub.setup_fake_fs(ps[0], '2G', saved_ps[0].url) fake_total = 2*1024*1024*1024 fake_available = 2*1024*1024*1024 ps_ops.reconnect_primary_storage(ps[0].uuid) ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1) if flavor['ceph']: ps[0].managementIp = ps[0].mons[0].hostname else: ps[0].managementIp = ps[0].hostname if ps[0].totalCapacity != fake_total: test_util.test_fail('totalCapacity %s not updated after reconnect ps' % (ps[0].totalCapacity)) if ps[0].availableCapacity != fake_available: test_util.test_fail('availableCapacity %s not updated after reconnect ps' % (ps[0].availableCapacity)) if flavor['ceph']: test_stub.remove_fake_ceph(ps[0]) else: test_stub.remove_fake_fs(ps[0], saved_ps[0].url) ps_ops.reconnect_primary_storage(ps[0].uuid) ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1) if flavor['ceph']: ps[0].managementIp = ps[0].mons[0].hostname else: ps[0].managementIp = ps[0].hostname if ps[0].totalCapacity != saved_ps[0].totalCapacity: test_util.test_fail('totalCapacity %s not updated after reconnect ps' % (ps[0].totalCapacity)) if ps[0].availableCapacity == 0: test_util.test_fail('availableCapacity %s not updated after reconnect ps' % (ps[0].availableCapacity)) test_util.test_pass('Test primary storage capacity after reconnect ps pass.')
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 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 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('Create Data Volume on ceph pool for VM Test') cond = res_ops.gen_query_conditions('type', '=', inventory.CEPH_PRIMARY_STORAGE_TYPE) ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1) if not ps: test_util.test_skip('skip test that ceph ps not found.') ps = ps[0] vm = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm) pool = ps_ops.create_ceph_primary_storage_pool(ps.uuid, 'woodpecker_7') test_util.test_dsc('Create shareable volume and check') disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_primary_storage_uuid(ps.uuid) volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags([ 'ceph::pool::woodpecker_7', 'ephemeral::shareable', 'capability::virtio-scsi' ]) #volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() test_util.test_dsc('Attach shareable volume to stopped VM and check') #mv vm checker later, to save some time. vm.check() vm.stop() volume.attach(vm) #volume.check() vm.start() vm.check() volume.check() if volume.get_volume().installPath.find('woodpecker') < 0: test_util.test_fail( 'data volume is expected to create on pool woodpecker, while its %s.' % (volume.get_volume().installPath)) test_util.test_dsc('Detach volume and check') volume.detach(vm.get_vm().uuid) volume.check() test_util.test_dsc('Delete volume and check') volume.delete() volume.check() test_obj_dict.rm_volume(volume) ps_ops.delete_ceph_primary_storage_pool(pool.uuid) vm.destroy() vm.check() test_util.test_pass( 'Create Shareable Data Volume on ceph pool and attach to stopped VM Test Success' )
def test(): test_util.test_dsc('Test update instance offering') 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_uuid = host[0].uuid new_offering = test_lib.lib_create_instance_offering(cpuNum = 1, \ cpuSpeed = 16, memorySize = 536870912, name = 'orgin_instance_name') test_obj_dict.add_instance_offering(new_offering) vm = test_stub.create_vm(vm_name = 'test_update_instance_offering', \ host_uuid = host_uuid, \ instance_offering_uuid = new_offering.uuid) test_obj_dict.add_vm(vm) vm.stop() #These parameters are need to be populated. updated_offering = test_lib.lib_update_instance_offering(new_offering.uuid, cpuNum = 2, cpuSpeed = 16, \ memorySize = 1073741824, name = 'updated_instance_name', \ volume_iops = None, volume_bandwidth = None, \ net_outbound_bandwidth = None, net_inbound_bandwidth = None) vm.start() vm.check() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Test updated instance offering Pass')
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_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_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 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 ps = ps[0] avail_cap = ps.availableCapacity vm = test_stub.create_vm(vm_name='basic-test-vm') test_obj_dict.add_vm(vm) ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1)[0] avail_cap1 = ps.availableCapacity if avail_cap == avail_cap1: test_util.test_fail( 'PS capacity is same after create vm. Capacity before create vm: %s, after create vm: %s ' % (avail_cap, avail_cap1)) time.sleep(1) vm.destroy() vm.expunge() ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1)[0] avail_cap2 = ps.availableCapacity if avail_cap != avail_cap2: test_util.test_fail( 'PS capacity is not same after create/expunge vm. Capacity before create vm: %s, after expunge vm: %s ' % (avail_cap, avail_cap2)) test_lib.lib_set_delete_policy('vm', delete_policy) test_util.test_pass('Expunge VM Test Success')
def test(): global new_offering_uuid test_util.test_dsc('Test memory status after change VM offering') 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_uuid = host[0].uuid zone_uuid = host[0].zoneUuid host_avail_mem1 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host_uuid]).availableMemory zone_avail_mem1 = test_lib.lib_get_cpu_memory_capacity(zone_uuids = [zone_uuid]).availableMemory #unit is KB new_offering1 = test_lib.lib_create_instance_offering(cpuNum = 1, \ memorySize = 536870912, name = 'new_instance1') test_obj_dict.add_instance_offering(new_offering1) new_offering_uuid = new_offering1.uuid vm = test_stub.create_vm(vm_name = 'test_avail_memory', \ host_uuid = host_uuid, \ instance_offering_uuid = new_offering1.uuid) test_obj_dict.add_vm(vm) vm.stop() new_offering2 = test_lib.lib_create_instance_offering(cpuNum = 1, \ memorySize = 1073741824, name = 'new_instance2') test_obj_dict.add_instance_offering(new_offering2) new_offering_uuid = new_offering2.uuid vm_inv = vm.get_vm() vm.change_instance_offering(new_offering_uuid) vm.start() host_avail_mem2 = test_lib.lib_get_cpu_memory_capacity(host_uuids = [host_uuid]).availableMemory host_mem_diff = host_avail_mem1 - host_avail_mem2 if host_avail_mem2 >= host_avail_mem1 : test_util.test_fail('Host available memory is not correct after change vm template. Previous value: %s , Current value: %s' % (host_avail_mem1, host_avail_mem2)) else: test_util.test_logger('Host available memory before change template: %s , after change template: %s , the difference: %s' % (host_avail_mem1, host_avail_mem2, host_mem_diff)) zone_avail_mem2 = test_lib.lib_get_cpu_memory_capacity(zone_uuids = [zone_uuid]).availableMemory zone_mem_diff = zone_avail_mem1 - zone_avail_mem2 if zone_avail_mem2 >= zone_avail_mem1 : test_util.test_fail('Zone available memory is not correct after change vm template. Previous value: %s , Current value: %s' % (zone_avail_mem1, zone_avail_mem2)) else: test_util.test_logger('Zone available memory before change template: %s , after change template: %s , the difference: %s' % (zone_avail_mem1, zone_avail_mem2, zone_mem_diff)) if zone_mem_diff != host_mem_diff: test_util.test_fail('available memory change is not correct after change vm template. zone changed value: %s , host changed value: %s' % ((zone_avail_mem1 - zone_avail_mem2), (host_avail_mem1 - host_avail_mem2))) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Test available memory when changing instance offering Pass')
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('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 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 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 ps = ps[0] avail_cap = ps.availableCapacity vm = test_stub.create_vm(vm_name = 'basic-test-vm') test_obj_dict.add_vm(vm) ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1)[0] avail_cap1 = ps.availableCapacity if avail_cap == avail_cap1: test_util.test_fail('PS capacity is same after create vm. Capacity before create vm: %s, after create vm: %s ' % (avail_cap, avail_cap1)) time.sleep(1) vm.destroy() vm.expunge() ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1)[0] avail_cap2 = ps.availableCapacity if avail_cap != avail_cap2: test_util.test_fail('PS capacity is not same after create/expunge vm. Capacity before create vm: %s, after expunge vm: %s ' % (avail_cap, avail_cap2)) test_lib.lib_set_delete_policy('vm', delete_policy) test_util.test_pass('Expunge VM Test Success')
def test(): global test_obj_dict test_util.test_dsc('Create test vm on each ps and check') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) pss = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond) for ps in pss: vm = test_stub.create_specified_ps_vm(ps_uuid = ps.uuid) test_obj_dict.add_vm(vm) vm.check() if test_lib.lib_get_primary_storage_by_vm(vm.get_vm()).uuid != ps.uuid: test_util.test_pass('[vm:] %s is expected to create on [ps:] %s' % (vm.get_vm().uuid, ps.uuid)) vm.destroy() test_util.test_pass('Create VirtualRouter VM on each PS Test Success')
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(): global test_obj_dict test_util.test_dsc('Create test vm on each ps and check') cond = res_ops.gen_query_conditions('state', '=', 'Enabled') cond = res_ops.gen_query_conditions('status', '=', 'Connected', cond) pss = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond) for ps in pss: vm = test_stub.create_specified_ps_vm(ps_uuid=ps.uuid) test_obj_dict.add_vm(vm) vm.check() if test_lib.lib_get_primary_storage_by_vm(vm.get_vm()).uuid != ps.uuid: test_util.test_pass('[vm:] %s is expected to create on [ps:] %s' % (vm.get_vm().uuid, ps.uuid)) vm.destroy() test_util.test_pass('Create VirtualRouter VM on each PS Test Success')
def create_onlinechange_vm(test_stub=None, test_obj_dict=None): 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] test_offering = test_lib.lib_create_instance_offering(cpuNum=1, memorySize=1024 * 1024 * 1024, name='test_offering') test_obj_dict.add_instance_offering(test_offering) vm = test_stub.create_vm(vm_name='test_update_instance_offering', host_uuid=host.uuid, instance_offering_uuid=test_offering.uuid) test_obj_dict.add_vm(vm) vm.check() return vm
def test(): test_util.test_dsc('Create Data Volume on ceph pool for VM Test') cond = res_ops.gen_query_conditions('type', '=', inventory.CEPH_PRIMARY_STORAGE_TYPE) ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit = 1) if not ps: test_util.test_skip('skip test that ceph ps not found.' ) ps = ps[0] vm = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm) pool = ps_ops.add_ceph_primary_storage_pool(ps.uuid, 'woodpecker', isCreate=True) test_util.test_dsc('Create volume and check') disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_primary_storage_uuid(ps.uuid) volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags(['ceph::pool::woodpecker']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() test_util.test_dsc('Attach volume and check') #mv vm checker later, to save some time. vm.check() volume.attach(vm) volume.check() if volume.get_volume().installPath.find('woodpecker') < 0: test_util.test_fail('data volume is expected to create on pool woodpecker, while its %s.' % (volume.get_volume().installPath)) test_util.test_dsc('Detach volume and check') volume.detach() volume.check() test_util.test_dsc('Delete volume and check') volume.delete() volume.check() test_obj_dict.rm_volume(volume) ps_ops.delete_ceph_primary_storage_pool(pool.uuid) vm.destroy() vm.check() test_util.test_pass('Create Data Volume on ceph pool for VM Test Success')
def create_onlinechange_vm(test_stub=None, test_obj_dict=None): 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] test_offering = test_lib.lib_create_instance_offering(cpuNum=1, memorySize=1024 * 1024 * 1024, name='test_offering') test_obj_dict.add_instance_offering(test_offering) vm = test_stub.create_vm(vm_name='test_update_instance_offering', host_uuid=host.uuid, instance_offering_uuid=test_offering.uuid) test_obj_dict.add_vm(vm) vm.check() return vm
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(): 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(): """ """ image_uuid = None flag1 = False flag2 = False global bss, vm, host test_util.test_dsc( 'test for creating root volume template with bss disconnected and disable' ) #create a new vm image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm = test_stub.create_vm(image_uuid=image_uuid) # firstly,test for bss state disable # change backup storage state cond = res_ops.gen_query_conditions('state', '=', 'Enabled') bss = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit=1) bs_ops.change_backup_storage_state(bss[0].uuid, DISABLE) #prepare to create root volume template after buckup_storage change state to disable root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) image_option1 = test_util.ImageOption() image_option1.set_root_volume_uuid(root_volume_uuid) image_option1.set_name('image_for_bss_disconnected_test') image_option1.set_format('qcow2') image_option1.set_backup_storage_uuid_list([bss[0].uuid]) # image_option1.set_platform('Linux') # bs_type = bss[0].type vm.stop() # this API can only be invoke when vm is stopped try: img_ops.create_root_volume_template(image_option1) except: bs_ops.change_backup_storage_state(bss[0].uuid, ENABLE) flag1 = True # secondly,test for bss disconnected # change bss.host(IP address) to let bss disconnected. host = bss[0].hostname bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, infoValue) try: bs_ops.reconnect_backup_storage(bss[0].uuid) except: #can't reconnect the bs,so the bs'status is disconnected pass #create root volume template after buckup_storage change state to disable try: img_ops.create_root_volume_template(image_option1) except: bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, host) bs_ops.reconnect_backup_storage(bss[0].uuid) flag2 = True if flag1 and flag2: vm.clean() test_util.test_pass( "can't create root volume template,The test that create root volume template from root volume with ImageStoreBackupStorage server disconnected or disable is " "success! ") else: vm.clean() test_util.test_fail( "success create root image,The test that create root volume template from root volume with ImageStoreBackupStorage server disconnected or dieable is " "fail! ")
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 email_endpoint_uuid,email_platform_uuid,my_sns_topic_uuid,host_sns_topic_uuid,ps_uuid,hostname,host_management_ip,host_uuid,host_status,bs_uuid,bs_type,bs_status bs_cond = res_ops.gen_query_conditions('status', '=', 'Connected') bs_list = res_ops.query_resource(res_ops.BACKUP_STORAGE, bs_cond) for bss in bs_list: if bss.type ==res_ops.SFTP_BACKUP_STORAGE: bs_uuid =bss.uuid bs_type =bss.type hostname = bss.hostname break elif bss.type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_uuid=bss.uuid bs_type=bss.type hostname = bss.hostname break else: test_util.test_skip('No match backupStorage,test skip') smtp_server = os.environ.get('smtpServer') pop_server = os.environ.get('popServer') smtp_port = os.environ.get('smtpPort') username = os.environ.get('mailUsername') password = os.environ.get('mailPassword') email_platform_name='Alarm_email' email_platform = zwt_ops.create_sns_email_platform(smtp_server, smtp_port,email_platform_name , username, password) email_platform_uuid = email_platform.uuid try: zwt_ops.validate_sns_email_platform(email_platform_uuid) except: test_util.test_fail('Validate SNS Email Platform Failed, Email Plarform: %s' % email_platform_uuid) email_endpoint_uuid = zwt_ops.create_sns_email_endpoint(username, 'test_qa', email_platform_uuid).uuid my_sns_topic = zwt_ops.create_sns_topic('my_sns_topic') my_sns_topic_uuid = my_sns_topic.uuid zwt_ops.subscribe_sns_topic(my_sns_topic_uuid, email_endpoint_uuid) host_sns_topic = zwt_ops.create_sns_topic('host_topic') host_sns_topic_uuid = host_sns_topic.uuid zwt_ops.subscribe_sns_topic(host_sns_topic_uuid, email_endpoint_uuid) ps_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] ps_namespace = 'ZStack/PrimaryStorage' ps_disconnected = 'PrimaryStorageDisconnected' ps_event_sub_uuid = zwt_ops.subscribe_event(ps_namespace, ps_disconnected, ps_actions).uuid event_list.append(ps_event_sub_uuid) bs_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] bs_namespace = 'ZStack/BackupStorage' bs_disconnected = 'BackupStorageDisconnected' bs_event_sub_uuid = zwt_ops.subscribe_event(bs_namespace, bs_disconnected, bs_actions).uuid event_list.append(bs_event_sub_uuid) host_actions = [{"actionUuid": host_sns_topic_uuid, "actionType": "sns"}] host_namespace = 'ZStack/Host' host_status_changed = 'HostStatusChanged' host_status_labels = [{"key": "NewStatus", "op": "Equal", "value": "Disconnected"}] host_status_event_sub_uuid = zwt_ops.subscribe_event(host_namespace, host_status_changed, host_actions, host_status_labels).uuid event_list.append(host_status_event_sub_uuid) host_disconnected = 'HostDisconnected' host_disconnected_event_sub_uuid = zwt_ops.subscribe_event(host_namespace, host_disconnected, host_actions).uuid event_list.append(host_disconnected_event_sub_uuid) if zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected, ps_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected, bs_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, host_status_changed, host_status_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, host_disconnected, host_disconnected_event_sub_uuid): test_util.test_fail('email already exsist before test') # Disconnected ps ,bs and host zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid primary_storage_option = test_util.PrimaryStorageOption() primary_storage_option.set_type('nfs') primary_storage_option.set_zone_uuid(zone_uuid) primary_storage_option.set_name('test_nfs_ps') primary_storage_option.set_url('222.222.222.222/nfs/') try: ps_uuid = ps_ops.create_nfs_primary_storage(primary_storage_option).uuid ps_ops.reconnect_primary_storage(ps_uuid) except: pass if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', '222.222.222.222') try: bs_ops.reconnect_backup_storage(bs_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid) bs_status = res_ops.query_resource(res_ops.IMAGE_STORE_BACKUP_STORAGE, cond)[0].status elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid,'hostname','222.222.222.222') try: bs_ops.reconnect_backup_storage(bs_uuid) except: cond=res_ops.gen_query_conditions('uuid','=',bs_uuid) bs_status=res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE,cond)[0].status host_cond = res_ops.gen_query_conditions('status', '=', 'Connected') host = res_ops.query_resource_with_num(res_ops.HOST, host_cond, start=0, limit=1)[0] host_uuid = host.uuid host_management_ip = host.managementIp host_ops.update_host(host_uuid, 'managementIp', '222.222.222.222') try: host_ops.reconnect_host(host_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', host_uuid) bs_status = res_ops.query_resource(res_ops.HOST, cond)[0].status # wait for send email time.sleep(120) ps_ops.delete_primary_storage(ps_uuid) if hostname: if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) host_ops.update_host(host_uuid, 'managementIp', host_management_ip) host_ops.reconnect_host(host_uuid) zwt_ops.delete_sns_topic(host_sns_topic_uuid) zwt_ops.delete_sns_topic(my_sns_topic_uuid) for event_uuid in event_list: zwt_ops.unsubscribe_event(event_uuid) zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) zwt_ops.delete_sns_application_platform(email_platform_uuid) check_1 = zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected, ps_event_sub_uuid) check_2 = zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected, bs_event_sub_uuid) check_3 = zwt_ops.check_sns_email(pop_server, username, password, host_status_changed, host_status_event_sub_uuid) check_4 = zwt_ops.check_sns_email(pop_server, username, password, host_disconnected, host_disconnected_event_sub_uuid) if check_1 and check_2 and check_3 and check_4: test_util.test_pass('test host ,bs, ps disconnected event with email success!') else: test_util.test_fail('cannt receive all event mail')
def test(): global ps 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) if 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 ps was found, skip test.') ps_ops.reconnect_primary_storage(ps[0].uuid) saved_ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1) if flavor['ceph']: ps[0].managementIp = ps[0].mons[0].hostname else: ps[0].managementIp = ps[0].hostname if flavor['ceph']: test_stub.setup_fake_ceph(ps[0], 631242663936, 428968118272) fake_total = 631242663936 fake_available = 428968118272 else: test_stub.setup_fake_fs(ps[0], '2G', saved_ps[0].url) fake_total = 2 * 1024 * 1024 * 1024 fake_available = 2 * 1024 * 1024 * 1024 ps_ops.reconnect_primary_storage(ps[0].uuid) ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1) if flavor['ceph']: ps[0].managementIp = ps[0].mons[0].hostname else: ps[0].managementIp = ps[0].hostname if ps[0].totalCapacity != fake_total: test_util.test_fail('totalCapacity %s not updated after reconnect ps' % (ps[0].totalCapacity)) if ps[0].availableCapacity != fake_available: test_util.test_fail( 'availableCapacity %s not updated after reconnect ps' % (ps[0].availableCapacity)) if flavor['ceph']: test_stub.remove_fake_ceph(ps[0]) else: test_stub.remove_fake_fs(ps[0], saved_ps[0].url) ps_ops.reconnect_primary_storage(ps[0].uuid) ps = res_ops.query_resource_with_num(res_ops.PRIMARY_STORAGE, cond, limit=1) if flavor['ceph']: ps[0].managementIp = ps[0].mons[0].hostname else: ps[0].managementIp = ps[0].hostname if ps[0].totalCapacity != saved_ps[0].totalCapacity: test_util.test_fail('totalCapacity %s not updated after reconnect ps' % (ps[0].totalCapacity)) if ps[0].availableCapacity == 0: test_util.test_fail( 'availableCapacity %s not updated after reconnect ps' % (ps[0].availableCapacity)) test_util.test_pass( 'Test primary storage capacity after reconnect ps 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 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 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 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 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 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(): 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] ps_type = ps.type #TODO: Fix ceph testing if ps_type == 'Ceph' or ps_type == 'SharedMountPoint': test_util.test_skip('skip test for ceph and smp.') 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) vm.check() avail_cap = get_storage_capacity(ps_type, host.uuid, ps.uuid) 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) avail_cap_tmp = get_storage_capacity(ps_type, host.uuid, ps.uuid) 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) test_util.test_logger( 'Current available storage size: %d' % get_storage_capacity(ps_type, host.uuid, ps.uuid)) volume.attach(vm) except Exception as e: test_util.test_logger( "Unexpected volume Creation Failure in storage over provision test. " ) raise e times += 1 time.sleep(2) avail_cap2 = get_storage_capacity(ps_type, host.uuid, ps.uuid) 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 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 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 new_offering_uuid test_util.test_dsc('Test memory status after change VM offering') 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_uuid = host[0].uuid zone_uuid = host[0].zoneUuid host_avail_mem1 = test_lib.lib_get_cpu_memory_capacity( host_uuids=[host_uuid]).availableMemory zone_avail_mem1 = test_lib.lib_get_cpu_memory_capacity( zone_uuids=[zone_uuid]).availableMemory #unit is KB new_offering1 = test_lib.lib_create_instance_offering(cpuNum = 1, \ memorySize = 536870912, name = 'new_instance1') test_obj_dict.add_instance_offering(new_offering1) new_offering_uuid = new_offering1.uuid vm = test_stub.create_vm(vm_name = 'test_avail_memory', \ host_uuid = host_uuid, \ instance_offering_uuid = new_offering1.uuid) test_obj_dict.add_vm(vm) vm.stop() new_offering2 = test_lib.lib_create_instance_offering(cpuNum = 1, \ memorySize = 1073741824, name = 'new_instance2') test_obj_dict.add_instance_offering(new_offering2) new_offering_uuid = new_offering2.uuid vm_inv = vm.get_vm() vm.change_instance_offering(new_offering_uuid) vm.start() host_avail_mem2 = test_lib.lib_get_cpu_memory_capacity( host_uuids=[host_uuid]).availableMemory host_mem_diff = host_avail_mem1 - host_avail_mem2 if host_avail_mem2 >= host_avail_mem1: test_util.test_fail( 'Host available memory is not correct after change vm template. Previous value: %s , Current value: %s' % (host_avail_mem1, host_avail_mem2)) else: test_util.test_logger( 'Host available memory before change template: %s , after change template: %s , the difference: %s' % (host_avail_mem1, host_avail_mem2, host_mem_diff)) zone_avail_mem2 = test_lib.lib_get_cpu_memory_capacity( zone_uuids=[zone_uuid]).availableMemory zone_mem_diff = zone_avail_mem1 - zone_avail_mem2 if zone_avail_mem2 >= zone_avail_mem1: test_util.test_fail( 'Zone available memory is not correct after change vm template. Previous value: %s , Current value: %s' % (zone_avail_mem1, zone_avail_mem2)) else: test_util.test_logger( 'Zone available memory before change template: %s , after change template: %s , the difference: %s' % (zone_avail_mem1, zone_avail_mem2, zone_mem_diff)) if zone_mem_diff != host_mem_diff: test_util.test_fail( 'available memory change is not correct after change vm template. zone changed value: %s , host changed value: %s' % ((zone_avail_mem1 - zone_avail_mem2), (host_avail_mem1 - host_avail_mem2))) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass( 'Test available memory when changing instance offering Pass')
def test(): """ """ global image_uuid, backup_storage_inventory_uuid test_util.test_dsc('create image check timeout test') #modify default timeout value set_global_timeout_value() #create sftp server vm sftp_vm_offering = test_lib.lib_create_instance_offering(cpuNum = 1, \ memorySize = 536870912, name = 'sftp_vm_instance_name', \ volume_iops = None, volume_bandwidth = None, \ net_outbound_bandwidth = vm_outbound_bandwidth, net_inbound_bandwidth = None) test_obj_dict.add_instance_offering(sftp_vm_offering) sftp_server_vm = test_stub.create_vm(vm_name = 'sftp-vm', image_name = 'img5h', \ instance_offering_uuid = sftp_vm_offering.uuid) test_obj_dict.add_vm(sftp_server_vm) sftp_server_vm.check() #create backup storage on previous vm sftp_backup_storage_option = test_util.SftpBackupStorageOption() sftp_backup_storage_option.name = "bs_from_sftp_server" sftp_backup_storage_option.username = "******" sftp_backup_storage_option.hostname = sftp_server_vm.get_vm().vmNics[0].ip sftp_backup_storage_option.password = "******" sftp_backup_storage_option.sshPort = 22 sftp_backup_storage_option.url = "/zstack_bs" backup_storage_inventory = bs_ops.create_backup_storage(sftp_backup_storage_option) if not backup_storage_inventory.uuid: backup_storage_inventory_uuid = backup_storage_inventory.uuid #create a new vm for creating image step vm_offering = test_lib.lib_create_instance_offering(cpuNum = 1, \ memorySize = 536870912, name = 'image_create_test_vm', \ volume_iops = None, volume_bandwidth = None, \ net_outbound_bandwidth = None, net_inbound_bandwidth = None) test_obj_dict.add_instance_offering(vm_offering) vm = test_stub.create_vm(vm_name = 'timeout-test-vm', image_name = 'img5h', \ instance_offering_uuid = vm_offering.uuid) test_obj_dict.add_vm(vm) vm.check() #populate vm with big files, the max http execute time is 30 mins. #the max disk throughput is 50MB/s, use dd to generate 10GB big file will cost ~2400s. #the total disk size after dd is 1.0+5=6GB #import tempfile #script_file = tempfile.NamedTemporaryFile(delete=False) #script_file.write("dd if=/dev/random of=test1 bs=1M count=5120") #script_file.close() #if not test_lib.lib_execute_shell_script_in_vm(vm.get_vm(), script_file.name, timeout=3600): # test_util.test_fail("generate 5GB big file failed") cmd = "dd if=/dev/random of=test1 bs=1M count=5120" ret, output, stderr = ssh.execute(cmd, vm.get_vm().vmNics[0].ip, "root", "password", False, 22) if ret != 0: test_util.test_fail("generate 5GB big file failed") #attach backup storage to zone cond = res_ops.gen_query_conditions('state', '=', 'Enabled') zone = res_ops.query_resource_with_num(res_ops.ZONE, cond, limit = 1) bs_ops.attach_backup_storage(backup_storage_inventory.uuid, zone[0].uuid) #invoke API with timeout vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid image_option1 = test_util.ImageOption() image_option1.set_root_volume_uuid(root_volume_uuid) image_option1.set_name('big_image_for_upload') image_option1.set_format('qcow2') image_option1.set_backup_storage_uuid_list([backup_storage_inventory.uuid]) #image_option1.set_platform('Linux') #bs_type = backup_storage_list[0].type #this API can only be invoke when vm is stopped vm.stop() vm.check() time1 = time.time() image = img_ops.create_root_volume_template(image_option1) time2 = time.time() image_uuid = image.uuid cost_time = time2 - time1 test_util.test_logger("start time: %s" % (time1)) test_util.test_logger("end time: %s" % (time2)) test_util.test_logger("total time: %s" % (cost_time)) if cost_time > int(timeout_value): test_util.test_fail("The test create image cost time is greater than %s hours: \ %s, which does not meet the test criterial." % (str(timeout_value), cost_time))
def test(): """ """ global image_uuid, backup_storage_inventory_uuid test_util.test_dsc('create image check timeout test') #modify default timeout value set_global_timeout_value() #create sftp server vm sftp_vm_offering = test_lib.lib_create_instance_offering(cpuNum = 1, \ cpuSpeed = 16, memorySize = 536870912, name = 'sftp_vm_instance_name', \ volume_iops = None, volume_bandwidth = None, \ net_outbound_bandwidth = vm_outbound_bandwidth, net_inbound_bandwidth = None) test_obj_dict.add_instance_offering(sftp_vm_offering) sftp_server_vm = test_stub.create_vm(vm_name = 'sftp-vm', image_name = 'img5h', \ instance_offering_uuid = sftp_vm_offering.uuid) test_obj_dict.add_vm(sftp_server_vm) sftp_server_vm.check() #create backup storage on previous vm sftp_backup_storage_option = test_util.SftpBackupStorageOption() sftp_backup_storage_option.name = "bs_from_sftp_server" sftp_backup_storage_option.username = "******" sftp_backup_storage_option.hostname = sftp_server_vm.get_vm().vmNics[0].ip sftp_backup_storage_option.password = "******" sftp_backup_storage_option.sshPort = 22 sftp_backup_storage_option.url = "/zstack_bs" backup_storage_inventory = bs_ops.create_backup_storage( sftp_backup_storage_option) if not backup_storage_inventory.uuid: backup_storage_inventory_uuid = backup_storage_inventory.uuid #create a new vm for creating image step vm_offering = test_lib.lib_create_instance_offering(cpuNum = 1, \ cpuSpeed = 16, memorySize = 536870912, name = 'image_create_test_vm', \ volume_iops = None, volume_bandwidth = None, \ net_outbound_bandwidth = None, net_inbound_bandwidth = None) test_obj_dict.add_instance_offering(vm_offering) vm = test_stub.create_vm(vm_name = 'timeout-test-vm', image_name = 'img5h', \ instance_offering_uuid = vm_offering.uuid) test_obj_dict.add_vm(vm) vm.check() #populate vm with big files, the max http execute time is 30 mins. #the max disk throughput is 50MB/s, use dd to generate 10GB big file will cost ~2400s. #the total disk size after dd is 1.0+5=6GB #import tempfile #script_file = tempfile.NamedTemporaryFile(delete=False) #script_file.write("dd if=/dev/random of=test1 bs=1M count=5120") #script_file.close() #if not test_lib.lib_execute_shell_script_in_vm(vm.get_vm(), script_file.name, timeout=3600): # test_util.test_fail("generate 5GB big file failed") cmd = "dd if=/dev/random of=test1 bs=1M count=5120" ret, output, stderr = ssh.execute(cmd, vm.get_vm().vmNics[0].ip, "root", "password", False, 22) if ret != 0: test_util.test_fail("generate 5GB big file failed") #attach backup storage to zone cond = res_ops.gen_query_conditions('state', '=', 'Enabled') zone = res_ops.query_resource_with_num(res_ops.ZONE, cond, limit=1) bs_ops.attach_backup_storage(backup_storage_inventory.uuid, zone[0].uuid) #invoke API with timeout vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid image_option1 = test_util.ImageOption() image_option1.set_root_volume_uuid(root_volume_uuid) image_option1.set_name('big_image_for_upload') image_option1.set_format('qcow2') image_option1.set_backup_storage_uuid_list([backup_storage_inventory.uuid]) #image_option1.set_platform('Linux') #bs_type = backup_storage_list[0].type #this API can only be invoke when vm is stopped vm.stop() vm.check() time1 = time.time() image = img_ops.create_root_volume_template(image_option1) time2 = time.time() image_uuid = image.uuid cost_time = time2 - time1 test_util.test_logger("start time: %s" % (time1)) test_util.test_logger("end time: %s" % (time2)) test_util.test_logger("total time: %s" % (cost_time)) if cost_time > int(timeout_value): test_util.test_fail( "The test create image cost time is greater than %s hours: \ %s, which does not meet the test criterial." % (str(timeout_value), cost_time))
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_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 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 bs 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) if flavor['sftp']: cond = res_ops.gen_query_conditions('type', '=', 'SftpBackupStorage', cond) elif flavor['imagestore']: cond = res_ops.gen_query_conditions('type', '=', 'ImageStoreBackupStorage', cond) elif flavor['ceph']: cond = res_ops.gen_query_conditions('type', '=', 'Ceph', cond) bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit=1) if not bs: test_util.test_skip('No Enabled/Connected bs was found, skip test.') bs_ops.reconnect_backup_storage(bs[0].uuid) saved_bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit=1) if flavor['ceph']: bs[0].managementIp = bs[0].mons[0].hostname else: bs[0].managementIp = bs[0].hostname if flavor['ceph']: test_stub.setup_fake_ceph(bs[0], 631242663936, 428968118272) fake_total = 631242663936 fake_available = 428968118272 else: test_stub.setup_fake_fs(bs[0], '2G', saved_bs[0].url) fake_total = 2 * 1024 * 1024 * 1024 fake_available = 2 * 1024 * 1024 * 1024 bs_ops.reconnect_backup_storage(bs[0].uuid) bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit=1) if flavor['ceph']: bs[0].managementIp = bs[0].mons[0].hostname else: bs[0].managementIp = bs[0].hostname if bs[0].totalCapacity != fake_total: test_util.test_fail('totalCapacity %s not updated after reconnect bs' % (bs[0].totalCapacity)) if bs[0].availableCapacity != fake_available: test_util.test_fail( 'availableCapacity %s not updated after reconnect bs' % (bs[0].availableCapacity)) if flavor['ceph']: test_stub.remove_fake_ceph(bs[0]) else: test_stub.remove_fake_fs(bs[0], saved_bs[0].url) bs_ops.reconnect_backup_storage(bs[0].uuid) bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit=1) if flavor['ceph']: bs[0].managementIp = bs[0].mons[0].hostname else: bs[0].managementIp = bs[0].hostname if bs[0].totalCapacity != saved_bs[0].totalCapacity: test_util.test_fail('totalCapacity %s not updated after reconnect bs' % (bs[0].totalCapacity)) if bs[0].availableCapacity == 0: test_util.test_fail( 'availableCapacity %s not updated after reconnect bs' % (bs[0].availableCapacity)) test_util.test_pass( 'Test backup storage capacity after reconnect bs pass.')
def test(): global email_endpoint_uuid, email_platform_uuid, my_sns_topic_uuid, host_sns_topic_uuid, ps_uuid, hostname, host_management_ip, host_uuid, host_status, bs_uuid, bs_type, bs_status bs_cond = res_ops.gen_query_conditions('status', '=', 'Connected') bs_list = res_ops.query_resource(res_ops.BACKUP_STORAGE, bs_cond) for bss in bs_list: if bss.type == res_ops.SFTP_BACKUP_STORAGE: bs_uuid = bss.uuid bs_type = bss.type hostname = bss.hostname break elif bss.type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_uuid = bss.uuid bs_type = bss.type hostname = bss.hostname break else: test_util.test_skip('No match backupStorage,test skip') smtp_server = os.environ.get('smtpServer') pop_server = os.environ.get('popServer') smtp_port = os.environ.get('smtpPort') username = os.environ.get('mailUsername') password = os.environ.get('mailPassword') email_platform_name = 'Alarm_email' email_platform = zwt_ops.create_sns_email_platform(smtp_server, smtp_port, email_platform_name, username, password) email_platform_uuid = email_platform.uuid try: zwt_ops.validate_sns_email_platform(email_platform_uuid) except: test_util.test_fail( 'Validate SNS Email Platform Failed, Email Plarform: %s' % email_platform_uuid) email_endpoint_uuid = zwt_ops.create_sns_email_endpoint( username, 'test_qa', email_platform_uuid).uuid my_sns_topic = zwt_ops.create_sns_topic('my_sns_topic') my_sns_topic_uuid = my_sns_topic.uuid zwt_ops.subscribe_sns_topic(my_sns_topic_uuid, email_endpoint_uuid) host_sns_topic = zwt_ops.create_sns_topic('host_topic') host_sns_topic_uuid = host_sns_topic.uuid zwt_ops.subscribe_sns_topic(host_sns_topic_uuid, email_endpoint_uuid) ps_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] ps_namespace = 'ZStack/PrimaryStorage' ps_disconnected = 'PrimaryStorageDisconnected' ps_event_sub_uuid = zwt_ops.subscribe_event(ps_namespace, ps_disconnected, ps_actions).uuid event_list.append(ps_event_sub_uuid) bs_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] bs_namespace = 'ZStack/BackupStorage' bs_disconnected = 'BackupStorageDisconnected' bs_event_sub_uuid = zwt_ops.subscribe_event(bs_namespace, bs_disconnected, bs_actions).uuid event_list.append(bs_event_sub_uuid) host_actions = [{"actionUuid": host_sns_topic_uuid, "actionType": "sns"}] host_namespace = 'ZStack/Host' host_status_changed = 'HostStatusChanged' host_status_labels = [{ "key": "NewStatus", "op": "Equal", "value": "Disconnected" }] host_status_event_sub_uuid = zwt_ops.subscribe_event( host_namespace, host_status_changed, host_actions, host_status_labels).uuid event_list.append(host_status_event_sub_uuid) host_disconnected = 'HostDisconnected' host_disconnected_event_sub_uuid = zwt_ops.subscribe_event( host_namespace, host_disconnected, host_actions).uuid event_list.append(host_disconnected_event_sub_uuid) if zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected, ps_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected, bs_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, host_status_changed, host_status_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, host_disconnected, host_disconnected_event_sub_uuid): test_util.test_fail('email already exsist before test') # Disconnected ps ,bs and host zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid primary_storage_option = test_util.PrimaryStorageOption() primary_storage_option.set_type('nfs') primary_storage_option.set_zone_uuid(zone_uuid) primary_storage_option.set_name('test_nfs_ps') primary_storage_option.set_url('222.222.222.222/nfs/') try: ps_uuid = ps_ops.create_nfs_primary_storage( primary_storage_option).uuid ps_ops.reconnect_primary_storage(ps_uuid) except: pass if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', '222.222.222.222') try: bs_ops.reconnect_backup_storage(bs_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid) bs_status = res_ops.query_resource( res_ops.IMAGE_STORE_BACKUP_STORAGE, cond)[0].status elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', '222.222.222.222') try: bs_ops.reconnect_backup_storage(bs_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid) bs_status = res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE, cond)[0].status host_cond = res_ops.gen_query_conditions('status', '=', 'Connected') host = res_ops.query_resource_with_num(res_ops.HOST, host_cond, start=0, limit=1)[0] host_uuid = host.uuid host_management_ip = host.managementIp host_ops.update_host(host_uuid, 'managementIp', '222.222.222.222') try: host_ops.reconnect_host(host_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', host_uuid) bs_status = res_ops.query_resource(res_ops.HOST, cond)[0].status # wait for send email time.sleep(60) ps_ops.delete_primary_storage(ps_uuid) if hostname: if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info( bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) host_ops.update_host(host_uuid, 'managementIp', host_management_ip) host_ops.reconnect_host(host_uuid) zwt_ops.delete_sns_topic(host_sns_topic_uuid) zwt_ops.delete_sns_topic(my_sns_topic_uuid) for event_uuid in event_list: zwt_ops.unsubscribe_event(event_uuid) zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) zwt_ops.delete_sns_application_platform(email_platform_uuid) check_1 = zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected, ps_event_sub_uuid) check_2 = zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected, bs_event_sub_uuid) check_3 = zwt_ops.check_sns_email(pop_server, username, password, host_status_changed, host_status_event_sub_uuid) check_4 = zwt_ops.check_sns_email(pop_server, username, password, host_disconnected, host_disconnected_event_sub_uuid) if check_1 and check_2 and check_3 and check_4: test_util.test_pass( 'test host ,bs, ps disconnected event with email success!') else: test_util.test_fail('cannt receive all event mail')
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(): 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 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 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 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 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 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 bs 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) if flavor['sftp']: cond = res_ops.gen_query_conditions('type', '=', 'SftpBackupStorage', cond) elif flavor['imagestore']: cond = res_ops.gen_query_conditions('type', '=', 'ImageStoreBackupStorage', cond) elif flavor['ceph']: cond = res_ops.gen_query_conditions('type', '=', 'Ceph', cond) bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit = 1) if not bs: test_util.test_skip('No Enabled/Connected bs was found, skip test.' ) bs_ops.reconnect_backup_storage(bs[0].uuid) saved_bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit = 1) if flavor['ceph']: bs[0].managementIp = bs[0].mons[0].hostname else: bs[0].managementIp = bs[0].hostname if flavor['ceph']: test_stub.setup_fake_ceph(bs[0], 631242663936, 428968118272) fake_total = 631242663936 fake_available = 428968118272 else: test_stub.setup_fake_fs(bs[0], '2G', saved_bs[0].url) fake_total = 2*1024*1024*1024 fake_available = 2*1024*1024*1024 bs_ops.reconnect_backup_storage(bs[0].uuid) bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit = 1) if flavor['ceph']: bs[0].managementIp = bs[0].mons[0].hostname else: bs[0].managementIp = bs[0].hostname if bs[0].totalCapacity != fake_total: test_util.test_fail('totalCapacity %s not updated after reconnect bs' % (bs[0].totalCapacity)) if bs[0].availableCapacity != fake_available: test_util.test_fail('availableCapacity %s not updated after reconnect bs' % (bs[0].availableCapacity)) if flavor['ceph']: test_stub.remove_fake_ceph(bs[0]) else: test_stub.remove_fake_fs(bs[0], saved_bs[0].url) bs_ops.reconnect_backup_storage(bs[0].uuid) bs = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit = 1) if flavor['ceph']: bs[0].managementIp = bs[0].mons[0].hostname else: bs[0].managementIp = bs[0].hostname if bs[0].totalCapacity != saved_bs[0].totalCapacity: test_util.test_fail('totalCapacity %s not updated after reconnect bs' % (bs[0].totalCapacity)) if bs[0].availableCapacity == 0: test_util.test_fail('availableCapacity %s not updated after reconnect bs' % (bs[0].availableCapacity)) test_util.test_pass('Test backup storage capacity after reconnect bs 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(): """ """ image_uuid = None flag1 = False flag2 = False global bss,vm,host test_util.test_dsc('test for creating root volume template with bss disconnected and disable') #create a new vm image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm = test_stub.create_vm(image_uuid=image_uuid) # firstly,test for bss state disable # change backup storage state cond = res_ops.gen_query_conditions('state', '=', 'Enabled') bss = res_ops.query_resource_with_num(res_ops.BACKUP_STORAGE, cond, limit=1) bs_ops.change_backup_storage_state(bss[0].uuid,DISABLE) #prepare to create root volume template after buckup_storage change state to disable root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) image_option1 = test_util.ImageOption() image_option1.set_root_volume_uuid(root_volume_uuid) image_option1.set_name('image_for_bss_disconnected_test') image_option1.set_format('qcow2') image_option1.set_backup_storage_uuid_list([bss[0].uuid]) # image_option1.set_platform('Linux') # bs_type = bss[0].type vm.stop() # this API can only be invoke when vm is stopped try: img_ops.create_root_volume_template(image_option1) except: bs_ops.change_backup_storage_state(bss[0].uuid, ENABLE) flag1=True # secondly,test for bss disconnected # change bss.host(IP address) to let bss disconnected. host = bss[0].hostname bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, infoValue) try: bs_ops.reconnect_backup_storage(bss[0].uuid) except: #can't reconnect the bs,so the bs'status is disconnected pass #create root volume template after buckup_storage change state to disable try: img_ops.create_root_volume_template(image_option1) except: bs_ops.update_image_store_backup_storage_info(bss[0].uuid, infoType, host) bs_ops.reconnect_backup_storage(bss[0].uuid) flag2=True if flag1 and flag2: vm.clean() test_util.test_pass( "can't create root volume template,The test that create root volume template from root volume with ImageStoreBackupStorage server disconnected or disable is " "success! ") else: vm.clean() test_util.test_fail( "success create root image,The test that create root volume template from root volume with ImageStoreBackupStorage server disconnected or dieable is " "fail! ")
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 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')