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_vm_to_differnt_cluster(vm): test_util.test_dsc("migrate vm to different cluster") if not test_lib.lib_check_vm_live_migration_cap(vm.vm): test_util.test_skip('skip migrate if live migrate not supported') current_host = test_lib.lib_find_host_by_vm(vm.vm) conditions = res_ops.gen_query_conditions('clusterUuid', '!=', current_host.clusterUuid) candidate_hosts = res_ops.query_resource(res_ops.HOST, conditions, None) if len(candidate_hosts) == 0: test_util.test_fail('Not find available Hosts to do migration') vm.migrate(candidate_hosts[0].uuid)
def migrate_vm_to_random_host(vm): test_util.test_dsc("migrate vm to random host") if not test_lib.lib_check_vm_live_migration_cap(vm.vm): test_util.test_skip('skip migrate if live migrate not supported') target_host = test_lib.lib_find_random_host(vm.vm) current_host = test_lib.lib_find_host_by_vm(vm.vm) vm.migrate(target_host.uuid) new_host = test_lib.lib_get_vm_host(vm.vm) if not new_host: test_util.test_fail('Not find available Hosts to do migration') if new_host.uuid != target_host.uuid: test_util.test_fail('[vm:] did not migrate from [host:] %s to target [host:] %s, but to [host:] %s' % (vm.vm.uuid, current_host.uuid, target_host.uuid, new_host.uuid)) else: test_util.test_logger('[vm:] %s has been migrated from [host:] %s to [host:] %s' % (vm.vm.uuid, current_host.uuid, target_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 test(): vm1 = test_stub.create_vr_vm('maintain_host_vm1', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm1) vm2 = test_stub.create_vr_vm('maintain_host_vm2', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm2) vm1.check() vm2.check() if not test_lib.lib_check_vm_live_migration_cap(vm1.vm) or not test_lib.lib_check_vm_live_migration_cap(vm2.vm): test_util.test_skip('skip migrate if live migrate not supported') 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 = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) test_util.test_dsc('Attach volume and check') volume.attach(vm1) volume.check() current_host1 = test_lib.lib_get_vm_host(vm1.vm) conditions = res_ops.gen_query_conditions('clusterUuid', '=', vm1.vm.clusterUuid) conditions = res_ops.gen_query_conditions('state', '=', host_header.ENABLED, conditions) conditions = res_ops.gen_query_conditions('status', '=', host_header.CONNECTED, conditions) all_hosts = res_ops.query_resource(res_ops.HOST, conditions) if len(all_hosts) <= 1: test_util.test_fail('Not available host to do maintenance, since there is only %s host' % len(all_hosts)) target_host = random.choice(all_hosts) if current_host1.uuid != target_host.uuid: vm1.migrate(target_host.uuid) current_host2 = test_lib.lib_get_vm_host(vm2.vm) if current_host2.uuid != target_host.uuid: vm2.migrate(target_host.uuid) new_host = test_lib.lib_get_vm_host(vm1.vm) if new_host.uuid != target_host.uuid: test_util.test_fail('VM did not migrate to target [host:] %s, but to [host:] %s' % (target_host.uuid, new_host.uuid)) volume.check() host = test_kvm_host.ZstackTestKvmHost() host.set_host(target_host) host.maintain() #need to update vm's inventory, since they will be changed by maintenace mode vm1.update() vm2.update() vm1.check() vm2.check() volume.check() host.change_state(test_kvm_host.ENABLE_EVENT) if not linux.wait_callback_success(is_host_connected, host.get_host().uuid, 120): test_util.test_fail('host status is not changed to connected, after changing its state to Enable') vm1.migrate(target_host.uuid) vm2.migrate(target_host.uuid) vm1.check() vm2.check() volume.check() vm1.destroy() test_obj_dict.rm_vm(vm1) vm2.destroy() test_obj_dict.rm_vm(vm2) volume.delete() test_obj_dict.rm_volume(volume) test_util.test_pass('Maintain Host Test Success')
def test(): vm1 = test_stub.create_vr_vm('maintain_host_vm1', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm1) vm2 = test_stub.create_vr_vm('maintain_host_vm2', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm2) vm1.check() vm2.check() if not test_lib.lib_check_vm_live_migration_cap( vm1.vm) or not test_lib.lib_check_vm_live_migration_cap(vm2.vm): test_util.test_skip('skip migrate if live migrate not supported') current_host1 = test_lib.lib_get_vm_host(vm1.vm) current_host2 = test_lib.lib_get_vm_host(vm2.vm) conditions = res_ops.gen_query_conditions('clusterUuid', '=', vm1.vm.clusterUuid) conditions = res_ops.gen_query_conditions('state', '=', host_header.ENABLED, conditions) conditions = res_ops.gen_query_conditions('status', '=', host_header.CONNECTED, conditions) all_hosts = res_ops.query_resource(res_ops.HOST, conditions) if len(all_hosts) <= 1: test_util.test_fail( 'Not available host to do maintenance, since there is only %s host' % len(all_hosts)) vr = test_lib.lib_get_all_vrs() if len(vr) == 0: test_util.test_skip('Skip test if not using vr') vr_uuid = vr[0].uuid vr_host_uuid = test_lib.lib_get_vm_host(vr[0]).uuid for host_n in all_hosts: print 'host_n%s' % (host_n.uuid) if host_n.uuid != current_host1.uuid: if host_n.uuid != current_host2.uuid: if host_n.uuid != vr_host_uuid: target_host = host_n print 'target_host_uuid%s' % (target_host.uuid) vm1.migrate(target_host.uuid) vm2.migrate(target_host.uuid) break else: test_util.test_skip('can not find a host to migrate two host') new_host = test_lib.lib_get_vm_host(vm1.vm) if new_host.uuid != target_host.uuid: test_util.test_fail( 'VM did not migrate to target [host:] %s, but to [host:] %s' % (target_host.uuid, new_host.uuid)) new_host1 = test_lib.lib_get_vm_host(vm2.vm) if new_host1.uuid != target_host.uuid: test_util.test_fail( 'VM did not migrate to target [host:] %s, but to [host:] %s' % (target_host.uuid, new_host1.uuid)) host = test_kvm_host.ZstackTestKvmHost() host.set_host(target_host) host.maintain() #need to update vm's inventory, since they will be changed by maintenace mode vm1.update() vm2.update() ps = test_lib.lib_get_primary_storage_by_vm(vm1.get_vm()) if ps.type == inventory.LOCAL_STORAGE_TYPE: vm1.set_state(vm_header.STOPPED) vm2.set_state(vm_header.STOPPED) vm1.check() vm2.check() host.change_state(test_kvm_host.ENABLE_EVENT) if not linux.wait_callback_success(is_host_connected, host.get_host().uuid, 120): test_util.test_fail( 'host status is not changed to connected or host state is not changed to Enabled within 120s' ) if ps.type == inventory.LOCAL_STORAGE_TYPE: vm1.start() vm2.start() vm1.set_state(vm_header.RUNNING) vm2.set_state(vm_header.RUNNING) vm1.check() vm2.check() post_host1 = test_lib.lib_get_vm_host(vm1.vm) post_host2 = test_lib.lib_get_vm_host(vm2.vm) if post_host1.uuid != current_host1.uuid: vm1.migrate(current_host1.uuid) if post_host2.uuid != current_host2.uuid: vm2.migrate(current_host2.uuid) vm1.check() vm2.check() vm1.destroy() test_obj_dict.rm_vm(vm1) vm2.destroy() test_obj_dict.rm_vm(vm2) test_util.test_pass('Maintain Host Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout global test_host if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) vr_host_ips = [] for vr in vrs: vr_host_ips.append(test_lib.lib_find_host_by_vr(vr).managementIp) if test_lib.lib_is_vm_running(vr) != True: vm_ops.start_vm(vr.uuid) time.sleep(60) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '=', mn_ip, conditions) #for vr_host_ip in vr_host_ips: # conditions = res_ops.gen_query_conditions('managementIp', '!=', vr_host_ip, conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() if not test_lib.lib_check_vm_live_migration_cap(vm.vm): test_util.test_skip('skip ha if live migrate not supported') 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 localstorage') host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_util.test_logger("host %s is disconnecting" % (host_ip)) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") host_list = test_stub.get_sce_hosts(test_lib.all_scenario_config, test_lib.scenario_file) for host in host_list: if host.ip_ == host_ip: test_host = host break if not test_host: test_util.test_fail('there is no host with ip %s in scenario file.' % (host_ip)) test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold') test_util.test_logger( "wait for 30 seconds to ensure vm disconnected, then just wait 90s for target up." ) time.sleep(30) if test_lib.lib_wait_target_up(vm.vm.vmNics[0].ip, '22', 90): test_util.test_logger("%s can be connected within 120s" % (vm.vm.vmNics[0].ip)) test_stub.start_host(test_host, test_lib.all_scenario_config) vm.destroy() test_util.test_pass('Test VM ha change to running within 120s Success')
def test(): vm1 = test_stub.create_vr_vm('maintain_host_vm1', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm1) vm2 = test_stub.create_vr_vm('maintain_host_vm2', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm2) vm1.check() vm2.check() if not test_lib.lib_check_vm_live_migration_cap( vm1.vm) or not test_lib.lib_check_vm_live_migration_cap(vm2.vm): test_util.test_skip('skip migrate if live migrate not supported') ps = test_lib.lib_get_primary_storage_by_uuid( vm1.get_vm().allVolumes[0].primaryStorageUuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: test_util.test_skip( 'skip migrate vm with data volume if localstorate is used') ps = test_lib.lib_get_primary_storage_by_uuid( vm2.get_vm().allVolumes[0].primaryStorageUuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: test_util.test_skip( 'skip migrate vm with data volume if localstorate is used') 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 = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) test_util.test_dsc('Attach volume and check') volume.attach(vm1) volume.check() current_host1 = test_lib.lib_get_vm_host(vm1.vm) conditions = res_ops.gen_query_conditions('clusterUuid', '=', vm1.vm.clusterUuid) conditions = res_ops.gen_query_conditions('state', '=', host_header.ENABLED, conditions) conditions = res_ops.gen_query_conditions('status', '=', host_header.CONNECTED, conditions) all_hosts = res_ops.query_resource(res_ops.HOST, conditions) if len(all_hosts) <= 1: test_util.test_fail( 'Not available host to do maintenance, since there is only %s host' % len(all_hosts)) target_host = random.choice(all_hosts) if current_host1.uuid != target_host.uuid: vm1.migrate(target_host.uuid) current_host2 = test_lib.lib_get_vm_host(vm2.vm) if current_host2.uuid != target_host.uuid: vm2.migrate(target_host.uuid) new_host = test_lib.lib_get_vm_host(vm1.vm) if new_host.uuid != target_host.uuid: test_util.test_fail( 'VM did not migrate to target [host:] %s, but to [host:] %s' % (target_host.uuid, new_host.uuid)) volume.check() host = test_kvm_host.ZstackTestKvmHost() host.set_host(target_host) host.maintain() #need to update vm's inventory, since they will be changed by maintenace mode vm1.update() vm2.update() vm1.check() vm2.check() volume.check() host.change_state(test_kvm_host.ENABLE_EVENT) if not linux.wait_callback_success(is_host_connected, host.get_host().uuid, 120): test_util.test_fail( 'host status is not changed to connected, after changing its state to Enable' ) vm1.migrate(target_host.uuid) vm2.migrate(target_host.uuid) vm1.check() vm2.check() volume.check() vm1.destroy() test_obj_dict.rm_vm(vm1) vm2.destroy() test_obj_dict.rm_vm(vm2) volume.delete() test_obj_dict.rm_volume(volume) test_util.test_pass('Maintain Host Test Success')
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(): vm1 = test_stub.create_vr_vm('maintain_host_vm1', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm1) vm2 = test_stub.create_vr_vm('maintain_host_vm2', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm2) vm1.check() vm2.check() if not test_lib.lib_check_vm_live_migration_cap(vm1.vm) or not test_lib.lib_check_vm_live_migration_cap(vm2.vm): test_util.test_skip('skip migrate if live migrate not supported') current_host1 = test_lib.lib_get_vm_host(vm1.vm) current_host2 = test_lib.lib_get_vm_host(vm2.vm) conditions = res_ops.gen_query_conditions('clusterUuid', '=', vm1.vm.clusterUuid) conditions = res_ops.gen_query_conditions('state', '=', host_header.ENABLED, conditions) conditions = res_ops.gen_query_conditions('status', '=', host_header.CONNECTED, conditions) all_hosts = res_ops.query_resource(res_ops.HOST, conditions) if len(all_hosts) <= 1: test_util.test_fail('Not available host to do maintenance, since there is only %s host' % len(all_hosts)) vr = test_lib.lib_get_all_vrs() if len(vr) == 0: test_util.test_skip('Skip test if not using vr') vr_uuid = vr[0].uuid vr_host_uuid = test_lib.lib_get_vm_host(vr[0]).uuid for host_n in all_hosts: print'host_n%s'% (host_n.uuid) if host_n.uuid != current_host1.uuid: if host_n.uuid != current_host2.uuid: if host_n.uuid != vr_host_uuid: target_host = host_n print'target_host_uuid%s'%(target_host.uuid) vm1.migrate(target_host.uuid) vm2.migrate(target_host.uuid) break else: test_util.test_skip('can not find a host to migrate two host') new_host = test_lib.lib_get_vm_host(vm1.vm) if new_host.uuid != target_host.uuid: test_util.test_fail('VM did not migrate to target [host:] %s, but to [host:] %s' % (target_host.uuid, new_host.uuid)) new_host1 = test_lib.lib_get_vm_host(vm2.vm) if new_host1.uuid != target_host.uuid: test_util.test_fail('VM did not migrate to target [host:] %s, but to [host:] %s' % (target_host.uuid, new_host1.uuid)) host = test_kvm_host.ZstackTestKvmHost() host.set_host(target_host) host.maintain() #need to update vm's inventory, since they will be changed by maintenace mode vm1.update() vm2.update() ps = test_lib.lib_get_primary_storage_by_vm(vm1.get_vm()) if ps.type == inventory.LOCAL_STORAGE_TYPE: vm1.set_state(vm_header.STOPPED) vm2.set_state(vm_header.STOPPED) vm1.check() vm2.check() host.change_state(test_kvm_host.ENABLE_EVENT) if not linux.wait_callback_success(is_host_connected, host.get_host().uuid, 120): test_util.test_fail('host status is not changed to connected or host state is not changed to Enabled within 120s') if ps.type == inventory.LOCAL_STORAGE_TYPE: vm1.start() vm2.start() vm1.set_state(vm_header.RUNNING) vm2.set_state(vm_header.RUNNING) vm1.check() vm2.check() post_host1 = test_lib.lib_get_vm_host(vm1.vm) post_host2 = test_lib.lib_get_vm_host(vm2.vm) if post_host1.uuid != current_host1.uuid: vm1.migrate(current_host1.uuid) if post_host2.uuid != current_host2.uuid: vm2.migrate(current_host2.uuid) vm1.check() vm2.check() vm1.destroy() test_obj_dict.rm_vm(vm1) vm2.destroy() test_obj_dict.rm_vm(vm2) test_util.test_pass('Maintain Host Test Success')
def test(): global vm 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") image_option = test_util.ImageOption() image_option.set_name('test_image_cache_cleanup') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url(os.environ.get('imageUrl_s')) image_option.set_backup_storage_uuid_list([bss[0].uuid]) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option = test_util.VmOption() vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(new_image.image.uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('test_image_cache_cleanup_migration_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() if not test_lib.lib_check_vm_live_migration_cap(vm.vm): test_util.test_skip('skip migrate if live migrate not supported') ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) test_obj_dict.add_vm(vm) vm.check() if ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: test_util.test_skip('ceph is not directly using image cache, skip test.') host = test_lib.lib_find_host_by_vm(vm.get_vm()) test_stub.migrate_vm_to_random_host(vm) vm.check() test_stub.migrate_vm_to_random_host(vm) vm.check() new_image.delete() new_image.expunge() vm.destroy() vm.expunge() ps_ops.cleanup_imagecache_on_primary_storage(ps.uuid) count = 0 while True: image_cache_path = "%s/imagecache/template/%s" % (ps.mountPath, new_image.image.uuid) if not test_lib.lib_check_file_exist(host, image_cache_path): break elif count > 5: test_util.test_fail('image cache is expected to be deleted') test_util.test_logger('check %s times: image cache still exist' % (count)) time.sleep(5) count += 1 count = 0 while True: image_cache_path = "%s/zstore-cache/%s" % (ps.mountPath, new_image.image.uuid) if not test_lib.lib_check_file_exist(host, image_cache_path): break elif count > 5: test_util.test_fail('image cache is expected to be deleted') test_util.test_logger('check %s times: image cache still exist' % (count)) time.sleep(5) count += 1 test_util.test_pass('Migrate VM Test Success')
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 vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") max_attempts = test_lib.lib_get_ha_selffencer_maxattempts() test_lib.lib_set_ha_selffencer_maxattempts('3') storagechecker_timeout = test_lib.lib_get_ha_selffencer_storagechecker_timeout() test_lib.lib_set_ha_selffencer_storagechecker_timeout('5') vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) for vr in vrs: if test_lib.lib_is_vm_running(vr) != True: vm_ops.start_vm(vr.uuid) time.sleep(60) conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '!=', os.environ.get('hostIp'), conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() if not test_lib.lib_check_vm_live_migration_cap(vm.vm): test_util.test_skip('skip ha if live migrate not supported') 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 localstorage') #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') cmd = "ifdown %s && sleep 180 && ifup %s" % (l2_network_interface, l2_network_interface) host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180) if not rsp: test_util.test_logger("host is expected to shutdown after its network down for a while") test_util.test_logger("wait for 600 seconds") time.sleep(600) vm.update() if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip: test_util.test_fail("VM is expected to start running on another host") vm.set_state(vm_header.RUNNING) vm.check() vm.destroy() test_lib.lib_set_ha_selffencer_maxattempts(max_attempts) test_lib.lib_set_ha_selffencer_storagechecker_timeout(storagechecker_timeout) os.system('bash -ex %s %s' % (os.environ.get('hostRecoverScript'), host_ip)) host_ops.reconnect_host(host_uuid) test_util.test_pass('Test VM ha on host failure Success')
def test(): global vm 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") image_option = test_util.ImageOption() image_option.set_name('test_image_cache_cleanup') image_option.set_format('qcow2') image_option.set_mediaType('RootVolumeTemplate') image_option.set_url(os.environ.get('imageUrl_s')) image_option.set_backup_storage_uuid_list([bss[0].uuid]) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.add_root_volume_template() l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option = test_util.VmOption() vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(new_image.image.uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('test_image_cache_cleanup_migration_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() if not test_lib.lib_check_vm_live_migration_cap(vm.vm): test_util.test_skip('skip migrate if live migrate not supported') ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) test_obj_dict.add_vm(vm) vm.check() if ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE: test_util.test_skip( 'ceph is not directly using image cache, skip test.') host = test_lib.lib_find_host_by_vm(vm.get_vm()) test_stub.migrate_vm_to_random_host(vm) vm.check() test_stub.migrate_vm_to_random_host(vm) vm.check() new_image.delete() new_image.expunge() vm.destroy() vm.expunge() ps_ops.cleanup_imagecache_on_primary_storage(ps.uuid) count = 0 while True: image_cache_path = "%s/imagecache/template/%s" % (ps.mountPath, new_image.image.uuid) if not test_lib.lib_check_file_exist(host, image_cache_path): break elif count > 5: test_util.test_fail('image cache is expected to be deleted') test_util.test_logger('check %s times: image cache still exist' % (count)) time.sleep(5) count += 1 count = 0 while True: image_cache_path = "%s/zstore-cache/%s" % (ps.mountPath, new_image.image.uuid) if not test_lib.lib_check_file_exist(host, image_cache_path): break elif count > 5: test_util.test_fail('image cache is expected to be deleted') test_util.test_logger('check %s times: image cache still exist' % (count)) time.sleep(5) count += 1 test_util.test_pass('Migrate VM Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") max_attempts = test_lib.lib_get_ha_selffencer_maxattempts() test_lib.lib_set_ha_selffencer_maxattempts('3') storagechecker_timeout = test_lib.lib_get_ha_selffencer_storagechecker_timeout( ) test_lib.lib_set_ha_selffencer_storagechecker_timeout('5') vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) for vr in vrs: if test_lib.lib_is_vm_running(vr) != True: vm_ops.start_vm(vr.uuid) time.sleep(60) conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '!=', os.environ.get('hostIp'), conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() if not test_lib.lib_check_vm_live_migration_cap(vm.vm): test_util.test_skip('skip ha if live migrate not supported') 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 localstorage') #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') cmd = "ifdown %s && sleep 180 && ifup %s" % (l2_network_interface, l2_network_interface) host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180) if not rsp: test_util.test_logger( "host is expected to shutdown after its network down for a while") test_util.test_logger("wait for 600 seconds") time.sleep(600) vm.update() if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host_ip: test_util.test_fail("VM is expected to start running on another host") vm.set_state(vm_header.RUNNING) vm.check() vm.destroy() test_lib.lib_set_ha_selffencer_maxattempts(max_attempts) test_lib.lib_set_ha_selffencer_storagechecker_timeout( storagechecker_timeout) os.system('bash -ex %s %s' % (os.environ.get('hostRecoverScript'), host_ip)) host_ops.reconnect_host(host_uuid) test_util.test_pass('Test VM ha on host failure Success')
def test(): vm1 = test_stub.create_vr_vm('maintain_host_vm1', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm1) vm2 = test_stub.create_vr_vm('maintain_host_vm2', 'imageName_s', 'l3VlanNetwork2') test_obj_dict.add_vm(vm2) vm1.check() vm2.check() if not test_lib.lib_check_vm_live_migration_cap( vm1.vm) or not test_lib.lib_check_vm_live_migration_cap(vm2.vm): test_util.test_skip('skip migrate if live migrate not supported') current_host1 = test_lib.lib_get_vm_host(vm1.vm) conditions = res_ops.gen_query_conditions('clusterUuid', '=', vm1.vm.clusterUuid) conditions = res_ops.gen_query_conditions('state', '=', host_header.ENABLED, conditions) conditions = res_ops.gen_query_conditions('status', '=', host_header.CONNECTED, conditions) all_hosts = res_ops.query_resource(res_ops.HOST, conditions) if len(all_hosts) <= 1: test_util.test_fail( 'Not available host to do maintenance, since there is only %s host' % len(all_hosts)) target_host = random.choice(all_hosts) if current_host1.uuid != target_host.uuid: vm1.migrate(target_host.uuid) current_host2 = test_lib.lib_get_vm_host(vm2.vm) if current_host2.uuid != target_host.uuid: vm2.migrate(target_host.uuid) new_host = test_lib.lib_get_vm_host(vm1.vm) if new_host.uuid != target_host.uuid: test_util.test_fail( 'VM did not migrate to target [host:] %s, but to [host:] %s' % (target_host.uuid, new_host.uuid)) host = test_kvm_host.ZstackTestKvmHost() host.set_host(target_host) host.maintain() #need to update vm's inventory, since they will be changed by maintenace mode vm1.update() vm2.update() vm1.set_state(vm_header.STOPPED) vm2.set_state(vm_header.STOPPED) vm1.check() vm2.check() host.change_state(test_kvm_host.ENABLE_EVENT) if not linux.wait_callback_success(is_host_connected, host.get_host().uuid, 120): test_util.test_fail( 'host status is not changed to connected, after changing its state to Enable' ) vm1.migrate(target_host.uuid) vm2.migrate(target_host.uuid) vm1.check() vm2.check() vm1.destroy() test_obj_dict.rm_vm(vm1) vm2.destroy() test_obj_dict.rm_vm(vm2) test_util.test_pass('Maintain Host Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout global test_host if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) vr_host_ips = [] for vr in vrs: vr_host_ips.append(test_lib.lib_find_host_by_vr(vr).managementIp) if test_lib.lib_is_vm_running(vr) != True: vm_ops.start_vm(vr.uuid) time.sleep(60) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '=', mn_ip, conditions) #for vr_host_ip in vr_host_ips: # conditions = res_ops.gen_query_conditions('managementIp', '!=', vr_host_ip, conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() if not test_lib.lib_check_vm_live_migration_cap(vm.vm): test_util.test_skip('skip ha if live migrate not supported') 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 localstorage') host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_util.test_logger("host %s is disconnecting" %(host_ip)) ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") host_list = test_stub.get_sce_hosts(test_lib.all_scenario_config, test_lib.scenario_file) for host in host_list: if host.ip_ == host_ip: test_host = host break if not test_host: test_util.test_fail('there is no host with ip %s in scenario file.' %(host_ip)) test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold') test_util.test_logger("wait for 30 seconds to ensure vm disconnected, then just wait 90s for target up.") time.sleep(30) if test_lib.lib_wait_target_up(vm.vm.vmNics[0].ip, '22', 90): test_util.test_logger("%s can be connected within 120s" %(vm.vm.vmNics[0].ip)) test_stub.start_host(test_host, test_lib.all_scenario_config) vm.destroy() test_util.test_pass('Test VM ha change to running within 120s Success')
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 vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") 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 #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName #vr_host_ips = [] #for vr in vrs: # vr_ip = test_lib.lib_find_host_by_vr(vr).managementIp # #ensure mn host has no vr # if vr_ip == mn_ip: # conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip) # host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid # vm_ops.migrate_vm(vr.uuid, host_uuid) # vr_host_ips.append(vr_ip) # if test_lib.lib_is_vm_running(vr) != True: # vm_ops.start_vm(vr.uuid) #time.sleep(60) conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '=', mn_ip, conditions) #for vr_host_ip in vr_host_ips: # conditions = res_ops.gen_query_conditions('managementIp', '!=', vr_host_ip, conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vm.check() test_stub.ensure_host_has_no_vr(host_uuid) if not test_lib.lib_check_vm_live_migration_cap(vm.vm): vm.destroy() test_util.test_skip('skip ha if live migrate not supported') ps = test_lib.lib_get_primary_storage_by_uuid( vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: vm.destroy() test_util.test_skip('Skip test on localstorage') host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" % (host_ip)) host_list = test_stub.get_sce_hosts(test_lib.all_scenario_config, test_lib.scenario_file) for host in host_list: if host.ip_ == host_ip: test_host = host break if not test_host: test_util.test_fail('there is no host with ip %s in scenario file.' % (host_ip)) #test_stub.down_host_network(host_ip, test_lib.all_scenario_config) test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold') time.sleep(30) #test_stub.up_host_network(host_ip, test_lib.all_scenario_config) test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) time.sleep(120) cmd = "nohup zstack-ctl start &" host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') if not test_lib.lib_execute_ssh_cmd( mn_ip, host_username, host_password, cmd, timeout=300): test_util.test_fail("CMD:%s execute failed on %s" % (cmd, mn_ip)) #test_util.test_logger("wait for 480 seconds") #time.sleep(480) time.sleep(120) cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) if not res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped": test_util.test_fail("vm is not stopped as expected.") vm.destroy() #this is used to design to check mn works normally time.sleep(20) vm.create() vm.check() vm.destroy() #host_ops.reconnect_host(host_uuid) test_util.test_pass( 'Test checking vm status after force stop and start success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if test_lib.lib_get_ha_enable() != 'true': test_util.test_skip("vm ha not enabled. Skip test") 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 #l3_name = os.environ.get('l3NoVlanNetworkName1') l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName #vr_host_ips = [] #for vr in vrs: # vr_ip = test_lib.lib_find_host_by_vr(vr).managementIp # #ensure mn host has no vr # if vr_ip == mn_ip: # conditions = res_ops.gen_query_conditions('managementIp', '!=', mn_ip) # host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid # vm_ops.migrate_vm(vr.uuid, host_uuid) # vr_host_ips.append(vr_ip) # if test_lib.lib_is_vm_running(vr) != True: # vm_ops.start_vm(vr.uuid) #time.sleep(60) conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') conditions = res_ops.gen_query_conditions('status', '=', 'Connected', conditions) conditions = res_ops.gen_query_conditions('managementIp', '=', mn_ip, conditions) #for vr_host_ip in vr_host_ips: # conditions = res_ops.gen_query_conditions('managementIp', '!=', vr_host_ip, conditions) host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid vm_creation_option.set_host_uuid(host_uuid) vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multihost_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vm.check() test_stub.ensure_host_has_no_vr(host_uuid) if not test_lib.lib_check_vm_live_migration_cap(vm.vm): vm.destroy() test_util.test_skip('skip ha if live migrate not supported') ps = test_lib.lib_get_primary_storage_by_uuid(vm.get_vm().allVolumes[0].primaryStorageUuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: vm.destroy() test_util.test_skip('Skip test on localstorage') host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp host_port = test_lib.lib_get_host_port(host_ip) test_util.test_logger("host %s is disconnecting" %(host_ip)) host_list = test_stub.get_sce_hosts(test_lib.all_scenario_config, test_lib.scenario_file) for host in host_list: if host.ip_ == host_ip: test_host = host break if not test_host: test_util.test_fail('there is no host with ip %s in scenario file.' %(host_ip)) #test_stub.down_host_network(host_ip, test_lib.all_scenario_config) test_stub.stop_host(test_host, test_lib.all_scenario_config, 'cold') time.sleep(30) #test_stub.up_host_network(host_ip, test_lib.all_scenario_config) test_stub.start_host(test_host, test_lib.all_scenario_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) time.sleep(120) cmd = "nohup zstack-ctl start &" host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') if not test_lib.lib_execute_ssh_cmd(mn_ip, host_username, host_password, cmd, timeout = 300): test_util.test_fail("CMD:%s execute failed on %s" %(cmd, mn_ip)) #test_util.test_logger("wait for 480 seconds") #time.sleep(480) time.sleep(120) cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid) if not res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped": test_util.test_fail("vm is not stopped as expected.") vm.destroy() #this is used to design to check mn works normally time.sleep(20) vm.create() vm.check() vm.destroy() #host_ops.reconnect_host(host_uuid) test_util.test_pass('Test checking vm status after force stop and start success')