def migrate_mn_vm(origin_host, target_host, scenarioConfig): if test_lib.lib_cur_cfg_is_a_and_b(["test-config-vyos-flat-dhcp-nfs-sep-pub-man.xml"], ["scenario-config-nfs-sep-pub.xml"]) or \ test_lib.lib_cur_cfg_is_a_and_b(["test-config-vyos-ceph-3-nets-sep.xml"], ["scenario-config-ceph-sep-pub.xml"]): cmd = 'zsha migrate %s' % (target_host.managementIp_) host_config = sce_ops.get_scenario_config_vm(origin_host.name_, scenarioConfig) test_lib.lib_execute_ssh_cmd(origin_host.managementIp_, host_config.imageUsername_, host_config.imagePassword_,cmd) else: cmd = 'zsha migrate %s' % (target_host.ip_) host_config = sce_ops.get_scenario_config_vm(origin_host.name_, scenarioConfig) test_lib.lib_execute_ssh_cmd(origin_host.ip_, host_config.imageUsername_, host_config.imagePassword_,cmd)
def shutdown_host_network(host_vm, scenarioConfig, downMagt=True): ''' Here we change l2network_nic to be global is due to the maybe failed once all mn nodes disconnected In that case, lib_get_l2_magt_nic_by_vr_offering will be failed because of mn is disconnected. Of course, to be global means the management network can be only selected once in ZStack DB. ''' global l2network_nic zstack_management_ip = scenarioConfig.basicConfig.zstackManagementIp.text_ cond = res_ops.gen_query_conditions('vmNics.ip', '=', host_vm.ip_) host_vm_inv = sce_ops.query_resource(zstack_management_ip, res_ops.VM_INSTANCE, cond).inventories[0] cond = res_ops.gen_query_conditions('uuid', '=', host_vm_inv.hostUuid) host_inv = sce_ops.query_resource(zstack_management_ip, res_ops.HOST, cond).inventories[0] host_vm_config = sce_ops.get_scenario_config_vm(host_vm_inv.name_, scenarioConfig) if not l2network_nic: if downMagt: l2network_nic = test_lib.lib_get_l2_magt_nic_by_vr_offering() else: l2network_nic = test_lib.lib_get_l2_pub_nic_by_vr_offering() if not l2network_nic: test_util.test_fail("fail to get management l2 by vr offering") #l2network_nic = os.environ.get('l2ManagementNetworkInterface').replace("eth", "zsn") cmd = "ifdown %s" % (l2network_nic) sce_ops.execute_in_vm_console(zstack_management_ip, host_inv.managementIp, host_vm_inv.uuid, host_vm_config, cmd)
def wait_for_mn_ha_ready(scenarioConfig, scenarioFile): mn_host_list = get_mn_host(scenarioConfig, scenarioFile) if len(mn_host_list) < 1: return [] for i in range(0, 5): for host in mn_host_list: host_config = sce_ops.get_scenario_config_vm(host.name_, scenarioConfig) try: cmd = "zsha status" zsha_status = test_lib.lib_execute_ssh_cmd(host.ip_, host_config.imageUsername_, host_config.imagePassword_,cmd) if zsha_status.find('3 osds: 3 up, 3 in') <= 0: continue if zsha_status.count('alive') < 3: continue if zsha_status.count(': ceph') < 3: continue if zsha_status.count(': running') < 1: continue if zsha_status.count('3 mons at') < 1: continue return True except: continue time.sleep(10) return False
def upgrade_zsha(scenarioConfig, scenarioFile): host_list = get_mn_host(scenarioConfig, scenarioFile) test_host = host_list[0] test_host_ip = test_host.ip_ zsha_path = "/home/%s/zs-ha" % test_host_ip config_path = "/home/%s/config.json" % test_host_ip current_zsha_path = "/tmp/zstack-ha-installer/zsha" check_cmd = "ls -l %s" % current_zsha_path host_config = sce_ops.get_scenario_config_vm(test_host.name_, scenarioConfig) former_time = [] for host in host_list: former_zsha = test_lib.lib_execute_ssh_cmd(host.ip_, host_config.imageUsername_, host_config.imagePassword_, check_cmd) former_time.append(former_zsha.split()[7]) upgrade_zsha_cmd = "%s install -p %s -c %s" % ( zsha_path, host_config.imagePassword_, config_path) test_lib.lib_execute_ssh_cmd(test_host_ip, host_config.imageUsername_, host_config.imagePassword_, upgrade_zsha_cmd) current_time = [] for host in host_list: current_zsha = test_lib.lib_execute_ssh_cmd(host.ip_, host_config.imageUsername_, host_config.imagePassword_, check_cmd) current_time.append(current_zsha.split()[7]) for i in range(len(former_time)): if current_time[i] == former_time[i]: return False return True
def get_s_vm_cfg_lst_vip_bind(scenarioConfig, scenarioFile, retry_times=1): """ It gets host with vip bound, while returned a s_vm config """ mha_s_vm_list = get_mha_s_vm_list_from_scenario_file(scenarioConfig, scenarioFile) if len(mha_s_vm_list) < 1: return [] test_util.test_logger("@@DEBUG@@: mha_s_vm_list=<%s>" %(str(mha_s_vm_list))) host_list = [] vip = os.environ['zstackHaVip'] for host in mha_s_vm_list: host_config = sce_ops.get_scenario_config_vm(host.name_, scenarioConfig) cmd = "ip a|grep " + vip try: for retry_cnt in range(retry_times): if sce_is_sep_pub(): vm_list = test_lib.lib_execute_ssh_cmd(host.managementIp_, host_config.imageUsername_, host_config.imagePassword_,cmd) else: vm_list = test_lib.lib_execute_ssh_cmd(host.ip_, host_config.imageUsername_, host_config.imagePassword_,cmd) if vm_list: host_list.append(host) break time.sleep(1) except Exception, e: test_util.test_logger("@@get host exception@@:%s" %(str(e))) continue
def deploy_ha_env(scenarioConfig, scenarioFile, deploy_config, config_json, deploy_tool, mn_img): prepare_config_json(scenarioConfig, scenarioFile, deploy_config, config_json) test_host = get_mn_host(scenarioConfig, scenarioFile)[0] test_host_ip = test_host.ip_ test_host_config = sce_ops.get_scenario_config_vm(test_host.name_, scenarioConfig) host_password = test_host_config.imagePassword_ mn_image_path = "/home/%s/mn.qcow2" % test_host_ip installer_path = "/home/%s/zs-ha" % test_host_ip config_path = "/home/%s/config.json" % test_host_ip ssh.scp_file(config_json, config_path, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_) cmd1 = "ceph osd pool create zstack 128" cmd2 = "qemu-img convert -f qcow2 -O raw %s rbd:zstack/mnvm.img" % mn_image_path cmd3 = '%s -a -p %s -c %s' % (installer_path, host_password, config_path) test_util.test_logger("[%s] %s" % (test_host_ip, cmd1)) ssh.execute(cmd1, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22) test_util.test_logger("[%s] %s" % (test_host_ip, cmd2)) ssh.execute(cmd2, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22) test_util.test_logger("[%s] %s" % (test_host_ip, cmd3)) ssh.execute(cmd3, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22)
def deploy_ha_env(scenarioConfig, scenarioFile, deploy_config, config_json, deploy_tool, mn_img): prepare_config_json(scenarioConfig, scenarioFile, deploy_config, config_json) test_host = get_mn_host[0] test_host_ip = test_host.ip_ test_host_config = sce_ops.get_scenario_config_vm(test_host.name_, scenarioConfig) host_password = test_host_config.imagePassword_ ssh.scp_file(deploy_tool, "/tmp/ZStack-HA-Installer", test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_) ssh.scp_file(config_json, "/tmp/config.json", test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_) ssh.scp_file(mn_img, "/tmp/mn.qcow2", test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_) cmd1 = "bash %s -- -I %s" % ('/tmp/ZStack-HA-Installer', '/tmp/mn.qcow2') cmd2 = 'bash %s -- -i -a -p %s -c %s' % ('/tmp/ZStack-HA-Installer', host_password, '/tmp/config.json') ssh.execute(cmd1, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22) ssh.execute(cmd2, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22)
def shutdown_host_network(host_vm, scenarioConfig, downMagt=True): ''' Here we change l2network_nic to be global is due to the maybe failed once all mn nodes disconnected In that case, lib_get_l2_magt_nic_by_vr_offering will be failed because of mn is disconnected. Of course, to be global means the management network can be only selected once in ZStack DB. ''' global l2network_nic zstack_management_ip = scenarioConfig.basicConfig.zstackManagementIp.text_ cond = res_ops.gen_query_conditions('vmNics.ip', '=', host_vm.ip_) host_vm_inv = sce_ops.query_resource(zstack_management_ip, res_ops.VM_INSTANCE, cond).inventories[0] cond = res_ops.gen_query_conditions('uuid', '=', host_vm_inv.hostUuid) host_inv = sce_ops.query_resource(zstack_management_ip, res_ops.HOST, cond).inventories[0] host_vm_config = sce_ops.get_scenario_config_vm(host_vm_inv.name_, scenarioConfig) if not l2network_nic: if downMagt: l2network_nic = test_lib.lib_get_l2_magt_nic_by_vr_offering() else: l2network_nic = test_lib.lib_get_l2_pub_nic_by_vr_offering() if not l2network_nic: test_util.test_fail("fail to get management l2 by vr offering") #l2network_nic = os.environ.get('l2ManagementNetworkInterface').replace("eth", "zsn") cmd = "ifdown %s" % (l2network_nic) sce_ops.execute_in_vm_console(zstack_management_ip, host_inv.managementIp, host_vm_inv.uuid, host_vm_config, cmd)
def check_vm_running_exist_on_host(vm_uuid, host_ip, scenarioConfig, scenarioFile): mn_host_list = get_mn_host(scenarioConfig, scenarioFile) cmd = "virsh list|grep %s|awk '{print $3}'" %(vm_uuid) host = mn_host_list[0] host_config = sce_ops.get_scenario_config_vm(host.name_, scenarioConfig) vm_is_exist = True if test_lib.lib_execute_ssh_cmd(host_ip, host_config.imageUsername_, host_config.imagePassword_,cmd) else False return vm_is_exist
def prepare_etc_hosts(scenarioConfig, scenarioFile, deploy_config, config_json): mn_host_list = get_mn_host(scenarioConfig, scenarioFile) if len(mn_host_list) < 1: return False for i in range(len(mn_host_list)): os.system('echo %s %s >> /etc/hosts' % (mn_host_list[i].ip_, mn_host_list[i].ip_.replace('.', '-'))) for i in range(len(mn_host_list)): test_host_config = sce_ops.get_scenario_config_vm(mn_host_list[i].name_, scenarioConfig) ssh.scp_file('/etc/hosts', '/etc/hosts', mn_host_list[i].ip_, test_host_config.imageUsername_, test_host_config.imagePassword_)
def prepare_etc_hosts(scenarioConfig, scenarioFile, deploy_config, config_json): mha_s_vm_list = get_mha_s_vm_list_from_scenario_file(scenarioConfig, scenarioFile) if len(mha_s_vm_list) < 1: return False for i in range(len(mha_s_vm_list)): os.system('echo %s %s >> /etc/hosts' % (mha_s_vm_list[i].ip_, mha_s_vm_list[i].ip_.replace('.', '-'))) for i in range(len(mha_s_vm_list)): test_host_config = sce_ops.get_scenario_config_vm(mha_s_vm_list[i].name_, scenarioConfig) ssh.scp_file('/etc/hosts', '/etc/hosts', mha_s_vm_list[i].ip_, test_host_config.imageUsername_, test_host_config.imagePassword_)
def recover_host_vlan(host_vm, scenarioConfig, deploy_config): host_ip = host_vm.ip_ test_lib.lib_wait_target_up(host_ip, '22', 120) host_config = sce_ops.get_scenario_config_vm(host_vm.name_,scenarioConfig) for l3network in xmlobject.safe_list(host_config.l3Networks.l3Network): if hasattr(l3network, 'l2NetworkRef'): for l2networkref in xmlobject.safe_list(l3network.l2NetworkRef): nic_name = sce_ops.get_ref_l2_nic_name(l2networkref.text_, deploy_config) if nic_name.find('.') >= 0 : vlan = nic_name.split('.')[1] test_util.test_logger('[vm:] %s %s is created.' % (host_ip, nic_name.replace("eth", "zsn"))) cmd = 'vconfig add %s %s' % (nic_name.split('.')[0].replace("eth", "zsn"), vlan) test_lib.lib_execute_ssh_cmd(host_ip, host_config.imageUsername_, host_config.imagePassword_, cmd) return True
def get_host_by_mn_vm(vm_uuid, scenarioConfig, scenarioFile): mn_host_list = get_mn_host(scenarioConfig, scenarioFile) if len(mn_host_list) < 1: return None host_list = [] for host in mn_host_list: host_config = sce_ops.get_scenario_config_vm(host.name_, scenarioConfig) cmd = "virsh list | grep MN-VM" vm_list = test_lib.lib_execute_ssh_cmd(host.ip_, host_config.imageUsername_, vm_config.imagePassword_, cmd) if vm_list: host_list.append(host)
def update_mn_vm_config(mn_vm_host, option, content, scenarioConfig, new_config="/tmp/zstack-ha-installer/config.json"): cmd1 = 'sed -i "s/\\\"%s\\\": \\\".*\\\"/\\\"%s\\\": \\\"%s\\\"/g" %s' % ( option, option, content, new_config) cmd2 = "zsha import-config %s" % new_config host_config = sce_ops.get_scenario_config_vm(mn_vm_host.name_, scenarioConfig) test_lib.lib_execute_ssh_cmd(mn_vm_host.ip_, host_config.imageUsername_, host_config.imagePassword_, cmd1) test_lib.lib_execute_ssh_cmd(mn_vm_host.ip_, host_config.imageUsername_, host_config.imagePassword_, cmd2)
def get_host_by_mn_vm_consul(scenarioConfig, scenarioFile): mn_host_list = get_mn_host(scenarioConfig, scenarioFile) if len(mn_host_list) < 1: return [] host_list = [] for host in mn_host_list: host_config = sce_ops.get_scenario_config_vm(host.name_, scenarioConfig) cmd = "consul kv get z/last_start_vm_output | awk -F '[' '{print $2}' | awk -F ']' '{print $1}'" try: host_ip = test_lib.lib_execute_ssh_cmd(host.ip_, host_config.imageUsername_, host_config.imagePassword_,cmd) except: continue if host_ip != "" and host_ip != False: return host_ip.strip() return ""
def reopen_host_network(host_vm, scenarioConfig): zstack_management_ip = scenarioConfig.basicConfig.zstackManagementIp.text_ cond = res_ops.gen_query_conditions('vmNics.ip', '=', host_vm.ip_) host_vm_inv = sce_ops.query_resource(zstack_management_ip, res_ops.VM_INSTANCE, cond).inventories[0] cond = res_ops.gen_query_conditions('uuid', '=', host_vm_inv.hostUuid) host_inv = sce_ops.query_resource(zstack_management_ip, res_ops.HOST, cond).inventories[0] host_vm_config = sce_ops.get_scenario_config_vm(host_vm_inv.name_, scenarioConfig) l2network_nic = os.environ.get('l2ManagementNetworkInterface') cmd = "ifup %s" % (l2network_nic) sce_ops.execute_in_vm_console(zstack_management_ip, host_inv.managementIp, host_vm_inv.uuid, host_vm_config, cmd)
def get_host_by_consul_leader(scenarioConfig, scenarioFile): mn_host_list = get_mn_host(scenarioConfig, scenarioFile) if len(mn_host_list) < 1: return [] host_list = [] for i in range(5): for host in mn_host_list: host_config = sce_ops.get_scenario_config_vm(host.name_, scenarioConfig) cmd = "consul info |grep -i leader_addr | awk '{print $3}' | awk -F ':' '{print $1}'" host_ip = test_lib.lib_execute_ssh_cmd(host.ip_, host_config.imageUsername_, host_config.imagePassword_,cmd) if host_ip != "" and host_ip != False and host_ip.count('.') == 3: return host_ip.strip() else: test_util.test_logger("@@@host.ip_: %s exception when execute consul info" %(host.ip_)) time.sleep(1) return ""
def recover_host(host_vm, scenarioConfig, deploy_config): stop_host(host_vm, scenarioConfig) host_inv = start_host(host_vm, scenarioConfig) if not host_inv: return False host_ip = host_vm.ip_ test_lib.lib_wait_target_up(host_ip, '22', 120) host_config = sce_ops.get_scenario_config_vm(host_inv.name,scenarioConfig) for l3network in xmlobject.safe_list(host_config.l3Networks.l3Network): if hasattr(l3network, 'l2NetworkRef'): for l2networkref in xmlobject.safe_list(l3network.l2NetworkRef): nic_name = sce_ops.get_ref_l2_nic_name(l2networkref.text_, deploy_config) if nic_name.find('.') >= 0 : vlan = nic_name.split('.')[1] test_util.test_logger('[vm:] %s %s is created.' % (host_ip, nic_name.replace("eth","zsn"))) cmd = 'vconfig add %s %s' % (nic_name.split('.')[0].replace("eth","zsn"), vlan) test_lib.lib_execute_ssh_cmd(host_ip, host_config.imageUsername_, host_config.imagePassword_, cmd) return True
def reopen_host_network(host_vm, scenarioConfig, param_l2_nic=""): ''' This function can be only invoked after shutdown_host_network. ''' global l2network_nic zstack_management_ip = scenarioConfig.basicConfig.zstackManagementIp.text_ cond = res_ops.gen_query_conditions('vmNics.ip', '=', host_vm.ip_) host_vm_inv = sce_ops.query_resource(zstack_management_ip, res_ops.VM_INSTANCE, cond).inventories[0] cond = res_ops.gen_query_conditions('uuid', '=', host_vm_inv.hostUuid) host_inv = sce_ops.query_resource(zstack_management_ip, res_ops.HOST, cond).inventories[0] host_vm_config = sce_ops.get_scenario_config_vm(host_vm_inv.name_, scenarioConfig) if not l2network_nic and not param_l2_nic: test_util.test_fail("fail to get management l2 by vr offering") #l2network_nic = os.environ.get('l2ManagementNetworkInterface').replace("eth", "zsn") cmd = "ifup %s" % (l2network_nic) if param_l2_nic: cmd = "ifup %s" % (param_l2_nic) sce_ops.execute_in_vm_console(zstack_management_ip, host_inv.managementIp, host_vm_inv.uuid, host_vm_config, cmd)
def get_host_by_mn_vm(scenarioConfig, scenarioFile): mn_host_list = get_mn_host(scenarioConfig, scenarioFile) if len(mn_host_list) < 1: return [] test_util.test_logger("@@DEBUG@@: mn_host_list=<%s>" %(str(mn_host_list))) host_list = [] for host in mn_host_list: host_config = sce_ops.get_scenario_config_vm(host.name_, scenarioConfig) cmd = "virsh list | grep -v paused | grep \"ZStack Management Node VM\"" try: if sce_is_sep_pub(): vm_list = test_lib.lib_execute_ssh_cmd(host.managementIp_, host_config.imageUsername_, host_config.imagePassword_,cmd) else: vm_list = test_lib.lib_execute_ssh_cmd(host.ip_, host_config.imageUsername_, host_config.imagePassword_,cmd) if vm_list: host_list.append(host) except Exception, e: test_util.test_logger("@@get host exception@@:%s" %(str(e))) continue
def get_host_by_mn_vm(scenarioConfig, scenarioFile): mn_host_list = get_mn_host(scenarioConfig, scenarioFile) if len(mn_host_list) < 1: return [] host_list = [] for host in mn_host_list: host_config = sce_ops.get_scenario_config_vm(host.name_, scenarioConfig) cmd = "virsh list | grep -v paused | grep \"ZStack Management Node VM\"" try: vm_list = test_lib.lib_execute_ssh_cmd(host.ip_, host_config.imageUsername_, host_config.imagePassword_, cmd) if vm_list: host_list.append(host) except: continue return host_list
def reopen_host_network(host_vm, scenarioConfig, param_l2_nic=""): ''' This function can be only invoked after shutdown_host_network. ''' global l2network_nic zstack_management_ip = scenarioConfig.basicConfig.zstackManagementIp.text_ cond = res_ops.gen_query_conditions('vmNics.ip', '=', host_vm.ip_) host_vm_inv = sce_ops.query_resource(zstack_management_ip, res_ops.VM_INSTANCE, cond).inventories[0] cond = res_ops.gen_query_conditions('uuid', '=', host_vm_inv.hostUuid) host_inv = sce_ops.query_resource(zstack_management_ip, res_ops.HOST, cond).inventories[0] host_vm_config = sce_ops.get_scenario_config_vm(host_vm_inv.name_, scenarioConfig) if not l2network_nic and not param_l2_nic: test_util.test_fail("fail to get management l2 by vr offering") #l2network_nic = os.environ.get('l2ManagementNetworkInterface').replace("eth", "zsn") cmd = "ifup %s" % (l2network_nic) if param_l2_nic: cmd = "ifup %s" % (param_l2_nic) sce_ops.execute_in_vm_console(zstack_management_ip, host_inv.managementIp, host_vm_inv.uuid, host_vm_config, cmd)
def get_host_by_consul_leader(scenarioConfig, scenarioFile): mn_host_list = get_mn_host(scenarioConfig, scenarioFile) if len(mn_host_list) < 1: return [] host_list = [] for host in mn_host_list: host_config = sce_ops.get_scenario_config_vm(host.name_, scenarioConfig) cmd = "consul info |grep -i leader_addr | awk '{print $3}' | awk -F ':' '{print $1}'" try: host_ip = test_lib.lib_execute_ssh_cmd(host.ip_, host_config.imageUsername_, host_config.imagePassword_, cmd) except: continue if host_ip != "" and host_ip != False and host_ip.count('.') == 3: return host_ip.strip() return ""
def recover_vlan_in_host(host_ip, scenarioConfig, deploy_config): test_util.test_logger("func: recover_vlan_in_host; host_ip=%s" %(host_ip)) host_inv = query_host(host_ip, scenarioConfig) test_lib.lib_wait_target_up(host_ip, '22', 120) host_config = sce_ops.get_scenario_config_vm(host_inv.name,scenarioConfig) for l3network in xmlobject.safe_list(host_config.l3Networks.l3Network): test_util.test_logger("loop in for l3network") if hasattr(l3network, 'l2NetworkRef'): test_util.test_logger("below if l2NetworkRef") for l2networkref in xmlobject.safe_list(l3network.l2NetworkRef): test_util.test_logger("loop in l2networkref") nic_name = sce_ops.get_ref_l2_nic_name(l2networkref.text_, deploy_config) test_util.test_logger("nic_name=%s; l2networkref.text_=%s" %(nic_name, l2networkref.text_)) if nic_name.find('.') >= 0 : vlan = nic_name.split('.')[1] test_util.test_logger('[vm:] %s %s is created.' % (host_ip, nic_name.replace("eth","zsn"))) cmd = 'vconfig add %s %s' % (nic_name.split('.')[0].replace("eth","zsn"), vlan) test_util.test_logger("vconfig cmd=%s" %(cmd)) test_lib.lib_execute_ssh_cmd(host_ip, host_config.imageUsername_, host_config.imagePassword_, cmd) return True
def check_if_vip_is_on_host(scenarioConfig, scenarioFile, host_ip, retry_times=1): """ It checks whether vip is on host_ip """ mha_s_vm_list = get_mha_s_vm_list_from_scenario_file(scenarioConfig, scenarioFile) if len(mha_s_vm_list) < 1: test_util.test_fail("not found mha host in check_if_vip_is_on_host") test_util.test_logger("@@DEBUG@@: mha_s_vm_list=<%s>" %(str(mha_s_vm_list))) vip = os.environ['zstackHaVip'] cmd = "ip a|grep " + vip for retry_cnt in range(retry_times): for host in mha_s_vm_list: if host.ip_ == host_ip: host_config = sce_ops.get_scenario_config_vm(host.name_, scenarioConfig) is_find = test_lib.lib_execute_ssh_cmd(host.ip_, host_config.imageUsername_, host_config.imagePassword_,cmd) if is_find: return True time.sleep(1) test_util.test_logger("not find vip in host_ip:%s" %(host_ip)) return False
def up_host_network(host_ip, scenarioConfig, network_type): zstack_management_ip = scenarioConfig.basicConfig.zstackManagementIp.text_ cond = res_ops.gen_query_conditions('vmNics.ip', '=', host_ip) host_vm_inv = sce_ops.query_resource(zstack_management_ip, res_ops.VM_INSTANCE, cond).inventories[0] cond = res_ops.gen_query_conditions('uuid', '=', host_vm_inv.hostUuid) host_inv = sce_ops.query_resource(zstack_management_ip, res_ops.HOST, cond).inventories[0] host_vm_config = sce_ops.get_scenario_config_vm(host_vm_inv.name_, scenarioConfig) if network_type == "storage_net": filter_key = "br_vx" elif network_type == "managment_net": filter_key = "br_bond0" else: test_util.test_fail("not support netwoek_type=%s" %(str(network_type))) cmd = "virsh domiflist %s|grep %s|awk '{print $1}'|xargs -i virsh domif-setlink %s {} up" % (host_vm_inv.uuid, filter_key, host_vm_inv.uuid) if test_lib.lib_execute_ssh_cmd(host_inv.managementIp, host_username, host_password, "pwd"): test_lib.lib_execute_ssh_cmd(host_inv.managementIp, host_username, host_password, cmd) elif test_lib.lib_execute_ssh_cmd(host_inv.managementIp, host_username, host_password2, "pwd"): test_lib.lib_execute_ssh_cmd(host_inv.managementIp, host_username, host_password2, cmd) else: test_util.test_fail("The candidate password are both not for the physical host %s, tried password %s;%s with username %s" %(host_inv.managementIp, host_password, host_password2, host_username))
def stop_consul(mn_host, scenarioConfig): cmd = "systemctl stop consul.service" host_config = sce_ops.get_scenario_config_vm(mn_host.name_, scenarioConfig) test_lib.lib_execute_ssh_cmd(mn_host.ip_, host_config.imageUsername_, host_config.imagePassword_, cmd)
def destroy_mn_vm(mn_host, scenarioConfig): cmd = "virsh destroy \"ZStack Management Node VM\"" host_config = sce_ops.get_scenario_config_vm(mn_host.name_, scenarioConfig) test_lib.lib_execute_ssh_cmd(mn_host.ip_, host_config.imageUsername_, host_config.imagePassword_, cmd)
def shutdown_host_network(host_vm, scenarioConfig): l2network_nic = os.environ.get('l2ManagementNetworkInterface') host_config = sce_ops.get_scenario_config_vm(host_vm.name_, scenarioConfig) cmd = "ifdown %s" % (l2network_nic) test_lib.lib_execute_ssh_cmd(host_vm.ip_, host_config.imageUsername_, host_config.imagePassword_, cmd)
def migrate_mn_vm(origin_host, target_host, scenarioConfig): cmd = 'zsha --migrate %s' % (target_host.ip_) host_config = sce_ops.get_scenario_config_vm(origin_host.name_, scenarioConfig) test_lib.lib_execute_ssh_cmd(origin_host.ip_, host_config.imageUsername_, host_config.imagePassword_, cmd)
def start_zsha(mn_host, scenarioConfig): cmd = "zsha start" host_config = sce_ops.get_scenario_config_vm(mn_host.name_, scenarioConfig) test_lib.lib_execute_ssh_cmd(mn_host.ip_, host_config.imageUsername_, host_config.imagePassword_, cmd)
def deploy_ha_env(scenarioConfig, scenarioFile, deploy_config, config_json, deploy_tool, mn_img): prepare_config_json(scenarioConfig, scenarioFile, deploy_config, config_json) mn_ha_storage_type = sce_ops.get_mn_ha_storage_type(scenarioConfig, scenarioFile, deploy_config) if mn_ha_storage_type == 'ceph': os.system('sed -i s/node/ceph-/g %s' %(config_json)) test_host = get_mn_host(scenarioConfig,scenarioFile)[0] test_host_ip = test_host.ip_ test_host_config = sce_ops.get_scenario_config_vm(test_host.name_, scenarioConfig) host_password = test_host_config.imagePassword_ mn_image_path = "/home/%s/mn.qcow2" % test_host_ip installer_path = "/home/%s/zs-ha" % test_host_ip config_path = "/home/%s/config.json" % test_host_ip ssh.scp_file(config_json, config_path, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_) ssh.scp_file(mn_img, mn_image_path, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_) ssh.scp_file(deploy_tool, installer_path, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_) cmd0 = "chmod a+x %s" % (installer_path) test_util.test_logger("[%s] %s" % (test_host_ip, cmd0)) ssh.execute(cmd0, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22) if mn_ha_storage_type == 'ceph': if test_lib.lib_cur_cfg_is_a_and_b(["test-config-vyos-ceph-3-nets-sep.xml"], ["scenario-config-storage-separate-ceph.xml"]): ceph_node_ip = get_host_by_index_in_scenario_file(scenarioConfig, scenarioFile, 0).ip_ mn_image_path = "/home/%s/mn.qcow2" % ceph_node_ip ssh.scp_file(mn_img, mn_image_path, ceph_node_ip, test_host_config.imageUsername_, test_host_config.imagePassword_) cmd0="yum install -y --disablerepo=* --enablerepo=zstack-local qemu-img" test_util.test_logger("[%s] %s" % (ceph_node_ip, cmd0)) ssh.execute(cmd0, ceph_node_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22) else: ceph_node_ip = test_host_ip cmd1="ceph osd pool create zstack 128" test_util.test_logger("[%s] %s" % (ceph_node_ip, cmd1)) ssh.execute(cmd1, ceph_node_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22) cmd2="qemu-img convert -f qcow2 -O raw %s rbd:zstack/mnvm.img" % mn_image_path test_util.test_logger("[%s] %s" % (ceph_node_ip, cmd2)) if test_lib.lib_execute_ssh_cmd(ceph_node_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, cmd2, timeout=7200 ) == False: test_util.test_fail("fail to run cmd: %s on %s" %(cmd2, ceph_node_ip)) elif mn_ha_storage_type == 'nfs': prepare_etc_hosts(scenarioConfig, scenarioFile, deploy_config, config_json) cmd1 = "cp %s /storage/mnvm.img" % (mn_image_path) test_util.test_logger("[%s] %s" % (test_host_ip, cmd1)) ssh.execute(cmd1, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22) elif mn_ha_storage_type == 'fusionstor': cmd1 = "lichbd pool create zstack -p nbd" test_util.test_logger("[%s] %s" % (test_host_ip, cmd1)) ssh.execute(cmd1, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22) cmd2 = "lichbd vol import %s zstack/mnvm.img -p nbd" %(mn_image_path) test_util.test_logger("[%s] %s" % (test_host_ip, cmd2)) ssh.execute(cmd2, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22) cmd3 = "lich.inspect --localize /default/zstack/mnvm.img 0" test_util.test_logger("[%s] %s" % (test_host_ip, cmd3)) ssh.execute(cmd3, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22) cmd3='%s install -p %s -c %s' % (installer_path, host_password, config_path) test_util.test_logger("[%s] %s" % (test_host_ip, cmd3)) #ssh.execute(cmd3, test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, True, 22) if test_lib.lib_execute_ssh_cmd(test_host_ip, test_host_config.imageUsername_, test_host_config.imagePassword_, cmd3, timeout=3600 ) == False: test_util.test_fail("fail to run cmd: %s on %s" %(cmd3, test_host_ip))