Skip to content

Commit

Permalink
Update the logging namespace - generic (n-w)
Browse files Browse the repository at this point in the history
Issue: autotest#3048

Signed-off-by: Xu Han <[email protected]>
  • Loading branch information
luckyh committed Jan 18, 2022
1 parent b2c9322 commit 9c4c59d
Show file tree
Hide file tree
Showing 26 changed files with 237 additions and 243 deletions.
74 changes: 38 additions & 36 deletions generic/tests/netperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from provider import netperf_base
from provider import win_driver_utils

LOG_JOB = logging.getLogger('avocado.test')

_netserver_started = False


Expand Down Expand Up @@ -53,7 +55,7 @@ def mtu_set(mtu):
server_mtu_cmd = params.get("server_mtu_cmd")
client_mtu_cmd = params.get("client_mtu_cmd")
host_mtu_cmd = params.get("host_mtu_cmd")
error_context.context("Changing the MTU of guest", logging.info)
error_context.context("Changing the MTU of guest", test.log.info)
if params.get("os_type") == "linux":
ethname = utils_net.get_linux_ifname(server_ctl, mac)
netperf_base.ssh_cmd(server_ctl, server_mtu_cmd % (ethname, mtu))
Expand All @@ -62,7 +64,7 @@ def mtu_set(mtu):
server_ctl, "macaddress", mac, "netconnectionid")
netperf_base.ssh_cmd(server_ctl, server_mtu_cmd % (connection_id, mtu))

error_context.context("Changing the MTU of client", logging.info)
error_context.context("Changing the MTU of client", test.log.info)
netperf_base.ssh_cmd(client, client_mtu_cmd
% (params.get("client_physical_nic"), mtu))

Expand All @@ -82,7 +84,7 @@ def mtu_set(mtu):
if vm.virtnet[0].nettype == "macvtap":
target_ifaces.extend([vm.virtnet[0].netdst, vm.get_ifname(0)])
error_context.context("Change all Bridge NICs MTU to %s"
% mtu, logging.info)
% mtu, test.log.info)
for iface in target_ifaces:
try:
process.run(host_mtu_cmd % (iface, mtu), ignore_status=False,
Expand All @@ -103,12 +105,12 @@ def mtu_set(mtu):
session = vm.wait_for_serial_login(timeout=login_timeout)
if cmd:
s, o = session.cmd_status_output(cmd)
logging.info(o)
test.log.info(o)
if "querysettings" in cmd:
if ".sys" in o:
verifier_clear_cmd = "verifier /reset"
status, output = session.cmd_status_output(verifier_clear_cmd)
logging.info(output)
test.log.info(output)
if ".sys" in output:
msg = "% does not work correctly" % verifier_clear_cmd
test.error(msg)
Expand Down Expand Up @@ -154,7 +156,7 @@ def mtu_set(mtu):
test.error("Not found devcon.exe, details: %s" % output)

error_context.context("Uninstall %s driver" % driver_name,
logging.info)
test.log.info)
win_driver_utils.uninstall_driver(session, test,
devcon_path, driver_name,
device_name, device_hwid)
Expand All @@ -169,7 +171,7 @@ def mtu_set(mtu):
test.fail("Failed to install driver '%s', "
"details:\n%s" % (driver_name, output))
if driver_name == "VIOPROT":
logging.info("Will install inf file found at '%s'", inf_path)
test.log.info("Will install inf file found at '%s'", inf_path)
install_cmd = params.get("install_vioprot_cmd") % inf_path
status, output = session.cmd_status_output(install_cmd)
if status:
Expand All @@ -196,7 +198,7 @@ def mtu_set(mtu):
session.cmd_status_output("ethtool -L %s combined %s" %
(ethname, queues))
else:
logging.info("FIXME: support to enable MQ for Windows guest!")
test.log.info("FIXME: support to enable MQ for Windows guest!")

if params.get("server_private_ip") and params.get("os_type") == "linux":
server_ip = params.get("server_private_ip")
Expand Down Expand Up @@ -227,12 +229,12 @@ def mtu_set(mtu):
else:
server_cyg = None

logging.debug(process.system_output("numactl --hardware",
verbose=False, ignore_status=True,
shell=True).decode())
logging.debug(process.system_output("numactl --show",
verbose=False, ignore_status=True,
shell=True).decode())
test.log.debug(process.system_output("numactl --hardware",
verbose=False, ignore_status=True,
shell=True).decode())
test.log.debug(process.system_output("numactl --show",
verbose=False, ignore_status=True,
shell=True).decode())
# pin guest vcpus/memory/vhost threads to last numa node of host by default
numa_node = netperf_base.pin_vm_threads(vm, params.get("numa_node"))

Expand Down Expand Up @@ -284,7 +286,7 @@ def mtu_set(mtu):
session2.close()
netperf_base.pin_vm_threads(vm2, numa_node)

