Skip to content

Commit

Permalink
Merge pull request #3192 from luckyh/logger-qemu-b1
Browse files Browse the repository at this point in the history
Update the logging namespace - qemu (b part 1)
  • Loading branch information
vivianQizhu authored Feb 22, 2022
2 parents 95e9e3f + 78059be commit 19113f9
Show file tree
Hide file tree
Showing 28 changed files with 137 additions and 170 deletions.
19 changes: 9 additions & 10 deletions qemu/tests/balloon_boot_in_pause.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import random

from avocado.core import exceptions
Expand Down Expand Up @@ -40,7 +39,7 @@ def memory_check(self, step, changed_mem):
:return: memory size get from monitor and guest
:rtype: tuple
"""
error_context.context("Check memory status %s" % step, logging.info)
error_context.context("Check memory status %s" % step, self.test.log.info)
mmem = self.get_ballooned_memory()
gmem = self.get_memory_status()
if self.pre_gmem:
Expand All @@ -65,7 +64,7 @@ def balloon_memory(self, new_mem):
:param new_mem: New desired memory.
:type new_mem: int
"""
error_context.context("Change VM memory to %s" % new_mem, logging.info)
error_context.context("Change VM memory to %s" % new_mem, self.test.log.info)
try:
self.vm.balloon(new_mem)
except Exception as e:
Expand All @@ -74,7 +73,7 @@ def balloon_memory(self, new_mem):
if self.get_ballooned_memory() != self.pre_mem:
self.test.fail("Memory changed before guest resumed")

