Skip to content

Commit

Permalink
Update the logging namespace - qemu (k-m)
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 3661d8e commit 7de296c
Show file tree
Hide file tree
Showing 52 changed files with 510 additions and 541 deletions.
14 changes: 6 additions & 8 deletions qemu/tests/kdump_with_stress.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

from virttest import error_context
from virttest import utils_test
from virttest import utils_misc
Expand Down Expand Up @@ -28,18 +26,18 @@ def install_stress_app(session):
"""
stress_path = data_dir.get_deps_dir("stress")
stress_guest_path = params["tmp_dir"]
logging.info("Copy stress package to guest.")
test.log.info("Copy stress package to guest.")
session.cmd_status_output("mkdir -p %s" % stress_guest_path)
vm.copy_files_to(stress_path, stress_guest_path)
session.cmd(params["install_cmd"])

logging.info("Install app successed")
test.log.info("Install app successed")

def start_stress(session):
"""
Load stress in guest.
"""
error_context.context("Load stress in guest", logging.info)
error_context.context("Load stress in guest", test.log.info)
stress_type = params.get("stress_type", "none")

if stress_type == "none":
Expand All @@ -58,15 +56,15 @@ def start_stress(session):
install_stress_app(session)

cmd = params.get("start_cmd")
logging.info("Launch stress app in guest with command: '%s'", cmd)
test.log.info("Launch stress app in guest with command: '%s'", cmd)
session.sendline(cmd)

running = utils_misc.wait_for(lambda: stress_running(session),
timeout=150, step=5)
if not running:
test.error("Stress isn't running")

logging.info("Stress running now")
test.log.info("Stress running now")

def stress_running(session):
"""
Expand Down Expand Up @@ -98,7 +96,7 @@ def stress_running(session):
start_stress(session)

error_context.context("Kdump Testing, force the Linux kernel to crash",
logging.info)
test.log.info)
crash_cmd = params.get("crash_cmd", "echo c > /proc/sysrq-trigger")
if crash_cmd == "nmi":
kdump.crash_test(test, vm, None, crash_cmd, timeout)
Expand Down
13 changes: 6 additions & 7 deletions qemu/tests/kernbench.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os
import re

Expand Down Expand Up @@ -49,7 +48,7 @@ def check_ept():
process.system(cmd, timeout=100, shell=True)

def install_gcc():
logging.info("Update gcc to request version....")
test.log.info("Update gcc to request version....")
cmd = "rpm -q gcc"
cpp_link = params.get("cpp_link")
gcc_link = params.get("gcc_link")
Expand All @@ -70,7 +69,7 @@ def install_gcc():
libgcc_link, cpp_link, gcc_link)
(s, o) = cmd_status_output(cmd)
if s:
logging.debug("Fail to install gcc.output:%s", o)
test.log.debug("Fail to install gcc.output:%s", o)

def record_result(result):
re_result = params.get("re_result")
Expand All @@ -85,7 +84,7 @@ def record_result(result):
f1.write(result_str)
f1.close()
open(os.path.basename(result_file), 'w').write(result)
logging.info("Test result got from %s:\n%s", result_file, result)
test.log.info("Test result got from %s:\n%s", result_file, result)

test_type = params.get("test_type")
guest_thp_cmd = params.get("guest_thp_cmd")
Expand All @@ -112,7 +111,7 @@ def record_result(result):
download_if_not_exists()

if "guest" in test_type:
logging.info("test in guest")
test.log.info("test in guest")
vm.copy_files_to(tmp_dir, os.path.dirname(tmp_dir))
if guest_thp_cmd is not None:
session.cmd_output(guest_thp_cmd)
Expand All @@ -129,12 +128,12 @@ def record_result(result):
else:
cpu_num = cpu.online_count()
test_cmd = params.get("test_cmd") % (int(cpu_num) * cpu_multiplier)
logging.info("Start making the kernel ....")
test.log.info("Start making the kernel ....")
(s, o) = cmd_status_output(test_cmd, timeout=cmd_timeout)
if s:
test.error("Fail command:%s\n Output:%s" % (test_cmd, o))
else:
logging.info("Output for command %s is:\n %s", test_cmd, o)
test.log.info("Output for command %s is:\n %s", test_cmd, o)
record_result(o)
finally:
if params.get("post_cmd"):
Expand Down
21 changes: 10 additions & 11 deletions qemu/tests/kernel_install.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os

from avocado.utils import aurl
Expand Down Expand Up @@ -47,15 +46,15 @@ def _save_bootloader_config(session):
try:
default_kernel = session.cmd_output("grubby --default-kernel")
except Exception as e:
logging.warn("Save grub config failed: '%s'", e)
test.log.warn("Save grub config failed: '%s'", e)

return default_kernel

def _restore_bootloader_config(session, default_kernel):
error_context.context("Restore the grub to old version")

if not default_kernel:
logging.warn("Could not get previous grub config, do noting.")
test.log.warn("Could not get previous grub config, do noting.")
return

