Skip to content

Commit

Permalink
Update the logging namespace - qemu (n)
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 3cdcd13
Show file tree
Hide file tree
Showing 40 changed files with 262 additions and 306 deletions.
3 changes: 1 addition & 2 deletions qemu/tests/nbd_map_snapshots.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import socket

from avocado.utils import process
Expand Down Expand Up @@ -61,7 +60,7 @@ def _qemu_io(img, cmd):
map_cmd = params["map_cmd"]
check_msg = params["check_msg"]

logging.info("Dump the info of '%s'", nbd_image)
test.log.info("Dump the info of '%s'", nbd_image)
try:
result = process.run(map_cmd + " " + nbd_image, ignore_status=True,
shell=True)
Expand Down
6 changes: 2 additions & 4 deletions qemu/tests/nbd_unix_connection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

from avocado.utils import process

from provider.nbd_image_export import QemuNBDExportImage
Expand Down Expand Up @@ -28,12 +26,12 @@ def run_nbd_connect_cmd(cmd):
nbd_export.create_image()
nbd_export.export_image()
# stop/suspend export
logging.info("Suspend qemu-nbd to stop export:")
test.log.info("Suspend qemu-nbd to stop export:")
try:
nbd_export.suspend_export()
nbd_connect_cmd = params["nbd_connect_cmd"]
for iteration in range(5):
run_nbd_connect_cmd(nbd_connect_cmd)
finally:
logging.info('Stop export test image.')
test.log.info('Stop export test image.')
nbd_export.stop_export()
5 changes: 2 additions & 3 deletions qemu/tests/negative_create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import re

from virttest import virt_vm
Expand Down Expand Up @@ -30,8 +29,8 @@ def run(test, params, env):
env_process.preprocess_vm(test, params, env, params["main_vm"])
except (virt_vm.VMError, utils_net.NetError) as err:
message = str(err)
logging.debug("VM Failed to create. This was expected. Reason:\n%s",
message)
test.log.debug("VM Failed to create. This was expected. Reason:\n%s",
message)

error_msg = params.get("error_msg")
if error_msg and not re.search(error_msg, message, re.M | re.I):
Expand Down
29 changes: 14 additions & 15 deletions qemu/tests/nested_block_resize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import logging
import os
import time

Expand Down Expand Up @@ -30,14 +29,14 @@ def run(test, params, env):
"""

def _on_exit(obj, msg):
logging.info("Receive exit msg:%s", msg)
test.log.info("Receive exit msg:%s", msg)
obj.set_msg_loop(False)
status = msg.split(":")[1]
if status != "0":
test.fail("Get L2 guest unexpected exit message")

def _on_resize(obj, msg):
logging.info("Receive resize msg:%s", msg)
test.log.info("Receive resize msg:%s", msg)
data_image_params = params.object_params("stg0")
data_image_size = params.get_numeric("new_image_size_stg0")
data_image_filename = storage.get_image_filename(data_image_params,
Expand All @@ -49,22 +48,22 @@ def _on_resize(obj, msg):
time.sleep(2)
vm.verify_status("running")
guest_cmd_output = session.cmd("lsblk -dn", timeout=60).strip()
logging.debug("Guest cmd output: '%s'", guest_cmd_output)
test.log.debug("Guest cmd output: '%s'", guest_cmd_output)
obj.send_message("status-req")
logging.info("Finish handle on_resize")
test.log.info("Finish handle on_resize")

def _on_status(obj, msg):
logging.info("Receive status msg:%s", msg)
test.log.info("Receive status msg:%s", msg)
status = msg.split(":")[1]
# Notify L2 exit
obj.send_message("exit")
if status != "running":
test.fail("Get unexpected status of L2 guest " + status)
logging.info("Finish handle on_status")
test.log.info("Finish handle on_status")

# Error contexts are used to give more info on what was
# going on when one exception happened executing test code.
error_context.context("Get the main VM", logging.info)
error_context.context("Get the main VM", test.log.info)
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
session = vm.wait_for_login()
Expand All @@ -87,20 +86,20 @@ def _on_status(obj, msg):
mq_listen_port = params.get_numeric("mq_listen_port", 5000)
guest_ip_list = [vm.get_address()]

logging.info("Cloning %s", playbook_repo)
test.log.info("Cloning %s", playbook_repo)
process.run("git clone {src} {dst}".format(src=playbook_repo,
dst=playbook_dir),
verbose=False)

error_context.base_context("Generate playbook related options.",
logging.info)
test.log.info)
extra_vars = {"ansible_ssh_extra_args": ansible_ssh_extra_args,
"ansible_ssh_pass": guest_passwd,
"mq_port": mq_listen_port,
"test_harness_log_dir": test_harness_log_dir}
extra_vars.update(json.loads(ansible_extra_vars))

error_context.context("Execute the ansible playbook.", logging.info)
error_context.context("Execute the ansible playbook.", test.log.info)
playbook_executor = ansible.PlaybookExecutor(
inventory="{},".format(",".join(guest_ip_list)),
site_yml=toplevel_playbook,
Expand All @@ -120,7 +119,7 @@ def _on_status(obj, msg):

host = "127.0.0.1"

logging.info("host:{} port:{}".format(host, mq_port))
test.log.info("host:{} port:{}".format(host, mq_port))
client = message_queuing.MQClient(host, mq_port)
time.sleep(2)

Expand All @@ -130,7 +129,7 @@ def _on_status(obj, msg):

try:
client.msg_loop(timeout=wait_response_timeout)
logging.debug("Finish msg_loop")
test.log.debug("Finish msg_loop")
finally:
ansible_log = "ansible_playbook.log"
try:
Expand All @@ -142,11 +141,11 @@ def _on_status(obj, msg):
test.fail(
"Ansible playbook execution failed, please check the "
"{} for details.".format(ansible_log))
logging.info("Ansible playbook execution passed.")
test.log.info("Ansible playbook execution passed.")
finally:
playbook_executor.store_playbook_log(test_harness_log_dir,
ansible_log)
playbook_executor.close()
client.close()
mq_publisher.close()
logging.debug("MQ closed")
test.log.debug("MQ closed")
19 changes: 9 additions & 10 deletions qemu/tests/nested_block_resize_l1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import time

from virttest import error_context
Expand All @@ -22,33 +21,33 @@ def run(test, params, env):
"""