logging.info("Resume the guest")
self.test.log.info("Resume the guest")
self.vm.resume()
elif new_mem == self.get_ballooned_memory():
pass
Expand Down Expand Up @@ -113,13 +112,13 @@ def error_report(self, step, expect_value, monitor_value, guest_value):
:param monitor_value: memory size report from monitor
:param guest_value: memory size report from guest
"""
logging.error("Memory size mismatch %s:\n", step)
self.test.log.error("Memory size mismatch %s:\n", step)
error_msg = "Wanted to be changed: %s\n" % (expect_value - self.pre_mem)
error_msg += "Changed in monitor: %s\n" % (monitor_value
- self.pre_mem)
if self.pre_gmem:
error_msg += "Changed in guest: %s\n" % (guest_value - self.pre_gmem)
logging.error(error_msg)
self.test.log.error(error_msg)


class BallooningTestPauseWin(BallooningTestPause):
Expand Down Expand Up @@ -196,11 +195,11 @@ def _memory_check_after_sub_test():
if vm.monitor.verify_status('paused'):
error_context.context("Running balloon %s test when"
" the guest in paused status" % tag,
logging.info)
test.log.info)
else:
error_context.context("Running balloon %s test after"
" the guest turned to running status" % tag,
logging.info)
test.log.info)
params_tag = params.object_params(tag)
balloon_type = params_tag['balloon_type']
if balloon_type == 'evict':
Expand All @@ -217,7 +216,7 @@ def _memory_check_after_sub_test():
subtest = params.get("sub_test_after_balloon")
if subtest:
error_context.context("Running subtest after guest balloon test",
logging.info)
test.log.info)
qemu_should_quit = balloon_test.run_balloon_sub_test(test, params,
env, subtest)
if qemu_should_quit == 1:
Expand All @@ -233,5 +232,5 @@ def _memory_check_after_sub_test():
"after %s seconds" % timeout)

error_context.context("Reset guest memory to original one after all the "
"test", logging.info)
"test", test.log.info)
balloon_test.reset_memory()
51 changes: 25 additions & 26 deletions qemu/tests/balloon_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import time
import re
import logging
import random

from avocado.core import exceptions
Expand Down Expand Up @@ -31,8 +30,8 @@ def __init__(self, test, params, env):
sleep_time = 180
else:
sleep_time = 90
logging.info("Waiting %d seconds for guest's "
"applications up", sleep_time)
self.test.log.info("Waiting %d seconds for guest's "
"applications up", sleep_time)
time.sleep(sleep_time)
self.params["balloon_test_setup_ready"] = True
# ori_mem/gmem is original memory
Expand All @@ -58,11 +57,11 @@ def get_ballooned_memory(self):
if self.vm.monitor.protocol == "qmp":
ballooned_mem = ballooned_mem / (1024 ** 2)
else:
logging.info('could not get balloon_memory, cause vm.monitor '
'is None')
self.test.log.info('could not get balloon_memory, cause '
'vm.monitor is None')
return 0
except qemu_monitor.MonitorError as emsg:
logging.error(emsg)
self.test.log.error(emsg)
return 0
return ballooned_mem

Expand All @@ -78,7 +77,7 @@ def memory_check(self, step, ballooned_mem):
:return: memory size get from monitor and guest
:rtype: tuple
"""
error_context.context("Check memory status %s" % step, logging.info)
error_context.context("Check memory status %s" % step, self.test.log.info)
mmem = self.get_ballooned_memory()
gmem = self.get_memory_status()
gcompare_threshold = int(self.params.get("guest_compare_threshold",
Expand Down Expand Up @@ -121,7 +120,7 @@ def enable_polling(self, device_path):
"""
polling_interval = int(self.params.get("polling_interval", 2))
sleep_time = int(self.params.get("polling_sleep_time", 20))
error_context.context("Enable polling", logging.info)
error_context.context("Enable polling", self.test.log.info)
self.vm.monitor.qom_set(device_path, "guest-stats-polling-interval",
polling_interval)
time.sleep(sleep_time)
Expand All @@ -144,7 +143,7 @@ def _memory_stats_compare(self, keyname, memory_stat_qmp):
check_mem_ratio = float(self.params.get("check_mem_ratio", 0.1))
check_mem_diff = float(self.params.get("check_mem_diff", 150))
error_context.context("Get memory from guest aligned"
" with %s." % keyname, logging.info)
" with %s." % keyname, self.test.log.info)
if keyname == "stat-free-memory":
guest_mem = self.get_guest_free_mem(self.vm)
elif keyname == "stat-total-memory":
Expand Down Expand Up @@ -198,7 +197,7 @@ def balloon_memory(self, new_mem):
:type new_mem: int
"""
self.env["balloon_test"] = 0
error_context.context("Change VM memory to %s" % new_mem, logging.info)
error_context.context("Change VM memory to %s" % new_mem, self.test.log.info)
try:
self.vm.balloon(new_mem)
self.env["balloon_test"] = 1
Expand Down Expand Up @@ -246,7 +245,7 @@ def run_balloon_sub_test(self, test, params, env, test_tag):
sub_type=test_tag)
qemu_quit_after_test = -1
if "shutdown" in test_tag:
logging.info("Guest shutdown normally after balloon")
self.test.log.info("Guest shutdown normally after balloon")
qemu_quit_after_test = 1
if params.get("session_need_update", "no") == "yes":
self.session = self.get_session(self.vm)
Expand All @@ -273,14 +272,14 @@ def wait_for_balloon_complete(self, timeout):
"""
Wait until guest memory don't change
"""
logging.info("Wait until guest memory don't change")
self.test.log.info("Wait until guest memory don't change")
threshold = int(self.params.get("guest_stable_threshold", 100))
is_stable = self._mem_state(threshold)
ret = utils_misc.wait_for(lambda: next(is_stable), timeout,
step=float(self.params.get("guest_check_step",
10.0)))
if not ret:
logging.warning("guest memory is not stable after %ss", timeout)
self.test.log.warning("guest memory is not stable after %ss", timeout)

def get_memory_boundary(self, balloon_type=''):
"""
Expand All @@ -296,7 +295,7 @@ def get_memory_boundary(self, balloon_type=''):
min_size = int(float(utils_misc.normalize_data_size(min_size)))
balloon_buffer = int(self.params.get("balloon_buffer", 300))
if self.params.get('os_type') == 'windows':
logging.info("Get windows miminum balloon value:")
self.test.log.info("Get windows miminum balloon value:")
self.vm.balloon(1)
balloon_timeout = self.params.get("balloon_timeout", 900)
self.wait_for_balloon_complete(balloon_timeout)
Expand Down Expand Up @@ -449,13 +448,13 @@ def error_report(self, step, expect_value, monitor_value, guest_value):
:param guest_value: memory size report from guest, this value can be
None
"""
logging.error("Memory size mismatch %s:\n", step)
self.test.log.error("Memory size mismatch %s:\n", step)
error_msg = "Wanted to be changed: %s\n" % (expect_value - self.pre_mem)
if monitor_value:
error_msg += "Changed in monitor: %s\n" % (monitor_value
- self.pre_mem)
error_msg += "Changed in guest: %s\n" % (guest_value - self.pre_gmem)
logging.error(error_msg)
self.test.log.error(error_msg)

def get_memory_status(self):
"""
Expand Down Expand Up @@ -507,7 +506,7 @@ def operate_balloon_service(self, session, operation):
:return: cmd execution output
"""
error_context.context("%s Balloon Service in guest." % operation,
logging.info)
self.test.log.info)
drive_letter = self.get_disk_vol(session)
try:
operate_cmd = self.params["%s_balloon_service"
Expand All @@ -531,15 +530,15 @@ def configure_balloon_service(self, session):
uninstall/stop
"""
error_context.context("Check Balloon Service status before install"
"service", logging.info)
"service", self.test.log.info)
output = self.operate_balloon_service(session, "status")
if re.search("running", output.lower(), re.M):
logging.info("Balloon service is already running !")
self.test.log.info("Balloon service is already running !")
elif re.search("stop", output.lower(), re.M):
logging.info("Balloon service is stopped,start it now")
self.test.log.info("Balloon service is stopped,start it now")
self.operate_balloon_service(session, "run")
else:
logging.info("Install Balloon Service in guest.")
self.test.log.info("Install Balloon Service in guest.")
self.operate_balloon_service(session, "install")


Expand All @@ -560,13 +559,13 @@ def error_report(self, step, expect_value, monitor_value, guest_value):
@param guest_value: memory size report from guest, this value can be
None
"""
logging.error("Memory size mismatch %s:\n", step)
self.test.log.error("Memory size mismatch %s:\n", step)
error_msg = "Assigner to VM: %s\n" % expect_value
if monitor_value:
error_msg += "Reported by monitor: %s\n" % monitor_value
if guest_value:
error_msg += "Reported by guest OS: %s\n" % guest_value
logging.error(error_msg)
self.test.log.error(error_msg)

def get_memory_status(self):
"""
Expand Down Expand Up @@ -599,7 +598,7 @@ def run(test, params, env):
guest_ori_mem = balloon_test.get_total_mem()

for tag in params.objects('test_tags'):
error_context.context("Running %s test" % tag, logging.info)
error_context.context("Running %s test" % tag, test.log.info)
params_tag = params.object_params(tag)
if params_tag.get('expect_memory'):
expect_mem = int(params_tag.get('expect_memory'))
Expand Down Expand Up @@ -640,8 +639,8 @@ def run(test, params, env):
res2 = float(normalize_data_size(process.getoutput(get_res_cmd)))
time.sleep(30)
res3 = float(normalize_data_size(process.getoutput(get_res_cmd)))
logging.info("The RES values are %sM, %sM, and %sM sequentially",
res1, res2, res3)
test.log.info("The RES values are %sM, %sM, and %sM sequentially",
res1, res2, res3)
if res2 - res1 < consumed_mem * 0.5:
test.error("QEMU should consume more memory")
if res3 - res1 > res1 * 0.1:
Expand Down
17 changes: 8 additions & 9 deletions qemu/tests/balloon_hotplug.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import random
import re
import time
Expand Down Expand Up @@ -37,7 +36,7 @@ def run_pm_test(pm_test, plug_type):
:param plug_type:balloon device plug operation,e.g.hot_plug or hot_unplug
"""
error_context.context("Run %s test after %s balloon device"
% (pm_test, plug_type), logging.info)
% (pm_test, plug_type), test.log.info)
utils_test.run_virt_sub_test(test, params, env, pm_test)