cmd = "grubby --set-default=%s" % default_kernel.strip()
Expand All @@ -69,8 +68,8 @@ def _clean_up_tmp_files(file_list):
try:
os.unlink(f)
except Exception as e:
logging.warn("Could remove tmp file '%s', error message: '%s'",
f, e)
test.log.warn("Could remove tmp file '%s', error message: '%s'",
f, e)

def _build_params(param_str, default_value=""):
param = _tmp_params_dict.get(param_str)
Expand All @@ -87,8 +86,8 @@ def _build_params(param_str, default_value=""):
timeout = float(params.get("login_timeout", 240))
session = vm.wait_for_login(timeout=timeout)

logging.info("Guest kernel before install: %s",
session.cmd('uname -a').strip())
test.log.info("Guest kernel before install: %s",
session.cmd('uname -a').strip())

error_context.context("Save current default kernel information")
default_kernel = _save_bootloader_config(session)
Expand Down Expand Up @@ -176,8 +175,8 @@ def _build_params(param_str, default_value=""):
utils_test.run_virt_sub_test(test, params, env,
sub_type=sub_test, tag=tag)
except Exception as e:
logging.error("Fail to run sub_test '%s', error message: '%s'",
sub_test, e)
test.log.error("Fail to run sub_test '%s', error message: '%s'",
sub_test, e)

if params.get("restore_defaut_kernel", "no") == "yes":
# Restore grub
Expand All @@ -193,8 +192,8 @@ def _build_params(param_str, default_value=""):
vm.reboot()

session = vm.wait_for_login(timeout=timeout)
logging.info("Guest kernel after install: %s",
session.cmd('uname -a').strip())
test.log.info("Guest kernel after install: %s",
session.cmd('uname -a').strip())

# Finally, let me clean up the tmp files.
_clean_up_tmp_files(_tmp_file_list)
12 changes: 5 additions & 7 deletions qemu/tests/kexec.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

from virttest import error_context


Expand All @@ -20,7 +18,7 @@ def run(test, params, env):

def check_x2apic_flag():
x2apic_enabled = False
error_context.context("Check x2apic enabled in guest", logging.info)
error_context.context("Check x2apic enabled in guest", test.log.info)
x2apic_output = session.cmd_output(check_x2apic_cmd).strip()
x2apic_check_string = params.get("x2apic_check_string").split(",")
for check_string in x2apic_check_string:
Expand All @@ -30,7 +28,7 @@ def check_x2apic_flag():
test.fail("x2apic is not enabled in guest.")

def install_new_kernel():
error_context.context("Install a new kernel in guest", logging.info)
error_context.context("Install a new kernel in guest", test.log.info)
try:
# pylint: disable=E0611
from qemu.tests import rh_kernel_update
Expand Down Expand Up @@ -60,7 +58,7 @@ def install_new_kernel():

check_cur_kernel_cmd = params.get("check_cur_kernel_cmd")
cur_kernel_version = session.cmd_output(check_cur_kernel_cmd).strip()
logging.info("Current kernel is: %s", cur_kernel_version)
test.log.info("Current kernel is: %s", cur_kernel_version)
cmd = params.get("check_installed_kernel")
output = session.cmd_output(cmd, timeout=cmd_timeout)
kernels = output.split()
Expand All @@ -73,7 +71,7 @@ def install_new_kernel():
test.error("Could not find new kernel, "
"command line output: %s" % output)
msg = "Reboot to kernel %s through kexec" % new_kernel
error_context.context(msg, logging.info)
error_context.context(msg, test.log.info)
cmd = params.get("get_kernel_image") % new_kernel
kernel_file = session.cmd_output(cmd).strip().splitlines()[0]
cmd = params.get("get_kernel_ramdisk") % new_kernel
Expand All @@ -84,7 +82,7 @@ def install_new_kernel():
session.sendline(cmd)
session = vm.wait_for_login(timeout=login_timeout)
kernel = session.cmd_output(check_cur_kernel_cmd).strip()
logging.info("Current kernel is: %s", kernel)
test.log.info("Current kernel is: %s", kernel)
if kernel.strip() != new_kernel.strip():
test.fail("Fail to boot to kernel %s, current kernel is %s"
% (new_kernel, kernel))
Expand Down
10 changes: 6 additions & 4 deletions qemu/tests/kill_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import logging
import os

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


