Skip to content

Commit

Permalink
Update the logging namespace - qemu (q)
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 290bcf5 commit 824dd38
Show file tree
Hide file tree
Showing 38 changed files with 529 additions and 547 deletions.
23 changes: 11 additions & 12 deletions qemu/tests/qcow2perf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
import logging

from avocado.utils import process

Expand Down Expand Up @@ -41,7 +40,7 @@ def run(test, params, env):
interval_size = int(interval_size)
write_unit = ""

error_context.context("Init images for testing", logging.info)
error_context.context("Init images for testing", test.log.info)
sn_list = []
for img in re.split(r"\s+", image_chain.strip()):
image_params = params.object_params(img)
Expand All @@ -51,7 +50,7 @@ def run(test, params, env):

# Write to the test image
error_context.context("Prepare the image with write a certain size block",
logging.info)
test.log.info)
dropcache = 'echo 3 > /proc/sys/vm/drop_caches && sleep 5'
snapshot_file = sn_list[test_image][0].image_filename

Expand All @@ -60,29 +59,29 @@ def run(test, params, env):
writecmd0 = writecmd % (write_round, offset, interval_size,
write_unit, interval_size, write_unit)
iocmd0 = iocmd % (writecmd0, io_options, snapshot_file)
logging.info("writecmd-offset-0: %s", writecmd0)
test.log.info("writecmd-offset-0: %s", writecmd0)
process.run(dropcache, shell=True)
output = process.run(iocmd0, shell=True)
else:
offset = 1
writecmd1 = writecmd % (write_round, offset, interval_size,
write_unit, interval_size, write_unit)
iocmd1 = iocmd % (writecmd1, io_options, snapshot_file)
logging.info("writecmd-offset-1: %s", writecmd1)
test.log.info("writecmd-offset-1: %s", writecmd1)
process.run(dropcache, shell=True)
output = process.run(iocmd1, shell=True)

error_context.context("Do one operations to the image and "
"measure the time", logging.info)
"measure the time", test.log.info)

if op_type == "read":
readcmd = opcmd % (io_options, snapshot_file)
logging.info("read: %s", readcmd)
test.log.info("read: %s", readcmd)
process.run(dropcache, shell=True)
output = process.run(readcmd, shell=True)
elif op_type == "commit":
commitcmd = opcmd % (cache_mode, snapshot_file)
logging.info("commit: %s", commitcmd)
test.log.info("commit: %s", commitcmd)
process.run(dropcache, shell=True)
output = process.run(commitcmd, shell=True)
elif op_type == "rebase":
Expand All @@ -91,19 +90,19 @@ def run(test, params, env):
new_base_img.create(params.object_params(new_base))
rebasecmd = opcmd % (new_base_img.image_filename,
cache_mode, snapshot_file)
logging.info("rebase: %s", rebasecmd)
test.log.info("rebase: %s", rebasecmd)
process.run(dropcache, shell=True)
output = process.run(rebasecmd, shell=True)
elif op_type == "convert":
convertname = sn_list[test_image][0].image_filename + "_convert"
convertcmd = opcmd % (snapshot_file, cache_mode, convertname)
logging.info("convert: %s", convertcmd)
test.log.info("convert: %s", convertcmd)
process.run(dropcache, shell=True)
output = process.run(convertcmd, shell=True)

error_context.context("Result recording", logging.info)
error_context.context("Result recording", test.log.info)
result_file = open("%s/%s_%s_results" %
(test.resultsdir, "qcow2perf", op_type), 'w')
result_file.write("%s:%s\n" % (op_type, output))
logging.info("%s takes %s", op_type, output)
test.log.info("%s takes %s", op_type, output)
result_file.close()
30 changes: 16 additions & 14 deletions qemu/tests/qemu_disk_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from virttest import error_context
from avocado.core import exceptions

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


class QemuImgTest(qemu_storage.QemuImg):

Expand Down Expand Up @@ -60,15 +62,15 @@ def commit(self, drop=False, cache_mode=None, base=None):
self.params.object_params(base), self.root_dir)
cmds.extend(["-b", base_image_filename])
cmds.extend(["-f", self.image_format, self.image_filename])
logging.info("Commit image %s", self.image_filename)
LOG_JOB.info("Commit image %s", self.image_filename)
process.system(" ".join(cmds))

@error_context.context_aware
def start_vm(self, t_params=None):
"""
Start a vm and wait for it bootup;
"""
error_context.context("start vm", logging.info)
error_context.context("start vm", LOG_JOB.info)
params = self.params.object_params(self.tag)
if t_params:
params.update(t_params)
Expand All @@ -90,7 +92,7 @@ def start_vm(self, t_params=None):