def enable_balloon_service():
Expand All @@ -47,7 +46,7 @@ def enable_balloon_service():
if params['os_type'] != 'windows':
return
error_context.context("Install and check balloon service in windows "
"guest", logging.info)
"guest", test.log.info)
session = vm.wait_for_login()
driver_name = params.get("driver_name", "balloon")
session = utils_test.qemu.windrv_check_running_verifier(session,
Expand All @@ -69,7 +68,7 @@ def enable_balloon_service():

balloon_device = params.get("balloon_device", "virtio-balloon-pci")
error_context.context("Hotplug and unplug balloon device in a loop",
logging.info)
test.log.info)
for i in range(int(params.get("balloon_repeats", 3))):
vm.devices.set_dirty()
new_dev = qdevices.QDevice(balloon_device,
Expand All @@ -78,7 +77,7 @@ def enable_balloon_service():
"balloon_bus", 'pci.0')})

error_context.context("Hotplug balloon device for %d times" % (i+1),
logging.info)
test.log.info)
out = vm.devices.simple_hotplug(new_dev, vm.monitor)
if out[1] is False:
test.fail("Failed to hotplug balloon in iteration %s, %s"
Expand All @@ -100,7 +99,7 @@ def enable_balloon_service():
enable_balloon_service()

error_context.context("Check whether balloon device work after hotplug",
logging.info)
test.log.info)
balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))

