Skip to content

Commit

Permalink
Update the logging namespace - qemu (u)
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 27, 2022
1 parent 722406c commit 18b7dc3
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 116 deletions.
7 changes: 3 additions & 4 deletions qemu/tests/uefi_boot_from_device.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import re
import logging

from avocado.utils import process

Expand All @@ -27,7 +26,7 @@ def create_cdroms(cdrom_test):
"""
Create 'test' cdrom with one file on it
"""
logging.info("creating test cdrom")
test.log.info("creating test cdrom")
process.run("dd if=/dev/urandom of=test bs=10M count=1")
process.run("mkisofs -o %s test" % cdrom_test)
process.run("rm -f test")
Expand All @@ -36,7 +35,7 @@ def cleanup_cdroms(cdrom_test):
"""
Removes created cdrom
"""
logging.info("cleaning up temp cdrom images")
test.log.info("cleaning up temp cdrom images")
os.remove(cdrom_test)

def boot_check(info):
Expand Down Expand Up @@ -83,7 +82,7 @@ def count_of_move_step(boot_dev):
vm.send_key("down")
vm.send_key("kp_enter")

error_context.context("Check boot result", logging.info)
error_context.context("Check boot result", test.log.info)
if not utils_misc.wait_for(lambda: boot_check(boot_entry_info),
timeout, 1):
test.fail("Could not boot from '%s'" % dev_name)
Expand Down
8 changes: 3 additions & 5 deletions qemu/tests/uefi_check_debugcon.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 utils_misc
from virttest import utils_package
Expand Down Expand Up @@ -63,7 +61,7 @@ def trace_kvm_pio():
utils_package.package_install("trace-cmd")
if params.get("ovmf_log"):
error_context.context("Append debugcon parameter to "
"qemu command lines.", logging.info)
"qemu command lines.", test.log.info)
ovmf_log = utils_misc.get_path(test.debugdir, params["ovmf_log"])
params["extra_params"] %= ovmf_log
params["start_vm"] = "yes"
Expand All @@ -79,11 +77,11 @@ def trace_kvm_pio():
timeout = int(params.get("timeout", 120))
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
error_context.context("Remove the existing isa-log device.", logging.info)
error_context.context("Remove the existing isa-log device.", test.log.info)
remove_isa_debugcon(vm)
vm.destroy()
error_context.context("Run trace record command on host.",
logging.info)
test.log.info)
bg = utils_test.BackgroundTest(trace_kvm_pio, ())
bg.start()
if not utils_misc.wait_for(lambda: bg.is_alive, timeout):
Expand Down
5 changes: 2 additions & 3 deletions qemu/tests/uefi_check_log_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import re
import os
import logging

from avocado.utils import process

Expand Down Expand Up @@ -33,7 +32,7 @@ def create_cdroms(cdrom_test):
"""
Create 'test' cdrom with one file on it
"""
logging.info("creating test cdrom")
test.log.info("creating test cdrom")
process.run("dd if=/dev/urandom of=test bs=10M count=1")
process.run("mkisofs -o %s test" % cdrom_test)
process.run("rm -f test")
Expand Down Expand Up @@ -63,5 +62,5 @@ def create_cdroms(cdrom_test):
% expect_result)
finally:
if params.get("cdroms") == "test":
logging.info("cleaning up temp cdrom images")
test.log.info("cleaning up temp cdrom images")
os.remove(cdrom_test)
4 changes: 1 addition & 3 deletions qemu/tests/uefi_check_secure_mor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

from virttest import env_process
from virttest import data_dir

Expand Down Expand Up @@ -49,7 +47,7 @@ def execute_powershell_command(command, timeout=60):
# Copy Device Guard to guest
dgreadiness_host_path = data_dir.get_deps_dir("dgreadiness")
dst_path = params["dst_path"]
logging.info("Copy Device Guuard to guest.")
test.log.info("Copy Device Guuard to guest.")
s, o = session.cmd_status_output("mkdir %s" % dst_path)
if s and "already exists" not in o:
test.error("Could not create Device Guard directory in "
Expand Down
5 changes: 2 additions & 3 deletions qemu/tests/uefi_pkg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import re
import json
import logging

from avocado.utils import process
from virttest import error_context
Expand Down Expand Up @@ -39,7 +38,7 @@ def check_element(filename, file_list):

query_package = params["query_package"]
error_context.context("Check edk2-ovmf package has been "
"installed already", logging.info)
"installed already", test.log.info)
status, output = process.getstatusoutput(query_package,
ignore_status=True,
shell=True)
Expand All @@ -62,7 +61,7 @@ def check_element(filename, file_list):
"equal to %s. The actual file list is %s",
params["number_of_files"], meta_files)
error_context.context("Check the 'filename' elements in both json"
" files point to valid files.", logging.info)
" files point to valid files.", test.log.info)
for meta_file in meta_files:
with open(meta_file, "r") as f:
content = json.load(f)
Expand Down
5 changes: 2 additions & 3 deletions qemu/tests/uefi_secureboot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import logging