error_context.context("Prepare env of server/client/host", logging.info)
error_context.context("Prepare env of server/client/host", test.log.info)
prepare_list = set([server_ctl, client, host])
tag_dict = {server_ctl: "server", client: "client", host: "host"}
if client_pub_ip:
Expand All @@ -311,7 +313,7 @@ def mtu_set(mtu):
env.stop_ip_sniffing()

try:
error_context.context("Start netperf testing", logging.info)
error_context.context("Start netperf testing", test.log.info)
start_test(server_ip, server_ctl, host, clients, test.resultsdir,
test_duration=int(params.get('l')),
sessions_rr=params.get('sessions_rr'),
Expand Down Expand Up @@ -405,7 +407,7 @@ def start_test(server, server_ctl, host, clients, resultsdir, test_duration=60,
mpstat_index = 0

for protocol in protocols.split():
error_context.context("Testing %s protocol" % protocol, logging.info)
error_context.context("Testing %s protocol" % protocol, LOG_JOB.info)
if protocol in ("TCP_RR", "TCP_CRR"):
sessions_test = sessions_rr.split()
sizes_test = sizes_rr.split()
Expand Down Expand Up @@ -463,18 +465,18 @@ def start_test(server, server_ctl, host, clients, resultsdir, test_duration=60,
test.write_test_keyval(
{'%s--%s' % (prefix, key): ret[key]})

logging.info(row)
LOG_JOB.info(row)
fd.write(row + "\n")

fd.flush()

logging.debug("Remove temporary files")
LOG_JOB.debug("Remove temporary files")
process.system_output("rm -f /tmp/netperf.%s.nf" % ret['pid'],
verbose=False, ignore_status=True,
shell=True)
logging.info("Netperf thread completed successfully")
LOG_JOB.info("Netperf thread completed successfully")
else:
logging.debug(
LOG_JOB.debug(
"Not all netperf clients start to work, please enlarge"
" '%s' number or skip this tests", int(j))
continue
Expand All @@ -493,9 +495,9 @@ def launch_client(sessions, server, server_ctl, host, clients, l, nf_args,
global _netserver_started
# Start netserver
if _netserver_started:
logging.debug("Netserver already started.")
LOG_JOB.debug("Netserver already started.")
else:
error_context.context("Start Netserver on guest", logging.info)
error_context.context("Start Netserver on guest", LOG_JOB.info)
if params.get("os_type") == "windows":
timeout = float(params.get("timeout", "240"))
cdrom_drv = utils_misc.get_winutils_vol(server_ctl)
Expand All @@ -506,7 +508,7 @@ def launch_client(sessions, server, server_ctl, host, clients, l, nf_args,
netserver_path = params.get("netserver_path")
netperf_install_cmd = params.get("netperf_install_cmd")
start_session = server_cyg
logging.info("Start netserver with cygwin, cmd is: %s",
LOG_JOB.info("Start netserver with cygwin, cmd is: %s",
netserv_start_cmd)
if "netserver" not in server_ctl.cmd_output("tasklist"):
netperf_pack = "netperf-%s" % params.get("netperf_version")
Expand All @@ -516,7 +518,7 @@ def launch_client(sessions, server, server_ctl, host, clients, l, nf_args,
netperf_pack in server_ctl.cmd(p_check_cmd)):
error_context.context(
"Install netserver in Windows guest cygwin",
logging.info)
LOG_JOB.info)
cmd = "xcopy %s %s /S /I /Y" % (
netperf_src, cygwin_root)
server_ctl.cmd(cmd)
Expand All @@ -525,26 +527,26 @@ def launch_client(sessions, server, server_ctl, host, clients, l, nf_args,
if "netserver.exe" not in server_ctl.cmd(s_check_cmd):
err_msg = "Install netserver cygwin failed"
test.error(err_msg)
logging.info(
LOG_JOB.info(
"Install netserver in cygwin successfully")
else:
start_session = server_ctl
netserv_start_cmd = params.get("netserv_start_cmd") % cdrom_drv
logging.info("Start netserver without cygwin, cmd is: %s",
LOG_JOB.info("Start netserver without cygwin, cmd is: %s",
netserv_start_cmd)

error_context.context("Start netserver on windows guest",
logging.info)
LOG_JOB.info)
start_netserver_win(start_session, netserv_start_cmd, test)

else:
logging.info("Netserver start cmd is '%s'", server_path)
LOG_JOB.info("Netserver start cmd is '%s'", server_path)
netperf_base.ssh_cmd(server_ctl, "pidof netserver || %s" % server_path)
ncpu = netperf_base.ssh_cmd(
server_ctl, "cat /proc/cpuinfo |grep processor |wc -l")
ncpu = re.findall(r"\d+", ncpu)[-1]

logging.info("Netserver start successfully")
LOG_JOB.info("Netserver start successfully")

def count_interrupt(name):
"""
Expand Down Expand Up @@ -664,12 +666,12 @@ def parse_demo_result(fname, sessions):
if "Interim" in this:
result += float(re.findall(r"Interim result: *(\S+)", this)[0])
result = result / niteration
logging.debug("niteration: %s", niteration)
LOG_JOB.debug("niteration: %s", niteration)
return result

tries = int(params.get("tries", 1))
while tries > 0:
error_context.context("Start netperf client threads", logging.info)
error_context.context("Start netperf client threads", LOG_JOB.info)
pid = str(os.getpid())
fname = "/tmp/netperf.%s.nf" % pid
netperf_base.ssh_cmd(clients[-1], "rm -f %s" % fname)
Expand All @@ -689,7 +691,7 @@ def parse_demo_result(fname, sessions):

if utils_misc.wait_for(all_clients_up, timeout_netperf_start, 0.0, 0.2,
"Wait until all netperf clients start to work"):
logging.debug("All netperf clients start to work.")
LOG_JOB.debug("All netperf clients start to work.")

# real & effective test starts
if get_status_flag:
Expand All @@ -707,7 +709,7 @@ def parse_demo_result(fname, sessions):
msg = "Initial state not match end state:\n"
msg += " start state: %s\n" % start_state
msg += " end state: %s\n" % end_state
logging.warn(msg)
LOG_JOB.warn(msg)
else:
for i in range(len(end_state) // 2):
ret[end_state[i * 2]] = (end_state[i * 2 + 1] -
Expand All @@ -716,7 +718,7 @@ def parse_demo_result(fname, sessions):
client_thread.join()

error_context.context("Testing Results Treatment and Report",
logging.info)
LOG_JOB.info)
f = open(fname, "w")
f.write(finished_result)
f.close()
Expand All @@ -726,4 +728,4 @@ def parse_demo_result(fname, sessions):
else:
stop_netperf_clients()
tries = tries - 1
logging.debug("left %s times", tries)
LOG_JOB.debug("left %s times", tries)
23 changes: 11 additions & 12 deletions generic/tests/netstress_kill_guest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os
import time

Expand Down Expand Up @@ -52,7 +51,7 @@ def kill_and_check(test, vm):
vm.destroy(gracefully=False)
if not vm.wait_until_dead(timeout=60):
test.fail("VM is not dead after destroy operation")
logging.info("VM is dead as expected")
test.log.info("VM is dead as expected")

def netperf_stress(test, params, vm):
"""
Expand Down Expand Up @@ -102,7 +101,7 @@ def netperf_stress(test, params, vm):
package_sizes=params.get("netperf_sizes"))
if utils_misc.wait_for(n_client.is_netperf_running, 10, 0, 1,
"Wait netperf test start"):
logging.info("Netperf test start successfully.")
test.log.info("Netperf test start successfully.")
else:
test.error("Can not start netperf client.")
finally:
Expand All @@ -112,20 +111,20 @@ def netperf_stress(test, params, vm):

def netload_kill_problem(test, session_serial):
firewall_flush = params.get("firewall_flush", "service iptables stop")
error_context.context("Stop firewall in guest and host.", logging.info)
error_context.context("Stop firewall in guest and host.", test.log.info)
try:
process.run(firewall_flush, shell=True)
except Exception:
logging.warning("Could not stop firewall in host")
test.log.warning("Could not stop firewall in host")

try:
session_serial.cmd(firewall_flush)
except Exception:
logging.warning("Could not stop firewall in guest")
test.log.warning("Could not stop firewall in guest")

try:
error_context.context(("Run subtest netperf_stress between"
" host and guest.", logging.info))
" host and guest.", test.log.info))
stress_thread = None
wait_time = int(params.get("wait_bg_time", 60))
bg_stress_run_flag = params.get("bg_stress_run_flag")
Expand All @@ -136,10 +135,10 @@ def netload_kill_problem(test, session_serial):
stress_thread.start()
utils_misc.wait_for(lambda: wait_time, 0, 1,
"Wait netperf_stress test start")
logging.info("Sleep %ss before killing the VM", vm_wait_time)
test.log.info("Sleep %ss before killing the VM", vm_wait_time)
time.sleep(vm_wait_time)
msg = "During netperf running, Check that we can kill VM with signal 0"
error_context.context(msg, logging.info)
error_context.context(msg, test.log.info)
kill_and_check(test, vm)
finally:
try:
Expand All @@ -150,9 +149,9 @@ def netload_kill_problem(test, session_serial):
def netdriver_kill_problem(test, session_serial):
times = params.get_numeric("repeat_times", 10)
modules = get_ethernet_driver(session_serial)
logging.debug("Guest network driver(s): %s", modules)
test.log.debug("Guest network driver(s): %s", modules)
msg = "Repeatedly load/unload network driver(s) for %s times." % times
error_context.context(msg, logging.info)
error_context.context(msg, test.log.info)
for i in range(times):
for module in modules:
error_context.context("Unload driver %s. Repeat: %s/%s" %
Expand All @@ -164,7 +163,7 @@ def netdriver_kill_problem(test, session_serial):
session_serial.cmd_output_safe("modprobe %s" % module)

error_context.context("Check that we can kill VM with signal 0.",
logging.info)
test.log.info)
kill_and_check(test, vm)

vm = env.get_vm(params["main_vm"])
Expand Down
Loading

0 comments on commit 9c4c59d

Please sign in to comment.