def run(test, params, env): """ KVM boot time test: 1) Set init run level to 1 2) Send a shutdown command to the guest, or issue a system_powerdown monitor command (depending on the value of shutdown_method) 3) Boot up the guest and measure the boot time 4) set init run level back to the old one :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) error.context("Set guest run level to 1", logging.info) single_user_cmd = params['single_user_cmd'] session.cmd(single_user_cmd) try: error.context("Shut down guest", logging.info) session.cmd('sync') vm.destroy() error.context("Boot up guest and measure the boot time", logging.info) utils_memory.drop_caches() vm.create() vm.verify_alive() session = vm.wait_for_serial_login(timeout=timeout) boot_time = utils_misc.monotonic_time() - vm.start_monotonic_time test.write_test_keyval({'result': "%ss" % boot_time}) expect_time = int(params.get("expect_bootup_time", "17")) logging.info("Boot up time: %ss" % boot_time) finally: try: error.context("Restore guest run level", logging.info) restore_level_cmd = params['restore_level_cmd'] session.cmd(restore_level_cmd) session.cmd('sync') vm.destroy(gracefully=False) env_process.preprocess_vm(test, params, env, vm.name) vm.verify_alive() vm.wait_for_login(timeout=timeout) except Exception: logging.warning("Can not restore guest run level, " "need restore the image") params["restore_image_after_testing"] = "yes" if boot_time > expect_time: raise error.TestFail("Guest boot up is taking too long: %ss" % boot_time) session.close()
def run(test, params, env): """ KVM boot time test: 1) Set init run level to 1 2) Send a shutdown command to the guest, or issue a system_powerdown monitor command (depending on the value of shutdown_method) 3) Boot up the guest and measure the boot time 4) set init run level back to the old one :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) error.context("Set guest run level to 1", logging.info) single_user_cmd = params['single_user_cmd'] session.cmd(single_user_cmd) try: error.context("Shut down guest", logging.info) session.cmd('sync') vm.destroy() error.context("Boot up guest and measure the boot time", logging.info) utils_memory.drop_caches() vm.create() vm.verify_alive() session = vm.wait_for_serial_login(timeout=timeout) boot_time = utils_misc.monotonic_time() - vm.start_monotonic_time test.write_test_keyval({'result': "%ss" % boot_time}) expect_time = int(params.get("expect_bootup_time", "17")) logging.info("Boot up time: %ss" % boot_time) finally: try: error.context("Restore guest run level", logging.info) restore_level_cmd = params['restore_level_cmd'] session.cmd(restore_level_cmd) session.cmd('sync') vm.destroy(gracefully=False) env_process.preprocess_vm(test, params, env, vm.name) vm.verify_alive() vm.wait_for_login(timeout=timeout) except Exception: logging.warning("Can not restore guest run level, " "need restore the image") params["restore_image_after_testing"] = "yes" if boot_time > expect_time: raise error.TestFail( "Guest boot up is taking too long: %ss" % boot_time) session.close()
def run(test, params, env): """ KVM restore from file-test: 1) Pause VM 2) Save VM to file 3) Restore VM from file, and measure the time it takes 4) Remove VM restoration file 5) Check VM :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) expect_time = int(params.get("expect_restore_time", 25)) session = vm.wait_for_login(timeout=timeout) save_file = params.get( "save_file", os.path.join("/tmp", utils_misc.generate_random_string(8))) try: error.context("Pause VM", logging.info) vm.pause() error.context("Save VM to file", logging.info) vm.save_to_file(save_file) error.context("Restore VM from file", logging.info) time.sleep(10) utils_memory.drop_caches() vm.restore_from_file(save_file) session = vm.wait_for_login(timeout=timeout) restore_time = utils_misc.monotonic_time() - vm.start_monotonic_time test.write_test_keyval({'result': "%ss" % restore_time}) logging.info("Restore time: %ss" % restore_time) finally: try: error.context("Remove VM restoration file", logging.info) os.remove(save_file) error.context("Check VM", logging.info) vm.verify_alive() vm.wait_for_login(timeout=timeout) except Exception: logging.warning("Unable to restore VM, restoring from image") params["restore_image_after_testing"] = "yes" if restore_time > expect_time: raise error.TestFail("Guest restoration took too long: %ss" % restore_time) session.close()
def run(test, params, env): """ KVM restore from file-test: 1) Pause VM 2) Save VM to file 3) Restore VM from file, and measure the time it takes 4) Remove VM restoration file 5) Check VM :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) expect_time = int(params.get("expect_restore_time", 25)) session = vm.wait_for_login(timeout=timeout) save_file = params.get("save_file", os.path.join("/tmp", utils_misc.generate_random_string(8))) try: error.context("Pause VM", logging.info) vm.pause() error.context("Save VM to file", logging.info) vm.save_to_file(save_file) error.context("Restore VM from file", logging.info) time.sleep(10) utils_memory.drop_caches() vm.restore_from_file(save_file) session = vm.wait_for_login(timeout=timeout) restore_time = utils_misc.monotonic_time() - vm.start_monotonic_time test.write_test_keyval({'result': "%ss" % restore_time}) logging.info("Restore time: %ss" % restore_time) finally: try: error.context("Remove VM restoration file", logging.info) os.remove(save_file) error.context("Check VM", logging.info) vm.verify_alive() vm.wait_for_login(timeout=timeout) except Exception: logging.warning("Unable to restore VM, restoring from image") params["restore_image_after_testing"] = "yes" if restore_time > expect_time: raise error.TestFail( "Guest restoration took too long: %ss" % restore_time) session.close()
def run(test, params, env): """ KVM reboot time test: 1) Set init run level to 1 2) Restart guest 3) Wait for the console 4) Send a 'reboot' command to the guest 5) Boot up the guest and measure the boot time 6) Restore guest run level :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) error_context.context("Set guest run level to 1", logging.info) single_user_cmd = params['single_user_cmd'] session.cmd(single_user_cmd) try: error_context.context("Restart guest", logging.info) session.cmd('sync') vm.destroy() error_context.context("Boot up guest", logging.info) vm.create() vm.verify_alive() session = vm.wait_for_serial_login(timeout=timeout) error_context.context("Send a 'reboot' command to the guest", logging.info) utils_memory.drop_caches() session.cmd('reboot & exit', timeout=1, ignore_all_errors=True) before_reboot_stamp = utils_misc.monotonic_time() error_context.context("Boot up the guest and measure the boot time", logging.info) session = vm.wait_for_serial_login(timeout=timeout) reboot_time = utils_misc.monotonic_time() - before_reboot_stamp test.write_test_keyval({'result': "%ss" % reboot_time}) expect_time = int(params.get("expect_reboot_time", "30")) logging.info("Reboot time: %ss", reboot_time) finally: try: error_context.context("Restore guest run level", logging.info) restore_level_cmd = params['restore_level_cmd'] session.cmd(restore_level_cmd) session.cmd('sync') vm.destroy(gracefully=False) env_process.preprocess_vm(test, params, env, vm.name) vm.verify_alive() vm.wait_for_login(timeout=timeout) except Exception: logging.warning("Can not restore guest run level, " "need restore the image") params["restore_image_after_testing"] = "yes" if reboot_time > expect_time: test.fail("Guest reboot is taking too long: %ss" % reboot_time) session.close()
def run(test, params, env): """ KVM reboot time test: 1) Set init run level to 1 2) Restart guest 3) Wait for the console 4) Send a 'reboot' command to the guest 5) Boot up the guest and measure the boot time 6) Restore guest run level :param test: QEMU test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) error_context.context("Set guest run level to 1", logging.info) single_user_cmd = params['single_user_cmd'] session.cmd(single_user_cmd) try: error_context.context("Restart guest", logging.info) session.cmd('sync') vm.destroy() error_context.context("Boot up guest", logging.info) vm.create() vm.verify_alive() session = vm.wait_for_serial_login(timeout=timeout) error_context.context("Send a 'reboot' command to the guest", logging.info) utils_memory.drop_caches() session.cmd('reboot & exit', timeout=1, ignore_all_errors=True) before_reboot_stamp = utils_misc.monotonic_time() error_context.context("Boot up the guest and measure the boot time", logging.info) session = vm.wait_for_serial_login(timeout=timeout) reboot_time = utils_misc.monotonic_time() - before_reboot_stamp test.write_test_keyval({'result': "%ss" % reboot_time}) expect_time = int(params.get("expect_reboot_time", "30")) logging.info("Reboot time: %ss" % reboot_time) finally: try: error_context.context("Restore guest run level", logging.info) restore_level_cmd = params['restore_level_cmd'] session.cmd(restore_level_cmd) session.cmd('sync') vm.destroy(gracefully=False) env_process.preprocess_vm(test, params, env, vm.name) vm.verify_alive() vm.wait_for_login(timeout=timeout) except Exception: logging.warning("Can not restore guest run level, " "need restore the image") params["restore_image_after_testing"] = "yes" if reboot_time > expect_time: test.fail("Guest reboot is taking too long: %ss" % reboot_time) session.close()