def run(test, params, env):
"""
Expand All @@ -26,12 +28,12 @@ def run(test, params, env):
kill_on_vms = params.get("kill_on_vms", "")
vms = kill_on_vms.split(',')
app_name = params.get("kill_app_name", None)
logging.debug("vms %s", vms)
test.log.debug("vms %s", vms)
if not vms:
test.fail("Kill app test launched without any VM parameter")
else:
for vm in vms:
logging.debug("vm %s", vm)
test.log.debug("vm %s", vm)
if vm in params:
kill_app(vm, app_name, params, env)

Expand All @@ -49,10 +51,10 @@ def kill_app(vm_name, app_name, params, env):
vm_session = vm.wait_for_login(
timeout=int(params.get("login_timeout", 360)))
# get PID of remote-viewer and kill it
logging.info("Get PID of %s", app_name)
LOG_JOB.info("Get PID of %s", app_name)
vm_session.cmd("pgrep %s" % app_name)

logging.info("Try to kill %s", app_name)
LOG_JOB.info("Try to kill %s", app_name)
vm_session.cmd("pkill %s" % app_name
.split(os.path.sep)[-1])
vm.verify_alive()
Expand Down
19 changes: 9 additions & 10 deletions qemu/tests/ksm_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import time
import random
import os
Expand Down Expand Up @@ -36,7 +35,7 @@ def _start_allocator(vm, session, timeout):
:param timeout: Timeout that will be used to verify if guest script
started properly.
"""
logging.debug("Starting guest script on guest %s", vm.name)
test.log.debug("Starting guest script on guest %s", vm.name)
session.sendline("$(command -v python python3 | head -1) "
"/tmp/ksm_overcommit_guest.py")
try:
Expand All @@ -58,8 +57,8 @@ def _execute_allocator(command, vm, session, timeout):
:return: Tuple (match index, data)
"""
logging.debug("Executing '%s' on guest script loop, vm: %s, timeout: "
"%s", command, vm.name, timeout)
test.log.debug("Executing '%s' on guest script loop, vm: %s, timeout: "
"%s", command, vm.name, timeout)
session.sendline(command)
try:
(match, data) = session.read_until_last_line_matches(
Expand All @@ -78,7 +77,7 @@ def _execute_allocator(command, vm, session, timeout):
session = vm.wait_for_login(timeout=timeout)

# Prepare work in guest
error_context.context("Turn off swap in guest", logging.info)
error_context.context("Turn off swap in guest", test.log.info)
session.cmd_status_output("swapoff -a")
script_file_path = os.path.join(data_dir.get_root_dir(),
"shared/scripts/ksm_overcommit_guest.py")
Expand Down Expand Up @@ -108,9 +107,9 @@ def _execute_allocator(command, vm, session, timeout):
if query_regex:
sharing_page_0 = re.findall(query_regex, sharing_page_0)[0]

error_context.context("Start to allocate pages inside guest", logging.info)
error_context.context("Start to allocate pages inside guest", test.log.info)
_start_allocator(vm, session, 60)
error_context.context("Start to fill memory in guest", logging.info)
error_context.context("Start to fill memory in guest", test.log.info)
mem_fill = "mem = MemFill(%s, 0, %s)" % (shared_mem, seed)
_execute_allocator(mem_fill, vm, session, fill_timeout)
cmd = "mem.value_fill()"
Expand All @@ -125,7 +124,7 @@ def _execute_allocator(command, vm, session, timeout):
sharing_page_1 = re.findall(query_regex, sharing_page_1)[0]

error_context.context("Start to fill memory with random value in guest",
logging.info)
test.log.info)
split = params.get("split")
if split == "yes":
if test_type == "negative":
Expand All @@ -143,7 +142,7 @@ def _execute_allocator(command, vm, session, timeout):
sharing_page_2 = re.findall(query_regex, sharing_page_2)[0]

# clean up work in guest
error_context.context("Clean up env in guest", logging.info)
error_context.context("Clean up env in guest", test.log.info)
session.cmd_output("die()", 20)
session.cmd_status_output("swapon -a")
session.cmd_output("echo 3 > /proc/sys/vm/drop_caches")
Expand Down Expand Up @@ -176,7 +175,7 @@ def _execute_allocator(command, vm, session, timeout):
turns = 0
while (fail_type > 0):
if fail_type % 2 == 1:
logging.error(fail[turns])
test.log.error(fail[turns])
fail_type = fail_type / 2
turns += 1
test.fail("KSM test failed: %s %s %s" %
Expand Down
11 changes: 5 additions & 6 deletions qemu/tests/ksm_ksmtuned.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re
import os
import time
import logging

from shutil import copyfile

Expand Down Expand Up @@ -39,8 +38,8 @@ def check_ksm(mem, threshold_reached=False):
"""
def heavyload_install():
if session.cmd_status(test_install_cmd) != 0:
logging.warning("Could not find installed heavyload in guest, "
"will install it via winutils.iso ")
test.log.warning("Could not find installed heavyload in guest, "
"will install it via winutils.iso ")
winutil_drive = utils_misc.get_winutils_vol(session)
if not winutil_drive:
test.cancel("WIN_UTILS CDROM not found.")
Expand Down Expand Up @@ -88,9 +87,9 @@ def check_qemu_used_mem(qemu_pid, mem):
free_mem_host = utils_memory.freememtotal()
ksm_status = process.getoutput(params['cmd_check_ksm_status'])
vm.destroy()
logging.info("The ksm threshold is %sM, QEMU used memory is %sM, "
"and the total free memory on host is %sM",
ksm_thres // 1024, mem // 1024, free_mem_host // 1024)
test.log.info("The ksm threshold is %sM, QEMU used memory is %sM, "
"and the total free memory on host is %sM",
ksm_thres // 1024, mem // 1024, free_mem_host // 1024)
if threshold_reached:
if free_mem_host > ksm_thres:
test.error("Host memory is not consumed as much as expected")
Expand Down
Loading

0 comments on commit 7de296c

Please sign in to comment.