from virttest import error_context
from virttest import utils_misc
Expand Down Expand Up @@ -65,11 +64,11 @@ def _check_signed():
sign_info = session.cmd_output(check_sign_cmd)
signed = _check_signed()
error_context.context('Guest signed status is %s, shutdown and reboot '
'guest with secure boot' % signed, logging.info)
'guest with secure boot' % signed, test.log.info)
session.close()
vm.destroy()
if utils_misc.wait_for(vm.is_dead, 180, 1, 1):
logging.info("Guest managed to shutdown cleanly")
test.log.info("Guest managed to shutdown cleanly")
params['ovmf_vars_filename'] = 'OVMF_VARS.secboot.fd'
env_process.preprocess_vm(test, params, env, params['main_vm'])
vm = env.get_vm(params['main_vm'])
Expand Down
4 changes: 3 additions & 1 deletion qemu/tests/uefishell.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from virttest import utils_misc
from virttest import env_process

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


class UEFIShellTest(object):
"""
Expand Down Expand Up @@ -106,7 +108,7 @@ def send_command(self, command, check_result=None, interval=0.5):
:param interval: time interval between commands
:return if check_result is not None, return matched string list
"""
logging.info("Send uefishell command: %s", command)
LOG_JOB.info("Send uefishell command: %s", command)
output = self.session.cmd_output(command)
time.sleep(interval)
# Judge if cmd is run successfully via environment variable 'lasterror'
Expand Down
5 changes: 2 additions & 3 deletions qemu/tests/unplug_block_during_io_reboot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import time
import re

Expand Down Expand Up @@ -45,7 +44,7 @@ def _get_data_disk():

def _run_stress_background():
""" Run stress under background. """
logging.info("Start io stress under background.")
test.log.info("Start io stress under background.")
thread = utils_misc.InterruptedThread(
target[os_type]['name'], (target[os_type]['args'],))
thread.start()
Expand Down Expand Up @@ -79,5 +78,5 @@ def _run_stress_background():
stress_thread.join(suppress_exception=True)
session.close()
vm.monitor.system_reset()
logging.info('Login guest after reboot.')
test.log.info('Login guest after reboot.')
session = vm.wait_for_login(timeout=360)
7 changes: 3 additions & 4 deletions qemu/tests/unsafe_rebase_to_none_existing_backing_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import json

from avocado.utils import process
Expand Down Expand Up @@ -36,7 +35,7 @@ def _get_compat_version():

def _verify_qemu_img_info(output, b_fmt, b_name):
"""Verify qemu-img info output for this case."""
logging.info("Verify snapshot's backing file information.")
test.log.info("Verify snapshot's backing file information.")
res = json.loads(output)
if (res["backing-filename-format"] != b_fmt or
res["backing-filename"] != b_name):
Expand All @@ -50,7 +49,7 @@ def _verify_qemu_img_info(output, b_fmt, b_name):

