Skip to content

Commit

Permalink
Update the logging namespace - qemu (op)
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 authored and leidwang committed Aug 5, 2022
1 parent a859290 commit 456a262
Show file tree
Hide file tree
Showing 28 changed files with 266 additions and 281 deletions.
8 changes: 3 additions & 5 deletions qemu/tests/offload_checksum_windows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

from virttest import utils_test
from virttest import error_context
from virttest import utils_net
Expand Down Expand Up @@ -42,11 +40,11 @@ def start_test(checksum_config="tcp"):
param config: the setting config for checksum, tcp or disable
"""
error_context.context("Start set tx/rx checksum offload to %s" % checksum_config,
logging.info)
test.log.info)
set_offload_checksum_windows(vm, True, checksum_config)
set_offload_checksum_windows(vm, False, checksum_config)

error_context.context("Start file transfer test", logging.info)
error_context.context("Start file transfer test", test.log.info)
utils_test.run_file_transfer(test, params, env)

timeout = params.get("timeout", 360)
Expand All @@ -55,7 +53,7 @@ def start_test(checksum_config="tcp"):

session = vm.wait_for_login(timeout=timeout)
error_context.context("Check if the driver is installed and "
"verified", logging.info)
"verified", test.log.info)
driver_name = params.get("driver_name", "netkvm")
session = utils_test.qemu.windrv_check_running_verifier(session, vm,
test,
Expand Down
39 changes: 19 additions & 20 deletions qemu/tests/openflow_acl_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import functools
import logging
import re
import os

Expand Down Expand Up @@ -42,7 +41,7 @@ def access_service(access_sys, access_targets, disabled, host_ip,
err_type = ""
for asys in access_sys:
for atgt in access_targets:
logging.debug("Try to access target %s from %s", atgt, asys)
test.log.debug("Try to access target %s from %s", atgt, asys)

access_params = access_sys[asys]
atgt_disabled = access_params['disabled_%s' % atgt]
Expand Down Expand Up @@ -119,7 +118,7 @@ def access_service(access_sys, access_targets, disabled, host_ip,
err_msg += "Command: %s " % access_cmd
err_msg += "Output: %s" % out
if disabled and atgt_disabled and stat != 0:
logging.debug("Can not access target as expect.")
test.log.debug("Can not access target as expect.")
if not disabled and stat != 0:
if ref:
err_msg += "Can not access %s at the" % atgt
Expand Down Expand Up @@ -189,7 +188,7 @@ def remote_login(client, host, src, params_login, host_ip):
src_name = src
if src != "localhost":
src_name = src.name
logging.info("Login %s from %s", host, src_name)
test.log.info("Login %s from %s", host, src_name)
port = params_login["target_port"]
username = params_login["username"]
password = params_login["password"]
Expand All @@ -216,7 +215,7 @@ def remote_login(client, host, src, params_login, host_ip):
raise remote.LoginBadClientError(client)

if src == "localhost":
logging.debug("Login with command %s", cmd)
test.log.debug("Login with command %s", cmd)
session = aexpect.ShellSession(cmd, linesep=linesep, prompt=prompt)
else:
if params_login.get("os_type") == "windows":
Expand All @@ -228,7 +227,7 @@ def remote_login(client, host, src, params_login, host_ip):
else:
cmd += " || sleep 5"
session = src.wait_for_login()
logging.debug("Sending login command: %s", cmd)
test.log.debug("Sending login command: %s", cmd)
session.sendline(cmd)
try:
out = remote.handle_prompts(session, username, password,
Expand Down Expand Up @@ -262,7 +261,7 @@ def setup_service(setup_target):

error_context.context("Set up %s service in %s"
% (setup_params.get("service"), setup_target),
logging.info)
test.log.info)
if params.get("copy_ftp_site") and setup_target != "localhost":
ftp_site = os.path.join(data_dir.get_deps_dir(),
params.get("copy_ftp_site"))
Expand All @@ -271,8 +270,8 @@ def setup_service(setup_target):
access_param = setup_params.object_params(setup_target)
if "ftp" in access_param.get("access_cmd") and os_type == "linux":
setup_func(
"sed -i 's/anonymous_enable=NO/anonymous_enable=YES/g' %s"
% params["vsftpd_conf"])
"sed -i 's/anonymous_enable=NO/anonymous_enable=YES/g' %s"
% params["vsftpd_conf"])
if prepare_cmd:
setup_func(prepare_cmd, timeout=setup_timeout)
setup_func(setup_cmd, timeout=setup_timeout)
Expand All @@ -298,7 +297,7 @@ def stop_service(setup_target):

error_context.context("Stop %s service in %s"
% (setup_params.get("service"), setup_target),
logging.info)
test.log.info)
if stop_cmd:
setup_func(stop_cmd, timeout=setup_timeout)

Expand Down Expand Up @@ -384,9 +383,9 @@ def stop_service(setup_target):
access_sys[target]['disabled_%s' % tgt] = acl_disabled

error_context.context("Try to access target before setup the rules",
logging.info)
test.log.info)
access_service(access_sys, access_targets, False, host_ip, ref=True)
error_context.context("Disable the access in ovs", logging.info)
error_context.context("Disable the access in ovs", test.log.info)
br_infos = utils_net.openflow_manager(br_name, "show").stdout.decode()
if_port = re.findall(r"(\d+)\(%s\)" % if_name, br_infos)
if not if_port:
Expand All @@ -396,33 +395,33 @@ def stop_service(setup_target):
acl_cmd = get_acl_cmd(acl_protocol, if_port, "drop", acl_extra_options)
utils_net.openflow_manager(br_name, "add-flow", acl_cmd)
acl_rules = utils_net.openflow_manager(
br_name, "dump-flows").stdout.decode()
br_name, "dump-flows").stdout.decode()
if not acl_rules_check(acl_rules, acl_cmd):
test.fail("Can not find the rules from ovs-ofctl: %s" % acl_rules)

error_context.context("Try to acess target to exam the disable rules",
logging.info)
test.log.info)
access_service(access_sys, access_targets, True, host_ip)
error_context.context("Enable the access in ovs", logging.info)
error_context.context("Enable the access in ovs", test.log.info)
acl_cmd = get_acl_cmd(acl_protocol, if_port, "normal", acl_extra_options)
utils_net.openflow_manager(br_name, "mod-flows", acl_cmd)
acl_rules = utils_net.openflow_manager(
br_name, "dump-flows").stdout.decode()
br_name, "dump-flows").stdout.decode()
if not acl_rules_check(acl_rules, acl_cmd):
test.fail("Can not find the rules from ovs-ofctl: %s" % acl_rules)

error_context.context("Try to acess target to exam the enable rules",
logging.info)
test.log.info)
access_service(access_sys, access_targets, False, host_ip)
error_context.context("Delete the access rules in ovs", logging.info)
error_context.context("Delete the access rules in ovs", test.log.info)
acl_cmd = get_acl_cmd(acl_protocol, if_port, "", acl_extra_options)
utils_net.openflow_manager(br_name, "del-flows", acl_cmd)
acl_rules = utils_net.openflow_manager(
br_name, "dump-flows").stdout.decode()
br_name, "dump-flows").stdout.decode()
if acl_rules_check(acl_rules, acl_cmd):
test.fail("Still can find the rules from ovs-ofctl: %s" % acl_rules)
error_context.context("Try to acess target to exam after delete the rules",
logging.info)
test.log.info)
access_service(access_sys, access_targets, False, host_ip)

for setup_target in params.get("setup_targets", "").split():
Expand Down
45 changes: 22 additions & 23 deletions qemu/tests/openflow_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import re
import time

Expand Down Expand Up @@ -69,9 +68,9 @@ def tcpdump_catch_packet_test(session, drop_flow=False):
err_msg += "%s " % (packet_receive and "can" or "can not")
err_msg += "receive the packets"
test.error(err_msg)
logging.info("Correct, flow %s dropped, tcpdump %s receive the packet",
(drop_flow and "was" or "was not"),
(packet_receive and "can" or "can not"))
test.log.info("Correct, flow %s dropped, tcpdump %s receive the packet",
(drop_flow and "was" or "was not"),
(packet_receive and "can" or "can not"))

def arp_entry_clean(entry=None):
"""
Expand Down Expand Up @@ -119,17 +118,17 @@ def ping_test(session, dst, drop_flow=False):

