Skip to content

Commit

Permalink
Update the logging namespace - generic (a-m)
Browse files Browse the repository at this point in the history
Skipped:
* autotest_control.py
* autotest_distro_detect.py
* autotest_regression.py

Issue: autotest#3048

Signed-off-by: Xu Han <[email protected]>
  • Loading branch information
luckyh committed Jan 18, 2022
1 parent b2c9322 commit 528ce39
Show file tree
Hide file tree
Showing 24 changed files with 209 additions and 215 deletions.
5 changes: 2 additions & 3 deletions generic/tests/boot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import time
import logging

from virttest import error_context
from virttest import utils_test
Expand All @@ -23,7 +22,7 @@ def run(test, params, env):
serial_login = params.get("serial_login", "no") == "yes"
vms = env.get_all_vms()
for vm in vms:
error_context.context("Try to log into guest '%s'." % vm.name, logging.info)
error_context.context("Try to log into guest '%s'." % vm.name, test.log.info)
if serial_login:
session = vm.wait_for_serial_login(timeout=timeout)
else:
Expand All @@ -40,7 +39,7 @@ def run(test, params, env):
session.close()
if params.get("reboot_method"):
for vm in vms:
error_context.context("Reboot guest '%s'." % vm.name, logging.info)
error_context.context("Reboot guest '%s'." % vm.name, test.log.info)
if params["reboot_method"] == "system_reset":
time.sleep(int(params.get("sleep_before_reset", 10)))
# Reboot the VM
Expand Down
5 changes: 2 additions & 3 deletions generic/tests/boot_savevm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import time
import tempfile
import os
Expand Down Expand Up @@ -52,7 +51,7 @@ def run(test, params, env):

successful_login = False
while (time.time() - start_time) < savevm_login_timeout:
logging.info("Save/Restore cycle %d", cycles + 1)
test.log.info("Save/Restore cycle %d", cycles + 1)
time.sleep(savevm_delay)
vm.pause()
if params['save_method'] == 'save_to_file':
Expand All @@ -77,7 +76,7 @@ def run(test, params, env):
if not successful_login:
test.fail("Can't log on '%s' %s" % (vm.name, info))
else:
logging.info("Test ended %s", info)
test.log.info("Test ended %s", info)

if params.get("with_floppy") == "yes":
vm.destroy()
Expand Down
5 changes: 2 additions & 3 deletions generic/tests/clock_getres.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os

from virttest import error_context
Expand Down Expand Up @@ -37,9 +36,9 @@ def run(test, params, env):
session.cmd("gcc -lrt -o %s %s" % (getres_cmd, dest_name))

session.cmd(getres_cmd)
logging.info("PASS: Guest reported appropriate clock resolution")
test.log.info("PASS: Guest reported appropriate clock resolution")
sub_test = params.get("sub_test")
if sub_test:
error_context.context("Run sub test '%s' after checking"
" clock resolution" % sub_test, logging.info)
" clock resolution" % sub_test, test.log.info)
utils_test.run_virt_sub_test(test, params, env, sub_test)
19 changes: 9 additions & 10 deletions generic/tests/dd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
import os
import re
import logging
import aexpect

from virttest import utils_misc
Expand Down Expand Up @@ -59,7 +58,7 @@ def _get_file(filename, select, test=test):
except IndexError:
err = ("Incorrect cfg: dd_select out of the range (disks=%s,"
" select=%s)" % (disks, select))
logging.error(err)
test.log.error(err)
test.error(err)

def _check_disk_partitions_number():
Expand All @@ -72,7 +71,7 @@ def _check_disk_partitions_number():
vm = env.get_vm(params['main_vm'])
timeout = int(params.get("login_timeout", 360))

error_context.context("Wait guest boot up", logging.info)
error_context.context("Wait guest boot up", test.log.info)
session = vm.wait_for_login(timeout=timeout)

dd_keys = ['dd_if', 'dd_of', 'dd_bs', 'dd_count', 'dd_iflag',
Expand All @@ -98,8 +97,8 @@ def _check_disk_partitions_number():
psize = float(
utils_numeric.normalize_data_size(
params.get("partition_size", '2G')
)
)
)
start = 0.0
dev_id = os.path.split(path)[-1]
dev_partitioned.append(dev_id)
Expand Down Expand Up @@ -145,10 +144,10 @@ def _check_disk_partitions_number():
cmd = [dd_cmd.format(*t) for t in
zip_longest(*remaining, fillvalue=fillvalue)]
cmd = ' & '.join(cmd)
logging.info("Using '%s' cmd", cmd)
test.log.info("Using '%s' cmd", cmd)

try:
error_context.context("Execute dd in guest", logging.info)
error_context.context("Execute dd in guest", test.log.info)
try:
(stat, out) = session.cmd_status_output(cmd, timeout=dd_timeout)
except aexpect.ShellTimeoutError:
Expand All @@ -160,9 +159,9 @@ def _check_disk_partitions_number():
out = details.output

