def test(): if res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE): test_util.test_skip("sftp backupstorage doesn't support for clone test. Skip test") global vm vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_resize_vm", image_name, l3_name) test_obj_dict.add_vm(vm) vm.check() vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024*1024*1024*5 vol_ops.resize_volume(volume_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) new_vm = vm.clone(['vm_clone'])[0] test_obj_dict.add_vm(new_vm) new_volume_uuid = test_lib.lib_get_root_volume_uuid(new_vm.get_vm()) vol_size_after = test_lib.lib_get_root_volume(new_vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Resize VM Snapshot Test Success')
def test(): global test_obj_dict, bs, ps #judge whether BS is imagestore bs = res_ops.query_resource(res_ops.BACKUP_STORAGE) for i in bs: if i.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: break else: test_util.test_skip('Skip test on non-imagestore') #judge whether PS is SharedBlock ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for i in ps: if i.type in ['SharedBlock', 'AliyunNAS']: test_util.test_skip('Skip test on SharedBlock and PS') image_name = os.environ.get('imageName_s') l3_name = os.environ.get('l3PublicNetworkName') vm = test_stub.create_vm("test_vm", image_name, l3_name) #vm.check() test_obj_dict.add_vm(vm) new_vm = vm.clone(['test_vm_clone_with_on_data_volume'], full=True)[0] test_obj_dict.add_vm(new_vm) volumes_number = len(test_lib.lib_get_all_volumes(new_vm.vm)) if volumes_number != 1: test_util.test_fail('Did not find 1 volumes for [vm:] %s. But we assigned 1 data volume when create the vm. We only catch %s volumes' % (new_vm.vm.uuid, volumes_number)) else: test_util.test_logger('Find 1 volumes for [vm:] %s.' % new_vm.vm.uuid) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Test clone vm with one data volume Success')
def test(): ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard") vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid) test_obj_dict.add_vm(vm1) vm2 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid) test_obj_dict.add_vm(vm2) assert vm1.get_vm().hostUuid != vm2.get_vm().hostUuid vm3 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid) test_obj_dict.add_vm(vm3) assert vm1.get_vm().hostUuid != vm3.get_vm().hostUuid assert vm2.get_vm().hostUuid != vm3.get_vm().hostUuid try: vm4 = None vm4 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid) except: if not vm4: test_util.test_logger("vm4 isn't created as expected") finally: if vm4: test_util.test_fail("Test Fail, vm4 [uuid:%s] is not expected to be created" % vm4.get_vm().uuid) test_lib.lib_error_cleanup(test_obj_dict) ag_ops.delete_affinity_group(ag1.uuid) test_util.test_pass("Affinity Group antiHard policy pass")
def test(): h1_name = os.environ.get("hostName") cond = res_ops.gen_query_conditions('name', '=', h1_name) h1 = res_ops.query_resource(res_ops.HOST, cond) ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard") vm1 = test_stub.create_ag_vm(host_uuid=h1[0].uuid) assert vm1.get_vm().hostUuid == h1[0].uuid test_obj_dict.add_vm(vm1) new_vm = vm1.clone(names=["clone-vm1", "clone-vm2", "clone-vm3"], systemtag=["affinityGroupUuid::%s" % ag1.uuid]) test_obj_dict.add_vm(new_vm[0]) test_obj_dict.add_vm(new_vm[1]) test_obj_dict.add_vm(new_vm[2]) vmuuids = [] ag = test_lib.lib_get_affinity_group_by_name(name="ag1") for usage in ag.usages: vmuuids.append(usage.resourceUuid) assert new_vm[0].get_vm().uuid in vmuuids assert new_vm[1].get_vm().uuid in vmuuids assert new_vm[2].get_vm().uuid in vmuuids assert len(vmuuids) == 3 try: ag_ops.add_vm_to_affinity_group(ag1.uuid, vm1.get_vm().uuid) except: test_util.test_logger("vm1 is not expected to add into affinity group [uuid: %s]" % ag1.uuid) vmuuids = [] ag = test_lib.lib_get_affinity_group_by_name(name="ag1") for usage in ag.usages: vmuuids.append(usage.resourceUuid) assert vm1.get_vm().uuid not in vmuuids test_lib.lib_error_cleanup(test_obj_dict) ag_ops.delete_affinity_group(ag1.uuid) test_util.test_pass("Affinity Group antiHard policy pass")
def test(): test_util.test_dsc("create vpc vrouter and attach vpc l3 to vpc") vr1 = test_stub.create_vpc_vrouter("vpc1") vr2 = test_stub.create_vpc_vrouter("vpc2") test_util.test_dsc("create vm in ") test_stub.attach_l3_to_vpc_vr(vr1, ['l3VlanNetworkName1']) with test_lib.expected_failure('Attach vpc l3 to vpc2 which is already attached to vpc1', Exception): test_stub.attach_l3_to_vpc_vr(vr2, ['l3VlanNetworkName1']) test_util.test_dsc("Try to create vm in l3: l3VlanNetworkName1") vm = test_stub.create_vm_with_random_offering(vm_name='vpc_vm', l3_name='l3VlanNetworkName1') test_obj_dict.add_vm(vm) vm.check() with test_lib.expected_failure('Detach vpc l3 when have vm running on it', Exception): nic_uuid_list = [nic.uuid for nic in vr1.inv.vmNics if nic.metaData == '4'] for nic_uuid in nic_uuid_list: vr1.remove_nic(nic_uuid) test_util.test_dsc("Destroy vm and detach it again") vm.destroy() nic_uuid_list = [nic.uuid for nic in vr1.inv.vmNics if nic.metaData == '4'] for nic_uuid in nic_uuid_list: vr1.remove_nic(nic_uuid) test_lib.lib_error_cleanup(test_obj_dict) test_stub.remove_all_vpc_vrouter()
def test(): global test_obj_dict #volume_creation_option = test_util.VolumeOption() #test_util.test_dsc('Create volume and check') #disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) #volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) #volume = test_stub.create_volume(volume_creation_option) bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None, fields=['uuid']) if not bss: test_util.test_skip("not find available backup storage. Skip test") volume_creation_option = test_util.VolumeOption() test_util.test_dsc('Create volume and check') disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) volume1.check() volume_uuid = volume1.volume.uuid test_util.test_dsc('Create vm and check') vm = test_stub.create_vr_vm('migrate_volume_vm', 'imageName_net', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) vm.check() vm_uuid = vm.vm.uuid volume1.attach(vm) volume1.detach(vm_uuid) vm.stop() image_obj = volume1.create_template([bss[0].uuid]) vm.start() host_uuid = vm.vm.hostUuid ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) volume2 = image_obj.create_data_volume(ps.uuid, 'volumeName', host_uuid) test_obj_dict.add_volume(volume2) volume2.check() volume_uuid = volume2.volume.uuid ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type != inventory.LOCAL_STORAGE_TYPE: test_util.test_skip('Skip test on non-localstorage') snapshots = test_obj_dict.get_volume_snapshot(volume_uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('create_snapshot1') snapshots.check() snapshots.create_snapshot('create_snapshot2') snapshots.check() target_host = test_lib.lib_find_random_host_by_volume_uuid(volume_uuid) target_host_uuid = target_host.uuid vol_ops.migrate_volume(volume_uuid, target_host_uuid) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Cold migrate Data Volume from Template with Snapshot Test Success')
def test(): global vm vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_resize_vm", image_name, l3_name) test_obj_dict.add_vm(vm) vm.check() vm.stop() vm.check() vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024*1024*1024*5 snapshots = test_obj_dict.get_volume_snapshot(volume_uuid) snapshots.set_utility_vm(vm) snapshots.create_snapshot('create_snapshot1') snapshots.check() vol_ops.resize_volume(volume_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) snapshots.delete() test_obj_dict.rm_volume_snapshot(snapshots) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Resize VM Snapshot Test Success')
def error_cleanup(): global test_obj_dict try: hybrid.del_vpc() except: pass test_lib.lib_error_cleanup(test_obj_dict)
def error_cleanup(): global volume_offering_uuid test_lib.lib_error_cleanup(test_obj_dict) try: vol_ops.delete_disk_offering(volume_offering_uuid) except: pass
def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] test_util.test_dsc("create vpc vrouter and attach vpc l3 to vpc") for vpc_name in vpc_name_list: vr_list.append(test_stub.create_vpc_vrouter(vpc_name)) for vr, l3_list in izip(vr_list, vpc_l3_list): test_stub.attach_l3_to_vpc_vr(vr, l3_list) vm1, vm2 = [test_stub.create_vm_with_random_offering(vm_name='vpc_vm_{}'.format(name), l3_name=name) for name in (flavor['vm1l3'], flavor['vm2l3'])] [test_obj_dict.add_vm(vm) for vm in (vm1, vm2)] [vm.check() for vm in (vm1, vm2)] test_util.test_dsc("test two vm connectivity") [test_stub.run_command_in_vm(vm.get_vm(), 'iptables -F') for vm in (vm1, vm2)] test_stub.check_icmp_connection_to_public_ip(vm1, expected_result='PASS') test_stub.check_icmp_connection_to_public_ip(vm2, expected_result='PASS') test_util.test_dsc("disable snat") vr1_uuid = vr_list[0].inv.uuid for i in range(0,101): vpc_ops.set_vpc_vrouter_network_service_state(vr1_uuid, networkService='SNAT', state='disable') test_stub.check_icmp_connection_to_public_ip(vm1, expected_result='FAIL') vpc_ops.set_vpc_vrouter_network_service_state(vr1_uuid, networkService='SNAT', state='enable') test_stub.check_icmp_connection_to_public_ip(vm1, expected_result='PASS') test_lib.lib_error_cleanup(test_obj_dict) test_stub.remove_all_vpc_vrouter()
def test(): test_util.test_dsc("create vr vm and vpc vrouter") vm = test_stub.create_vr_vm('vr_vm','imageName_s','l3NoVlanNetworkName2') test_obj_dict.add_vm(vm) if not test_lib.lib_find_vr_by_vm(vm.vm) or not test_lib.lib_find_vr_by_vm(vm.vm)[0]: test_lib.lib_error_cleanup(test_obj_dict) test_util.test_skip("skip the test for no vr found in the env.") vpc_vr = test_stub.create_vpc_vrouter() check_host_prometheus_conf() check_vrouter_prometheus_conf() check_prometheus_data() hosts = test_lib.lib_get_all_hosts_from_plan() for host in hosts: host_ops.reconnect_host(host_uuid) check_host_prometheus_conf() check_vrouter_prometheus_conf() check_prometheus_data() test_lib.lib_execute_ssh_cmd(mn_ip,"root","password","zstack-ctl restart_node",timeout=300) check_host_prometheus_conf() check_vrouter_prometheus_conf() check_prometheus_data() test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Test prometheus Success')
def test(): h1_name = os.environ.get("hostName") cond = res_ops.gen_query_conditions('name', '=', h1_name) h1 = res_ops.query_resource(res_ops.HOST, cond) ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard") vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid, host_uuid=h1[0].uuid) assert vm1.get_vm().hostUuid == h1[0].uuid test_obj_dict.add_vm(vm1) h2_name = os.environ.get("hostName2") cond = res_ops.gen_query_conditions('name', '=', h2_name) h2 = res_ops.query_resource(res_ops.HOST, cond) vm2 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid, host_uuid=h2[0].uuid) assert vm2.get_vm().hostUuid == h2[0].uuid test_obj_dict.add_vm(vm2) try: vm1.migrate(vm2.get_vm().hostUuid) except: test_util.test_logger("vm1 is not expected to migrate to host2 [uuid: %s]" % vm2.get_vm().hostUuid) h3_name = os.environ.get("hostName3") cond = res_ops.gen_query_conditions('name', '=', h3_name) h3 = res_ops.query_resource(res_ops.HOST, cond) vm1.migrate(h3[0].uuid) vm1.migrate(h1[0].uuid) test_lib.lib_error_cleanup(test_obj_dict) ag_ops.delete_affinity_group(ag1.uuid) test_util.test_pass("Affinity Group antiHard policy pass")
def test(): global test_obj_dict ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern1 = 'L3-%s'%os.environ['dportgroup'] if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern1): network_pattern1 = 'L3-%s'%os.environ['portgroup0'] disk_offering1 = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName')) vm = test_stub.create_vm_in_vcenter(vm_name = 'test_for_sync_volume_size_vm', image_name = ova_image_name, l3_name = network_pattern1) test_obj_dict.add_vm(vm) vm.check() ps_uuid = vm.vm.allVolumes[0].primaryStorageUuid volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering1.uuid) volume_creation_option.set_name('test_for_sync_volume_size_volume') volume_creation_option.set_primary_storage_uuid(ps_uuid) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() #SyncVolumeSize vol_ops.sync_volume_size(volume.get_volume().uuid) volume.attach(vm) volume.check() vol_ops.sync_volume_size(volume.get_volume().uuid) #cleanup test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass("Test sync volume size in vcenter passed.")
def test(): h1_name = os.environ.get("hostName") cond = res_ops.gen_query_conditions('name', '=', h1_name) h1 = res_ops.query_resource(res_ops.HOST, cond) ag1 = ag_ops.create_affinity_group(name="ag1", policy="antiHard") vm1 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid, host_uuid=h1[0].uuid) assert vm1.get_vm().hostUuid == h1[0].uuid test_obj_dict.add_vm(vm1) h2_name = os.environ.get("hostName2") cond = res_ops.gen_query_conditions('name', '=', h2_name) h2 = res_ops.query_resource(res_ops.HOST, cond) vm2 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid, host_uuid=h2[0].uuid) assert vm2.get_vm().hostUuid == h2[0].uuid test_obj_dict.add_vm(vm2) try: vm3 = None vm3 = test_stub.create_ag_vm(affinitygroup_uuid=ag1.uuid, host_uuid=h2[0].uuid) except: if not vm3: test_util.test_logger("vm3 isn't created as expected") finally: if vm3: test_util.test_fail("Test Fail, vm3 [uuid:%s] is not expected to be created" % vm3.get_vm().uuid) test_lib.lib_error_cleanup(test_obj_dict) ag_ops.delete_affinity_group(ag1.uuid) test_util.test_pass("Affinity Group antiHard policy pass")
def test(): global vm loop = 20 count = 0 vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_libvirt_snapshot_vm", image_name, l3_name) test_obj_dict.add_vm(vm) vm.check() volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid snapshots = test_obj_dict.get_volume_snapshot(volume_uuid) snapshots.set_utility_vm(vm) while count <= loop: sp_name = "create_snapshot" + str(count) snapshots.create_snapshot(sp_name) snapshots.check() count += 1 host = test_lib.lib_find_host_by_vm(vm.get_vm()) result = test_lib.lib_execute_ssh_cmd(host.managementIp, 'root', 'password', 'service libvirtd restart') time.sleep(600) vm.check() snapshots.check() snapshots.delete() test_obj_dict.rm_volume_snapshot(snapshots) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Libvirt restart with snapshot passed')
def error_cleanup(): global schd test_lib.lib_error_cleanup(test_obj_dict) if schd: schd_ops.delete_scheduler(schd.uuid)
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) if schd_job: schd_ops.del_scheduler_job(schd_job.uuid) if schd_trigger: schd_ops.del_scheduler_trigger(schd_trigger.uuid)
def error_cleanup(): global image1 test_lib.lib_error_cleanup(test_obj_dict) try: image1.delete() except: pass
def error_cleanup(): global test_obj_dict global test_file_des global ct_original con_ops.change_global_config('vm', 'cleanTraffic', ct_original) os.system('rm -f %s' % test_file_des) test_lib.lib_error_cleanup(test_obj_dict)
def env_recover(): local_ps, shared_ps = test_stub.PSEnvChecker().get_two_ps() if local_ps.state == 'Disabled': ps_ops.change_primary_storage_state(local_ps.uuid, state='enable') if shared_ps.state == 'Disabled': ps_ops.change_primary_storage_state(shared_ps.uuid, state='enable') test_lib.lib_error_cleanup(test_obj_dict)
def test(): global test_obj_dict volumes = [] ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern = 'L3-%s'%os.environ['dportgroup'] if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern): network_pattern = 'L3-%s'%os.environ['portgroup0'] disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName')) #create vm with disk vm = test_stub.create_vm_in_vcenter(vm_name = 'vm_2', image_name = ova_image_name, l3_name = network_pattern, disk_offering_uuids = [disk_offering.uuid, disk_offering.uuid] ) test_obj_dict.add_vm(vm) vm.check() vcenter = os.environ.get('vcenter') SI = vct_ops.connect_vcenter(vcenter) content = SI.RetrieveContent() vm = vct_ops.get_vm(content, name = 'vm_2')[0] vct_ops.delete_virtual_disk(vm, 2) vct_ops.delete_virtual_disk(vm, 2) vcenter_uuid = vct_ops.lib_get_vcenter_by_name(vcenter).uuid vct_ops.sync_vcenter(vcenter_uuid) time.sleep(5) allvolumes = vct_ops.lib_get_vm_by_name('vm_2').allVolumes assert len(allvolumes) == 1 for volume in allvolumes: if volume.type == 'Data': volumes.append(volume.installPath) assert set(volumes) == set([]) #cleanup test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass("sync after detaching disk from vm in vmware test passed.")
def test(): l3_vr_network = os.environ['l3vCenterNoVlanNetworkName'] image_name = os.environ['image_dhcp_name'] vm = test_stub.create_vm_in_vcenter(vm_name='vm', image_name = image_name, l3_name=l3_vr_network) test_obj_dict.add_vm(vm) vm.check() clone_vm = vm.clone(['clone_vm'])[0] test_obj_dict.add_vm(clone_vm) clone_vm.check() names = [] for i in range(3): names.append('clone' + str(i+1)) clone_vms = clone_vm.clone(names) for _vm in clone_vms: _vm.check() test_obj_dict.add_vm(_vm) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass("test vcenter clone vm pass")
def test(): test_lib.lib_set_vm_numa('true') vm = test_stub.create_vr_vm('migrate_vm', 'imageName3', 'l3VlanNetwork2') test_obj_dict.add_vm(vm) vm.check() (available_cpu_before, available_memory_before, vm_outer_cpu_before, vm_outer_mem_before, vm_interal_cpu_before, vm_interal_mem_before) = test_stub.check_cpu_mem(vm) test_stub.migrate_vm_to_random_host(vm) vm.check() vm_instance_offering = test_lib.lib_get_instance_offering_by_uuid(vm.get_vm().instanceOfferingUuid) MEMchange = 126*1024*1024 AlignedMemChange = 128*1024*1024 vm_ops.update_vm(vm.get_vm().uuid, vm_instance_offering.cpuNum + 1, vm_instance_offering.memorySize + MEMchange) vm.update() time.sleep(10) vm.check() (available_cpu_after, available_memory_after, vm_outer_cpu_after, vm_outer_mem_after, vm_interal_cpu_after, vm_internal_mem_after) = test_stub.check_cpu_mem(vm) assert available_cpu_before == available_cpu_after + 1 assert available_memory_after + AlignedMemChange / float(test_lib.lib_get_provision_memory_rate()) in range(available_memory_before-1, available_memory_before+1) assert vm_outer_cpu_before == vm_outer_cpu_after - 1 assert vm_outer_mem_before == vm_outer_mem_after - AlignedMemChange assert vm_interal_cpu_before == vm_interal_cpu_after - 1 assert vm_interal_mem_before == vm_internal_mem_after - AlignedMemChange/1024/1024 test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('VM online change instance offering after migration Test Pass')
def test(): global test_obj_dict #enable vmware vmotion SI = vct_ops.connect_vcenter(os.environ['vcenter']) content = SI.RetrieveContent() hosts = vct_ops.get_host(content) for host in hosts: vct_ops.enable_vmotion(host) network_pattern = 'L3-%s'%os.environ['dportgroup'] if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern): network_pattern = 'L3-%s'%os.environ['portgroup0'] ova_image_name = os.environ['vcenterDefaultmplate'] disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('largeDiskOfferingName')) #create vm vm = test_stub.create_vm_in_vcenter(vm_name = 'migrate_vm', image_name = ova_image_name, l3_name = network_pattern) vm.check() test_obj_dict.add_vm(vm) #check whether vm migration candidate hosts exist candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm.vm.uuid).inventories if candidate_hosts == []: test_util.test_logger('Not find vm migration candidate hosts, skip test migrate vm') else: test_util.test_dsc('Migrate vm to the specified host') host_uuid = candidate_hosts[0].uuid vm_ops.migrate_vm(vm.vm.uuid, host_uuid) vm.update() vm.check() #check whether the specified host is effective assert candidate_hosts[0].name == test_lib.lib_find_host_by_vm(vm.vm).name #check the consistency of the migration in zstack and vmware assert candidate_hosts[0].name == vct_ops.find_host_by_vm(content, vm.vm.name) test_util.test_dsc('vm in suspended state does not allow migration') vm.suspend() candidate_host = vm_ops.get_vm_migration_candidate_hosts(vm.vm.uuid).inventories assert candidate_host == [] #create vm with disk vm1 = test_stub.create_vm_in_vcenter(vm_name = 'migrate_vm_with_disk', image_name = ova_image_name, l3_name = network_pattern, disk_offering_uuids = [disk_offering.uuid]) vm1.check() test_obj_dict.add_vm(vm1) #check whether vm migration candidate hosts exist candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm1.vm.uuid).inventories if candidate_hosts == []: test_util.test_logger('Not find vm migration candidate hosts, skip test migrate vm with disk') else: test_util.test_dsc('Migrate vm with disk to the specified host') host_uuid = candidate_hosts[0].uuid vm_ops.migrate_vm(vm1.vm.uuid, host_uuid) vm1.update() vm1.check() assert candidate_hosts[0].name == test_lib.lib_find_host_by_vm(vm1.vm).name assert candidate_hosts[0].name == vct_ops.find_host_by_vm(content, vm1.vm.name) #cleanup test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass("Migrate vm test passed.")
def test(): test_util.test_dsc("STEP1: Ceate vm instance offering") vm_instance_offering = test_lib.lib_create_instance_offering(cpuNum = 1, memorySize = 1024 * 1024 * 1024) test_obj_dict.add_instance_offering(vm_instance_offering) test_util.test_dsc("STEP2: Ceate vm and wait until it up for testing") vm = test_stub.create_vm(vm_name = 'ckvmoffering-c6-64', image_name = "imageName_i_c6", instance_offering_uuid=vm_instance_offering.uuid) test_obj_dict.add_vm(vm) vm.check() test_util.test_dsc("STEP3: Continuously Hot Plugin CPU and Memory and check capacity") last_cpu = vm_instance_offering.cpuNum last_mem = vm_instance_offering.memorySize cpu_change = 0 mem_change_list = [random.randint(0, 500)*1024*1024 for _ in xrange(8)] for mem_change in mem_change_list: with test_stub.CapacityCheckerContext(vm, cpu_change, mem_change) as cc: vm_ops.update_vm(vm.get_vm().uuid, last_cpu + cpu_change, last_mem + mem_change) last_cpu += cpu_change last_mem += cc.mem_aligned_change vm.update() test_stub.online_hotplug_cpu_memory(vm) time.sleep(5) test_util.test_dsc("STEP4: Destroy test object") test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('VM online change instance offering Test Pass')
def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] ps_env = test_stub.PSEnvChecker() local_ps, shared_ps = ps_env.get_two_ps() disk_offering_uuids = [random.choice(res_ops.get_resource(res_ops.DISK_OFFERING)).uuid] test_util.test_dsc("Create VM: {}".format(os.environ.get('CASE_FLAVOR'))) vm = test_stub.create_vm_with_random_offering(vm_name='test_vm', disk_offering_uuids=disk_offering_uuids if flavor["data_vol"] else None, ps_uuid=local_ps.uuid if flavor["root_vol"] is LOCAL else shared_ps.uuid, l3_name='l3VlanNetworkName1', image_name='imageName_net', system_tags=['primaryStorageUuidForDataVolume::{}'.format(local_ps.uuid if flavor["data_vol"] in (LOCAL, MIXED) else shared_ps.uuid)] if flavor["data_vol"] else None) test_obj_dict.add_vm(vm) vm.check() if flavor['data_vol'] is MIXED: test_util.test_dsc("Create volume from shared_ps and attached to VM") volume = test_stub.create_multi_volumes(count=1, ps=shared_ps)[0] test_obj_dict.add_volume(volume) volume.attach(vm) vm.check() test_util.test_dsc("perform basic ops on vm") for action in ('stop', 'start', 'check', 'reboot', 'check', 'suspend', 'resume', 'check'): getattr(vm, action)() test_lib.lib_error_cleanup(test_obj_dict)
def env_recover(): with test_lib.ignored(AttributeError): test.pf1.delete() with test_lib.ignored(AttributeError): test.pf2.delete() test_lib.lib_error_cleanup(test_obj_dict) test_stub.remove_all_vpc_vrouter()
def error_cleanup(): global project_uuid,project_operator_uuid, vxlan_pool_uuid,vni_range_uuid,l2_vxlan_network_uuid,account1_uuid,account2_uuid if project_operator_uuid: iam2_ops.delete_iam2_virtual_id(project_operator_uuid) if project_uuid: iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) if vni_range_uuid: vxlan_ops.delete_vni_range(vni_range_uuid) vpc_ops.remove_all_vpc_vrouter() test_lib.lib_error_cleanup(test_obj_dict) if vxlan_pool_uuid: net_ops.delete_l2(vxlan_pool_uuid) if l2_vxlan_network_uuid: net_ops.delete_l2(l2_vxlan_network_uuid) if account1_uuid: acc_ops.delete_account(account1_uuid) if account2_uuid: acc_ops.delete_account(account2_uuid) if platform_admin_uuid: iam2_ops.delete_iam2_virtual_id(platform_admin_uuid)
def env_recover(): test_util.test_dsc("Destroy test object") test_lib.lib_error_cleanup(test_obj_dict) if new_ps_list: for new_ps in new_ps_list: ps_ops.detach_primary_storage(new_ps.uuid, new_ps.attachedClusterUuids[0]) ps_ops.delete_primary_storage(new_ps.uuid)
def test(): global vm vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') l3_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vm("test_resize_vm", image_name, l3_name) test_obj_dict.add_vm(vm) vm.check() vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size volume_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid set_size = 1024*1024*1024*5 vol_ops.resize_volume(volume_uuid, set_size) vm.update() vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm) image_option = test_util.ImageOption() image_option.set_root_volume_uuid(volume_uuid) image_option.set_name('image_resize_template') image_option.set_backup_storage_uuid_list([bs_list[0].uuid]) image = img_ops.create_root_volume_template(image_option) new_vm = test_stub.create_vm("test_vm_after_resize", 'image_resize_template', l3_name) test_obj_dict.add_vm(new_vm) new_vm.check() new_volume_uuid = test_lib.lib_get_root_volume_uuid(new_vm.get_vm()) vol_size_after = test_lib.lib_get_root_volume(new_vm.get_vm()).size if set_size != vol_size_after: test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Create Template for Resize VM Test Success')
def error_cleanup(): global default_snapshot_depth conf_ops.change_global_config('volumeSnapshot', \ 'incrementalSnapshot.maxNum', default_snapshot_depth) test_lib.lib_error_cleanup(test_obj_dict)
def error_cleanup(): global test_obj_dict global pf_dict test_lib.lib_error_cleanup(test_obj_dict) for j in pf_dict: net_ops.delete_port_forwarding(pf_dict[j])
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) os.system('rm -f %s' % tmp_file)
def error_cleanup(): global test_obj_dict test_lib.lib_error_cleanup(test_obj_dict)
def env_recover(): test_lib.lib_error_cleanup(test_obj_dict) test_stub.remove_all_vpc_vrouter()
def env_recover(): test_lib.lib_error_cleanup(test_obj_dict)
def test(): global mevoco1_ip global mevoco2_ip global ipsec1 global ipsec2 mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['secondZStackMnIp'] os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip l3_uuid1 = test_lib.lib_get_l3_by_name( os.environ.get('l3PublicNetworkName')).uuid pri_l3_uuid1 = test_lib.lib_get_l3_by_name( os.environ.get('l3VlanNetworkName1')).uuid vip1 = test_stub.create_vip('ipsec1_vip', l3_uuid1) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid1) first_zstack_cidrs = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip pri_l3_uuid2 = test_lib.lib_get_l3_by_name( os.environ.get('l3VlanDNATNetworkName')).uuid cond = res_ops.gen_query_conditions('name', '=', 'virtual-router-vm') l3_uuid2 = res_ops.query_resource(res_ops.VR_OFFERING, cond)[0].publicNetworkUuid vip2 = test_stub.create_vip('ipsec2_vip', l3_uuid2) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid2) second_zstack_cidrs = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create ipsec in mevoco1') ipsec1 = ipsec_ops.create_ipsec_connection('ipsec1', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [second_zstack_cidrs]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [first_zstack_cidrs]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create test vm in mevoco1') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm1) vm1.check() os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create test vm in mevoco2') vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict2.add_vm(vm2) vm2.check() os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail( 'vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail( 'vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip ipsec_ops.delete_ipsec_connection(ipsec1.uuid) if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail( 'vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail( 'vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] after Ipsec is deleted' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_lib.lib_error_cleanup(test_obj_dict1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_lib.lib_error_cleanup(test_obj_dict2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_pass('Create Ipsec Success')
def env_recover(): for maintenance_ps in maintenance_ps_list: ps_ops.change_primary_storage_state(maintenance_ps.uuid, state='enable') test_lib.lib_error_cleanup(test_obj_dict)
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) if original_rate: test_lib.lib_set_provision_storage_rate(original_rate)
def error_cleanup(): global test_obj_dict global Port global ct_original con_ops.change_global_config('vm', 'cleanTraffic', ct_original) test_lib.lib_error_cleanup(test_obj_dict)
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) if volume_offering_uuid: vol_ops.delete_disk_offering(volume_offering_uuid)
def test(): global test_obj_dict, bs #judge whether BS is imagestore bs = res_ops.query_resource(res_ops.BACKUP_STORAGE) for i in bs: if i.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: break else: test_util.test_skip('Skip test on non-imagestore') #Skip for AliyunNAS PS ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for i in ps: if i.type == 'AliyunNAS': test_util.test_skip('Skip test on AliyunNAS PS') volume_creation_option = test_util.VolumeOption() test_util.test_dsc('Create volume and check') disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('smallDiskOfferingName')) volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume_uuid = volume.volume.uuid vol_size = volume.volume.size image_name = os.environ.get('imageName_s') l3_name = os.environ.get('l3PublicNetworkName') vm = test_stub.create_vm("test_vm", image_name, l3_name) #vm.check() test_obj_dict.add_vm(vm) volume.attach(vm) vm.stop() new_vm = vm.clone(['test_vm_clone_with_one_data_volume'], full=True)[0] test_obj_dict.add_vm(new_vm) volumes_number = len(test_lib.lib_get_all_volumes(new_vm.vm)) if volumes_number != 2: test_util.test_fail( 'Did not find 2 volumes for [vm:] %s. But we assigned 2 data volume when create the vm. We only catch %s volumes' % (new_vm.vm.uuid, volumes_number)) else: test_util.test_logger('Find 2 volumes for [vm:] %s.' % new_vm.vm.uuid) #Set_size = 1024*1024*1024*5 #Vol_ops.resize_data_volume(volume_uuid, set_size) #Vm.update() #Vol_size_after = test_lib.lib_get_data_volumes(vm.get_vm())[0].size #If set_size != vol_size_after: # test_util.test_fail('Resize Data Volume failed, size = %s' % vol_size_after) #Volume.detach() #Vm.update() #Target_host = test_lib.lib_find_random_host(vm.get_vm()) #Vol_ops.migrate_volume(volume_uuid, target_host.uuid) #Cond = res_ops.gen_query_conditions('uuid', '=', volume_uuid) #Data_volume = res_ops.query_resource(res_ops.VOLUME, cond) #Vol_size_after = data_volume[0].size #If set_size != vol_size_after: # test_util.test_fail('Resize Data Volume failed, size = %s' % vol_size_after) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Test clone vm with one data volume Success')
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) if new_offering_uuid: vm_ops.delete_instance_offering(new_offering_uuid)
def error_cleanup(): global test_obj_dict hybrid.tear_down() test_lib.lib_error_cleanup(test_obj_dict)
def error_cleanup(): test_lib.lib_set_vm_numa('false') test_lib.lib_error_cleanup(test_obj_dict)
def error_cleanup(): global test_obj_dict global delete_policy test_lib.lib_error_cleanup(test_obj_dict) test_lib.lib_set_delete_policy('vm', delete_policy)
def test(): global mevoco1_ip global mevoco2_ip global ipsec1 global ipsec2 mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['secondZStackMnIp'] test_util.test_dsc('Create test vm in mevoco1') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm1) vm1.check() pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vip1 = test_stub.create_vip('ipsec1_vip', l3_uuid1) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid1) first_zstack_cidrs = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create test vm in mevoco2') vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict2.add_vm(vm2) vm2.check() pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vip2 = test_stub.create_vip('ipsec2_vip', l3_uuid2) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid2) second_zstack_cidrs = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create ipsec in mevoco1') ipsec1 = ipsec_ops.create_ipsec_connection('ipsec1', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [second_zstack_cidrs], ike_auth_algorithm="sha384") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [first_zstack_cidrs], ike_auth_algorithm="sha384") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail( 'vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail( 'vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip ipsec_ops.delete_ipsec_connection(ipsec1.uuid) if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail( 'vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail( 'vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] after Ipsec is deleted' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_lib.lib_error_cleanup(test_obj_dict1) vip1.delete() test_obj_dict1.rm_vip(vip1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_lib.lib_error_cleanup(test_obj_dict2) vip2.delete() test_obj_dict2.rm_vip(vip2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_pass('Create Ipsec Success')
def test(): global mevoco1_ip global mevoco2_ip global ipsec1 global ipsec2 mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['secondZStackMnIp'] test_util.test_dsc('Create test vm in mevoco1') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm1) vm1.check() pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vip1 = test_stub.create_vip('ipsec1_vip', l3_uuid1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create test vm in mevoco2') vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict2.add_vm(vm2) vm2.check() pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vip2 = test_stub.create_vip('ipsec2_vip', l3_uuid2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create ipsec in mevoco1') ipsec1 = ipsec_ops.create_ipsec_connection('ipsec1', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [os.environ['secondZStackCidrs']]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [os.environ['firstZStackCidrs']], policy_encryption_algorithm="aes-256") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] even policyEncryptionAlgorithm is different' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] even policyEncryptionAlgorithm is different' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [os.environ['firstZStackCidrs']]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip ipsec_ops.delete_ipsec_connection(ipsec1.uuid) if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] after Ipsec is deleted' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_lib.lib_error_cleanup(test_obj_dict1) vip1.delete() test_obj_dict1.rm_vip(vip1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_lib.lib_error_cleanup(test_obj_dict2) vip2.delete() test_obj_dict2.rm_vip(vip2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_pass('Create Ipsec Success')
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) if original_rate: test_lib.lib_set_provision_storage_rate(original_rate) test_lib.lib_set_delete_policy('vm', delete_policy) test_lib.lib_set_delete_policy('volume', delete_policy)
def test(): global test_obj_dict ova_image_name = os.environ['vcenterDefaultmplate'] network_pattern1 = 'L3-%s' % os.environ['dportgroup'] if not vct_ops.lib_get_vcenter_l3_by_name(network_pattern1): network_pattern1 = 'L3-%s' % os.environ['portgroup0'] disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('largeDiskOfferingName')) #create vm with disk vm = test_stub.create_vm_in_vcenter( vm_name='vm_with_disk', image_name=ova_image_name, l3_name=network_pattern1, disk_offering_uuids=[disk_offering.uuid]) test_obj_dict.add_vm(vm) vm.check() #create vm1 without disk vm1 = test_stub.create_vm_in_vcenter(vm_name='test_detached_volume_vm', image_name=ova_image_name, l3_name=network_pattern1) test_obj_dict.add_vm(vm1) vm1.check() test_util.test_dsc('Create 2 volumes') disk_offering1 = test_lib.lib_get_disk_offering_by_name( os.environ.get('largeDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering1.uuid) volume_creation_option.set_name('vcenter_datavolume') volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume_creation_option.set_name('vcenter_datavolume1') volume1 = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume1) volume1.check() test_util.test_dsc('Attach volume to vm, volume1 to vm1') #mv vm checker later, to save some time. volume.attach(vm) volume.check() volume1.attach(vm1) volume1.check() test_util.test_dsc('Detach volume1 and attach it to vm') volume1.detach() volume1.check() volume1.attach(vm) volume1.check() test_util.test_dsc('Destroy vm and attach volume to vm1') vm.destroy() volume.attach(vm1) volume.check() test_util.test_dsc('Expunge vm and attach volume1 to vm1') vm.expunge() test_obj_dict.rm_vm(vm) volume1.attach(vm1) volume1.check() volume.detach() volume.check() volume1.delete() volume1.check() test_obj_dict.rm_volume(volume1) #cleanup test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass("Test for detached vcenter volume passed.")
def test(): global mevoco1_ip global mevoco2_ip global ipsec1 global ipsec2 mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['secondZStackMnIp'] os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip l3_uuid1 = test_lib.lib_get_l3_by_name(os.environ.get('l3PublicNetworkName')).uuid pri_l3_uuid1 = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanNetworkName1')).uuid vip1 = test_stub.create_vip('ipsec1_vip', l3_uuid1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip l3_uuid2 = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanDNATNetworkName')).uuid pri_l3_uuid2 = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanDNATNetworkName')).uuid vip2 = test_stub.create_vip('ipsec2_vip', l3_uuid2) test_util.test_dsc('Create ipsec in mevoco1') ipsec1 = ipsec_ops.create_ipsec_connection('ipsec1', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [os.environ['secondZStackCidrs']]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [os.environ['firstZStackCidrs']]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create test vm in mevoco1') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm1) vm1.check() os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create test vm in mevoco2') vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict2.add_vm(vm2) vm2.check() os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip ipsec_ops.delete_ipsec_connection(ipsec1.uuid) if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] after Ipsec is deleted' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_lib.lib_error_cleanup(test_obj_dict1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_lib.lib_error_cleanup(test_obj_dict2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_pass('Create Ipsec Success')
def error_cleanup(): global vm_inv os.system('rm -f %s' % tmp_file) sce_ops.destroy_vm(zstack_management_ip, vm_inv.uuid) test_lib.lib_error_cleanup(test_obj_dict)
def env_recover(): global curr_deploy_conf global test_obj_dict global l3_name test_lib.lib_error_cleanup(test_obj_dict) net_ops.add_l3_resource(curr_deploy_conf, l3_name)
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) os.system('rm -f %s' % test_image) test_lib.lib_set_delete_policy('image', delete_policy)
def test(): global mevoco1_ip global mevoco2_ip global ipsec1 global ipsec2 vip_bandwidth = 1 * 1024 mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['secondZStackMnIp'] test_util.test_dsc('Create test vm in mevoco1') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm1) vm1.check() vm1_inv = vm1.get_vm() vm1_nic = vm1.vm.vmNics[0] pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vip1 = test_stub.create_vip('ipsec1_vip', l3_uuid1) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid1) first_zstack_cidrs = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create test vm in mevoco2') vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict2.add_vm(vm2) vm2.check() vm2_inv = vm2.get_vm() pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vip2 = test_stub.create_vip('ipsec2_vip', l3_uuid2) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid2) second_zstack_cidrs = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create ipsec in mevoco1') ipsec1 = ipsec_ops.create_ipsec_connection('ipsec1', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [second_zstack_cidrs]) vip1_qos = net_ops.set_vip_qos(vip_uuid=vip1.get_vip().uuid, inboundBandwidth=vip_bandwidth * 8 * 1024, outboundBandwidth=vip_bandwidth * 8 * 1024) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [first_zstack_cidrs]) vip2_qos = net_ops.set_vip_qos(vip_uuid=vip2.get_vip().uuid, inboundBandwidth=vip_bandwidth * 8 * 1024, outboundBandwidth=vip_bandwidth * 8 * 1024) test_stub.make_ssh_no_password(vm2_inv) test_stub.install_iperf(vm2_inv) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_stub.make_ssh_no_password(vm1_inv) test_stub.install_iperf(vm1_inv) iptables_cmd = "iptables -F" exec_cmd_in_vm(vm1, iptables_cmd, "Failed to clean iptables.") exec_cmd_in_vm(vm2, iptables_cmd, "Failed to clean iptables.") test_stub.test_iperf_bandwidth(vm1_inv, vm2_inv, vm1_nic.ip, 5001, 5001, vip_bandwidth) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip ipsec_ops.delete_ipsec_connection(ipsec1.uuid) test_lib.lib_error_cleanup(test_obj_dict1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_lib.lib_error_cleanup(test_obj_dict2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_pass('Test Ipsec VIP Qos Success')
def test(): global linked_account_uuid, project_uuid, project_operator_uuid, account_lists, vni_range_uuid, vxlan_pool_uuid, l2_vxlan_network_uuid, account1_uuid, account2_uuid, platform_admin_uuid # create vxlan pool and vni range zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid cluster_uuid = res_ops.get_resource(res_ops.CLUSTER)[0].uuid vxlan_pool_name = 'vxlan_pool_name' vxlan_pool_uuid = vxlan_ops.create_l2_vxlan_network_pool( vxlan_pool_name, zone_uuid).uuid vxlan_ops.create_vni_range('vni_range', 20, 40, vxlan_pool_uuid) systemTags = [ "l2NetworkUuid::%s::clusterUuid::%s::cidr::{172.20.0.1/16}" % (vxlan_pool_uuid, cluster_uuid) ] net_ops.attach_l2_vxlan_pool(vxlan_pool_uuid, cluster_uuid, systemTags) # 1 create project project_name = 'test_share_project1' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid cond = res_ops.gen_query_conditions("name", '=', "test_share_project1") linked_account_uuid = res_ops.query_resource(res_ops.ACCOUNT, cond)[0].uuid # 2 create project operator project_operator_name = 'share_username1' project_operator_password = '******' attributes = [{"name": "__ProjectOperator__", "value": project_uuid}] project_operator_uuid = iam2_ops.create_iam2_virtual_id( project_operator_name, project_operator_password, attributes=attributes).uuid # 3 login in project by project operator iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid], project_uuid) project_operator_session_uuid = iam2_ops.login_iam2_virtual_id( project_operator_name, project_operator_password) project_login_uuid = iam2_ops.login_iam2_project( project_name, session_uuid=project_operator_session_uuid).uuid # todo:use the shared resources # 4 create platformAdmin and login username = '******' password = '******' platform_admin_uuid = iam2_ops.create_iam2_virtual_id(username, password).uuid attributes = [{"name": "__PlatformAdmin__"}] iam2_ops.add_attributes_to_iam2_virtual_id(platform_admin_uuid, attributes) platform_admin_session_uuid = iam2_ops.login_iam2_virtual_id( username, password) # 5 share platform admin resources to project test_stub.share_admin_resource_include_vxlan_pool( [linked_account_uuid], platform_admin_session_uuid) # use the shared resources to create vm vm = test_stub.create_vm(session_uuid=project_login_uuid) volume = test_stub.create_volume(session_uuid=project_login_uuid) test_obj_dict.add_volume(volume) test_obj_dict.add_vm(vm) l2_vxlan_network_uuid = vxlan_ops.create_l2_vxlan_network( 'l2_vxlan', vxlan_pool_uuid, zone_uuid, session_uuid=project_login_uuid).uuid virtual_router_offering_uuid = res_ops.get_resource( res_ops.VR_OFFERING)[0].uuid vpc_ops.create_vpc_vrouter('vpc_router', virtual_router_offering_uuid, session_uuid=project_login_uuid) # 6 revoke platform admin resources from project test_stub.revoke_admin_resource([linked_account_uuid], platform_admin_session_uuid) # 7 share to all #create_account account1_uuid = acc_ops.create_account('user1', 'password', 'Normal').uuid account2_uuid = acc_ops.create_account('user2', 'password', 'Normal').uuid account_lists = res_ops.query_resource(res_ops.ACCOUNT) for account in account_lists: test_stub.share_admin_resource_include_vxlan_pool( [account.uuid], platform_admin_session_uuid) # 8 revoke resources from all for account in account_lists: test_stub.revoke_admin_resource([account.uuid], platform_admin_session_uuid) # 9 Negative test test_util.test_dsc( 'Doing negative test.Try to use the resources not shared to create vm') try: test_stub.create_vm(session_uuid=project_login_uuid) except: test_util.test_logger( 'Catch excepted excepttion.can not use the resources not shared to create vm' ) else: test_util.test_fail( 'Catch wrong logic:create vm success with the resources not shared ' ) test_util.test_dsc( 'Doing negative test.Try to use the resources not shared to create volume' ) try: test_stub.create_volume(session_uuid=project_login_uuid) except: test_util.test_logger( 'Catch excepted excepttion.can not use the resources not shared to create volume' ) else: test_util.test_fail( 'Catch wrong logic:create volume success with the resources not shared ' ) test_util.test_dsc( 'Doing negative test.Try to use the resources not shared to create vxlan network' ) try: vxlan_ops.create_l2_vxlan_network('l2_vxlan', vxlan_pool_uuid, zone_uuid, session_uuid=project_login_uuid) except: test_util.test_logger( 'Catch excepted excepttion.can not use the resources not shared to create l2 vxlan' ) else: test_util.test_fail( 'Catch wrong logic:create l2 vxlan success with the resources not shared ' ) test_util.test_dsc( 'Doing negative test.Try to use the resources not shared to create vpc_vrouter ' ) try: vpc_ops.create_vpc_vrouter('vpc_router', virtual_router_offerings, session_uuid=project_login_uuid) except: test_util.test_logger( 'Catch excepted excepttion.can not use the resources not shared to create vpc_router' ) else: test_util.test_fail( 'Catch wrong logic:create vpc_router success with the resources not shared ' ) # 10 delete acc_ops.logout(project_login_uuid) iam2_ops.delete_iam2_virtual_id(project_operator_uuid) iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) vni_range_uuid = res_ops.get_resource(res_ops.VNI_RANGE)[0].uuid vxlan_ops.delete_vni_range(vni_range_uuid) vpc_ops.remove_all_vpc_vrouter() test_lib.lib_error_cleanup(test_obj_dict) net_ops.delete_l2(vxlan_pool_uuid) net_ops.delete_l2(l2_vxlan_network_uuid) acc_ops.delete_account(account1_uuid) acc_ops.delete_account(account2_uuid) iam2_ops.delete_iam2_virtual_id(platform_admin_uuid)
def error_cleanup(): global vm_inv os.system('rm -f %s' % tmp_file) if vm_inv: test_stub.destroy_vm_scenario(vm_inv.uuid) test_lib.lib_error_cleanup(test_obj_dict)
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict) if original_rate: test_lib.lib_set_provision_memory_rate(original_rate) if new_offering_uuid: vm_ops.delete_instance_offering(new_offering_uuid)
def error_cleanup(): test_lib.lib_error_cleanup(test_obj_dict)
def error_cleanup(): os.system('rm -rf -%s' % tmp_file) test_lib.lib_error_cleanup(test_obj_dict)