def _on_exit(obj, msg):
logging.info("Receive exit msg:%s", msg)
test.log.info("Receive exit msg:%s", msg)
obj.set_msg_loop(False)
obj.send_message("exit:0")

def _on_status(obj, msg):
logging.info("Receive status msg:%s", msg)
test.log.info("Receive status msg:%s", msg)
vm_status = dict(vm.monitor.get_status())

logging.info(str(vm_status['status']))
test.log.info(str(vm_status['status']))
obj.send_message("status-rsp:" + vm_status['status'])
logging.info("Finish handle on_status")
test.log.info("Finish handle on_status")

# Error contexts are used to give more info on what was
# going on when one exception happened executing test code.
error_context.context("Get the main VM", logging.info)
error_context.context("Get the main VM", test.log.info)
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
session = vm.wait_for_login()

host = params.get("mq_publisher")
mq_port = params.get("mq_port", 5000)
logging.info("host:{} port:{}".format(host, mq_port))
test.log.info("host:{} port:{}".format(host, mq_port))
client = message_queuing.MQClient(host, mq_port)
time.sleep(2)
cmd_dd = params["cmd_dd"]
error_context.context('Do dd writing test on the data disk.',
logging.info)
test.log.info)
session.sendline(cmd_dd)
time.sleep(2)

Expand All @@ -57,11 +56,11 @@ def _on_status(obj, msg):
client.register_msg("status-req", _on_status)
client.register_msg("exit", _on_exit)
client.msg_loop(timeout=180)
logging.debug("Finish msg_loop")
test.log.debug("Finish msg_loop")
except message_queuing.MessageNotFoundError:
# Notify L1
client.send_message("exit:1")
test.fail("Nested block resize can not get expected message.")
finally:
client.close()
logging.debug("MQ closed")
test.log.debug("MQ closed")
10 changes: 4 additions & 6 deletions qemu/tests/nested_interactive_agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

from virttest import error_context
from virttest.utils_test import VMStress

Expand Down Expand Up @@ -42,19 +40,19 @@ def run(test, params, env):

try:
error_context.context('Receive the "APPROVE" message from MQ publisher '
'to continue the test.', logging.info)
'to continue the test.', test.log.info)
try:
event = mq_subscriber.receive_event(wait_response_timeout)
if event == "NOTIFY":
logging.warning('Got "NOTIFY" message to finish test')
test.log.warning('Got "NOTIFY" message to finish test')
return
elif event != 'APPROVE':
test.fail('Got unwanted message from MQ publisher.')
except message_queuing.UnknownEventError as err:
logging.error(err)
test.log.error(err)
test.error('The MQ publisher did not enter the "APPROVE" message '
'within the expected time.')
logging.info('Already captured the "APPROVE" message.')
test.log.info('Already captured the "APPROVE" message.')

if not stress_tool:
vm.reboot()
Expand Down
23 changes: 11 additions & 12 deletions qemu/tests/nested_libguestfs_unittest.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 cpu

Expand Down Expand Up @@ -44,44 +43,44 @@ def run(test, params, env):
session = vm.wait_for_login()

error_context.context("Check if libguestfs-tools is installed.",
logging.info)
test.log.info)
sm = utils_package.RemotePackageMgr(session, "libguestfs-tools")
if not (sm.is_installed("libguestfs-tools") or sm.install()):
test.cancel("Unable to install libguestfs-tools inside guest.")