info_msg = "Correct, icmp flow %s dropped, ping '%s', "
info_msg += "packets lost rate is: '%s'"
logging.info(info_msg, (drop_flow and "was" or "was not"),
(ping_status and "failed" or "success"),
packets_lost)
test.log.info(info_msg, (drop_flow and "was" or "was not"),
(ping_status and "failed" or "success"),
packets_lost)

def run_ping_bg(vm, dst):
"""
Run ping in background
"""
ping_cmd = "ping %s" % dst
session = vm.wait_for_login()
logging.info("Ping %s in background", dst)
test.log.info("Ping %s in background", dst)
session.sendline(ping_cmd)
return session

Expand Down Expand Up @@ -202,9 +201,9 @@ def nc_connect_test(sessions, addresses, drop_flow=False, nc_port="8899",
err_msg += " '%s'" % (nc_connect and "failed" or "success")
test.error(err_msg)

logging.info("Correct, '%s' flow %s dropped, and nc connect %s",
nc_protocol, (drop_flow and "was" or "was not"),
(nc_connect and "success" or "failed"))
test.log.info("Correct, '%s' flow %s dropped, and nc connect %s",
nc_protocol, (drop_flow and "was" or "was not"),
(nc_connect and "success" or "failed"))
finally:
for session in sessions:
session.cmd_output_safe("killall nc || killall ncat")
Expand Down Expand Up @@ -290,51 +289,51 @@ def remove_plus_items(open_flow_rules):
" ovs-ofctl: %s" % acl_rules)