@error_context.context_aware
def __create_file(self, dst):
logging.info("create tmp file on host")
LOG_JOB.info("create tmp file on host")
if not self.vm:
return False
src = self.params["tmp_file_name"]
Expand All @@ -101,7 +103,7 @@ def __create_file(self, dst):
return True

def __md5sum(self, dst):
logging.info("calculate MD5 of the file")
LOG_JOB.info("calculate MD5 of the file")
if not self.vm:
return False
login_timeout = int(self.params.get("login_timeout", 360))
Expand All @@ -110,7 +112,7 @@ def __md5sum(self, dst):
cmd = "%s %s" % (md5bin, dst)
status, output = session.cmd_status_output(cmd, timeout=300)
if status != 0:
logging.error("Execute '%s' with failures('%s') ", cmd, output)
LOG_JOB.error("Execute '%s' with failures('%s') ", cmd, output)
return None
md5 = re.findall(r"\w{32}", output)[0]
return md5
Expand All @@ -120,41 +122,41 @@ def save_file(self, dst):
login_timeout = int(self.params.get("login_timeout", 360))
cmd = self.params.get("sync_bin", "sync")
error_context.context("save file('%s') md5sum in guest" % dst,
logging.info)
LOG_JOB.info)
self.__create_file(dst)
session = self.vm.wait_for_login(timeout=login_timeout)
logging.info("sync guest data")
LOG_JOB.info("sync guest data")
cmd = utils_misc.set_winutils_letter(session, cmd)
status, output = session.cmd_status_output(cmd, timeout=300)
if status != 0:
logging.error("Execute '%s' with failures('%s') ", cmd, output)
LOG_JOB.error("Execute '%s' with failures('%s') ", cmd, output)
return None
session.close()
return self.__md5sum(dst)

@error_context.context_aware
def check_file(self, dst, md5):
error_context.context("check file('%s') md5sum in guest" % dst,
logging.info)
LOG_JOB.info)
if md5 != self.__md5sum(dst):
err = ("Md5 value does not match. "
"Expected value: %s Actual value: %s" %
(md5, self.__md5sum(dst)))
logging.error(err)
LOG_JOB.error(err)
return False
return True

@error_context.context_aware
def destroy_vm(self):
error_context.context("destroy vm", logging.info)
error_context.context("destroy vm", LOG_JOB.info)
if self.vm:
self.vm.destroy()
self.vm = None

@error_context.context_aware
def check_image(self, t_params=None):
error_context.context("check image file ('%s')" % self.image_filename,
logging.info)
LOG_JOB.info)
t_params = t_params or {}
return super(QemuImgTest, self).check_image(t_params, self.data_dir)

Expand All @@ -168,7 +170,7 @@ def verify_info(self, params=None):
"""
verify option is applied to image file correctly
"""
error_context.context("verify option of converted image", logging.info)
error_context.context("verify option of converted image", LOG_JOB.info)
image_filename = storage.get_image_filename(params, self.data_dir)
info = utils_test.get_image_info(image_filename)
avalue = evalue = ""
Expand Down Expand Up @@ -200,7 +202,7 @@ def verify_info(self, params=None):
@error_context.context_aware
def check_backingfile(self):
error_context.context("check image('%s') backing file" %
self.image_filename, logging.info)
self.image_filename, LOG_JOB.info)
out = self.get_info()
try:
backingfile = re.search(r'backing file: +(.*)', out, re.M).group(1)
Expand Down
10 changes: 6 additions & 4 deletions qemu/tests/qemu_disk_img_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from qemu.tests import qemu_disk_img

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


class CommitTest(qemu_disk_img.QemuImgTest):

Expand All @@ -23,7 +25,7 @@ def commit(self, t_params=None):
"""
commit snapshot to backing file;
"""
error_context.context("commit snapshot to backingfile", logging.info)
error_context.context("commit snapshot to backingfile", LOG_JOB.info)
params = self.params.object_params(self.tag)
if t_params:
params.update(t_params)
Expand Down Expand Up @@ -66,16 +68,16 @@ def _get_img_obj(tag):
sn_img = _get_img_obj(sn_tag)
org_size = json.loads(sn_img.info(output="json"))["actual-size"]
commit_test.commit()
error_context.context("sync host data after commit", logging.info)
error_context.context("sync host data after commit", test.log.info)
process.system("sync")
remain_size = json.loads(sn_img.info(output="json"))["actual-size"]