try:
error_context.context("Execute the libguestfs-test-tool unittest "
"directly launching qemu.", logging.info)
"directly launching qemu.", test.log.info)
stderr_file = "/tmp/lgf_stderr"
lgf_cmd = ("LIBGUESTFS_BACKEND=direct libguestfs-test-tool "
"--timeout {} 2> {}".format(unittest_timeout,
stderr_file))
lgf_s, lgf_o = session.cmd_status_output(lgf_cmd,
timeout=unittest_timeout)
logging.debug("libguestfs-test-tool stdout:\n%s", lgf_o)
test.log.debug("libguestfs-test-tool stdout:\n%s", lgf_o)
lgf_stderr = session.cmd_output("cat " + stderr_file)
lgf_tcg = re.search("Back to tcg accelerator", lgf_stderr)

error_context.context("Analyze the libguestfs-test-tool test result.",
logging.info)
test.log.info)
fail_msg = ("the exit status is non-zero" if lgf_s else
"back to tcg accelerator" if lgf_tcg and is_kvm_mode else "")
if fail_msg:
logging.debug("libguestfs-test-tool stderr:\n%s", lgf_stderr)
test.log.debug("libguestfs-test-tool stderr:\n%s", lgf_stderr)
test.fail("libguestfs-test-tool execution failed due to: %s. "
% fail_msg)

if cpu_arch != "s390":
error_context.context("Check the nested file status.", logging.info)
error_context.context("Check the nested file status.", test.log.info)
file_s, file_o = session.cmd_status_output("cat " + nested_file)
if re.match(r"[1Y]", file_o) and is_kvm_mode:
logging.info("Guest runs with nested flag, the nested feature has "
"been enabled.")
test.log.info("Guest runs with nested flag, the nested feature has "
"been enabled.")
elif file_s == 1 and not is_kvm_mode:
logging.info("Guest runs without nested flag, so the nested file "
"does not exist.")
test.log.info("Guest runs without nested flag, so the nested file "
"does not exist.")
else:
logging.error("Nested file status: %s, output: %s", file_s, file_o)
test.log.error("Nested file status: %s, output: %s", file_s, file_o)
test.fail("Getting the status of nested file has unexpected "
"result.")
finally:
Expand Down
7 changes: 3 additions & 4 deletions qemu/tests/nested_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import logging
import json

from avocado.utils import cpu
Expand Down Expand Up @@ -93,10 +92,10 @@ def generate_parameter_file(params):
if l2_kar_options:
kar_cmd += " %s" % l2_kar_options

logging.info("Kar cmd: %s", kar_cmd)
test.log.info("Kar cmd: %s", kar_cmd)

results_dir = test.logdir
logging.info("Result_dir: %s", results_dir)
test.log.info("Result_dir: %s", results_dir)

kar_repo = params.get("kar_repo")
cert_url = params.get("cert_url")
Expand Down Expand Up @@ -142,7 +141,7 @@ def generate_parameter_file(params):
"-i %s " \
% (playbook_file, params_file, invent_file)

logging.debug("ansible cmd: %s", ansible_cmd)
test.log.debug("ansible cmd: %s", ansible_cmd)

timeout = float(params.get("test_timeout", 3600))

Expand Down
10 changes: 4 additions & 6 deletions qemu/tests/netkvm_change_param_value_test.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 @@ -31,17 +29,17 @@ def start_test(param_name, param_value):
param param_value: the value to set to
"""
error_context.context("Start set %s to %s" % (param_name, param_value),
logging.info)
test.log.info)
utils_net.set_netkvm_param_value(vm, param_name, param_value)

logging.info("Check value after setting %s", param_name)
test.log.info("Check value after setting %s", param_name)
cur_value = utils_net.get_netkvm_param_value(vm, param_name)
if cur_value != param_value:
err_msg = "Current value: %s is not equal to target value: %s"
err_msg = err_msg % (cur_value, param_value)
test.fail(err_msg)

error_context.context("Start ping test", logging.info)
error_context.context("Start ping test", test.log.info)
guest_ip = vm.get_address()
status, output = utils_test.ping(guest_ip, 10, timeout=15)
if status:
Expand Down Expand Up @@ -69,7 +67,7 @@ def _get_driver_version(session):

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_verifier = params["driver_verifier"]
session = utils_test.qemu.windrv_check_running_verifier(session, vm,
test,
Expand Down
5 changes: 2 additions & 3 deletions qemu/tests/netkvm_cpu_mapping.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import re

from virttest import error_context
Expand All @@ -20,13 +19,13 @@ def run(test, params, env):
# boot the vm with the queues
queues = int(params["queues"])
error_context.context("Boot the guest with queues = %s" % queues,
logging.info)
test.log.info)

vm = env.get_vm(params["main_vm"])
vm.verify_alive()
nic = vm.virtnet[0]
nic_vectors = int(nic['vectors']) if nic['vectors'] else (2 * queues + 2)
error_context.context("Get CPU mapping info by traceview", logging.info)
error_context.context("Get CPU mapping info by traceview", test.log.info)
output = utils_net.dump_traceview_log_windows(params, vm)
check_reg = "SetupInterrruptAffinity.*?Option = 0x0"
mapping_count = len(re.findall(check_reg, output))
Expand Down
Loading

0 comments on commit 3cdcd13

Please sign in to comment.