Skip to content

Commit

Permalink
Update the logging namespace - qemu (t)
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 b8f1862 commit 01ed848
Show file tree
Hide file tree
Showing 45 changed files with 356 additions and 403 deletions.
17 changes: 8 additions & 9 deletions qemu/tests/tcpreplay.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import re
import os
import shutil
Expand Down Expand Up @@ -32,7 +31,7 @@ def execute_host_cmd(host_cmd, timeout=60):
param timeout: the timeout for running this command
return: the output of the host_cmd
"""
logging.info("Executing host command: %s", host_cmd)
test.log.info("Executing host command: %s", host_cmd)
cmd_result = process.run(host_cmd, timeout=timeout, shell=True)
output = cmd_result.stdout_text
return output
Expand Down Expand Up @@ -63,31 +62,31 @@ def copy_file_from_deps(file_name, sub_dir, dst_dir="/tmp"):
timeout = params.get_numeric("timeout", 60)

error_context.context("Copy %s to %s" % (tcpreplay_file_name, tmp_dir),
logging.info)
test.log.info)
tcpreplay_full_path = copy_file_from_deps(tcpreplay_file_name,
tcpreplay_dir, tmp_dir)

error_context.context("Compile tcpreplay", logging.info)
error_context.context("Compile tcpreplay", test.log.info)
uncompress_full_path = os.path.join(tmp_dir, uncompress_dir)

logging.info("Remove old uncompress directory")
test.log.info("Remove old uncompress directory")
shutil.rmtree(uncompress_full_path, ignore_errors=True)

logging.info(
test.log.info(
"Uncompress %s to %s", tcpreplay_full_path, uncompress_full_path)
uncompress_dir = archive.uncompress(
tcpreplay_full_path, tmp_dir)
if not uncompress_dir:
test.error("Can't uncompress %s" % tcpreplay_full_path)

logging.info("Compile files at %s", uncompress_full_path)
test.log.info("Compile files at %s", uncompress_full_path)
execute_host_cmd(tcpreplay_compile_cmd % uncompress_full_path, timeout)

error_context.context("Copy %s to %s" % (pcap_file_name, tmp_dir),
logging.info)
test.log.info)
copy_file_from_deps(pcap_file_name, tcpreplay_dir, tmp_dir)

error_context.context("Run tcpreplay with pcap file", logging.info)
error_context.context("Run tcpreplay with pcap file", test.log.info)
output = execute_host_cmd(run_tcpreplay_cmd)
result = re.search(r'Successful packets:\s+(\d+)', output)
success_packet = 0
Expand Down
7 changes: 3 additions & 4 deletions qemu/tests/thin_provision_check_mode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import logging

from avocado.utils import genio
from avocado.utils import path as utils_path
Expand Down Expand Up @@ -69,7 +68,7 @@ def get_guest_provisioning_mode(device):
utils_path.find_command("lsblk")
host_scsi_id, disk_name = get_host_scsi_disk()
provisioning_mode = get_provisioning_mode(disk_name, host_scsi_id)
logging.info("Current host provisioning_mode = '%s'", provisioning_mode)
test.log.info("Current host provisioning_mode = '%s'", provisioning_mode)

# prepare params to boot vm with scsi_debug disk.
vm_name = params["main_vm"]
Expand All @@ -80,7 +79,7 @@ def get_guest_provisioning_mode(device):
params["image_name_%s" % data_tag] = disk_name

error_context.context("boot guest with disk '%s'" % disk_name,
logging.info)
test.log.info)
# boot guest with scsi_debug disk
env_process.preprocess_vm(test, params, env, vm_name)
vm = env.get_vm(vm_name)
Expand All @@ -94,6 +93,6 @@ def get_guest_provisioning_mode(device):
test.fail("Can not get output file path in guest.")

mode = get_guest_provisioning_mode(output_path)
error_context.context("Checking provision mode %s" % mode, logging.info)
error_context.context("Checking provision mode %s" % mode, test.log.info)
if mode != target_mode:
test.fail("Got unexpected mode:%s", mode)
19 changes: 9 additions & 10 deletions qemu/tests/thin_provision_guest_fstrim.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
from avocado.utils import path as utils_path
from avocado.utils import process

Expand Down Expand Up @@ -86,7 +85,7 @@ def get_blocks():
params["image_name_%s" % data_tag] = disk_name

error_context.context("Boot guest with disk '%s'" % disk_name,
logging.info)
test.log.info)
# boot guest with scsi_debug disk
env_process.preprocess_vm(test, params, env, vm_name)
vm = env.get_vm(vm_name)
Expand All @@ -101,25 +100,25 @@ def get_blocks():
guest_dd_command = params["guest_dd_command"]
guest_rm_command = params["guest_rm_command"]

error_context.context("Format disk in guest.", logging.info)
error_context.context("Format disk in guest.", test.log.info)
session.cmd(guest_format_command)
count = get_blocks()
logging.info("The initial blocks is %d", count)
test.log.info("The initial blocks is %d", count)

error_context.context("Fill data disk in guest.", logging.info)
error_context.context("Fill data disk in guest.", test.log.info)
session.cmd(guest_dd_command, ignore_all_errors=True)
old_count = get_blocks()
error_context.context("Blocks before trim: %d" % old_count, logging.info)
error_context.context("Blocks before trim: %d" % old_count, test.log.info)

error_context.context("Remove data from disk in guest.", logging.info)
error_context.context("Remove data from disk in guest.", test.log.info)
session.cmd(guest_rm_command)

session.cmd("setenforce 0")
error_context.context("Execute guest-fstrim command.", logging.info)
error_context.context("Execute guest-fstrim command.", test.log.info)
agent_session.fstrim()
new_count = get_blocks()
error_context.context("Blocks after trim: %d" % new_count, logging.info)
error_context.context("Blocks after trim: %d" % new_count, test.log.info)

error_context.context("Compare blocks.", logging.info)
error_context.context("Compare blocks.", test.log.info)
if new_count >= old_count:
test.fail("Got unexpected result:%s %s" % (old_count, new_count))
5 changes: 2 additions & 3 deletions qemu/tests/thin_write_in_qemu_img_commit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import json
import re

Expand Down Expand Up @@ -36,13 +35,13 @@ def _get_image_object(tag):

def _create_external_snapshot(tag):
"""Create an external snapshot based on tag."""
logging.info("Create external snapshot %s.", tag)
test.log.info("Create external snapshot %s.", tag)
qit = QemuImgTest(test, params, env, snapshot)
qit.create_snapshot()

def _qemu_io(img, cmd):
"""Run qemu-io cmd to a given img."""
logging.info("Run qemu-io %s", img.image_filename)
test.log.info("Run qemu-io %s", img.image_filename)
q = QemuIOSystem(test, params, img.image_filename)
q.cmd_output(cmd, 120)

Expand Down
11 changes: 5 additions & 6 deletions qemu/tests/throttle_cdrom_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""IO-Throttling cdrom relevant testing"""