error_context.context("Check command exit status and output",
logging.info)
logging.debug("Returned dd_status: %s\nReturned output:\n%s",
stat, out)
test.log.info)
test.log.debug("Returned dd_status: %s\nReturned output:\n%s",
stat, out)
if stat != dd_stat:
err = ("Return code doesn't match (expected=%s, actual=%s)\n"
"Output:\n%s" % (dd_stat, stat, out))
Expand All @@ -171,7 +170,7 @@ def _check_disk_partitions_number():
err = ("Output doesn't match:\nExpected:\n%s\nActual:\n%s"
% (dd_output, out))
test.fail(err)
logging.info("dd test succeeded.")
test.log.info("dd test succeeded.")
finally:
for dev_id in dev_partitioned:
utils_disk.clean_partition_linux(session, dev_id)
Expand Down
3 changes: 1 addition & 2 deletions generic/tests/downgrade_qcow2_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging

from virttest import utils_test
from virttest import error_context
Expand All @@ -21,7 +20,7 @@ def run(test, params, env):
"""
ver_to = params.get("lower_version_qcow2", "0.10")
error_context.context("Downgrade qcow2 image version to '%s'"
% ver_to, logging.info)
% ver_to, test.log.info)
image = params.get("images").split()[0]
t_params = params.object_params(image)
qemu_image = qemu_storage.QemuImg(t_params, data_dir.get_data_dir(), image)
Expand Down
61 changes: 30 additions & 31 deletions generic/tests/ethtool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import re

import aexpect
Expand Down Expand Up @@ -55,14 +54,14 @@ def ethtool_get(session):
temp = re.findall(
"%s: (.*)" % feature_pattern.get(f), o)[0]
if temp.find("[fixed]") != -1:
logging.debug("%s is fixed", f)
test.log.debug("%s is fixed", f)
continue
status[f] = temp
except IndexError:
status[f] = None
logging.debug("(%s) failed to get status '%s'", ethname, f)
test.log.debug("(%s) failed to get status '%s'", ethname, f)

logging.debug("(%s) offload status: '%s'", ethname, str(status))
test.log.debug("(%s) offload status: '%s'", ethname, str(status))
return status

def ethtool_set(session, status):
Expand All @@ -73,47 +72,47 @@ def ethtool_set(session, status):
"""
txt = "Set offload status for device "
txt += "'%s': %s" % (ethname, str(status))
error_context.context(txt, logging.info)
error_context.context(txt, test.log.info)

cmd = "ethtool -K %s " % ethname
cmd += " ".join([o + ' ' + s for o, s in status.items()])
err_msg = "Failed to set offload status for device '%s'" % ethname
try:
session.cmd_output_safe(cmd)
except aexpect.ShellCmdError as e:
logging.error("%s, detail: %s", err_msg, e)
test.log.error("%s, detail: %s", err_msg, e)
return False

curr_status = dict((k, v) for k, v in ethtool_get(session).items()
if k in status.keys())
if curr_status != status:
logging.error("%s, got: '%s', expect: '%s'", err_msg,
str(curr_status), str(status))
test.log.error("%s, got: '%s', expect: '%s'", err_msg,
str(curr_status), str(status))
return False

return True

def ethtool_save_params(session):
error_context.context("Saving ethtool configuration", logging.info)
error_context.context("Saving ethtool configuration", test.log.info)
return ethtool_get(session)

def ethtool_restore_params(session, status):
cur_stat = ethtool_get(session)
if cur_stat != status:
error_context.context("Restoring ethtool configuration", logging.info)
error_context.context("Restoring ethtool configuration", test.log.info)
ethtool_set(session, status)

def compare_md5sum(name):
txt = "Comparing md5sum of the files on guest and host"
error_context.context(txt, logging.info)
error_context.context(txt, test.log.info)
host_result = crypto.hash_file(name, algorithm="md5")
try:
o = session.cmd_output("md5sum %s" % name)
guest_result = re.findall(r"\w+", o)[0]
except IndexError:
logging.error("Could not get file md5sum in guest")
test.log.error("Could not get file md5sum in guest")
return False
logging.debug("md5sum: guest(%s), host(%s)", guest_result, host_result)
test.log.debug("md5sum: guest(%s), host(%s)", guest_result, host_result)
return guest_result == host_result

def transfer_file(src):
Expand All @@ -130,7 +129,7 @@ def transfer_file(src):
(filename, params.get("filesize")))
failure = (False, "Failed to create file using dd, cmd: %s" % dd_cmd)
txt = "Creating file in source host, cmd: %s" % dd_cmd
error_context.context(txt, logging.info)
error_context.context(txt, test.log.info)
ethname = utils_net.get_linux_ifname(session,
vm.get_mac_address(0))
tcpdump_cmd = "tcpdump -lep -i %s -s 0 tcp -vv port ssh" % ethname
Expand Down Expand Up @@ -158,14 +157,14 @@ def transfer_file(src):
tcpdump_cmd += " and not port %s" % i

txt = "Listening traffic using command: %s" % tcpdump_cmd
error_context.context(txt, logging.info)
error_context.context(txt, test.log.info)
sess.sendline(tcpdump_cmd)
if not utils_misc.wait_for(
lambda: session.cmd_status("pgrep tcpdump") == 0, 30):
return (False, "Tcpdump process wasn't launched")