if pm_test_after_plug:
Expand All @@ -116,7 +115,7 @@ def enable_balloon_service():
time.sleep(10)

error_context.context("Unplug balloon device for %d times" % (i+1),
logging.info)
test.log.info)

out = vm.devices.simple_unplug(devs[0].get_aid(), vm.monitor,
timeout=unplug_timeout)
Expand All @@ -127,7 +126,7 @@ def enable_balloon_service():

if params.get("migrate_after_unplug", "no") == "yes":
error_context.context("Migrate after hotunplug balloon device",
logging.info)
test.log.info)
# temporary workaround for migration
del vm.params["balloon"]
del vm.params["balloon_dev_devid"]
Expand All @@ -140,5 +139,5 @@ def enable_balloon_service():
if not vm.is_alive():
return

error_context.context("Verify guest alive!", logging.info)
error_context.context("Verify guest alive!", test.log.info)
vm.verify_kernel_crash()
7 changes: 3 additions & 4 deletions qemu/tests/balloon_memhp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import random
import logging

from virttest import utils_test
from virttest import error_context
Expand Down Expand Up @@ -41,7 +40,7 @@ def check_memory():
(expected_mem, vm.name, guest_mem_size))
test.fail(msg)

error_context.context("Boot guest with balloon device", logging.info)
error_context.context("Boot guest with balloon device", test.log.info)
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
session = vm.wait_for_login()
Expand All @@ -54,7 +53,7 @@ def check_memory():
test, driver_name)
balloon_test = BallooningTestWin(test, params, env)
error_context.context("Config balloon service in guest",
logging.info)
test.log.info)
balloon_test.configure_balloon_service(session)

memhp_test = MemoryHotplugTest(test, params, env)
Expand All @@ -78,6 +77,6 @@ def check_memory():
finally:
if params['os_type'] == 'windows':
error_context.context("Clear balloon service in guest",
logging.info)
test.log.info)
balloon_test.operate_balloon_service(session, "uninstall")
session.close()
3 changes: 1 addition & 2 deletions qemu/tests/balloon_minimum.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import time
import logging

from virttest import utils_test
from virttest import error_context
Expand All @@ -22,7 +21,7 @@ def run(test, params, env):
:param env: Dictionary with test environment.
"""

error_context.context("Boot guest with balloon device", logging.info)
error_context.context("Boot guest with balloon device", test.log.info)
vm = env.get_vm(params["main_vm"])
session = vm.wait_for_login()
driver_name = params.get("driver_name", "balloon")
Expand Down
Loading

0 comments on commit 19113f9

Please sign in to comment.