import logging

from virttest import error_context
from virttest.qemu_capabilities import Flags
Expand All @@ -19,7 +18,7 @@ def run(test, params, env):
5) Execute eject media operation
"""

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()

Expand All @@ -31,7 +30,7 @@ def run(test, params, env):
if device_name is None:
test.fail("Fail to get cdrom device with drv throttle")

logging.info("Found cdrom device %s", device_name)
test.log.info("Found cdrom device %s", device_name)

eject_check = QMPEventCheckCDEject(vm, device_name)
change_check = QMPEventCheckCDChange(vm, device_name)
Expand All @@ -43,20 +42,20 @@ def run(test, params, env):

# change media
new_img_name = params.get("new_img_name")
error_context.context("Insert new image to device.", logging.info)
error_context.context("Insert new image to device.", test.log.info)
with change_check:
vm.change_media(device_name, new_img_name)

# After change medium throttle property is expected to be removed
error_context.context("Query cdrom device with new image.", logging.info)
error_context.context("Query cdrom device with new image.", test.log.info)
p_dict = {"removable": True, "file": new_img_name}
device_name = vm.get_block(p_dict)

if device_name is None:
test.fail("Fail to get cdrom device with new image after change")

# eject media
error_context.context("Eject device.", logging.info)
error_context.context("Eject device.", test.log.info)
with eject_check:
monitor.blockdev_open_tray(qdev, force=True)
monitor.blockdev_remove_medium(qdev)
17 changes: 8 additions & 9 deletions qemu/tests/throttle_multi_guests_parameter_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import logging
import shutil

from virttest import error_context
Expand Down Expand Up @@ -37,7 +36,7 @@ def copy_base_vm_image():
dst_filename = os.path.join(
dst_dir, '%s.%s' % (vm_name, src_format))
if not os.path.exists(dst_filename):
logging.info('Copying %s to %s.', src_filename, dst_filename)
test.log.info('Copying %s to %s.', src_filename, dst_filename)
shutil.copy(src_filename, dst_filename)

def wait_for_login_all_vms():
Expand All @@ -46,11 +45,11 @@ def wait_for_login_all_vms():

@error_context.context_aware
def fio_on_vm(vm_t, session_t):
error_context.context("Deploy fio", logging.info)
error_context.context("Deploy fio", test.log.info)
fio = generate_instance(params, vm_t, 'fio')
logging.info("fio: %s", fio)
test.log.info("fio: %s", fio)
tgm = ThrottleGroupManager(vm_t)
logging.info("tgm: %s", tgm)
test.log.info("tgm: %s", tgm)
groups = params["throttle_groups"].split()
testers = []
for group in groups:
Expand All @@ -59,23 +58,23 @@ def fio_on_vm(vm_t, session_t):
tester = ThrottleTester(test, params, vm_t, session_t,
group, images)
error_context.context("Build test stuff for %s:%s"
% (group, images), logging.info)
% (group, images), test.log.info)
tester.build_default_option()
tester.build_images_fio_option()
tester.set_fio(fio)
testers.append(tester)
error_context.context("Start groups testing:%s" % groups, logging.info)
error_context.context("Start groups testing:%s" % groups, test.log.info)
groups_tester = ThrottleGroupsTester(testers)
groups_tester.start()

def fio_on_vms():
"""Run fio on all started vms at the same time."""
logging.info("Start to do fio on multi-vms:")
test.log.info("Start to do fio on multi-vms:")
fio_parallel_params = []
for vm, session in zip(vms, sessions):
fio_parallel_params.append((fio_on_vm, (vm, session)))
utils_misc.parallel(fio_parallel_params)
logging.info("Done fio on multi-vms.")
test.log.info("Done fio on multi-vms.")

vms_list = params['vms'].split()
copy_base_vm_image()
Expand Down
21 changes: 10 additions & 11 deletions qemu/tests/throttle_operation_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""IO-Throttling group and other operation relevant testing"""
import json
import logging

