提交 4f1de935 编写于 作者: F Feng Yang 提交者: Lucas Meneghel Rodrigues

tests.ethool.py: Add error.context() support

log case steps into logging.info.
Signed-off-by: NFeng Yang <fyang@redhat.com>
Acked-by: NSuqin Huang <shuang@redhat.com>
上级 9262e6ff
...@@ -4,16 +4,24 @@ from autotest.client import utils ...@@ -4,16 +4,24 @@ from autotest.client import utils
from virttest import utils_net, utils_misc, remote, aexpect from virttest import utils_net, utils_misc, remote, aexpect
@error.context_aware
def run_ethtool(test, params, env): def run_ethtool(test, params, env):
""" """
Test offload functions of ethernet device using ethtool Test offload functions of ethernet device using ethtool
1) Log into a guest. 1) Log into a guest.
2) Initialize the callback of sub functions. 2) Saving ethtool configuration.
3) Enable/disable sub function of NIC. 3) Enable sub function of NIC.
4) Execute callback function. 4) Execute callback function.
5) Check the return value. 5) Disable sub function of NIC.
6) Restore original configuration. 6) Run callback function again.
7) Run file transfer test.
7.1) Creating file in source host.
7.2) Listening network traffic with tcpdump command.
7.3) Transfer file.
7.4) Comparing md5sum of the files on guest and host.
8) Repeat step 3 - 7.
9) Restore original configuration.
@param test: QEMU test object. @param test: QEMU test object.
@param params: Dictionary with the test parameters. @param params: Dictionary with the test parameters.
...@@ -41,7 +49,7 @@ def run_ethtool(test, params, env): ...@@ -41,7 +49,7 @@ def run_ethtool(test, params, env):
return output return output
def ethtool_get(f_type): def ethtool_get(session, f_type):
feature_pattern = { feature_pattern = {
'tx': 'tx.*checksumming', 'tx': 'tx.*checksumming',
'rx': 'rx.*checksumming', 'rx': 'rx.*checksumming',
...@@ -60,14 +68,16 @@ def run_ethtool(test, params, env): ...@@ -60,14 +68,16 @@ def run_ethtool(test, params, env):
logging.debug("(%s) %s: failed to get status", ethname, f_type) logging.debug("(%s) %s: failed to get status", ethname, f_type)
def ethtool_set(f_type, status): def ethtool_set(session, f_type, status):
""" """
Set ethernet device offload status Set ethernet device offload status
@param f_type: Offload type name @param f_type: Offload type name
@param status: New status will be changed to @param status: New status will be changed to
""" """
logging.info("(%s) %s: set status %s", ethname, f_type, status) txt = "Set ethernet device offload status."
txt += " (%s) %s: set status %s" % (ethname, f_type, status)
error.context(txt, logging.info)
if status not in ["off", "on"]: if status not in ["off", "on"]:
return False return False
...@@ -80,6 +90,7 @@ def run_ethtool(test, params, env): ...@@ -80,6 +90,7 @@ def run_ethtool(test, params, env):
send_cmd_safe(session, cmd) send_cmd_safe(session, cmd)
except aexpect.ShellCmdError, e: except aexpect.ShellCmdError, e:
logging.error("%s, detail: %s", err_msg, e) logging.error("%s, detail: %s", err_msg, e)
return False
if ethtool_get(session, f_type) == status: if ethtool_get(session, f_type) == status:
return True return True
...@@ -88,20 +99,21 @@ def run_ethtool(test, params, env): ...@@ -88,20 +99,21 @@ def run_ethtool(test, params, env):
return True return True
def ethtool_save_params(): def ethtool_save_params(session):
logging.info("Saving ethtool configuration") error.context("Saving ethtool configuration", logging.info)
for i in supported_features: for i in supported_features:
feature_status[i] = ethtool_get(i) feature_status[i] = ethtool_get(session, i)
def ethtool_restore_params(): def ethtool_restore_params(session):
logging.info("Restoring ethtool configuration") error.context("Restoring ethtool configuration", logging.info)
for i in supported_features: for i in supported_features:
ethtool_set(i, feature_status[i]) ethtool_set(session, i, feature_status[i])
def compare_md5sum(name): def compare_md5sum(name):
logging.info("Comparing md5sum of the files on guest and host") txt = "Comparing md5sum of the files on guest and host"
error.context(txt, logging.info)
host_result = utils.hash_file(name, method="md5") host_result = utils.hash_file(name, method="md5")
try: try:
o = session.cmd_output("md5sum %s" % name) o = session.cmd_output("md5sum %s" % name)
...@@ -122,15 +134,15 @@ def run_ethtool(test, params, env): ...@@ -122,15 +134,15 @@ def run_ethtool(test, params, env):
@return: Tuple (status, error msg/tcpdump result) @return: Tuple (status, error msg/tcpdump result)
""" """
sess = vm.wait_for_login(timeout=login_timeout) sess = vm.wait_for_login(timeout=login_timeout)
sess.cmd_output("rm -rf %s" % filename) session.cmd_output("rm -rf %s" % filename)
dd_cmd = ("dd if=/dev/urandom of=%s bs=1M count=%s" % dd_cmd = ("dd if=/dev/urandom of=%s bs=1M count=%s" %
(filename, params.get("filesize"))) (filename, params.get("filesize")))
failure = (False, "Failed to create file using dd, cmd: %s" % dd_cmd)
failure = (False, "Failed to create file using: %s" % dd_cmd) txt = "Creating file in source host, cmd: %s" % dd_cmd
error.context(txt, logging.info)
logging.info("Creating file in %s, cmd: %s", src, dd_cmd) ethname = utils_net.get_linux_ifname(session,
tcpdump_cmd = "tcpdump -lep -s 0 tcp -vv port ssh" vm.get_mac_address(0))
tcpdump_cmd = "tcpdump -lep -i %s -s 0 tcp -vv port ssh" % ethname
if src == "guest": if src == "guest":
tcpdump_cmd += " and src %s" % guest_ip tcpdump_cmd += " and src %s" % guest_ip
copy_files_func = vm.copy_files_from copy_files_func = vm.copy_files_from
...@@ -148,18 +160,20 @@ def run_ethtool(test, params, env): ...@@ -148,18 +160,20 @@ def run_ethtool(test, params, env):
# only capture the new tcp port after offload setup # only capture the new tcp port after offload setup
original_tcp_ports = re.findall("tcp.*:(\d+).*%s" % guest_ip, original_tcp_ports = re.findall("tcp.*:(\d+).*%s" % guest_ip,
utils.system_output("/bin/netstat -nap")) utils.system_output("/bin/netstat -nap"))
for i in original_tcp_ports: for i in original_tcp_ports:
tcpdump_cmd += " and not port %s" % i tcpdump_cmd += " and not port %s" % i
logging.debug("Listening traffic using command: %s", tcpdump_cmd) txt = "Listening traffic using command: %s" % tcpdump_cmd
error.context(txt, logging.info)
sess.sendline(tcpdump_cmd) sess.sendline(tcpdump_cmd)
if not utils_misc.wait_for( if not utils_misc.wait_for(
lambda:session.cmd_status("pgrep tcpdump") == 0, 30): lambda:session.cmd_status("pgrep tcpdump") == 0, 30):
return (False, "Tcpdump process wasn't launched") return (False, "Tcpdump process wasn't launched")
logging.info("Transfering file %s from %s", filename, src) txt = "Transfering file %s from %s" % (filename, src)
error.context(txt, logging.info)
try: try:
copy_files_func(filename, filename) copy_files_func(filename, filename)
except remote.SCPError, e: except remote.SCPError, e:
...@@ -197,7 +211,7 @@ def run_ethtool(test, params, env): ...@@ -197,7 +211,7 @@ def run_ethtool(test, params, env):
if not s: if not s:
logging.error(o) logging.error(o)
return False return False
logging.info("Check if contained large frame") error.context("Check if contained large frame", logging.info)
# MTU: default IPv4 MTU is 1500 Bytes, ethernet header is 14 Bytes # MTU: default IPv4 MTU is 1500 Bytes, ethernet header is 14 Bytes
return (status == "on") ^ (len([i for i in re.findall( return (status == "on") ^ (len([i for i in re.findall(
"length (\d*):", o) if int(i) > mtu]) == 0) "length (\d*):", o) if int(i) > mtu]) == 0)
...@@ -213,15 +227,18 @@ def run_ethtool(test, params, env): ...@@ -213,15 +227,18 @@ def run_ethtool(test, params, env):
vm = env.get_vm(params["main_vm"]) vm = env.get_vm(params["main_vm"])
vm.verify_alive() vm.verify_alive()
error.context("Log into a guest.", logging.info)
login_timeout = int(params.get("login_timeout", 360)) login_timeout = int(params.get("login_timeout", 360))
session = vm.wait_for_login(timeout=login_timeout) session = vm.wait_for_login(timeout=login_timeout)
# Let's just error the test if we identify that there's no ethtool installed # Let's just error the test if we identify that there's no ethtool installed
error.context("Check whether ethtool installed in guest.")
session.cmd("ethtool -h") session.cmd("ethtool -h")
mtu = 1514 mtu = 1514
feature_status = {} feature_status = {}
filename = "/tmp/ethtool.dd" filename = "/tmp/ethtool.dd"
guest_ip = vm.get_address() guest_ip = vm.get_address()
error.context("Try to get ethernet device name in guest.")
ethname = utils_net.get_linux_ifname(session, vm.get_mac_address(0)) ethname = utils_net.get_linux_ifname(session, vm.get_mac_address(0))
supported_features = params.get("supported_features") supported_features = params.get("supported_features")
...@@ -240,34 +257,36 @@ def run_ethtool(test, params, env): ...@@ -240,34 +257,36 @@ def run_ethtool(test, params, env):
"gro": (ro_callback, ("rx",), ("lro",)), "gro": (ro_callback, ("rx",), ("lro",)),
"lro": (rx_callback, (), ("gro",)), "lro": (rx_callback, (), ("gro",)),
} }
ethtool_save_params() ethtool_save_params(session)
failed_tests = [] failed_tests = []
try: try:
for f_type in supported_features: for f_type in supported_features:
callback = test_matrix[f_type][0] callback = test_matrix[f_type][0]
for i in test_matrix[f_type][2]: for i in test_matrix[f_type][2]:
if not ethtool_set(i, "off"): if not ethtool_set(session, i, "off"):
e_msg = "Failed to disable %s" % i e_msg = "Failed to disable %s" % i
logging.error(e_msg) logging.error(e_msg)
failed_tests.append(e_msg) failed_tests.append(e_msg)
for i in [f for f in test_matrix[f_type][1]] + [f_type]: for i in [f for f in test_matrix[f_type][1]] + [f_type]:
if not ethtool_set(i, "on"): if not ethtool_set(session, i, "on"):
e_msg = "Failed to enable %s" % i e_msg = "Failed to enable %s" % i
logging.error(e_msg) logging.error(e_msg)
failed_tests.append(e_msg) failed_tests.append(e_msg)
txt = "Run callback function %s" % callback.func_name
error.context(txt, logging.info)
if not callback(status="on"): if not callback(status="on"):
e_msg = "Callback failed after enabling %s" % f_type e_msg = "Callback failed after enabling %s" % f_type
logging.error(e_msg) logging.error(e_msg)
failed_tests.append(e_msg) failed_tests.append(e_msg)
if not ethtool_set(f_type, "off"): if not ethtool_set(session, f_type, "off"):
e_msg = "Failed to disable %s" % f_type e_msg = "Failed to disable %s" % f_type
logging.error(e_msg) logging.error(e_msg)
failed_tests.append(e_msg) failed_tests.append(e_msg)
txt = "Run callback function %s" % callback.func_name
error.context(txt, logging.info)
if not callback(status="off"): if not callback(status="off"):
e_msg = "Callback failed after disabling %s" % f_type e_msg = "Callback failed after disabling %s" % f_type
logging.error(e_msg) logging.error(e_msg)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册