def _verify_unsafe_rebase(img):
"""Verify qemu-img check output for this case."""
logging.info("Verify snapshot's unsafe check information.")
test.log.info("Verify snapshot's unsafe check information.")
res = process.run("%s check %s" % (img.image_cmd, img.image_filename),
ignore_status=True)
expected = ["Could not open backing file", img.base_image_filename,
Expand All @@ -64,7 +63,7 @@ def _verify_unsafe_rebase(img):
base_img, _ = _get_img_obj_and_params(base)
sn_img, sn_img_params = _get_img_obj_and_params(snapshot)

logging.info("Create a snapshot %s based on %s.", snapshot, base)
test.log.info("Create a snapshot %s based on %s.", snapshot, base)
# workaround to assign system disk's image_name to image_name_image1
params["image_name_image1"] = params["image_name"]
QemuImgTest(test, params, env, snapshot).create_snapshot()
Expand Down
11 changes: 5 additions & 6 deletions qemu/tests/usb_basic_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import time
import re
import logging

import aexpect
from virttest import utils_misc
Expand All @@ -12,7 +11,7 @@ def check_usb_device_monitor(test, params, env):
vm = env.get_vm(params["main_vm"])
vm.verify_alive()

error_context.context("Verify USB device in monitor.", logging.info)
error_context.context("Verify USB device in monitor.", test.log.info)
o = vm.monitor.info("usb")
if isinstance(o, dict):
o = o.get("return")
Expand Down Expand Up @@ -94,9 +93,9 @@ def check_usb_device(test, params, env):

if io_error_msg:
e_msg = "Error found in guest's dmesg"
logging.error(e_msg)
test.log.error(e_msg)
for line in io_error_msg:
logging.error(line)
test.log.error(line)
test.fail(e_msg)


Expand Down Expand Up @@ -126,14 +125,14 @@ def _check_dev():
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
timeout = float(params.get("login_timeout", 240))
error_context.context("Try to log into guest.", logging.info)
error_context.context("Try to log into guest.", test.log.info)
session = vm.wait_for_login(timeout=timeout)

error_context.context("Verify device(s) before rebooting.")
_check_dev()

if params.get("reboot_method"):
error_context.context("Reboot guest.", logging.info)
error_context.context("Reboot guest.", test.log.info)
if params["reboot_method"] == "system_reset":
time.sleep(int(params.get("sleep_before_reset", 10)))
session = vm.reboot(session, params["reboot_method"], 0, timeout)
Expand Down
10 changes: 6 additions & 4 deletions qemu/tests/usb_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from virttest import utils_misc

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


def parse_usb_topology(params):
"""
Expand Down Expand Up @@ -126,27 +128,27 @@ def _verify_guest_usb():
else:
o = output
if dev[1] not in o:
logging.info("%s does not exist", dev[1])
LOG_JOB.info("%s does not exist", dev[1])
return False
# match number of devices
dev_list = [dev[1] for dev in devs]
dev_nums = dict((i, dev_list.count(i)) for i in dev_list)
for k, v in dev_nums.items():
logging.info("the number of %s is %s", k, v)
LOG_JOB.info("the number of %s is %s", k, v)
if "Hub" in k and os_type == "linux":
o = hub_output
else:
o = output
count = o.count(k)
if count != v:
logging.info("expected %s %s, got %s in the guest",
LOG_JOB.info("expected %s %s, got %s in the guest",
v, k, count)
return False
return True

os_type = params.get("os_type")
if os_type == "linux":
logging.info("checking if there is I/O error in dmesg")
LOG_JOB.info("checking if there is I/O error in dmesg")
output = session.cmd_output("dmesg | grep -i usb",
float(params["cmd_timeout"]))
for line in output.splitlines():
Expand Down
10 changes: 4 additions & 6 deletions qemu/tests/usb_device_check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

from virttest import env_process
from virttest import error_context
from qemu.tests.usb_common import (parse_usb_topology,
Expand All @@ -23,14 +21,14 @@ def run(test, params, env):
"""
def _check_test_step_result(result, output):
if result:
logging.info(output)
test.log.info(output)
else:
test.fail(output)

# parse the usb topology from cfg
parsed_devs = parse_usb_topology(params)

logging.info("starting vm according to the usb topology")
test.log.info("starting vm according to the usb topology")
env_process.process(test, params, env,
env_process.preprocess_image,
env_process.preprocess_vm)
Expand All @@ -41,7 +39,7 @@ def _check_test_step_result(result, output):
devs = collect_usb_dev(params, vm, parsed_devs, "for_qemu")

error_context.context("verify usb devices information in qemu...",
logging.info)
test.log.info)
result, output = verify_usb_device_in_monitor_qtree(vm, devs)
_check_test_step_result(result, output)

Expand All @@ -51,7 +49,7 @@ def _check_test_step_result(result, output):
session = vm.wait_for_login(timeout=login_timeout)

error_context.context("verify usb devices information in guest...",
logging.info)
test.log.info)
result, output = verify_usb_device_in_guest(params, session, devs)
_check_test_step_result(result, output)

Expand Down
6 changes: 2 additions & 4 deletions qemu/tests/usb_device_check_negative.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

from virttest import (env_process,
error_context,
virt_vm)
Expand All @@ -20,10 +18,10 @@ def run(test, params, env):
"""
# parse the usb topology from cfg
parse_usb_topology(params)
logging.info("starting vm according to the usb topology")
test.log.info("starting vm according to the usb topology")
error_info = params["error_info"]
error_context.context(("verify [%s] is reported by QEMU..." %
error_info), logging.info)
error_info), test.log.info)
try:
env_process.process(test, params, env,
env_process.preprocess_image,
Expand Down
Loading

0 comments on commit 18b7dc3

Please sign in to comment.