from virttest import error_context
from virttest.qemu_monitor import QMPCmdError
Expand Down Expand Up @@ -41,9 +40,9 @@ def negative_test():
except QMPCmdError as err:
qmp_desc = err.data["desc"]
if qmp_desc.find(err_msg) >= 0:
logging.info("Find expected result for %s", name)
test.log.info("Find expected result for %s", name)
continue
logging.error(
test.log.error(
"Cannot got expected wrong result on %s: %s in %s",
name, err_msg, qmp_desc)
raise err
Expand Down Expand Up @@ -93,29 +92,29 @@ def operation_snapshot():
snapshot_test.prepare_snapshot_file()
snapshot_test.create_snapshot()

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(timeout=360)

error_context.context("Deploy fio", logging.info)
error_context.context("Deploy fio", test.log.info)
fio = generate_instance(params, vm, 'fio')

tgm = ThrottleGroupManager(vm)
groups = params["throttle_groups"].split()
operation = params["operation"]

# simple test on group1
error_context.context("Execute simple test on group1", logging.info)
error_context.context("Execute simple test on group1", test.log.info)
tester = ThrottleTester(test, params, vm, session, "group1", ["stg1"])
tester.build_default_option()
tester.build_images_fio_option()
tester.set_fio(fio)
tester.start()

# execute relevant operation
error_context.context("Execute operation %s" % operation, logging.info)
error_context.context("Execute operation %s" % operation, test.log.info)
locals_var = locals()
locals_var[operation]()
# test after operation
Expand All @@ -126,20 +125,20 @@ def operation_snapshot():
tgm.get_throttle_group_props(group)
images = params.get("throttle_group_member_%s" % group, "").split()
if len(images) == 0:
logging.warning("No images in group %s", group)
test.log.warning("No images in group %s", group)
continue
tester = ThrottleTester(test, params, vm, session, group, images)
error_context.context("Build test stuff for %s:%s" % (group, images),
logging.info)
test.log.info)
tester.build_default_option()
tester.build_images_fio_option()
tester.set_fio(fio)
testers.append(tester)

error_context.context("Start groups testing:%s" % groups, logging.info)
error_context.context("Start groups testing:%s" % groups, test.log.info)
groups_tester = ThrottleGroupsTester(testers)

repeat_test = params.get_numeric("repeat_test", 1)
for repeat in range(repeat_test):
error_context.context("Begin test loop:%d" % repeat, logging.info)
error_context.context("Begin test loop:%d" % repeat, test.log.info)
groups_tester.start()
10 changes: 4 additions & 6 deletions qemu/tests/throttle_parameter_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

from virttest import error_context

from provider.storage_benchmark import generate_instance
Expand All @@ -20,13 +18,13 @@ def run(test, params, env):
3) Execute one disk or all disks testing on groups parallel.
"""

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(timeout=360)

error_context.context("Deploy fio", logging.info)
error_context.context("Deploy fio", test.log.info)
fio = generate_instance(params, vm, 'fio')

tgm = ThrottleGroupManager(vm)
Expand All @@ -37,13 +35,13 @@ def run(test, params, env):
images = params["throttle_group_member_%s" % group].split()
tester = ThrottleTester(test, params, vm, session, group, images)
error_context.context("Build test stuff for %s:%s" % (group, images),
logging.info)
test.log.info)
tester.build_default_option()
tester.build_images_fio_option()
tester.set_fio(fio)
testers.append(tester)

error_context.context("Start groups testing:%s" % groups, logging.info)
error_context.context("Start groups testing:%s" % groups, test.log.info)
groups_tester = ThrottleGroupsTester(testers)

groups_tester.start()
3 changes: 1 addition & 2 deletions qemu/tests/time_conv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import logging
import time

from avocado.utils import process
Expand Down Expand Up @@ -43,7 +42,7 @@ def run(test, params, env):
time_conv = time.time() - start_time
time_list.append(time_conv)
process.run("rm -f %s" % conv_img)
logging.info("The time list is: %s", time_list)
test.log.info("The time list is: %s", time_list)
max_time = params["max_time"]
unexpected_time = [_ for _ in time_list if float(_) > float(max_time)]
if unexpected_time:
Expand Down
Loading

0 comments on commit 01ed848

Please sign in to comment.