diff --git a/qemu/tests/cfg/multi_nics_verify.cfg b/qemu/tests/cfg/multi_nics_verify.cfg index 6d7b357602d5ed7ba7e75f351944f2dbcfefea0d..39ca017f24ecb523f8494a279dd4e9246205eee4 100644 --- a/qemu/tests/cfg/multi_nics_verify.cfg +++ b/qemu/tests/cfg/multi_nics_verify.cfg @@ -1,15 +1,7 @@ - multi_nics_verify: guest_test.arp_set virt_test_type = qemu type = multi_nics_verify - only Linux no RHEL.3.9 - nics += ' nic2 nic3 nic4 nic5 nic6 nic7 nic8' + nics_num = 27 + start_vm = no kill_vm = no - flexible_nic_index = yes - mac_filter = "HWaddr (.\w+:\w+:\w+:\w+:\w+:\w+)" - ip_filter = "inet addr:(.\d+.\d+.\d+.\d+)" - net_check_cmd = "ifconfig" - strick_check = "" - flood_minutes = 1 - transfer_timeout = 1000 - reboot = yes diff --git a/qemu/tests/multi_nics_verify.py b/qemu/tests/multi_nics_verify.py index dd3bc1b4d4d7224b3b846bad67a137cb35b94cab..662e4abc392172654eea9c552cd449e75dced447 100644 --- a/qemu/tests/multi_nics_verify.py +++ b/qemu/tests/multi_nics_verify.py @@ -3,6 +3,7 @@ import logging from virttest import error_context from virttest import utils_net +from virttest import env_process @error_context.context_aware @@ -23,6 +24,12 @@ def run(test, params, env): :param env: Dictionary with test environment. """ def check_nics_num(expect_c, session): + """ + Check whether guest NICs number match with params set in cfg file + + :param expect_c: expected nics no. + :param session: in which session the guest runs in + """ txt = "Check whether guest NICs info match with params setting." error_context.context(txt, logging.info) nics_list = utils_net.get_linux_ifname(session) @@ -35,39 +42,65 @@ def run(test, params, env): return (False, msg) return (True, msg + 'Nics count match') + # Get the ethernet cards number from params + nics_num = int(params.get("nics_num", 8)) + for i in range(nics_num): + nics = "nic%s" % i + params["nics"] = ' '.join([params["nics"], nics]) + params["start_vm"] = "yes" + env_process.preprocess_vm(test, params, env, params["main_vm"]) + vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) - # Redirect ifconfig output from guest to log file - log_file = os.path.join(test.debugdir, "ifconfig") - ifconfig_output = session.cmd("ifconfig") - log_file_object = open(log_file, "w") - log_file_object.write(ifconfig_output) - # Get the ethernet cards number from params - nics_num = len(params.objects("nics")) logging.info("[ %s ] NICs card specified in config file" % nics_num) - # Pre-judgement for the ethernet interface - logging.debug(check_nics_num(nics_num, session)[1]) - txt = "Create configure file for every NIC interface in guest." - error_context.context(txt, logging.info) - ifname_list = utils_net.get_linux_ifname(session) - ifcfg_path = "/etc/sysconfig/network-scripts/ifcfg-%s" - for ifname in ifname_list: - eth_config_path = ifcfg_path % ifname - eth_config = "DEVICE=%s\\nBOOTPROTO=dhcp\\nONBOOT=yes" % ifname - cmd = "echo -e '%s' > %s" % (eth_config, eth_config_path) - s, o = session.cmd_status_output(cmd) - if s != 0: - err_msg = "Failed to create ether config file: %s\nReason is: %s" - test.error(err_msg % (eth_config_path, o)) + os_type = params.get("os_type", "linux") + if os_type == "linux": + # Redirect ifconfig output from guest to log file + log_file = os.path.join(test.debugdir, "ifconfig") + ifconfig_output = session.cmd("ifconfig") + log_file_object = open(log_file, "w") + log_file_object.write(ifconfig_output) + log_file_object.close() + + # Pre-judgement for the ethernet interface + logging.debug(check_nics_num(nics_num, session)[1]) + txt = "Create configure file for every NIC interface in guest." + error_context.context(txt, logging.info) + ifname_list = utils_net.get_linux_ifname(session) + ifcfg_path = "/etc/sysconfig/network-scripts/ifcfg-%s" + for ifname in ifname_list: + eth_config_path = ifcfg_path % ifname + eth_config = "DEVICE=%s\\nBOOTPROTO=dhcp\\nONBOOT=yes" % ifname + cmd = "echo -e '%s' > %s" % (eth_config, eth_config_path) + s, o = session.cmd_status_output(cmd) + if s != 0: + err_msg = "Failed to create ether config file: %s\nReason is: %s" + test.error(err_msg % (eth_config_path, o)) + session.close() + + # Reboot and check the configurations. + new_session = vm.reboot(session) + s, msg = check_nics_num(nics_num, new_session) + if not s: + test.fail(msg) + new_session.close() - # Reboot and check the configurations. - new_session = vm.reboot(session) - s, msg = check_nics_num(nics_num, new_session) - if not s: - test.fail(msg) + # NICs matched. + logging.info(msg) - # NICs matched. - logging.info(msg) + # Check all the interfaces in guest get ips + nic_interface = [] + session_srl = vm.wait_for_serial_login(timeout=int(params.get("login_timeout", 360))) + for index, nic in enumerate(vm.virtnet): + logging.info("index %s nic" % index) + guest_ip = utils_net.get_guest_ip_addr(session_srl, nic.mac, os_type, + ip_version="ipv4") + if not guest_ip: + err_log = "vm get interface %s's ip failed." % index + test.fail(err_log) + nic_interface.append(guest_ip) + session_srl.close() + logging.info("All the [ %s ] NICs get IPs." % nics_num)