"""Verify the snapshot file whether emptied after committing"""
logging.info("Verify the snapshot file whether emptied after committing")
test.log.info("Verify the snapshot file whether emptied after committing")
commit_size = org_size - remain_size
dd_size = eval(params["dd_total_size"])
if commit_size >= dd_size:
logging.info("The snapshot file was emptied!")
test.log.info("The snapshot file was emptied!")
else:
test.fail("The snapshot file was not emptied, check pls!")

Expand Down
8 changes: 5 additions & 3 deletions qemu/tests/qemu_disk_img_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from qemu.tests import qemu_disk_img

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


class ConvertTest(qemu_disk_img.QemuImgTest):

Expand All @@ -21,7 +23,7 @@ def convert(self, t_params=None):
"""
create image file from one format to another format
"""
error_context.context("convert image file", logging.info)
error_context.context("convert image file", LOG_JOB.info)
params = self.params.object_params(self.tag)
if t_params:
params.update(t_params)
Expand All @@ -43,7 +45,7 @@ def compare_test(self, t_params):
"""
for mode in t_params.objects("compare_mode_list"):
error_context.context("Compare images in %s mode" % mode,
logging.info)
LOG_JOB.info)
cmd_result = None
is_strict = ("strict" == mode)
image1 = self.image_filename
Expand Down Expand Up @@ -86,7 +88,7 @@ def run(test, params, env):
cluster_size_lst.append(None)
for cluster_size in cluster_size_lst:
if cluster_size is not None:
logging.info("convert image file with cluster_size=%s.", cluster_size)
test.log.info("convert image file with cluster_size=%s.", cluster_size)
n_params = convert_test.convert({"image_cluster_size": cluster_size})
convert_test.compare_test(n_params)
convert_test.verify_info(n_params)
Expand Down
4 changes: 3 additions & 1 deletion qemu/tests/qemu_disk_img_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from qemu.tests import qemu_disk_img

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


class InfoTest(qemu_disk_img.QemuImgTest):

Expand All @@ -17,7 +19,7 @@ def __init__(self, test, params, env, tag):
@error_context.context_aware
def start_vm(self, t_params=None):
"""Start a vm and wait for its bootup."""
error_context.context("start vm", logging.info)
error_context.context("start vm", LOG_JOB.info)
params = self.params.object_params(self.tag)
if t_params:
params.update(t_params)
Expand Down
4 changes: 3 additions & 1 deletion qemu/tests/qemu_disk_img_rebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from qemu.tests import qemu_disk_img

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


class RebaseTest(qemu_disk_img.QemuImgTest):

Expand All @@ -21,7 +23,7 @@ def rebase(self, t_params=None):
"""
Rebase snapshot, AKA changes backing file to new image;
"""
error_context.context("rebase snapshot to backingfile", logging.info)
error_context.context("rebase snapshot to backingfile", LOG_JOB.info)
params = self.params.object_params(self.tag)
if t_params:
params.update(t_params)
Expand Down
11 changes: 5 additions & 6 deletions qemu/tests/qemu_disk_img_snapshot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
from qemu.tests import qemu_disk_img
from avocado.core import exceptions

Expand Down Expand Up @@ -27,32 +26,32 @@ def run(test, params, env):
t_file = params["guest_file_name"]
snapshot_test = qemu_disk_img.QemuImgTest(test, params, env, base_image)

logging.info("Step1. save file md5sum before create snapshot.")
test.log.info("Step1. save file md5sum before create snapshot.")
snapshot_test.start_vm(params)
md5 = snapshot_test.save_file(t_file)
if not md5:
raise exceptions.TestError("Fail to save tmp file.")
snapshot_test.destroy_vm()

logging.info("Step2. create snapshot and check the result.")
test.log.info("Step2. create snapshot and check the result.")
snapshot_tag = snapshot_test.snapshot_create()
output = snapshot_test.snapshot_list()
if snapshot_tag not in output:
raise exceptions.TestFail("Snapshot created failed or missed;"
"snapshot list is: \n%s" % output)

logging.info("Step3. change tmp file before apply snapshot")
test.log.info("Step3. change tmp file before apply snapshot")
snapshot_test.start_vm(params)
change_md5 = snapshot_test.save_file(t_file)
if not change_md5 or change_md5 == md5:
raise exceptions.TestError("Fail to change tmp file.")
snapshot_test.destroy_vm()

logging.info("Step4. apply snapshot.")
test.log.info("Step4. apply snapshot.")
snapshot_test.snapshot_apply()
snapshot_test.snapshot_del()

logging.info("Step5. check md5sum after apply snapshot.")
test.log.info("Step5. check md5sum after apply snapshot.")
snapshot_test.start_vm(params)
ret = snapshot_test.check_file(t_file, md5)
if not ret:
Expand Down
Loading

0 comments on commit 824dd38

Please sign in to comment.