未验证 提交 a8b73bca 编写于 作者: Q Qianqian Zhu 提交者: GitHub

Merge pull request #1391 from xiywang/multi_nics_verify

multi_nics_verify: Boot 27 NICs and all the NICs can get IPs
- multi_nics_verify: guest_test.arp_set - multi_nics_verify: guest_test.arp_set
virt_test_type = qemu virt_test_type = qemu
type = multi_nics_verify type = multi_nics_verify
only Linux
no RHEL.3.9 no RHEL.3.9
nics += ' nic2 nic3 nic4 nic5 nic6 nic7 nic8' nics_num = 27
start_vm = no
kill_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
...@@ -3,6 +3,7 @@ import logging ...@@ -3,6 +3,7 @@ import logging
from virttest import error_context from virttest import error_context
from virttest import utils_net from virttest import utils_net
from virttest import env_process
@error_context.context_aware @error_context.context_aware
...@@ -23,6 +24,12 @@ def run(test, params, env): ...@@ -23,6 +24,12 @@ def run(test, params, env):
:param env: Dictionary with test environment. :param env: Dictionary with test environment.
""" """
def check_nics_num(expect_c, session): 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." txt = "Check whether guest NICs info match with params setting."
error_context.context(txt, logging.info) error_context.context(txt, logging.info)
nics_list = utils_net.get_linux_ifname(session) nics_list = utils_net.get_linux_ifname(session)
...@@ -35,39 +42,65 @@ def run(test, params, env): ...@@ -35,39 +42,65 @@ def run(test, params, env):
return (False, msg) return (False, msg)
return (True, msg + 'Nics count match') 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 = env.get_vm(params["main_vm"])
vm.verify_alive() vm.verify_alive()
session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) 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) logging.info("[ %s ] NICs card specified in config file" % nics_num)
# Pre-judgement for the ethernet interface os_type = params.get("os_type", "linux")
logging.debug(check_nics_num(nics_num, session)[1]) if os_type == "linux":
txt = "Create configure file for every NIC interface in guest." # Redirect ifconfig output from guest to log file
error_context.context(txt, logging.info) log_file = os.path.join(test.debugdir, "ifconfig")
ifname_list = utils_net.get_linux_ifname(session) ifconfig_output = session.cmd("ifconfig")
ifcfg_path = "/etc/sysconfig/network-scripts/ifcfg-%s" log_file_object = open(log_file, "w")
for ifname in ifname_list: log_file_object.write(ifconfig_output)
eth_config_path = ifcfg_path % ifname log_file_object.close()
eth_config = "DEVICE=%s\\nBOOTPROTO=dhcp\\nONBOOT=yes" % ifname
cmd = "echo -e '%s' > %s" % (eth_config, eth_config_path) # Pre-judgement for the ethernet interface
s, o = session.cmd_status_output(cmd) logging.debug(check_nics_num(nics_num, session)[1])
if s != 0: txt = "Create configure file for every NIC interface in guest."
err_msg = "Failed to create ether config file: %s\nReason is: %s" error_context.context(txt, logging.info)
test.error(err_msg % (eth_config_path, o)) 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. # NICs matched.
new_session = vm.reboot(session) logging.info(msg)
s, msg = check_nics_num(nics_num, new_session)
if not s:
test.fail(msg)
# NICs matched. # Check all the interfaces in guest get ips
logging.info(msg) 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)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册