• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import logging, time
2from autotest_lib.client.common_lib import error
3from autotest_lib.client.virt import virt_utils
4
5
6@error.context_aware
7def run_shutdown(test, params, env):
8    """
9    KVM shutdown test:
10    1) Log into a guest
11    2) Send a shutdown command to the guest, or issue a system_powerdown
12       monitor command (depending on the value of shutdown_method)
13    3) Wait until the guest is down
14
15    @param test: kvm test object
16    @param params: Dictionary with the test parameters
17    @param env: Dictionary with test environment
18    """
19    vm = env.get_vm(params["main_vm"])
20    vm.verify_alive()
21    timeout = int(params.get("login_timeout", 360))
22    session = vm.wait_for_login(timeout=timeout)
23
24    try:
25        error.base_context("shutting down the VM")
26        if params.get("shutdown_method") == "shell":
27            # Send a shutdown command to the guest's shell
28            session.sendline(vm.get_params().get("shutdown_command"))
29            error.context("waiting VM to go down (shutdown shell cmd)")
30        elif params.get("shutdown_method") == "system_powerdown":
31            # Sleep for a while -- give the guest a chance to finish booting
32            time.sleep(float(params.get("sleep_before_powerdown", 10)))
33            # Send a system_powerdown monitor command
34            vm.monitor.cmd("system_powerdown")
35            error.context("waiting VM to go down "
36                          "(system_powerdown monitor cmd)")
37
38        if not virt_utils.wait_for(vm.is_dead, 240, 0, 1):
39            raise error.TestFail("Guest refuses to go down")
40
41    finally:
42        session.close()
43