txt = "Transferring file %s from %s" % (filename, src)
error_context.context(txt, logging.info)
error_context.context(txt, test.log.info)
try:
copy_files_func(filename, filename)
except remote.SCPError as e:
Expand All @@ -184,37 +183,37 @@ def transfer_file(src):
def tx_callback(status="on"):
s, o = transfer_file("guest")
if not s:
logging.error(o)
test.log.error(o)
return False
return True

def rx_callback(status="on"):
s, o = transfer_file("host")
if not s:
logging.error(o)
test.log.error(o)
return False
return True

def so_callback(status="on"):
s, o = transfer_file("guest")
if not s:
logging.error(o)
test.log.error(o)
return False
error_context.context("Check if contained large frame", logging.info)
error_context.context("Check if contained large frame", test.log.info)
# MTU: default IPv4 MTU is 1500 Bytes, ethernet header is 14 Bytes
return (status == "on") ^ (len([i for i in re.findall(
r"length (\d*):", o) if int(i) > mtu]) == 0)

def ro_callback(status="on"):
s, o = transfer_file("host")
if not s:
logging.error(o)
test.log.error(o)
return False
return True

vm = env.get_vm(params["main_vm"])
vm.verify_alive()
error_context.context("Log into a guest.", logging.info)
error_context.context("Log into a guest.", test.log.info)
login_timeout = int(params.get("login_timeout", 360))
session = vm.wait_for_login(timeout=login_timeout)

Expand Down Expand Up @@ -260,30 +259,30 @@ def ro_callback(status="on"):
offload_stat.update(dict.fromkeys(test_matrix[f_type][2], "off"))
if not ethtool_set(session, offload_stat):
e_msg = "Failed to set offload status"
logging.error(e_msg)
test.log.error(e_msg)
failed_tests.append(e_msg)

txt = "Run callback function %s" % callback.__name__
error_context.context(txt, logging.info)
error_context.context(txt, test.log.info)

# Some older kernel versions split packets by GSO
# before tcpdump can capture the big packet, which
# corrupts our results. Disable check when GSO is
# enabled.
if not callback(status="on") and f_type != "gso":
e_msg = "Callback failed after enabling %s" % f_type
logging.error(e_msg)
test.log.error(e_msg)
failed_tests.append(e_msg)

if not ethtool_set(session, {f_type: "off"}):
e_msg = "Failed to disable %s" % f_type
logging.error(e_msg)
test.log.error(e_msg)
failed_tests.append(e_msg)
txt = "Run callback function %s" % callback.__name__
error_context.context(txt, logging.info)
error_context.context(txt, test.log.info)
if not callback(status="off"):
e_msg = "Callback failed after disabling %s" % f_type
logging.error(e_msg)
test.log.error(e_msg)
failed_tests.append(e_msg)

if failed_tests:
Expand All @@ -294,11 +293,11 @@ def ro_callback(status="on"):
if session:
session.close()
except Exception as detail:
logging.error("Fail to close session: '%s'", detail)
test.log.error("Fail to close session: '%s'", detail)

try:
session = vm.wait_for_serial_login(timeout=login_timeout)
ethtool_restore_params(session, pretest_status)
except Exception as detail:
logging.warn("Could not restore parameter of"
" eth card: '%s'", detail)
test.log.warn("Could not restore parameter of"
" eth card: '%s'", detail)
11 changes: 5 additions & 6 deletions generic/tests/fillup_disk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging

from virttest import error_context

Expand Down Expand Up @@ -31,28 +30,28 @@ def run(test, params, env):

try:
error_context.context("Start filling the disk in %s" % fill_dir,
logging.info)
test.log.info)
cmd = params.get("fillup_cmd")
while not filled:
# As we want to test the backing file, so bypass the cache
tmp_cmd = cmd % (fill_dir, number, fillup_size)
logging.debug(tmp_cmd)
test.log.debug(tmp_cmd)
s, o = session.cmd_status_output(tmp_cmd, timeout=fillup_timeout)
if "No space left on device" in o:
logging.debug("Successfully filled up the disk")
test.log.debug("Successfully filled up the disk")
filled = True
elif s != 0:
test.fail("Command dd failed to execute: %s" % o)
number += 1
finally:
error_context.context("Cleaning the temporary files...", logging.info)
error_context.context("Cleaning the temporary files...", test.log.info)
try:
clean_cmd = params.get("clean_cmd") % fill_dir
session2.cmd(clean_cmd, ignore_all_errors=True)
finally:
show_fillup_dir_cmd = params.get("show_fillup_dir_cmd") % fill_dir
output = session2.cmd(show_fillup_dir_cmd, ignore_all_errors=True)
logging.debug("The fill_up dir shows:\n %s", output)
test.log.debug("The fill_up dir shows:\n %s", output)
if session:
session.close()
if session2:
Expand Down
Loading

0 comments on commit 528ce39

Please sign in to comment.