error_context.context("Run tcpdump in guest %s" % vms[1].name,
logging.info)
test.log.info)
run_tcpdump_bg(vms[1], addresses, f_protocol)

if drop_flow or f_protocol is not "arp":
error_context.context("Clean arp cache in both guest",
logging.info)
test.log.info)
arp_entry_clean(addresses[1])

error_context.base_context(
"Exec '%s' flow '%s' test" %
(f_protocol, drop_flow and "drop" or "normal"))
if drop_flow:
error_context.context("Ping test form %s to %s" %
(vms[0].name, vms[1].name), logging.info)
(vms[0].name, vms[1].name), test.log.info)
ping_test(sessions[0], addresses[1], drop_icmp)
if params.get("run_file_transfer") == "yes":
error_context.context("Transfer file form %s to %s" %
(vms[0].name, vms[1].name),
logging.info)
test.log.info)
file_transfer(sessions, addresses, prepare_timeout)
else:
error_context.context("Ping test form %s to %s in background" %
(vms[0].name, vms[1].name), logging.info)
(vms[0].name, vms[1].name), test.log.info)
bg_ping_session = run_ping_bg(vms[0], addresses[1])

if f_protocol == 'arp' and drop_flow:
error_context.context("Check arp inside %s" % vms[0].name,
logging.info)
test.log.info)
check_arp_info(sessions[0], addresses[1], vms[0])
elif f_protocol == 'arp' or params.get("check_arp") == "yes":
time.sleep(2)
error_context.context("Check arp inside guests.", logging.info)
error_context.context("Check arp inside guests.", test.log.info)
for index, address in enumerate(addresses):
sess_index = (index + 1) % 2
mac = vms[index].virtnet.get_mac_address(0)
check_arp_info(sessions[sess_index], address, vms[index],
mac)

error_context.context("Run nc connect test via tcp", logging.info)
error_context.context("Run nc connect test via tcp", test.log.info)
nc_connect_test(sessions, addresses, drop_tcp)

error_context.context("Run nc connect test via udp", logging.info)
error_context.context("Run nc connect test via udp", test.log.info)
nc_connect_test(sessions, addresses, drop_udp, udp_model=True)

error_context.context("Check tcpdump data catch", logging.info)
error_context.context("Check tcpdump data catch", test.log.info)
tcpdump_catch_packet_test(sessions[1], drop_flow)
finally:
openflow_rules_ori = utils_net.openflow_manager(
Expand All @@ -348,10 +347,10 @@ def remove_plus_items(open_flow_rules):
set(openflow_rules.splitlines()))

if f_protocol == "tcp":
error_context.context("Run nc connect test via tcp", logging.info)
error_context.context("Run nc connect test via tcp", test.log.info)
nc_connect_test(sessions, addresses)
elif f_protocol == "udp":
error_context.context("Run nc connect test via udp", logging.info)
error_context.context("Run nc connect test via udp", test.log.info)
nc_connect_test(sessions, addresses, udp_model=True)

for session in sessions:
Expand Down
4 changes: 1 addition & 3 deletions qemu/tests/ovs_enslave_port.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

from avocado.utils import process
from virttest import error_context
from virttest import utils_net
Expand Down Expand Up @@ -31,7 +29,7 @@ def run(test, params, env):
host_bridge.del_br(new_br_name)
host_bridge.add_br(new_br_name)
error_context.context("OVS bridge %s created." % new_br_name,
logging.info)
test.log.info)

try:
ports = host_bridge.list_ports(netdst)
Expand Down
Loading

0 comments on commit 456a262

Please sign in to comment.