diff --git a/qemu/tests/cfg/timedrift_check_clock_offset.cfg b/qemu/tests/cfg/timedrift_check_clock_offset.cfg index fefa8f45a678ac7452142a3b154b8a39f318ecd2..77199d48a0f362235b37e3c42b6b22bc20f2bbe8 100644 --- a/qemu/tests/cfg/timedrift_check_clock_offset.cfg +++ b/qemu/tests/cfg/timedrift_check_clock_offset.cfg @@ -37,3 +37,15 @@ ntp_cmd = "(systemctl stop chronyd || service ntpdate stop)" ntp_cmd += " && chronyd -q 'server clock.redhat.com iburst'" ntp_query_cmd = "chronyd -Q 'server clock.redhat.com iburst'" + - hotplug_vcpu: + type = timedrift_check_when_hotplug_vcpu + start_vm = yes + vcpu_sockets = 2 + smp = 4 + vcpus_maxcpus = 6 + ntp_query_cmd = "chronyd -Q 'server clock.redhat.com iburst'" + clock_sync_command = "(systemctl stop chronyd || service ntpdate stop)" + clock_sync_command += " && chronyd -q 'server clock.redhat.com iburst'" + query_internal = 600 + query_times = 4 + drift_threshold = 3 diff --git a/qemu/tests/timedrift_check_when_hotplug_vcpu.py b/qemu/tests/timedrift_check_when_hotplug_vcpu.py new file mode 100644 index 0000000000000000000000000000000000000000..8b07b1f2e706ca862d1d6fbc670d33b235d24907 --- /dev/null +++ b/qemu/tests/timedrift_check_when_hotplug_vcpu.py @@ -0,0 +1,61 @@ +import re +import time +import logging + +from avocado.utils import process + +from virttest import error_context + + +@error_context.context_aware +def run(test, params, env): + """ + Check time offset after hotplug a vcpu. + + 1) sync host time with ntpserver + 2) boot guest with '-rtc base=utc,clock=host,driftfix=slew' + 3) stop auto sync service in guest (rhel7 only) + 4) sync guest system time with ntpserver + 5) hotplug a vcpu by qmp command + 6) query guest time offset with ntpserver for several times + + :param test: QEMU test object. + :param params: Dictionary with test parameters. + :param env: Dictionary with the test environment. + """ + clock_sync_command = params["clock_sync_command"] + + error_context.context("Sync host system time with ntpserver", logging.info) + process.system(clock_sync_command, shell=True) + + vm = env.get_vm(params["main_vm"]) + session = vm.wait_for_login() + + ntp_query_cmd = params.get("ntp_query_cmd", "") + query_times = int(params.get("query_times", "4")) + query_internal = float(params.get("query_internal", "600")) + drift_threshold = float(params.get("drift_threshold", "3")) + + error_context.context("Sync time from guest to ntpserver", logging.info) + session.cmd(clock_sync_command) + + error_context.context("Hotplug a vcpu to guest", logging.info) + if int(params["smp"]) < int(params["vcpus_maxcpus"]): + vm.hotplug_vcpu() + time.sleep(1) + else: + test.error("Invalid operation, valid index range 0:%d, used range 0:%d" + % (int(params["vcpus_maxcpus"])-1, int(params["smp"]) - 1)) + + error_context.context("Check time offset via ntp server", logging.info) + for query in range(query_times): + output = session.cmd_output(ntp_query_cmd) + try: + offset = re.findall(r"([+-]*\d+\.\d+) seconds", output, re.M)[0] + except IndexError: + test.error("Failed to get time offset") + if float(offset) >= drift_threshold: + test.fail("Uacceptable offset '%s', " % offset + + "threshold '%s'" % drift_threshold) + time.sleep(query_internal) + session.close()