From 6d57a109574e00cb57e300fdf6106de4179b7fa9 Mon Sep 17 00:00:00 2001 From: lijin Date: Wed, 6 Sep 2017 14:05:52 +0800 Subject: [PATCH] rng_hotplug:reboot/shutdown guest after plug/unplug rng device add optional steps to support reboot/shutdown guest after hotplug or hot-unplug rng devices Signed-off-by: lijin --- qemu/tests/cfg/rng_hotplug.cfg | 24 +++++++++---- qemu/tests/rng_hotplug.py | 62 +++++++++++++++++++++++----------- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/qemu/tests/cfg/rng_hotplug.cfg b/qemu/tests/cfg/rng_hotplug.cfg index fd378777..32cd95b3 100644 --- a/qemu/tests/cfg/rng_hotplug.cfg +++ b/qemu/tests/cfg/rng_hotplug.cfg @@ -7,6 +7,9 @@ rng_num = 1 read_rng_timeout = 360 no no_virtio_rng + rng_basic_test = rng_bat + shutdown_method = shell + check_img = yes Windows: session_cmd_timeout = 240 read_rng_cmd = "WIN_UTILS:\random_%PROCESSOR_ARCHITECTURE%.exe" @@ -29,12 +32,21 @@ stop_rngd = "service rngd stop" variants: - multi_rngs: - repeat_times = 1 rng_num = 4 - test_after_hotplug = rng_bat + - one_rng: + variants: + - @default: + - with_reboot: + pm_test_after_unplug = boot + pm_test_after_plug = boot + reboot_method = shell + - with_system_reset: + pm_test_after_unplug = boot + pm_test_after_plug = boot + reboot_method = system_reset + - with_shutdown_after_unplug: + pm_test_after_unplug = shutdown + - with_shutdown_after_plug: + pm_test_after_plug = shutdown - repeat_in_loop: repeat_times = 500 - rng_num = 1 - test_before_hotplug = rng_bat - test_after_hotplug = rng_bat - diff --git a/qemu/tests/rng_hotplug.py b/qemu/tests/rng_hotplug.py index a2419d12..89583a46 100644 --- a/qemu/tests/rng_hotplug.py +++ b/qemu/tests/rng_hotplug.py @@ -11,12 +11,16 @@ from avocado.core import exceptions def run(test, params, env): """ Test hotplug/unplug of rng device - 1) Boot up w/o rng device - 2) Hotplug one or more rng devices - 3) Run random read test after hotplug - 4) Unplug rng devices - 5) Repeat step 2 ~ step4 (option) - + 1) Boot up w/ one rng device + 2) Unplug rng device + 3) reboot/shutdown guest(optional) + 4) Hotplug one or more rng devices + 5) Run random read test after hotplug + 6) Unplug rng devices + 7) Repeat step 4 ~ step 6 (optional) + 8) Hotplug one rng device + 9) Run random read test after hotplug + 10) Reboot/shutdown guest(optional) :param test: QEMU test object :param params: Dictionary with the test parameters @@ -76,20 +80,28 @@ def run(test, params, env): raise exceptions.TestError(output) session.close() + def run_subtest(sub_test): + """ + Run subtest(e.g. rng_bat,reboot,shutdown) when it's not None + :param sub_test: subtest name + """ + error_context.context("Run %s subtest" % sub_test) + utils_test.run_virt_sub_test(test, params, env, sub_test) + login_timeout = int(params.get("login_timeout", 360)) repeat_times = int(params.get("repeat_times", 1)) rng_num = int(params.get("rng_num", 1)) - test_before_hotplug = params.get("test_before_hotplug") - test_after_hotplug = params.get("test_after_hotplug") + rng_basic_test = params.get("rng_basic_test") + pm_test_after_plug = params.get("pm_test_after_plug") + pm_test_after_unplug = params.get("pm_test_after_unplug") vm = env.get_vm(params["main_vm"]) vm.verify_alive() vm.wait_for_login(timeout=login_timeout) - if test_before_hotplug: - restart_rngd(vm) - error_context.context("Run %s before hotplug" % test_before_hotplug) - utils_test.run_virt_sub_test(test, params, env, test_before_hotplug) + # run rng test before hot-unplug + restart_rngd(vm) + run_subtest(rng_basic_test) # Unplug attached rng device device_ids = get_rng_id(vm) @@ -111,15 +123,27 @@ def run(test, params, env): hotplug_rng(vm, new_dev) dev_list.append(new_dev) - # Run test after hotplug - if test_after_hotplug and i == xrange(repeat_times)[-1]: - restart_rngd(vm) - error_context.context("Run %s after hotplug" % test_after_hotplug, - logging.info) - utils_test.run_virt_sub_test(test, params, env, - test_after_hotplug) + # run rng test after hotplug + restart_rngd(vm) + run_subtest(rng_basic_test) + + # run reboot/shutdown after hotplug + if pm_test_after_plug: + run_subtest(pm_test_after_plug) + # run rng test after reboot,skip followed test if + # pm_test_after_plug is shutdown + if vm.is_alive(): + run_subtest(rng_basic_test) + else: + return stop_rngd(vm) time.sleep(5) for dev in dev_list: unplug_rng(vm, dev) + + # run reboot/shutdown test after hot-unplug + if pm_test_after_unplug: + run_subtest(pm_test_after_unplug) + if not vm.is_alive(): + return -- GitLab