def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, "SharedBlock"] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) test_util.test_dsc('Create test vm and check') bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None) if not bss: test_util.test_skip("not find available backup storage. Skip test") test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'disable') test_stub.disable_all_pss() if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() volume.delete() volume.check() volume.expunge() volume.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS disable mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() vm.destroy() test_util.test_pass('PS maintain mode Test Success')
def test(): instance_offering_name = os.environ.get('instanceOfferingName_m') instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(instance_offering_name).uuid vm = test_stub.create_vm(image_name = os.environ.get('sshkeyImageName'), instance_offering_uuid = instance_offering_uuid) test_obj_dict.add_vm(vm) vm_ip = vm.get_vm().vmNics[0].ip time.sleep(10) test_lib.lib_add_vm_sshkey(vm.get_vm().uuid, os.environ.get('sshkeyPubKey')) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid host_ops.reconnect_host(host_uuid) vm.reboot() test_lib.lib_wait_target_up(vm_ip, '22', 240) time.sleep(10) for i in range(5): ssh_cmd = 'timeout 5 ssh -i %s -oPasswordAuthentication=no -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null %s echo pass' % (os.environ.get('sshkeyPriKey_file'), vm_ip) process_result = test_stub.execute_shell_in_process(ssh_cmd, tmp_file) if process_result == 0: break else: time.sleep(10) else: test_util.test_fail("fail to use ssh key connect to VM") vm.destroy() test_util.test_pass('Create VM Test Success')
def test(): test_util.test_dsc("create vr vm and vpc vrouter") vm = test_stub.create_vr_vm('vr_vm','imageName_s','l3NoVlanNetworkName2') test_obj_dict.add_vm(vm) if not test_lib.lib_find_vr_by_vm(vm.vm) or not test_lib.lib_find_vr_by_vm(vm.vm)[0]: test_lib.lib_error_cleanup(test_obj_dict) test_util.test_skip("skip the test for no vr found in the env.") vpc_vr = test_stub.create_vpc_vrouter() check_host_prometheus_conf() check_vrouter_prometheus_conf() check_prometheus_data() hosts = test_lib.lib_get_all_hosts_from_plan() for host in hosts: host_ops.reconnect_host(host_uuid) check_host_prometheus_conf() check_vrouter_prometheus_conf() check_prometheus_data() test_lib.lib_execute_ssh_cmd(mn_ip,"root","password","zstack-ctl restart_node",timeout=300) check_host_prometheus_conf() check_vrouter_prometheus_conf() check_prometheus_data() test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Test prometheus Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'disable') test_stub.disable_all_pss() if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to runnning when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() vm.suspend() vm.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) test_util.test_pass('PS disable mode Test Success')
def test(): test_util.test_dsc("check all hosts chrony status") host_uuid_list = [] host_ip_list = [] host_port_list = [] hosts = {} for host_id in range(len(res_ops.query_resource(res_ops.HOST))): managementIp = res_ops.query_resource(res_ops.HOST)[host_id].managementIp sshPort = res_ops.query_resource(res_ops.HOST)[host_id].sshPort uuid = res_ops.query_resource(res_ops.HOST)[host_id].uuid host_ip_list.append(managementIp) host_port_list.append(sshPort) host_uuid_list.append(uuid) hosts = dict(zip(host_ip_list, host_port_list)) print "hosts is %s" %(hosts) for k, v in hosts.items(): check_chrony_status(k, v) for host_uuid in host_uuid_list: host_ops.reconnect_host(host_uuid) time.sleep(5) for k, v in hosts.items(): check_chrony_status(k, v) host_ops.change_host_state(host_uuid_list[0], "disable") for k, v in hosts.items(): check_chrony_status(k, v) host_ops.change_host_state(host_uuid_list[0], "enable") test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Test chrony Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions("status", '=', "Connected") bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) os.system("echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm.vm.uuid) ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() vm.destroy() vm.check() #vm.expunge() #vm.check() test_util.test_pass('PS maintain mode Test Success')
def error_cleanup(): global email_endpoint_uuid,email_platform_uuid,my_sns_topic_uuid,host_sns_topic_uuid,ps_uuid,hostname,host_management_ip,host_status,bs_type,bs_status,event_list if host_status == 'Disconnected': host_ops.update_host(host_uuid, 'managementIp', host_management_ip) host_ops.reconnect_host(host_uuid) if bs_status == 'Disconnected': if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) if ps_uuid: ps_ops.delete_primary_storage(ps_uuid) if host_sns_topic_uuid: zwt_ops.delete_sns_topic(host_sns_topic_uuid) if my_sns_topic_uuid: zwt_ops.delete_sns_topic(my_sns_topic_uuid) if event_list: for event_uuid in event_list: zwt_ops.unsubscribe_event(event_uuid) if email_endpoint_uuid: zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) if email_platform_uuid: zwt_ops.delete_sns_application_platform(email_platform_uuid)
def test(): global vm_inv,host_name, host_uuid, host_management_ip, vm_ip, bs_name, bs_uuid test_util.test_dsc('Create test vm to test zstack upgrade by -u.') image_name = os.environ.get('imageTestAlarm_230_mn') iso_path = os.environ.get('iso_path') zstack_latest_version = os.environ.get('zstackLatestVersion') zstack_latest_path = os.environ.get('zstackLatestInstaller') vm_name = os.environ.get('vmName') + image_name upgrade_script_path = os.environ.get('upgradeScript') vm_inv = test_stub.create_vm_scenario(image_name, vm_name) vm_ip = vm_inv.vmNics[0].ip test_lib.lib_wait_target_up(vm_ip, 22) #vm_ip = '172.20.197.159' os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = vm_ip test_stub.make_ssh_no_password(vm_ip, tmp_file) test_util.test_logger('Update MN IP') test_stub.update_mn_hostname(vm_ip, tmp_file) test_stub.update_mn_ip(vm_ip, tmp_file) test_stub.start_mn(vm_ip, tmp_file) test_util.test_logger('Update host management IP and reconnect host') host_name = 'Host-1' cond1 = res_ops.gen_query_conditions('name', '=', host_name) test2 = res_ops.query_resource(res_ops.HOST, cond1) test_util.test_logger('aaaaa %s' % test2) #host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].inventories[0] management_ip = vm_ip host_uuid = scen_ops.query_resource(management_ip, res_ops.HOST, cond1).inventories[0].uuid print 'test = ' print host_uuid host_management_ip = vm_ip host_ops.update_host(host_uuid, 'managementIp', host_management_ip) host_ops.reconnect_host(host_uuid) test_util.test_logger('Update bs IP and reconnect bs') bs_name = 'BS-1' cond2 = res_ops.gen_query_conditions('name', '=', bs_name) #bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, conditions)[0].inventories[0].uuid bs_uuid = scen_ops.query_resource(management_ip, res_ops.BACKUP_STORAGE, cond2).inventories[0].uuid bs_ip = vm_ip bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', bs_ip) bs_ops.reconnect_backup_storage(bs_uuid) #test_stub.check_installation(vm_ip, tmp_file) test_util.test_logger('Upgrade zstack to latest') test_stub.update_iso(vm_ip, tmp_file, iso_path, upgrade_script_path) test_stub.upgrade_zstack(vm_ip, zstack_latest_path, tmp_file) test_stub.check_zstack_version(vm_ip, tmp_file, zstack_latest_version) test_stub.start_mn(vm_ip, tmp_file) test_stub.check_installation(vm_ip, tmp_file) os.system('rm -f %s' % tmp_file) test_stub.destroy_vm_scenario(vm_inv.uuid) test_util.test_pass('ZStack upgrade Test Success')
def env_recover(): global host_ip test_util.test_logger("recover host: %s" % (test_host.ip_)) test_stub.recover_host(test_host, test_lib.all_scenario_config, test_lib.deploy_config) test_stub.recover_host_vlan(test_host, test_lib.all_scenario_config, test_lib.deploy_config) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid)
def env_recover(): global host_ip cmd = 'bash -ex %s %s' % (os.environ.get('hostRecoverScript'), host_ip) test_util.test_logger(cmd) os.system(cmd) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid)
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.delete() volume.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() volume.recover() volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() volume.delete() #volume.expunge() volume.check() vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS maintain mode Test Success')
def env_recover(): global host_ip try: test_stub.up_host_network(host_ip, test_lib.all_scenario_config) except: pass conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid)
def test(): ps_env = test_stub.PSEnvChecker() mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName 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) host = random.choice(res_ops.query_resource(res_ops.HOST, conditions)) record['host_ip'] = host.managementIp record['host_port'] = host.sshPort record['host_uuid'] = host.uuid test_util.test_dsc("Create {0} vm each with {1} datavolume".format(VM_COUNT, DATA_VOLUME_NUMBER)) if ps_env.is_sb_ceph_env: ps_list = res_ops.query_resource(res_ops.PRIMARY_STORAGE) ps = random.choice(ps_list) ps_uuid = ps.uuid vm_list = test_stub.create_multi_vms(name_prefix='test-', count=VM_COUNT, data_volume_number=DATA_VOLUME_NUMBER, host_uuid=host.uuid, ps_uuid=ps_uuid, timeout=1800000, bs_type="ImageStoreBackupStorage" if ps.type == "SharedBlock" else "Ceph") else: vm_list = test_stub.create_multi_vms(name_prefix='test-', count=VM_COUNT, data_volume_number=DATA_VOLUME_NUMBER, host_uuid=host.uuid, timeout=1800000) for vm in vm_list: test_obj_dict.add_vm(vm) test_util.test_logger("host %s is disconnecting" % host.managementIp) for vm in vm_list: ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") #l2_network_interface = os.environ.get('l2ManagementNetworkInterface') l2interface = test_lib.lib_get_l2s_by_vm(vm.get_vm())[0].physicalInterface l2_network_interface = test_stub.get_host_l2_nic_name(l2interface) 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.managementIp, host_username, host_password, cmd, 240) 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 180 seconds") time.sleep(180) for vm in vm_list: vm.update() if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host.managementIp: test_util.test_fail("VM is expected to start running on another host") vm.set_state(vm_header.RUNNING) vm.check() cmd = 'PORT=%s bash -ex %s %s' % (host.sshPort, os.environ.get('hostRecoverScript'),host.managementIp) test_util.test_logger(cmd) os.system(cmd) host_ops.reconnect_host(host.uuid) test_util.test_pass('Multi PrimaryStorage Vm HA Test Pass')
def env_recover(): global test_host try: 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) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid) except: pass
def test(): global vm, kvm_host ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE) for i in ps: if i.type == inventory.LOCAL_STORAGE_TYPE: break else: test_util.test_skip('Skip test on non-localstoreate PS') #ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0] #if ps.type != inventory.LOCAL_STORAGE_TYPE: # test_util.test_skip('Skip test on non-localstorage') #if "test-config-local-ps.xml" != os.path.basename(os.environ.get('WOODPECKER_TEST_CONFIG_FILE')).strip(): # test_util.test_skip('Skip test on non-localstoreage') #query all hosts and change password conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') if res_ops.query_resource(res_ops.HOST, conditions): kvm_host = res_ops.query_resource(res_ops.HOST, conditions) for i in kvm_host: host_ops.update_kvm_host(i.uuid, 'password', 'password*()') cmd = 'echo "password*()"| passwd --stdin root' test_lib.lib_execute_ssh_cmd(i.managementIp,"root","password",cmd) host_ops.reconnect_host(i.uuid) else: test_util.test_skip("There is no host. Skip test") test_util.test_dsc('Test KVM Host Infomation: password') #create vm and stop and migrate vm = test_stub.create_vr_vm('migrate_stopped_vm', 'imageName_s', 'l3VlanNetwork2') vm.check() target_host = test_lib.lib_find_random_host(vm.vm) vm.stop() vol_ops.migrate_volume(vm.get_vm().allVolumes[0].uuid, target_host.uuid) vm.check() vm.start() vm.check() vm.destroy() vm.expunge() ################################# recover KVM HOST Password ################################# conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') if res_ops.query_resource(res_ops.HOST, conditions): kvm_host = res_ops.query_resource(res_ops.HOST, conditions) for i in kvm_host: host_ops.update_kvm_host(i.uuid, 'password', 'password') cmd = 'echo "password"| passwd --stdin root' test_lib.lib_execute_ssh_cmd(i.managementIp,"root","password*()",cmd) host_ops.reconnect_host(i.uuid) else: test_util.test_skip("There is no host. Skip test") test_util.test_dsc('Test KVM Host Infomation: password') test_util.test_pass('Migrate Stopped VM with special_password Test Success')
def error_cleanup(): global ps_uuid if ps_uuid != None: ps_ops.change_primary_storage_state(ps_uuid, 'enable') global host_uuid if host_uuid != None: host_ops.reconnect_host(host_uuid) global vr_uuid if vr_uuid != None: vm_ops.reconnect_vr(vr_uuid) global test_obj_dict test_lib.lib_error_cleanup(test_obj_dict)
def test(): test_util.test_dsc('Test Host Reconnect function and check if the available CPU and memory number are aligned between before and after reconnect action') vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) zone_uuid = vm.get_vm().zoneUuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid tot_res1 = test_lib.lib_get_cpu_memory_capacity([zone_uuid]) host_ops.reconnect_host(host_uuid) time.sleep(5) tot_res2 = test_lib.lib_get_cpu_memory_capacity([zone_uuid]) if compare_capacity( tot_res1, tot_res2): test_util.test_logger("the resource consumption are same after reconnect host") else: test_util.test_fail("the resource consumption are different after reconnect host: %s " % host_uuid) vm_offering_uuid = vm.get_vm().instanceOfferingUuid cond = res_ops.gen_query_conditions('uuid', '=', vm_offering_uuid) vm_offering = res_ops.query_resource(res_ops.INSTANCE_OFFERING, cond)[0] vm_cpu = vm_offering.cpuNum vm_memory = vm_offering.memorySize vm.destroy() test_obj_dict.rm_vm(vm) tot_res3 = test_lib.lib_get_cpu_memory_capacity([zone_uuid]) if compare_capacity(tot_res1, tot_res3, vm_cpu, vm_memory): test_util.test_logger("the resource consumption are aligned after destroy a vm") else: test_util.test_fail("the resource consumption are not aligned after destroy vm: %s on host: %s" % (vm.get_vm().uuid, host_uuid)) test_stub.ensure_hosts_connected(120) test_stub.ensure_pss_connected() vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) tot_res4 = test_lib.lib_get_cpu_memory_capacity([zone_uuid]) if compare_capacity(tot_res1, tot_res4): test_util.test_logger("the resource consumption are aligned after create a new vm") else: test_util.test_fail("the resource consumption are not aligned after create a new vm: %s " % vm.get_vm().uuid) vm.destroy() test_util.test_pass('Reconnect Host and Test CPU/Memory Capacity Pass')
def check_resource(): hosts = res_ops.query_resource(res_ops.HOST, [], None) for host in hosts: if host.status != "Connected": host_ops.reconnect_host(host.uuid) return False pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, [], None) for ps in pss: if ps.status != "Connected": ps_ops.reconnect_primary_storage(ps.uuid) return False bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, [], None) for bs in bss: if bs.status != "Connected": bs_ops.reconnect_backup_storage(bs.uuid) return False if os.environ.get('WOODPECKER_PARALLEL') != None and os.environ.get('WOODPECKER_PARALLEL') == '0': vms = res_ops.query_resource(res_ops.VM_INSTANCE, [], None) for vm in vms: if vm.type == 'UserVm': try: vm_ops.destroy_vm(vm.uuid) except: test_util.test_logger('ignore exception try to destroy vm') try: vm_ops.expunge_vm(vm.uuid) except: test_util.test_logger('ignore exception try to expunge vm') vrs = res_ops.query_resource(res_ops.APPLIANCE_VM, [], None) for vr in vrs: if vr.status != "Connected" or vr.state != "Running": if vr.applianceVmType != "vrouter": try: vm_ops.stop_vm(vr.uuid, force='cold') vm_ops.start_vm(vr.uuid) except: test_util.test_logger('Exception when reboot vr vm') else: try: vm_ops.stop_vm(vr.uuid, force='cold') except: test_util.test_logger('Exception when reboot vr vm') return False return True
def error_cleanup(): global ps_uuid test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') if ps_uuid != None: ps_ops.change_primary_storage_state(ps_uuid, 'enable') global host_uuid if host_uuid != None: host_ops.reconnect_host(host_uuid) global vr_uuid if vr_uuid != None: vm_ops.reconnect_vr(vr_uuid) global test_obj_dict test_lib.lib_error_cleanup(test_obj_dict)
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) #volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'disable') test_stub.disable_all_pss() if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() volume.detach(vm.get_vm().uuid) #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) volume.delete() #volume.expunge() volume.check() vm.destroy() test_util.test_pass('Delete volume under PS disable mode Test Success')
def error_cleanup(): global ps_uuid if ps_uuid != None: ps_ops.change_primary_storage_state(ps_uuid, 'enable') global host_uuid if host_uuid != None: host_ops.reconnect_host(host_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) #global vr_uuid #if vr_uuid != None: # vm_ops.reconnect_vr(vr_uuid) global test_obj_dict test_lib.lib_error_cleanup(test_obj_dict)
def error_cleanup(): global vm global host_ip global host_uuid global max_attempts global storagechecker_timeout if vm: try: vm.destroy() except: pass os.system('bash -ex %s %s' % (os.environ.get('hostRecoverScript'), host_ip)) host_ops.reconnect_host(host_uuid)
def test(): test_util.test_dsc('Test Host Reconnect function and check if the available CPU and memory number are aligned between before and after reconnect action') vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) zone_uuid = vm.get_vm().zoneUuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid tot_res1 = test_lib.lib_get_cpu_memory_capacity([zone_uuid]) host_ops.reconnect_host(host_uuid) tot_res2 = test_lib.lib_get_cpu_memory_capacity([zone_uuid]) if compare_capacity( tot_res1, tot_res2): test_util.test_logger("the resource consumption are same after reconnect host") else: test_util.test_fail("the resource consumption are different after reconnect host: %s " % host_uuid) vm_offering_uuid = vm.get_vm().instanceOfferingUuid cond = res_ops.gen_query_conditions('uuid', '=', vm_offering_uuid) vm_offering = res_ops.query_resource(res_ops.INSTANCE_OFFERING, cond)[0] vm_cpu = vm_offering.cpuNum * vm_offering.cpuSpeed vm_memory = vm_offering.memorySize vm.destroy() test_obj_dict.rm_vm(vm) tot_res3 = test_lib.lib_get_cpu_memory_capacity([zone_uuid]) if compare_capacity(tot_res1, tot_res3, vm_cpu, vm_memory): test_util.test_logger("the resource consumption are aligned after destroy a vm") else: test_util.test_fail("the resource consumption are not aligned after destroy vm: %s on host: %s" % (vm.get_vm().uuid, host_uuid)) vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) tot_res4 = test_lib.lib_get_cpu_memory_capacity([zone_uuid]) if compare_capacity(tot_res1, tot_res4): test_util.test_logger("the resource consumption are aligned after create a new vm") else: test_util.test_fail("the resource consumption are not aligned after create a new vm: %s " % vm.get_vm().uuid) vm.destroy() test_util.test_pass('Reconnect Host and Test CPU/Memory Capacity Pass')
def test(): global vm vm = test_stub.create_vm() #1 hostname='vm123.zstack.org' vm_ops.set_vm_hostname(vm.get_vm().uuid,'vm123.zstack.org') host=test_lib.lib_find_host_by_vm(vm.get_vm()) host_ops.reconnect_host(host.uuid) hostname_inv=vm_ops.get_vm_hostname(vm.get_vm().uuid) if hostname_inv != hostname: test_util.test_fail('can not get the vm hostname after set vm hostname') vm_inv=res_ops.get_resource(res_ops.VM_INSTANCE,uuid=vm.get_vm().uuid)[0] if vm_inv.vmNics[0].ip !=vm.get_vm().vmNics[0].ip: test_util.test_fail('can not get the correct ip address after set vm hostname and reconnected host') #2 hostname = 'vm1234.zstack.org' vm_ops.set_vm_hostname(vm.get_vm().uuid,hostname) host=test_lib.lib_find_host_by_vm(vm.get_vm()) vm_ops.reboot_vm(vm.get_vm().uuid) hostname_inv=vm_ops.get_vm_hostname(vm.get_vm().uuid) if hostname_inv != hostname: test_util.test_fail('can not get the vm hostname after set vm hostname') vm_inv=res_ops.get_resource(res_ops.VM_INSTANCE,uuid=vm.get_vm().uuid)[0] if vm_inv.vmNics[0].ip !=vm.get_vm().vmNics[0].ip: test_util.test_fail('can not get the correct ip address after set vm hostname and reboot vm') #3 hostname = 'vm12345.zstack.org' vm_ops.set_vm_hostname(vm.get_vm().uuid, hostname) host = test_lib.lib_find_host_by_vm(vm.get_vm()) host_ops.reconnect_host(host.uuid) vm_ops.reboot_vm(vm.get_vm().uuid) hostname_inv = vm_ops.get_vm_hostname(vm.get_vm().uuid) if hostname_inv != hostname: test_util.test_fail('can not get the vm hostname after set vm hostname') vm_inv = res_ops.get_resource(res_ops.VM_INSTANCE, uuid=vm.get_vm().uuid)[0] if vm_inv.vmNics[0].ip != vm.get_vm().vmNics[0].ip: test_util.test_fail('can not get the correct ip address after set vm hostname and reboot vm and reconnect host') test_util.test_pass('SetVMHostname and get vm\'s correct ip')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid test_obj_dict.add_vm(vm) vm.check() root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) vm.check() snapshots.create_snapshot('create_root_snapshot1') snapshots.check() snapshot1 = snapshots.get_current_snapshot() host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() vm.stop() vm.check() test_util.test_dsc('Use snapshot, volume and check') snapshots.use_snapshot(snapshot1) snapshots.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() test_util.test_pass('PS disable mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) #volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'disable') test_stub.disable_all_pss() if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) volume.delete() #volume.expunge() volume.check() vm.destroy() test_util.test_pass('Delete volume under PS disable mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid test_obj_dict.add_vm(vm) vm.check() root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) vm.check() snapshots.create_snapshot('create_root_snapshot1') snapshots.check() snapshot1 = snapshots.get_current_snapshot() host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'disable') test_stub.disable_all_pss() if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() test_util.test_dsc('Delete snapshot, volume and check') snapshots.delete_snapshot(snapshot1) snapshots.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() test_util.test_pass('PS disable mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) test_stub.ensure_pss_connected() vrs = test_lib.lib_get_all_vrs() for vr in vrs: vr_cond = res_ops.gen_query_conditions('uuid', '=', vr.uuid) vr_inv = res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0] if vr_inv.state == 'Stopped': vm_ops.start_vm(vr.uuid) else: test_lib.lib_wait_target_up(vr_inv.vmNics[0].ip, '22', 360) for _ in xrange(100): if res_ops.query_resource(res_ops.VM_INSTANCE, vr_cond)[0].state != 'Running': time.sleep(3) else: break vm.start() vm.check() vm.destroy() test_util.test_pass('PS maintain mode Test Success')
def error_cleanup(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout if vm: try: vm.destroy() except: pass os.system('bash -ex %s %s' % (os.environ.get('hostRecoverScript'), host_ip)) host_ops.reconnect_host(host_uuid)
def test(): recnt_timeout=5000 test_util.test_dsc('Test Host Reconnect within %s ms' % recnt_timeout) vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) zone_uuid = vm.get_vm().zoneUuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid host_ops.reconnect_host(host_uuid, timeout=recnt_timeout) vm.destroy() test_obj_dict.rm_vm(vm) test_util.test_pass('Reconnect Host within %s ms' % recnt_timeout)
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() vm.destroy() #vm.expunge() maintain mode is not support expunge ops. vm.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('PS maintain mode Test Success')
def test(): mn_ip = res_ops.query_resource(res_ops.MANAGEMENT_NODE)[0].hostName 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) host = random.choice(res_ops.query_resource(res_ops.HOST, conditions)) record['host_ip'] = host.managementIp record['host_port'] = host.sshPort record['host_uuid'] = host.uuid vm_list=list(test_stub.generate_local_shared_test_vms(test_obj_dict, vm_ha=True, host_uuid=host.uuid)) (vm_root_local, vm_root_local_data_local, vm_root_local_data_shared, vm_root_local_data_mixed, vm_root_shared, vm_root_shared_data_local, vm_root_shared_data_shared, vm_root_shared_data_mixed) = vm_list l2interface = test_lib.lib_get_l2s_by_vm(vm_list[0].get_vm())[0].physicalInterface l2_network_interface = test_stub.get_host_l2_nic_name(l2interface) 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.managementIp, host_username, host_password, cmd, 240) 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 180 seconds") time.sleep(180) for vm in vm_list: vm.update() for vm in (vm_root_shared,vm_root_shared_data_shared): if test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp == host.managementIp: test_util.test_fail("VM is expected to start running on another host") vm.set_state(vm_header.RUNNING) vm.check() for vm in (vm_root_local, vm_root_local_data_local, vm_root_local_data_shared, vm_root_local_data_mixed, vm_root_shared_data_local, vm_root_shared_data_mixed): assert vm.get_vm().state == inventory.STOPPED cmd = 'PORT=%s bash -ex %s %s' % (host.sshPort, os.environ.get('hostRecoverScript'),host.managementIp) test_util.test_logger(cmd) os.system(cmd) host_ops.reconnect_host(host.uuid)
def test(): test_util.test_dsc("create vr vm and vpc vrouter") check_host_prometheus_conf() check_prometheus_data() hosts = test_lib.lib_get_all_hosts_from_plan() for host in hosts: host_ops.reconnect_host(host_uuid) check_host_prometheus_conf() check_prometheus_data() test_lib.lib_execute_ssh_cmd(mn_ip,"root","password","zstack-ctl restart_node",timeout=300) check_host_prometheus_conf() check_prometheus_data() test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Test prometheus Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3') test_obj_dict.add_vm(vm) backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm) for bs in backup_storage_list: if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE: break else: vm.destroy() test_util.test_skip('Not find ceph type backup storage.') l3_1_name = os.environ.get('l3VlanNetwork3') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to stop when PS change to disable state') vm.set_state(vm_header.STOPPED) vm.check() test_stub.migrate_vm_to_random_host(vm) vm.check() volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'Enabled') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) test_util.test_pass('PS disable mode Test Success')
def test(): test_util.test_dsc('Create test vm with EIP and check.') vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid pri_l3_name = os.environ.get('l3VlanNetworkName1') pri_l3_uuid = test_lib.lib_get_l3_by_name(pri_l3_name).uuid pub_l3_name = os.environ.get('l3PublicNetworkName') pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid vm_nic = vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid vip = test_stub.create_vip('create_eip_test', pub_l3_uuid) test_obj_dict.add_vip(vip) eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm_nic_uuid, vm_obj=vm) vip.attach_eip(eip) vm.check() host_ops.reconnect_host(host_uuid) if not test_lib.lib_check_directly_ping(vip.get_vip().ip): test_util.test_fail('expected to be able to ping vip while it fail') vm.destroy() test_obj_dict.rm_vm(vm) if test_lib.lib_check_directly_ping(vip.get_vip().ip): test_util.test_fail( 'not expected to be able to ping vip while it succeed') eip.delete() vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass('Create EIP for VM Success')
def check_resource(): hosts = res_ops.query_resource(res_ops.HOST, [], None) for host in hosts: if host.status != "Connected": host_ops.reconnect_host(host.uuid) return False pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, [], None) for ps in pss: if ps.status != "Connected": ps_ops.reconnect_primary_storage(ps.uuid) return False bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, [], None) for bs in bss: if bs.status != "Connected": bs_ops.reconnect_backup_storage(bs.uuid) return False if os.environ.get('WOODPECKER_PARALLEL') != None and os.environ.get( 'WOODPECKER_PARALLEL') == '0': vms = res_ops.query_resource(res_ops.VM_INSTANCE, [], None) for vm in vms: if vm.type == 'UserVm' and vm.state == 'Running': vm_ops.stop_vm(vm.uuid, force='cold') vrs = res_ops.query_resource(res_ops.APPLIANCE_VM, [], None) for vr in vrs: if vr.status != "Connected" or vr.state != "Running": if vr.applianceVmType != "vrouter": try: vm_ops.stop_vm(vr.uuid, force='cold') vm_ops.start_vm(vr.uuid) except: test_util.test_logger('Exception when reboot vr vm') else: try: vm_ops.stop_vm(vr.uuid, force='cold') except: test_util.test_logger('Exception when reboot vr vm') return False return True
def test(): recnt_timeout=30000 test_util.test_dsc('Test Host Reconnect within %s ms' % recnt_timeout) vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) zone_uuid = vm.get_vm().zoneUuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid try: host_ops.reconnect_host(host_uuid, timeout=recnt_timeout) except: host_ops.reconnect_host(host_uuid, timeout=recnt_timeout) vm.destroy() test_obj_dict.rm_vm(vm) test_util.test_pass('Reconnect Host within %s ms' % recnt_timeout)
def error_cleanup(): global kvm_host_uuid host_ops.update_kvm_host(kvm_host_uuid, 'password', 'password') cmd = 'echo "password"| passwd --stdin root' os.system(cmd) host_ops.update_kvm_host(kvm_host_uuid, 'sshPort', '22') cmd = 'sed -i \'/Port 23/d\' /etc/ssh/sshd_config' os.system(cmd) cmd = 'service sshd restart' os.system(cmd) host_ops.update_kvm_host(kvm_host_uuid, 'username', 'root') cmd = 'userdel test' os.system(cmd) host_ops.reconnect_host(kvm_host_uuid) test_lib.lib_error_cleanup(test_obj_dict)
def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] test_util.test_dsc("create vpc vrouter and attach vpc l3 to vpc") vr = test_stub.create_vpc_vrouter() test_stub.attach_l3_to_vpc_vr(vr) test_util.test_dsc("create two vm, vm1 in l3 {}, vm2 in l3 {}".format(flavor['vm1l3'], flavor['vm2l3'])) vm1, vm2 = [test_stub.create_vm_with_random_offering(vm_name='vpc_vm_{}'.format(name), l3_name=name) for name in (flavor['vm1l3'], flavor['vm2l3'])] [test_obj_dict.add_vm(vm) for vm in (vm1,vm2)] [vm.check() for vm in (vm1,vm2)] if flavor['ops'] is VM_MIGRATE: test_stub.migrate_vm_to_random_host(vm2) elif flavor['ops'] is VM_REBOOT: vm1.reboot() elif flavor['ops'] is VR_REBOOT: vr.reboot() time.sleep(10) elif flavor['ops'] is VR_RECONNECT: vr.reconnect() elif flavor['ops'] is VR_MIGRATE: vr.migrate_to_random_host() elif flavor['ops'] is HOST_RECONNECT: host = test_lib.lib_find_host_by_vm(random.choice([vm1,vm2]).get_vm()) host_ops.reconnect_host(host.uuid) if flavor['ops'] is not None: for vm in (vm1, vm2): vm.check() test_util.test_dsc("test two vm connectivity") [test_stub.run_command_in_vm(vm.get_vm(), 'iptables -F') for vm in (vm1,vm2)] test_stub.check_icmp_between_vms(vm1, vm2, expected_result='PASS') test_stub.check_tcp_between_vms(vm1, vm2, ["22"], []) test_lib.lib_error_cleanup(test_obj_dict) test_stub.remove_all_vpc_vrouter()
def ensure_hosts_connected(exclude_host=[]): for i in range(300): #time.sleep(1) host_list = res_ops.query_resource(res_ops.HOST) for exh in exclude_host: for host in host_list: if exh.managementIp_ == host.managementIp or exh.ip_ == host.managementIp: host_list.remove(host) for host in host_list: try: host_ops.reconnect_host(host.uuid) except Exception, e: test_util.test_logger("time: %s reconnect host failed: %s" %(str(i), host.uuid)) break cond = res_ops.gen_query_conditions('uuid', '=', host.uuid) hosts = res_ops.query_resource_fields(res_ops.HOST, cond, None) if not "connected" in hosts[0].status.lower(): test_util.test_logger("time %s found not connected ps status: %s" %(str(i), hosts[0].status)) break else: return
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() vm.destroy() vm.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('PS disable mode Test Success')
def test(): instance_offering_name = os.environ.get('instanceOfferingName_m') instance_offering_uuid = test_lib.lib_get_instance_offering_by_name( instance_offering_name).uuid vm = test_stub.create_vm(image_name=os.environ.get('sshkeyImageName'), instance_offering_uuid=instance_offering_uuid) test_obj_dict.add_vm(vm) vm_ip = vm.get_vm().vmNics[0].ip time.sleep(10) test_lib.lib_add_vm_sshkey(vm.get_vm().uuid, os.environ.get('sshkeyPubKey')) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid host_ops.reconnect_host(host_uuid) vm.reboot() time.sleep(60) ssh_cmd = 'ssh -i %s -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null %s echo pass' % ( os.environ.get('sshkeyPriKey_file'), vm_ip) process_result = test_stub.execute_shell_in_process(ssh_cmd, tmp_file) if process_result != 0: test_util.test_fail("fail to use ssh key connect to VM") vm.destroy() test_util.test_pass('Create VM Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout must_ps_list = [inventory.LOCAL_STORAGE_TYPE, 'SharedMountPoint'] test_lib.skip_test_if_any_ps_not_deployed(must_ps_list) 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('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) #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('ls_vm_none_status') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts): test_util.test_fail("Not find out a suitable host") #vm.check() host_ip = test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp test_util.test_logger("host %s is disconnecting" %(host_ip)) test_stub.down_host_network(host_ip, test_lib.all_scenario_config) cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_none_status') cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond) for i in range(0, 300): vm_stop_time = i if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Unknown": test_stub.up_host_network(host_ip, test_lib.all_scenario_config) time.sleep(1) test_stub.recover_smp_nfs_server(host_ip) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid) break time.sleep(1) if vm_stop_time is None: vm_stop_time = 300 for i in range(vm_stop_time, 300): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Running": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within 300s.") vm.destroy() test_util.test_pass('Test VM none change to Stopped within 300s Success')
def test(): global kvm_host_uuid conditions = res_ops.gen_query_conditions('state', '=', 'Enabled') if res_ops.query_resource(res_ops.HOST, conditions): kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid else: test_util.test_skip("There is no host. Skip test") test_util.test_dsc('Test KVM Host Infomation: password, sshPort, username') #====================== Password ====================== test_util.test_dsc('Update Password') host_ops.update_kvm_host(kvm_host_uuid, 'password', 'zstackmevoco') exception_catch = 0 try: host_ops.reconnect_host(kvm_host_uuid) except: exception_catch = 1 finally: if exception_catch == 0: test_util.test_fail('not catch the exception, but shuold fail to reconnect KVM host after updating the password of KVM host') elif exception_catch == 1: test_util.test_dsc('catch the exception, cannot reconnect KVM host after updating the password of KVM host') test_util.test_dsc('Update KVM Host Password') cmd = 'echo "zstackmevoco"| passwd --stdin root' os.system(cmd) host_ops.reconnect_host(kvm_host_uuid) test_util.test_dsc('Recover KVM Host Password') host_ops.update_kvm_host(kvm_host_uuid, 'password', 'password') cmd = 'echo "password"| passwd --stdin root' os.system(cmd) #====================== sshPort ====================== test_util.test_dsc('Update sshPort') host_ops.update_kvm_host(kvm_host_uuid, 'sshPort', '23') exception_catch = 0 try: host_ops.reconnect_host(kvm_host_uuid) except: exception_catch = 1 finally: if exception_catch == 0: test_util.test_fail('not catch the exception, but shuold fail to reconnect KVM host after updating the sshPort of KVM host') elif exception_catch == 1: test_util.test_dsc('catch the exception, cannot reconnect KVM host after updating the sshPort of KVM host') test_util.test_dsc('Update KVM Host SSH Port') cmd = 'sed -i \'/#Port 22/ i Port 23\' /etc/ssh/sshd_config' os.system(cmd) cmd = 'service sshd restart' os.system(cmd) host_ops.reconnect_host(kvm_host_uuid) test_util.test_dsc('Recover KVM Host SSH Port') host_ops.update_kvm_host(kvm_host_uuid, 'sshPort', '22') cmd = 'sed -i \'/Port 23/d\' /etc/ssh/sshd_config' os.system(cmd) cmd = 'service sshd restart' os.system(cmd) #====================== username ====================== test_util.test_dsc('Update Username') host_ops.update_kvm_host(kvm_host_uuid, 'username', 'test') exception_catch = 0 try: host_ops.reconnect_host(kvm_host_uuid) except: exception_catch = 1 finally: if exception_catch == 0: test_util.test_fail('not catch the exception, but shuold fail to reconnect KVM host after updating the username of KVM host') elif exception_catch == 1: test_util.test_dsc('catch the exception, cannot reconnect KVM host after updating the username of KVM host') test_util.test_dsc('Update KVM Host username') cmd = 'adduser test' os.system(cmd) cmd = 'echo "password"| passwd --stdin test' os.system(cmd) host_ops.reconnect_host(kvm_host_uuid) test_util.test_dsc('Recover KVM Host username') host_ops.update_kvm_host(kvm_host_uuid, 'username', 'root') cmd = 'userdel test' os.system(cmd) test_util.test_pass('KVM Host Update Infomation SUCCESS')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions("status", '=', "Connected") bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) os.system( "echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm.vm.uuid) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'maintain') test_stub.maintain_all_pss() if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() test_util.test_dsc('Detach ISO to VM') img_ops.detach_iso(vm.vm.uuid) #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() vm.destroy() #vm.check() #vm.expunge() vm.check() test_util.test_pass('PS maintain mode Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) test_stub.skip_if_not_storage_network_separate(test_lib.all_scenario_config) 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('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid test_lib.clean_up_all_vr() 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) 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() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts): test_util.test_fail("Not find out a suitable host") host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid test_stub.ensure_all_vrs_on_host(host_uuid) 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)) 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) test_stub.check_if_vm_starting_incorrectly_on_original_host(vm.get_vm().uuid, host_uuid, max_count=300) 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) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid) vm.set_state(vm_header.RUNNING) vm.check() 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.destroy() test_util.test_pass('Test checking vm status after graceful 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") max_attempts = test_lib.lib_get_ha_selffencer_maxattempts() test_lib.lib_set_ha_selffencer_maxattempts('12') storagechecker_timeout = test_lib.lib_get_ha_selffencer_storagechecker_timeout( ) test_lib.lib_set_ha_selffencer_storagechecker_timeout('15') 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() #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, "OnHostFailure") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') host_username = os.environ.get('hostUsername') host_password = os.environ.get('hostPassword') cmd = "ifdown %s && sleep 180 && ifup %s" % (l2_network_interface, l2_network_interface) rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd, 180) if rsp: test_util.test_fail( "host is expected to shutdown after its network down for a while") else: test_util.test_logger("host may have been shutdown") cmd = "date" rsp = test_lib.lib_execute_ssh_cmd(host_ip, host_username, host_password, cmd) if rsp: test_util.test_fail( "host is expected to shutdown after its network down for a while") else: test_util.test_logger("host have been shutdown") try: vm.destroy() except: test_util.test_logger("destroy vm may time out since host is down") 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 Host Self fence Success')
def test(): global vm global host_uuid global test_host global host_ip global max_attempts global storagechecker_timeout must_ps_list = [inventory.LOCAL_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_if_any_ps_not_deployed(must_ps_list) 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('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) #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('ls_vm_ha_self_start') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts+mn_hosts+nfs_hosts): test_util.test_fail("Not find out a suitable host") host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid test_stub.ensure_all_vrs_on_host(host_uuid) #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) #target_host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid #for vr in vrs: # if test_lib.lib_find_host_by_vr(vr).managementIp != test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp: # vm_ops.migrate_vm(vr.uuid, target_host_uuid) #vm.check() 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') vm_stop_time = None cond = res_ops.gen_query_conditions('name', '=', 'ls_vm_ha_self_start') cond = res_ops.gen_query_conditions('uuid', '=', vm.vm.uuid, cond) for i in range(0, 180): vm_stop_time = i if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Stopped": 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) conditions = res_ops.gen_query_conditions('managementIp', '=', host_ip) kvm_host_uuid = res_ops.query_resource(res_ops.HOST, conditions)[0].uuid host_ops.reconnect_host(kvm_host_uuid) break time.sleep(1) if vm_stop_time is None: vm_stop_time = 180 for i in range(vm_stop_time, 180): if res_ops.query_resource(res_ops.VM_INSTANCE, cond)[0].state == "Starting": break time.sleep(1) else: test_util.test_fail("vm has not been changed to running as expected within 180s.") vm.destroy() test_util.test_pass('Test checking VM ha and none status when force stop vm Success.')
def env_recover(): test_lib.lib_error_cleanup(test_obj_dict) os.system('PORT=%s bash -ex %s %s' % (record['host_port'], os.environ.get('hostRecoverScript'), record['host_ip'])) host_ops.reconnect_host(record['host_uuid'])
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, "SharedBlock"] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) test_util.test_dsc('Create test vm and check') bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None) if not bss: test_util.test_skip("not find available backup storage. Skip test") test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags( ['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'disable') test_stub.disable_all_pss() if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() volume.delete() #volume.expunge() volume.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS disable mode Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout allow_ps_list = [ inventory.CEPH_PRIMARY_STORAGE_TYPE, inventory.NFS_PRIMARY_STORAGE_TYPE, 'SharedMountPoint' ] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) 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 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) 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) 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() test_stub.ensure_host_has_no_vr(host_uuid) #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, "OnHostFailure") l2_network_interface = os.environ.get('l2ManagementNetworkInterface') cmd = "ifconfig %s down && sleep 180 && ifconfig %s up" % ( 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 rsp: test_util.test_fail( "host is expected to shutdown after its network down for a while") else: test_util.test_logger("host may have been shutdown") 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() 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 email_endpoint_uuid, email_platform_uuid, my_sns_topic_uuid, host_sns_topic_uuid, ps_uuid, hostname, host_management_ip, host_uuid, host_status, bs_uuid, bs_type, bs_status bs_cond = res_ops.gen_query_conditions('status', '=', 'Connected') bs_list = res_ops.query_resource(res_ops.BACKUP_STORAGE, bs_cond) for bss in bs_list: if bss.type == res_ops.SFTP_BACKUP_STORAGE: bs_uuid = bss.uuid bs_type = bss.type hostname = bss.hostname break elif bss.type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_uuid = bss.uuid bs_type = bss.type hostname = bss.hostname break else: test_util.test_skip('No match backupStorage,test skip') smtp_server = os.environ.get('smtpServer') pop_server = os.environ.get('popServer') smtp_port = os.environ.get('smtpPort') username = os.environ.get('mailUsername') password = os.environ.get('mailPassword') email_platform_name = 'Alarm_email' email_platform = zwt_ops.create_sns_email_platform(smtp_server, smtp_port, email_platform_name, username, password) email_platform_uuid = email_platform.uuid try: zwt_ops.validate_sns_email_platform(email_platform_uuid) except: test_util.test_fail( 'Validate SNS Email Platform Failed, Email Plarform: %s' % email_platform_uuid) email_endpoint_uuid = zwt_ops.create_sns_email_endpoint( username, 'test_qa', email_platform_uuid).uuid my_sns_topic = zwt_ops.create_sns_topic('my_sns_topic') my_sns_topic_uuid = my_sns_topic.uuid zwt_ops.subscribe_sns_topic(my_sns_topic_uuid, email_endpoint_uuid) host_sns_topic = zwt_ops.create_sns_topic('host_topic') host_sns_topic_uuid = host_sns_topic.uuid zwt_ops.subscribe_sns_topic(host_sns_topic_uuid, email_endpoint_uuid) ps_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] ps_namespace = 'ZStack/PrimaryStorage' ps_disconnected = 'PrimaryStorageDisconnected' ps_event_sub_uuid = zwt_ops.subscribe_event(ps_namespace, ps_disconnected, ps_actions).uuid event_list.append(ps_event_sub_uuid) bs_actions = [{"actionUuid": my_sns_topic_uuid, "actionType": "sns"}] bs_namespace = 'ZStack/BackupStorage' bs_disconnected = 'BackupStorageDisconnected' bs_event_sub_uuid = zwt_ops.subscribe_event(bs_namespace, bs_disconnected, bs_actions).uuid event_list.append(bs_event_sub_uuid) host_actions = [{"actionUuid": host_sns_topic_uuid, "actionType": "sns"}] host_namespace = 'ZStack/Host' host_status_changed = 'HostStatusChanged' host_status_labels = [{ "key": "NewStatus", "op": "Equal", "value": "Disconnected" }] host_status_event_sub_uuid = zwt_ops.subscribe_event( host_namespace, host_status_changed, host_actions, host_status_labels).uuid event_list.append(host_status_event_sub_uuid) host_disconnected = 'HostDisconnected' host_disconnected_event_sub_uuid = zwt_ops.subscribe_event( host_namespace, host_disconnected, host_actions).uuid event_list.append(host_disconnected_event_sub_uuid) if zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected, ps_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected, bs_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, host_status_changed, host_status_event_sub_uuid): test_util.test_fail('email already exsist before test') if zwt_ops.check_sns_email(pop_server, username, password, host_disconnected, host_disconnected_event_sub_uuid): test_util.test_fail('email already exsist before test') # Disconnected ps ,bs and host zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid primary_storage_option = test_util.PrimaryStorageOption() primary_storage_option.set_type('nfs') primary_storage_option.set_zone_uuid(zone_uuid) primary_storage_option.set_name('test_nfs_ps') primary_storage_option.set_url('222.222.222.222/nfs/') try: ps_uuid = ps_ops.create_nfs_primary_storage( primary_storage_option).uuid ps_ops.reconnect_primary_storage(ps_uuid) except: pass if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info(bs_uuid, 'hostname', '222.222.222.222') try: bs_ops.reconnect_backup_storage(bs_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid) bs_status = res_ops.query_resource( res_ops.IMAGE_STORE_BACKUP_STORAGE, cond)[0].status elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', '222.222.222.222') try: bs_ops.reconnect_backup_storage(bs_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', bs_uuid) bs_status = res_ops.query_resource(res_ops.SFTP_BACKUP_STORAGE, cond)[0].status host_cond = res_ops.gen_query_conditions('status', '=', 'Connected') host = res_ops.query_resource_with_num(res_ops.HOST, host_cond, start=0, limit=1)[0] host_uuid = host.uuid host_management_ip = host.managementIp host_ops.update_host(host_uuid, 'managementIp', '222.222.222.222') try: host_ops.reconnect_host(host_uuid) except: cond = res_ops.gen_query_conditions('uuid', '=', host_uuid) bs_status = res_ops.query_resource(res_ops.HOST, cond)[0].status # wait for send email time.sleep(60) ps_ops.delete_primary_storage(ps_uuid) if hostname: if bs_type == res_ops.IMAGE_STORE_BACKUP_STORAGE: bs_ops.update_image_store_backup_storage_info( bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) elif bs_type == res_ops.SFTP_BACKUP_STORAGE: bs_ops.update_sftp_backup_storage_info(bs_uuid, 'hostname', hostname) bs_ops.reconnect_backup_storage(bs_uuid) host_ops.update_host(host_uuid, 'managementIp', host_management_ip) host_ops.reconnect_host(host_uuid) zwt_ops.delete_sns_topic(host_sns_topic_uuid) zwt_ops.delete_sns_topic(my_sns_topic_uuid) for event_uuid in event_list: zwt_ops.unsubscribe_event(event_uuid) zwt_ops.delete_sns_application_endpoint(email_endpoint_uuid) zwt_ops.delete_sns_application_platform(email_platform_uuid) check_1 = zwt_ops.check_sns_email(pop_server, username, password, ps_disconnected, ps_event_sub_uuid) check_2 = zwt_ops.check_sns_email(pop_server, username, password, bs_disconnected, bs_event_sub_uuid) check_3 = zwt_ops.check_sns_email(pop_server, username, password, host_status_changed, host_status_event_sub_uuid) check_4 = zwt_ops.check_sns_email(pop_server, username, password, host_disconnected, host_disconnected_event_sub_uuid) if check_1 and check_2 and check_3 and check_4: test_util.test_pass( 'test host ,bs, ps disconnected event with email success!') else: test_util.test_fail('cannt receive all event mail')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] #vr_uuid = vr.uuid #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) #volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) #volume.attach(vm1) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'maintain') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to stop when PS change to maintain state') vm.set_state(vm_header.STOPPED) vm.check() volume.delete() #volume.expunge() maintain mode is not support volume expunge volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) #vm_ops.reconnect_vr(vr_uuid) vrs = test_lib.lib_get_all_vrs() for vr in vrs: vm_ops.start_vm(vr.uuid) vm.start() vm.check() vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS maintain mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanDNATNetworkName') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid l3_net_list = [l3_net_uuid] l3_name2 = os.environ.get('l3VlanNetworkName1') l3_net_uuid2 = test_lib.lib_get_l3_by_name(l3_name2).uuid vm = test_stub.create_vm(l3_net_list, image_uuid, 'attach_nic_vm', \ default_l3_uuid = l3_net_uuid) test_obj_dict.add_vm(vm) vm.check() l3_1 = test_lib.lib_get_l3_by_name(l3_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid vm.add_nic(l3_net_uuid2) attached_nic = test_lib.lib_get_vm_last_nic(vm.get_vm()) if l3_net_uuid2 != attached_nic.l3NetworkUuid: test_util.test_fail("After attach a nic, VM:%s last nic is not belong l3: %s" % (vm.get_vm().uuid, l3_net_uuid2)) test_lib.lib_restart_vm_network(vm.get_vm()) vm.check() ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.remove_nic(attached_nic.uuid) attached_nic = test_lib.lib_get_vm_last_nic(vm.get_vm()) if l3_net_uuid != attached_nic.l3NetworkUuid: test_util.test_fail("After detached NIC, VM:%s only nic is not belong l3: %s" % (vm.get_vm().uuid, l3_net_uuid2)) vm.add_nic(l3_net_uuid2) attached_nic = test_lib.lib_get_vm_last_nic(vm.get_vm()) if l3_net_uuid2 != attached_nic.l3NetworkUuid: test_util.test_fail("After attach a nic, VM:%s last nic is not belong l3: %s" % (vm.get_vm().uuid, l3_net_uuid2)) test_lib.lib_restart_vm_network(vm.get_vm()) vm.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.check() vm.destroy() vm.check() #vm.expunge() test_util.test_pass('PS disable mode Test Success')
def test(): global vm global host_uuid global host_ip global max_attempts global storagechecker_timeout must_ps_list = [inventory.NFS_PRIMARY_STORAGE_TYPE] test_lib.skip_test_if_any_ps_not_deployed(must_ps_list) 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) #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() vr_hosts = test_stub.get_host_has_vr() mn_hosts = test_stub.get_host_has_mn() nfs_hosts = test_stub.get_host_has_nfs() if not test_stub.ensure_vm_not_on(vm.get_vm().uuid, vm.get_vm().hostUuid, vr_hosts + mn_hosts + nfs_hosts): test_util.test_fail("Not find out a suitable host") host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid test_stub.ensure_all_vrs_on_host(host_uuid) #vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) #target_host_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid #for vr in vrs: # if test_lib.lib_find_host_by_vr(vr).managementIp != test_lib.lib_find_host_by_vm(vm.get_vm()).managementIp: # vm_ops.migrate_vm(vr.uuid, target_host_uuid) #vm.check() 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_uuid = test_lib.lib_find_host_by_vm(vm.get_vm()).uuid ha_ops.set_vm_instance_ha_level(vm.get_vm().uuid, "NeverStop") test_util.test_logger("force stop host: %s" % (host_ip)) os.system('bash -ex %s %s' % (os.environ.get('hostForceStopScript'), host_ip)) test_util.test_logger("host is expected to shutdown for a while") test_util.test_logger("wait for 300 seconds") time.sleep(300) 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() if test_lib.lib_get_vm_last_host(vm.get_vm()).managementIp != host_ip: test_util.test_fail( "Migrated VM's last host is expected to be the last host[ip:%s]" % (host_ip)) vm.destroy() 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')