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(): global agent_url global vm imagestore = test_lib.lib_get_image_store_backup_storage() if imagestore == None: test_util.test_skip('Required imagestore to test') image_uuid = test_stub.get_image_by_bs(imagestore.uuid) cond = res_ops.gen_query_conditions('type', '=', 'SharedMountPoint') pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond) if len(pss) == 0: test_util.test_skip('Required %s ps to test' % (ps_type)) ps_uuid = pss[0].uuid vm = test_stub.create_vm(image_uuid=image_uuid, ps_uuid=ps_uuid) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid,'NeverStop') agent_url = KVM_MIGRATE_VM_PATH script = ''' { entity -> throw new Exception(\"shuang\") } ''' deploy_operations.remove_simulator_agent_script(agent_url) deploy_operations.deploy_simulator_agent_script(agent_url, script) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm.get_vm().uuid) start = time.time() no_exception = True if candidate_hosts != None and test_lib.lib_check_vm_live_migration_cap(vm.get_vm()): try: vm_ops.migrate_vm(vm.get_vm().uuid, candidate_hosts.inventories[0].uuid) no_exception = True except: test_util.test_logger('Expected exception for VM migration') no_exception = False else: test_util.test_skip('Required migratable host to test') if no_exception: test_util.test_fail('Expect exception for migration while there is none') vm.stop() cond = res_ops.gen_query_conditions('uuid', '=', vm.get_vm().uuid) for i in range(5): time.sleep(1) try: if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == vm_header.RUNNING: break except: test_util.test_logger('Retry until VM change to running') if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == vm_header.RUNNING: test_util.test_pass('HA after migrate failure test pass') test_util.test_fail('HA after migrate failure test fail')
def migrate_to_random_host(self, timeout=None, session_uuid=None): host_uuid = random.choice([ host.uuid for host in res_ops.get_resource(res_ops.HOST) if host.uuid != test_lib.lib_find_host_by_vm(self.inv).uuid ]) self.inv = vm_ops.migrate_vm(self.inv.uuid, host_uuid, timeout, session_uuid) super(ZstackTestVR, self).migrate(host_uuid)
def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] global agent_url global vm global live_migration ps_type = flavor['ps'] if ps_type == "Local": live_migration = config_ops.get_global_config_value('localStoragePrimaryStorage', 'liveMigrationWithStorage.allow') config_ops.change_global_config('localStoragePrimaryStorage', 'liveMigrationWithStorage.allow', 'true') imagestore = test_lib.lib_get_image_store_backup_storage() if imagestore == None: test_util.test_skip('Required imagestore to test') image_uuid = test_stub.get_image_by_bs(imagestore.uuid) cond = res_ops.gen_query_conditions('type', '=', ps_type) pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond) if len(pss) == 0: test_util.test_skip('Required %s ps to test' % (ps_type)) ps_uuid = pss[0].uuid vm = test_stub.create_vm(image_uuid=image_uuid, ps_uuid=ps_uuid) agent_url = flavor['agent_url'] agent_action = flavor['agent_action'] if agent_action == 1: agent_time = (24*60*60-60)*1000 elif agent_action == 2: agent_time = 360 * 1000 rsp = dep_ops.json_post("http://127.0.0.1:8888/test/api/v1.0/store/create", simplejson.dumps({"key": vm.get_vm().uuid, "value": '{"%s":%s}' % (agent_url, agent_action)})) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm.get_vm().uuid) start = time.time() if candidate_hosts != None and test_lib.lib_check_vm_live_migration_cap(vm.get_vm()): vm_ops.migrate_vm(vm.get_vm().uuid, candidate_hosts.inventories[0].uuid) else: test_util.test_skip('Required migratable host to test') end = time.time() if end - start < agent_time / 2 / 1000: test_util.test_fail('execution time too short %s' % (end - start))
def running_vm_operations(vm,bss): numa = config_ops.get_global_config_value('vm', 'numa') live_migration = config_ops.get_global_config_value('localStoragePrimaryStorage','liveMigrationWithStorage.allow') ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) vm_uuid = vm.get_vm().uuid #change vm's instanceoffering if numa == 'false': try: vm_ops.update_vm(vm_uuic,2,2048*1024*1024) test_util.test_fail('Test Fail.Cannot change instanceoffering of running vm when NUMA is false') except: config_ops.change_global_config('vm','numa','true') vm_ops.reboot_vm(vm_uuid) vm_ops.update_vm(vm_uuid,2,2048*1024*1024) #Change vm's status;set ha level/stop/del ha level/reboot/pause/resume/force stop ha_ops.set_vm_instance_ha_level(vm_uuid,'NeverStop') vm_ops.stop_vm(vm_uuid) ha_ops.del_vm_instance_ha_level(vm_uuid) vm_ops.stop_vm(vm_uuid) vm_ops.start_vm(vm_uuid) vm_ops.reboot_vm(vm_uuid) vm_ops.suspend_vm(vm_uuid) vm_ops.resume_vm(vm_uuid) vm_ops.stop_vm(vm_uuid,'cold') vm_ops.start_vm(vm_uuid) #clone vms vm_ops.clone_vm(vm_uuid,['vm-1','vm-2','vm-3'],'InstantStart') #migrate candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) migrate_host_uuids = [] if candidate_hosts == None: pass else: for host in candidate_hosts.inventories: migrate_host_uuids.append(host.uuid) if ps.type == 'LocalStorage': if live_migration == 'false': try: vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) test_util.test_fail('Test Fail.Cannot migrate localstorage vm when liveMigrationWithStorage is false.' ) except: config_ops.change_global_config('localStoragePrimaryStorage','liveMigrationWithStorage.allow','true') else: vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) test_util.test_logger('migrate vm success') else: vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0]) test_util.test_logger('migrate vm success') #change vm's password(qga) try: vm_ops.change_vm_password(vm_uuid,'root','testpassword') test_util.test_fail('Test Fail.Cannot change vm password when qga is disabled.') except: vm_ops.set_vm_qga_enable(vm_uuid) vm_ops.change_vm_password(vm_uuid,'root','testpassword') vm_ops.set_vm_qga_disable(vm_uuid) #snapshot operations sp_option = test_util.SnapshotOption() vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid test_util.test_logger('rootvolumerunning:%s' % root_volume_uuid) sp_option.set_volume_uuid(root_volume_uuid) sp = vol_ops.create_snapshot(sp_option) vm_ops.stop_vm(vm_uuid) vol_ops.use_snapshot(sp.uuid) vm_ops.start_vm(vm_uuid) vol_ops.delete_snapshot(sp.uuid) common_operations(vm,bss,'running') vm_ops.destroy_vm(vm_uuid) vm_ops.recover_vm(vm_uuid) vm_ops.start_vm(vm_uuid) vm.destroy() vm.expunge()
def test(): host = dict() host['Broadwell'] = [] host['Haswell-noTSX'] = [] _hosts = res_ops.query_resource(res_ops.HOST) if len(_hosts) < 4: test_util.test_fail("this case need at least 4 hosts") for i in _hosts[:2]: test_stub.set_host_cpu_model(i.managementIp, model='Broadwell') host['Broadwell'].append(i) for i in _hosts[2:]: test_stub.set_host_cpu_model(i.managementIp, model='Haswell-noTSX') host['Haswell-noTSX'].append(i) hosts = host['Broadwell'] + host['Haswell-noTSX'] clusters = res_ops.query_resource(res_ops.CLUSTER) for i in clusters: cls_ops.delete_cluster(i.uuid) clusters = [] zone = res_ops.query_resource(res_ops.ZONE)[0] cluster_option = test_util.ClusterOption() cluster_option.set_hypervisor_type('KVM') cluster_option.set_zone_uuid(zone.uuid) cluster_option.set_name('Broadwell_1') cluster1 = cls_ops.create_cluster(cluster_option) tag_ops.create_system_tag('ClusterVO', cluster1.uuid, tag="clusterKVMCpuModel::Broadwell") clusters.append(cluster1) cluster_option.set_name('Broadwell_2') cluster2 = cls_ops.create_cluster(cluster_option) tag_ops.create_system_tag('ClusterVO', cluster2.uuid, tag="clusterKVMCpuModel::Broadwell") clusters.append(cluster2) cluster_option.set_name('Haswell-noTSX_1') cluster3 = cls_ops.create_cluster(cluster_option) tag_ops.create_system_tag('ClusterVO', cluster3.uuid, tag="clusterKVMCpuModel::Haswell-noTSX") clusters.append(cluster3) conditions = res_ops.gen_query_conditions('name', '=', 'vlan-test9') l2 = res_ops.query_resource(res_ops.L2_VLAN_NETWORK, conditions)[0] conditions = res_ops.gen_query_conditions('name', '=', 'l2-public') l2_public = res_ops.query_resource(res_ops.L2_NETWORK, conditions)[0] ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) _hosts = [] for i in range(len(clusters)): net_ops.attach_l2(l2.uuid, clusters[i].uuid) net_ops.attach_l2(l2_public.uuid, clusters[i].uuid) for j in ps: ps_ops.attach_primary_storage(j.uuid, clusters[i].uuid) host_option = test_util.HostOption() host_option.set_cluster_uuid(clusters[i].uuid) host_option.set_username('root') host_option.set_password('password') host_option.set_name(hosts[i].managementIp) host_option.set_management_ip(hosts[i].managementIp) _hosts.append(host_ops.add_kvm_host(host_option)) # test host_option = test_util.HostOption() host_option.set_cluster_uuid(clusters[0].uuid) host_option.set_username('root') host_option.set_password('password') host_option.set_name(hosts[3].managementIp) host_option.set_management_ip(hosts[3].managementIp) try: _hosts.append(host_ops.add_kvm_host(host_option)) except Exception as e: test_util.test_logger(e) host_option.set_cluster_uuid(clusters[2].uuid) try: _hosts.append(host_ops.add_kvm_host(host_option)) except Exception as e: test_util.test_fail("test cluster cpu model faild") # migrate vm conditions = res_ops.gen_query_conditions('name', '=', 'ttylinux') img = res_ops.query_resource(res_ops.IMAGE, conditions)[0] ins = res_ops.query_resource(res_ops.INSTANCE_OFFERING)[0] conditions = res_ops.gen_query_conditions('name', '=', 'l3VlanNetwork9') l3 = res_ops.query_resource(res_ops.L3_NETWORK, conditions)[0] vms = [] for i in [0, 2]: vm_option = test_util.VmOption() vm_option.set_name("vm") vm_option.set_image_uuid(img.uuid) vm_option.set_cluster_uuid(clusters[i].uuid) vm_option.set_host_uuid(_hosts[i].uuid) vm_option.set_instance_offering_uuid(ins.uuid) vm_option.set_l3_uuids([l3.uuid]) vm_option.set_default_l3_uuid(l3.uuid) vms.append(vm_ops.create_vm(vm_option)) time.sleep(20) try: vm_ops.migrate_vm(vms[0].uuid, _hosts[1].uuid) except Exception as e: test_util.test_fail(e) try: vm_ops.migrate_vm(vms[1].uuid, _hosts[1].uuid) except Exception as e: test_util.test_logger(e) test_util.test_pass("test cluster cpu model pass")
def running_vm_operations(vm, bss): numa = config_ops.get_global_config_value('vm', 'numa') live_migration = config_ops.get_global_config_value( 'localStoragePrimaryStorage', 'liveMigrationWithStorage.allow') ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) vm_uuid = vm.get_vm().uuid #change vm's instanceoffering if numa == 'false': try: vm_ops.update_vm(vm_uuic, 2, 2048 * 1024 * 1024) test_util.test_fail( 'Test Fail.Cannot change instanceoffering of running vm when NUMA is false' ) except: config_ops.change_global_config('vm', 'numa', 'true') vm_ops.reboot_vm(vm_uuid) vm_ops.update_vm(vm_uuid, 2, 2048 * 1024 * 1024) #Change vm's status;set ha level/stop/del ha level/reboot/pause/resume/force stop ha_ops.set_vm_instance_ha_level(vm_uuid, 'neverstop') vm_ops.stop_vm(vm_uuid) ha_ops.del_vm_instance_ha_level(vm_uuid) vm_ops.stop_vm(vm_uuid) vm_ops.start_vm(vm_uuid) vm_ops.reboot_vm(vm_uuid) vm_ops.suspend_vm(vm_uuid) vm_ops.resume_vm(vm_uuid) vm_ops.stop_vm(vm_uuid, 'cold') vm_ops.start_vm(vm_uuid) #clone vms vm_ops.clone_vm(vm_uuid, ['vm-1', 'vm-2', 'vm-3'], 'InstantStart') #migrate candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) migrate_host_uuids = [] if candidate_hosts == None: pass else: for host in candidate_hosts.inventories: migrate_host_uuids.append(host.uuid) if ps.type == 'LocalStorage': if live_migration == 'false': try: vm_ops.migrate_vm(vm_uuid, migrate_host_uuids[0]) test_util.test_fail( 'Test Fail.Cannot migrate localstorage vm when liveMigrationWithStorage is false.' ) except: config_ops.change_global_config( 'localStoragePrimaryStorage', 'liveMigrationWithStorage.allow', 'true') else: vm_ops.migrate_vm(vm_uuid, migrate_host_uuids[0]) test_util.test_logger('migrate vm success') else: vm_ops.migrate_vm(vm_uuid, migrate_host_uuids[0]) test_util.test_logger('migrate vm success') #change vm's password(qga) try: vm_ops.change_vm_password(vm_uuid, 'root', 'testpassword') test_util.test_fail( 'Test Fail.Cannot change vm password when qga is disabled.') except: vm_ops.set_vm_qga_enable(vm_uuid) vm_ops.change_vm_password(vm_uuid, 'root', 'testpassword') vm_ops.set_vm_qga_disable(vm_uuid) #snapshot operations sp_option = test_util.SnapshotOption() vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume_uuid = vm_root_volume_inv.uuid test_util.test_logger('rootvolumerunning:%s' % root_volume_uuid) sp_option.set_volume_uuid(root_volume_uuid) sp = vol_ops.create_snapshot(sp_option) vm_ops.stop_vm(vm_uuid) vol_ops.use_snapshot(sp.uuid) vm_ops.start_vm(vm_uuid) vol_ops.delete_snapshot(sp.uuid) common_operations(vm, bss, 'running') vm_ops.destroy_vm(vm_uuid) vm_ops.recover_vm(vm_uuid) vm_ops.start_vm(vm_uuid) vm.destroy() vm.expunge()
def test(): global project_uuid, project_admin_uuid, virtual_id_uuid # 1 create project project_name = 'test_project' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid project_linked_account_uuid = project.linkedAccountUuid # 2 create virtual id project_admin_name = 'username' project_admin_password = '******' project_admin_uuid = iam2_ops.create_iam2_virtual_id( project_admin_name, project_admin_password).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid # 3 create project admin iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid], project_uuid) attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}] iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes) # 4 login in project by project admin project_admin_session_uuid = iam2_ops.login_iam2_virtual_id( project_admin_name, project_admin_password) project_login_uuid = iam2_ops.login_iam2_project( project_name, session_uuid=project_admin_session_uuid).uuid # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes) # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] image_option = test_util.ImageOption() image_option.set_name('fake_image') image_option.set_description('fake image') image_option.set_format('raw') image_option.set_mediaType('RootVolumeTemplate') image_option.set_backup_storage_uuid_list([bs.uuid]) image_option.url = "http://fake/fake.raw" image_option.set_session_uuid(project_login_uuid) image_uuid = img_ops.add_image(image_option).uuid img_ops.sync_image_size(image_uuid, session_uuid=project_login_uuid) img_ops.change_image_state(image_uuid, 'disable', session_uuid=project_login_uuid) img_ops.change_image_state(image_uuid, 'enable', session_uuid=project_login_uuid) if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: img_ops.export_image_from_backup_storage( image_uuid, bs.uuid, session_uuid=project_login_uuid) img_ops.delete_exported_image_from_backup_storage( image_uuid, bs.uuid, session_uuid=project_login_uuid) img_ops.set_image_qga_enable(image_uuid, session_uuid=project_login_uuid) img_ops.set_image_qga_disable(image_uuid, session_uuid=project_login_uuid) img_ops.delete_image(image_uuid, session_uuid=project_login_uuid) img_ops.expunge_image(image_uuid, session_uuid=project_login_uuid) # Volume related ops: Create, Delete, Expunge, Attach, Dettach, Enable, Disable disk_offering_uuid = res_ops.query_resource(res_ops.DISK_OFFERING)[0].uuid acc_ops.share_resources([project_linked_account_uuid], [disk_offering_uuid]) volume_option = test_util.VolumeOption() volume_option.set_disk_offering_uuid(disk_offering_uuid) volume_option.set_name('data_volume_project_management') volume_option.set_session_uuid(project_login_uuid) data_volume = vol_ops.create_volume_from_offering(volume_option) vol_ops.stop_volume(data_volume.uuid, session_uuid=project_login_uuid) vol_ops.start_volume(data_volume.uuid, session_uuid=project_login_uuid) vm_creation_option = test_util.VmOption() l3_net_uuid = test_lib.lib_get_l3_by_name( os.environ.get('l3VlanNetwork3')).uuid acc_ops.share_resources([project_linked_account_uuid], [l3_net_uuid]) vm_creation_option.set_l3_uuids([l3_net_uuid]) image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm_creation_option.set_image_uuid(image_uuid) acc_ops.share_resources([project_linked_account_uuid], [image_uuid]) instance_offering_uuid = test_lib.lib_get_instance_offering_by_name( os.environ.get('instanceOfferingName_s')).uuid vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) acc_ops.share_resources([project_linked_account_uuid], [instance_offering_uuid]) vm_creation_option.set_name('vm_for_project_management') vm_creation_option.set_session_uuid(project_login_uuid) vm = test_stub.create_vm(image_uuid=image_uuid, session_uuid=project_login_uuid) vm_uuid = vm.get_vm().uuid vol_ops.attach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid) vol_ops.detach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid) vol_ops.delete_volume(data_volume.uuid, session_uuid=project_login_uuid) vol_ops.expunge_volume(data_volume.uuid, session_uuid=project_login_uuid) # VM related ops: Create, Delete, Expunge, Start, Stop, Suspend, Resume, Migrate vm_ops.stop_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) if candidate_hosts != None and test_lib.lib_check_vm_live_migration_cap( vm.get_vm()): vm_ops.migrate_vm(vm_uuid, candidate_hosts.inventories[0].uuid, session_uuid=project_login_uuid) vm_ops.stop_vm(vm_uuid, force='cold', session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.suspend_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.resume_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.destroy_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.expunge_vm(vm_uuid, session_uuid=project_login_uuid) # L2 related ops: create, delete zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid try: l2 = net_ops.create_l2_novlan('l2_for_pm', 'eth0', zone_uuid, session_uuid=project_login_uuid) test_util.test_fail( "Expect exception: project admin not allowed to create Novlan L2 except vxlan" ) except: pass try: l2 = net_ops.create_l2_vlan('l2_for_pm', 'eth0', zone_uuid, 1234, session_uuid=project_login_uuid) test_util.test_fail( "Expect exception: project admin not allowed to create vlan L2 except vxlan" ) except: pass #net_ops.delete_l2(l2.uuid, session_uuid=project_login_uuid) # L3 related ops: # network service ops: # zwatch ops: # scheduler ops: # certificate # 11 delete acc_ops.logout(project_login_uuid) iam2_ops.delete_iam2_virtual_id(virtual_id_uuid) iam2_ops.delete_iam2_virtual_id(project_admin_uuid) iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) test_util.test_pass('success test iam2 login in by project admin!')
def test(): host = dict() host['Broadwell'] = [] host['Haswell-noTSX'] = [] _hosts = res_ops.query_resource(res_ops.HOST) if len(_hosts) < 4: test_util.test_fail("this case need at least 4 hosts") for i in _hosts[:2]: test_stub.set_host_cpu_model(i.managementIp, model='Broadwell') host['Broadwell'].append(i) for i in _hosts[2:]: test_stub.set_host_cpu_model(i.managementIp, model='Haswell-noTSX') host['Haswell-noTSX'].append(i) hosts = host['Broadwell'] + host['Haswell-noTSX'] clusters = res_ops.query_resource(res_ops.CLUSTER) for i in clusters: cls_ops.delete_cluster(i.uuid) clusters = [] zone = res_ops.query_resource(res_ops.ZONE)[0] cluster_option = test_util.ClusterOption() cluster_option.set_hypervisor_type('KVM') cluster_option.set_zone_uuid(zone.uuid) cluster_option.set_name('Broadwell_1') cluster1 = cls_ops.create_cluster(cluster_option) tag_ops.create_system_tag('ClusterVO',cluster1.uuid,tag="clusterKVMCpuModel::Broadwell") clusters.append(cluster1) cluster_option.set_name('Broadwell_2') cluster2 = cls_ops.create_cluster(cluster_option) tag_ops.create_system_tag('ClusterVO',cluster2.uuid,tag="clusterKVMCpuModel::Broadwell") clusters.append(cluster2) cluster_option.set_name('Haswell-noTSX_1') cluster3 = cls_ops.create_cluster(cluster_option) tag_ops.create_system_tag('ClusterVO',cluster3.uuid,tag="clusterKVMCpuModel::Haswell-noTSX") clusters.append(cluster3) conditions = res_ops.gen_query_conditions('name', '=', 'vlan-test9') l2 = res_ops.query_resource(res_ops.L2_VLAN_NETWORK, conditions)[0] conditions = res_ops.gen_query_conditions('name', '=', 'l2-public') l2_public = res_ops.query_resource(res_ops.L2_NETWORK, conditions)[0] ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) _hosts = [] for i in range(len(clusters)): net_ops.attach_l2(l2.uuid, clusters[i].uuid) net_ops.attach_l2(l2_public.uuid, clusters[i].uuid) for j in ps: ps_ops.attach_primary_storage(j.uuid, clusters[i].uuid) host_option = test_util.HostOption() host_option.set_cluster_uuid(clusters[i].uuid) host_option.set_username('root') host_option.set_password('password') host_option.set_name(hosts[i].managementIp) host_option.set_management_ip(hosts[i].managementIp) _hosts.append(host_ops.add_kvm_host(host_option)) # test host_option = test_util.HostOption() host_option.set_cluster_uuid(clusters[0].uuid) host_option.set_username('root') host_option.set_password('password') host_option.set_name(hosts[3].managementIp) host_option.set_management_ip(hosts[3].managementIp) try: _hosts.append(host_ops.add_kvm_host(host_option)) except Exception as e: test_util.test_logger(e) cond = res_ops.gen_query_conditions('name', '=', hosts[3].managementIp) host_uuid = res_ops.query_resource(res_ops.HOST, cond)[0].uuid host_ops.delete_host(host_uuid) host_option.set_cluster_uuid(clusters[2].uuid) try: _hosts.append(host_ops.add_kvm_host(host_option)) except Exception as e: test_util.test_fail("test cluster cpu model faild") # migrate vm conditions = res_ops.gen_query_conditions('name', '=', 'ttylinux') img = res_ops.query_resource(res_ops.IMAGE, conditions)[0] conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') ins = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0] conditions = res_ops.gen_query_conditions('name', '=', 'public network') l3 = res_ops.query_resource(res_ops.L3_NETWORK, conditions)[0] vms = [] for i in [0,2]: vm_option = test_util.VmOption() vm_option.set_name("vm") vm_option.set_image_uuid(img.uuid) vm_option.set_cluster_uuid(clusters[i].uuid) vm_option.set_host_uuid(_hosts[i].uuid) vm_option.set_instance_offering_uuid(ins.uuid) vm_option.set_l3_uuids([l3.uuid]) vm_option.set_default_l3_uuid(l3.uuid) vms.append(vm_ops.create_vm(vm_option)) time.sleep(20) try: vm_ops.migrate_vm(vms[0].uuid, _hosts[1].uuid) except Exception as e: test_util.test_fail(e) try: vm_ops.migrate_vm(vms[1].uuid, _hosts[1].uuid) except Exception as e: test_util.test_logger(e) test_util.test_pass("test cluster cpu model pass")
def test(): global host_config curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config) vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #pick up host1 host1_name = os.environ.get('hostName') host1 = res_ops.get_resource(res_ops.HOST, name = host1_name)[0] host3_name = os.environ.get('hostName3') host3 = res_ops.get_resource(res_ops.HOST, name = host3_name)[0] cond = res_ops.gen_query_conditions('clusterUuid', '=', host1.clusterUuid) cluster_hosts = res_ops.query_resource(res_ops.HOST, cond) if not len(cluster_hosts) > 1: test_util.test_skip('Skip test, since [cluster:] %s did not include more than 1 host' % host1.clusterUuid) for host in cluster_hosts: if host.uuid != host1.uuid: host2 = host 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) vm_creation_option.set_name('multizones_basic_vm') vm_creation_option.set_host_uuid(host1.uuid) l3_name = os.environ.get('l3VlanNetworkName1') l3 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name)[0] vm_creation_option.set_l3_uuids([l3.uuid]) vm1 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm1) vr_vm_inv = test_lib.lib_find_vr_by_vm(vm1.get_vm())[0] vr_host_uuid = vr_vm_inv.hostUuid #migrate vr to host3. if vr_host_uuid != host3.uuid: vm_ops.migrate_vm(vr_vm_inv.uuid, host3.uuid) host_config.set_cluster_uuid(host3.clusterUuid) host_config.set_username(os.environ.get('hostUsername')) host_config.set_password(os.environ.get('hostPassword')) host_config.set_name(host3_name) host_config.set_management_ip(host3.managementIp) target_host_uuid = host3.uuid test_util.test_dsc("Delete VR VM's host. VR should be migrated to Cluster1") host_ops.delete_host(target_host_uuid) vm1.check() #using the same L3 to create VM2 to check if VR is working well. vm_creation_option.set_host_uuid(None) vm2 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm2) vm2.check() host_ops.add_kvm_host(host_config) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Test VR migration when deleting Host is Success')
def migrate_to_random_host(self, timeout = None, session_uuid = None): host_uuid = random.choice([host.uuid for host in res_ops.get_resource(res_ops.HOST) if host.uuid != test_lib.lib_find_host_by_vm(self.inv).uuid]) self.inv = vm_ops.migrate_vm(self.inv.uuid, host_uuid, timeout, session_uuid) super(ZstackTestVR, self).migrate(host_uuid)
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(): global project_uuid, project_admin_uuid, virtual_id_uuid, project_operator_uuid, plain_user_uuid flavor = case_flavor[os.environ.get('CASE_FLAVOR')] # 1 create project project_name = 'test_project' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid project_linked_account_uuid = project.linkedAccountUuid if flavor['target_role'] == 'project_admin': # 2 create virtual id project_admin_name = 'username' project_admin_password = '******' project_admin_uuid = iam2_ops.create_iam2_virtual_id(project_admin_name, project_admin_password).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid # 3 create project admin iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],project_uuid) attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}] iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes) # login in project by project admin project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(project_admin_name, project_admin_password) project_login_uuid = iam2_ops.login_iam2_project(project_name, session_uuid=project_admin_session_uuid).uuid # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes) elif flavor['target_role'] == 'project_operator': project_operator_name = 'username2' 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 virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernamethree','password').uuid # 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 elif flavor['target_role'] == 'project_member': plain_user_name = 'username' plain_user_password = '******' plain_user_uuid = iam2_ops.create_iam2_virtual_id(plain_user_name, plain_user_password, project_uuid=project_uuid).uuid # 3 add virtual id to project iam2_ops.add_iam2_virtual_ids_to_project([plain_user_uuid],project_uuid) # 4 login in project by plain user plain_user_session_uuid = iam2_ops.login_iam2_virtual_id(plain_user_name, plain_user_password) # 4 login in project #project_inv=iam2_ops.get_iam2_projects_of_virtual_id(plain_user_session_uuid) project_login_uuid = iam2_ops.login_iam2_project(project_name, plain_user_session_uuid).uuid # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge if flavor['target_role'] == 'project_member': statements = [{"effect": "Allow", "actions": ["org.zstack.header.vm.**"]}] role_uuid = iam2_ops.create_role('test_role', statements).uuid iam2_ops.add_roles_to_iam2_virtual_id([role_uuid], plain_user_uuid) vm_creation_option = test_util.VmOption() l3_net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanNetwork3')).uuid acc_ops.share_resources([project_linked_account_uuid], [l3_net_uuid]) vm_creation_option.set_l3_uuids([l3_net_uuid]) image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm_creation_option.set_image_uuid(image_uuid) acc_ops.share_resources([project_linked_account_uuid], [image_uuid]) instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(os.environ.get('instanceOfferingName_s')).uuid vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) acc_ops.share_resources([project_linked_account_uuid], [instance_offering_uuid]) vm_creation_option.set_name('vm_for_project_management') vm_creation_option.set_session_uuid(project_login_uuid) vm = test_stub.create_vm(image_uuid = image_uuid, session_uuid=project_login_uuid) vm_uuid = vm.get_vm().uuid # VM related ops: Create, Delete, Expunge, Start, Stop, Suspend, Resume, Migrate vm_ops.stop_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) if candidate_hosts != None and test_lib.lib_check_vm_live_migration_cap(vm.get_vm()): vm_ops.migrate_vm(vm_uuid, candidate_hosts.inventories[0].uuid, session_uuid=project_login_uuid) vm_ops.stop_vm(vm_uuid, force='cold', session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.suspend_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.resume_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.destroy_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.expunge_vm(vm_uuid, session_uuid=project_login_uuid) # 11 delete acc_ops.logout(project_login_uuid) if virtual_id_uuid != None: iam2_ops.delete_iam2_virtual_id(virtual_id_uuid) if project_admin_uuid != None: iam2_ops.delete_iam2_virtual_id(project_admin_uuid) if project_operator_uuid != None: iam2_ops.delete_iam2_virtual_id(project_operator_uuid) if plain_user_uuid != None: iam2_ops.delete_iam2_virtual_id(plain_user_uuid) iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) test_util.test_pass('success test iam2 login in by project admin!')
def test(): global project_uuid, project_admin_uuid, virtual_id_uuid # 1 create project project_name = 'test_project' project = iam2_ops.create_iam2_project(project_name) project_uuid = project.uuid project_linked_account_uuid = project.linkedAccountUuid # 2 create virtual id project_admin_name = 'username' project_admin_password = '******' project_admin_uuid = iam2_ops.create_iam2_virtual_id(project_admin_name, project_admin_password).uuid virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid # 3 create project admin iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],project_uuid) attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}] iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes) # 4 login in project by project admin project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(project_admin_name, project_admin_password) project_login_uuid = iam2_ops.login_iam2_project(project_name, session_uuid=project_admin_session_uuid).uuid # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes) # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0] image_option = test_util.ImageOption() image_option.set_name('fake_image') image_option.set_description('fake image') image_option.set_format('raw') image_option.set_mediaType('RootVolumeTemplate') image_option.set_backup_storage_uuid_list([bs.uuid]) image_option.url = "http://fake/fake.raw" image_option.set_session_uuid(project_login_uuid) image_uuid = img_ops.add_image(image_option).uuid img_ops.sync_image_size(image_uuid, session_uuid=project_login_uuid) img_ops.change_image_state(image_uuid, 'disable', session_uuid=project_login_uuid) img_ops.change_image_state(image_uuid, 'enable', session_uuid=project_login_uuid) if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE: img_ops.export_image_from_backup_storage(image_uuid, bs.uuid, session_uuid=project_login_uuid) img_ops.delete_exported_image_from_backup_storage(image_uuid, bs.uuid, session_uuid=project_login_uuid) img_ops.set_image_qga_enable(image_uuid, session_uuid=project_login_uuid) img_ops.set_image_qga_disable(image_uuid, session_uuid=project_login_uuid) img_ops.delete_image(image_uuid, session_uuid=project_login_uuid) img_ops.expunge_image(image_uuid, session_uuid=project_login_uuid) # Volume related ops: Create, Delete, Expunge, Attach, Dettach, Enable, Disable disk_offering_uuid = res_ops.query_resource(res_ops.DISK_OFFERING)[0].uuid acc_ops.share_resources([project_linked_account_uuid], [disk_offering_uuid]) volume_option = test_util.VolumeOption() volume_option.set_disk_offering_uuid(disk_offering_uuid) volume_option.set_name('data_volume_project_management') volume_option.set_session_uuid(project_login_uuid) data_volume = vol_ops.create_volume_from_offering(volume_option) vol_ops.stop_volume(data_volume.uuid, session_uuid=project_login_uuid) vol_ops.start_volume(data_volume.uuid, session_uuid=project_login_uuid) vm_creation_option = test_util.VmOption() l3_net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanNetwork3')).uuid acc_ops.share_resources([project_linked_account_uuid], [l3_net_uuid]) vm_creation_option.set_l3_uuids([l3_net_uuid]) image_uuid = test_lib.lib_get_image_by_name("centos").uuid vm_creation_option.set_image_uuid(image_uuid) acc_ops.share_resources([project_linked_account_uuid], [image_uuid]) instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(os.environ.get('instanceOfferingName_s')).uuid vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) acc_ops.share_resources([project_linked_account_uuid], [instance_offering_uuid]) vm_creation_option.set_name('vm_for_project_management') vm_creation_option.set_session_uuid(project_login_uuid) vm = test_stub.create_vm(image_uuid = image_uuid, session_uuid=project_login_uuid) vm_uuid = vm.get_vm().uuid vol_ops.attach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid) vol_ops.detach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid) vol_ops.delete_volume(data_volume.uuid, session_uuid=project_login_uuid) vol_ops.expunge_volume(data_volume.uuid, session_uuid=project_login_uuid) # VM related ops: Create, Delete, Expunge, Start, Stop, Suspend, Resume, Migrate vm_ops.stop_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid) if candidate_hosts != None and test_lib.lib_check_vm_live_migration_cap(vm.get_vm()): vm_ops.migrate_vm(vm_uuid, candidate_hosts.inventories[0].uuid, session_uuid=project_login_uuid) vm_ops.stop_vm(vm_uuid, force='cold', session_uuid=project_login_uuid) vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.suspend_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.resume_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.destroy_vm(vm_uuid, session_uuid=project_login_uuid) vm_ops.expunge_vm(vm_uuid, session_uuid=project_login_uuid) # L2 related ops: create, delete zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid try: l2 = net_ops.create_l2_novlan('l2_for_pm', 'eth0', zone_uuid, session_uuid=project_login_uuid) test_util.test_fail("Expect exception: project admin not allowed to create Novlan L2 except vxlan") except: pass try: l2 = net_ops.create_l2_vlan('l2_for_pm', 'eth0', zone_uuid, 1234, session_uuid=project_login_uuid) test_util.test_fail("Expect exception: project admin not allowed to create vlan L2 except vxlan") except: pass #net_ops.delete_l2(l2.uuid, session_uuid=project_login_uuid) # L3 related ops: # network service ops: # zwatch ops: # scheduler ops: # certificate # 11 delete acc_ops.logout(project_login_uuid) iam2_ops.delete_iam2_virtual_id(virtual_id_uuid) iam2_ops.delete_iam2_virtual_id(project_admin_uuid) iam2_ops.delete_iam2_project(project_uuid) iam2_ops.expunge_iam2_project(project_uuid) test_util.test_pass('success test iam2 login in by project admin!')
def test(): global host_config curr_deploy_conf = exp_ops.export_zstack_deployment_config( test_lib.deploy_config) vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #pick up host1 host1_name = os.environ.get('hostName') host1 = res_ops.get_resource(res_ops.HOST, name=host1_name)[0] host3_name = os.environ.get('hostName3') host3 = res_ops.get_resource(res_ops.HOST, name=host3_name)[0] cond = res_ops.gen_query_conditions('clusterUuid', '=', host1.clusterUuid) cluster_hosts = res_ops.query_resource(res_ops.HOST, cond) if not len(cluster_hosts) > 1: test_util.test_skip( 'Skip test, since [cluster:] %s did not include more than 1 host' % host1.clusterUuid) for host in cluster_hosts: if host.uuid != host1.uuid: host2 = host 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) vm_creation_option.set_name('multizones_basic_vm') vm_creation_option.set_host_uuid(host1.uuid) l3_name = os.environ.get('l3VlanNetworkName1') l3 = res_ops.get_resource(res_ops.L3_NETWORK, name=l3_name)[0] vm_creation_option.set_l3_uuids([l3.uuid]) vm1 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm1) vr_vm_inv = test_lib.lib_find_vr_by_vm(vm1.get_vm())[0] vr_host_uuid = vr_vm_inv.hostUuid #migrate vr to host3. if vr_host_uuid != host3.uuid: vm_ops.migrate_vm(vr_vm_inv.uuid, host3.uuid) host_config.set_cluster_uuid(host3.clusterUuid) host_config.set_username(os.environ.get('hostUsername')) host_config.set_password(os.environ.get('hostPassword')) host_config.set_name(host3_name) host_config.set_management_ip(host3.managementIp) target_host_uuid = host3.uuid test_util.test_dsc( "Delete VR VM's host. VR should be migrated to Cluster1") host_ops.delete_host(target_host_uuid) vm1.check() #using the same L3 to create VM2 to check if VR is working well. vm_creation_option.set_host_uuid(None) vm2 = test_lib.lib_create_vm(vm_creation_option) test_obj_dict.add_vm(vm2) vm2.check() host_ops.add_kvm_host(host_config) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Test VR migration when deleting Host is Success')
def migrate(self, host_uuid): self.vm = vm_ops.migrate_vm(self.vm.uuid, host_uuid) super(ZstackTestVm, self).migrate(host_uuid)
def migrate(self, host_uuid, timeout = None, session_uuid = None): self.vm = vm_ops.migrate_vm(self.vm.uuid, host_uuid, timeout,\ session_uuid) super(ZstackTestVm, self).migrate(host_uuid)