|
| 1 | +""" |
| 2 | +rv_vmshutdown.py - shutdown the guest and verify it is a clean exit. |
| 3 | +
|
| 4 | +Requires: connected binaries remote-viewer, Xorg, gnome session |
| 5 | +
|
| 6 | +""" |
| 7 | +import logging |
| 8 | +from virttest.virt_vm import VMDeadError |
| 9 | +from autotest.client.shared import error |
| 10 | +from virttest.aexpect import ShellCmdError |
| 11 | +from virttest import utils_spice |
| 12 | +from virttest import utils_misc |
| 13 | +from virttest import utils_net |
| 14 | + |
| 15 | + |
| 16 | +def run_rv_vmshutdown(test, params, env): |
| 17 | + """ |
| 18 | + Tests clean exit after shutting down the VM. |
| 19 | + Covers two cases: |
| 20 | + (1)Shutdown from the command line of the guest. |
| 21 | + (2)Shutdown from the qemu monitor. |
| 22 | + |
| 23 | + Verify after the shutdown: |
| 24 | + (1)Verifying the guest is down |
| 25 | + (2)Verify the spice connection to the guest is no longer established |
| 26 | + (3)Verify the remote-viewer process is not running |
| 27 | +
|
| 28 | + @param test: QEMU test object. |
| 29 | + @param params: Dictionary with the test parameters. |
| 30 | + @param env: Dictionary with test environment. |
| 31 | + """ |
| 32 | + |
| 33 | + #Get the required variables |
| 34 | + rv_binary = params.get("rv_binary", "remote-viewer") |
| 35 | + host_ip = utils_net.get_host_ip_address(params) |
| 36 | + shutdownfrom = params.get("shutdownfrom") |
| 37 | + cmd_cli_shutdown = params.get("cmd_cli_shutdown") |
| 38 | + cmd_qemu_shutdown = params.get("cmd_qemu_shutdown") |
| 39 | + host_port = None |
| 40 | + |
| 41 | + guest_vm = env.get_vm(params["guest_vm"]) |
| 42 | + guest_vm.verify_alive() |
| 43 | + guest_session = guest_vm.wait_for_login( |
| 44 | + timeout=int(params.get("login_timeout", 360)), |
| 45 | + username="root", password="123456") |
| 46 | + |
| 47 | + client_vm = env.get_vm(params["client_vm"]) |
| 48 | + client_vm.verify_alive() |
| 49 | + client_session = client_vm.wait_for_login( |
| 50 | + timeout=int(params.get("login_timeout", 360)), |
| 51 | + username="root", password="123456") |
| 52 | + |
| 53 | + if guest_vm.get_spice_var("spice_ssl") == "yes": |
| 54 | + host_port = guest_vm.get_spice_var("spice_tls_port") |
| 55 | + else: |
| 56 | + host_port = guest_vm.get_spice_var("spice_port") |
| 57 | + |
| 58 | + #Determine if the test is to shutdown from cli or qemu monitor |
| 59 | + if shutdownfrom == "cmd": |
| 60 | + logging.info("Shutting down guest from command line:" + |
| 61 | + " %s\n" % cmd_cli_shutdown) |
| 62 | + output = guest_session.cmd(cmd_cli_shutdown) |
| 63 | + logging.debug("Guest is being shutdown: %s" % output) |
| 64 | + elif shutdownfrom == "qemu_monitor": |
| 65 | + logging.info("Shutting down guest from qemu monitor\n") |
| 66 | + output = guest_vm.monitor.cmd(cmd_qemu_shutdown) |
| 67 | + logging.debug("Output of %s: %s" % (cmd_qemu_shutdown, output)) |
| 68 | + else: |
| 69 | + raise error.TestFail("shutdownfrom var not set, valid values are" + |
| 70 | + " cmd or qemu_monitor") |
| 71 | + |
| 72 | + #wait for the guest vm to be shutoff |
| 73 | + logging.info("Waiting for the guest VM to be shutoff") |
| 74 | + utils_misc.wait_for(guest_vm.is_dead, 70, 30, 1, "waiting...") |
| 75 | + logging.info("Guest VM is now shutoff") |
| 76 | + |
| 77 | + #Verify there was a clean exit by |
| 78 | + #(1)Verifying the guest is down |
| 79 | + #(2)Verify the spice connection to the guest is no longer established |
| 80 | + #(3)Verify the remote-viewer process is not running |
| 81 | + try: |
| 82 | + guest_vm.verify_alive() |
| 83 | + raise error.TestFail("Guest VM is still alive, shutdown failed.") |
| 84 | + except VMDeadError as exc: |
| 85 | + if "VM is dead" in str(exc): |
| 86 | + logging.info("Guest VM is verified to be shutdown") |
| 87 | + else: |
| 88 | + raise error.TestFail("Unexpected Error: %s" % exc.value()) |
| 89 | + |
| 90 | + try: |
| 91 | + utils_spice.verify_established(client_vm, host_ip, host_port, rv_binary) |
| 92 | + raise error.TestFail("Remote-Viewer connection to guest" |
| 93 | + "is still established.") |
| 94 | + except utils_spice.RVConnectError: |
| 95 | + logging.info("There is no remote-viewer connection as expected") |
| 96 | + else: |
| 97 | + raise error.TestFail("Unexpected error while trying to see if there" |
| 98 | + " was no spice connection to the guest") |
| 99 | + |
| 100 | + #Verify the remote-viewer process is not running |
| 101 | + logging.info("Checking to see if remote-viewer process is still running on" |
| 102 | + " client after VM has been shutdown") |
| 103 | + try: |
| 104 | + pidoutput = str(client_session.cmd("pgrep remote-viewer")) |
| 105 | + raise error.TestFail("Remote-viewer is still running on the client.") |
| 106 | + except ShellCmdError: |
| 107 | + logging.info("Remote-viewer process is not running as expected.") |
| 108 | + else: |
| 109 | + raise error.TestFail("Unexpected error while trying to verify" + |
| 110 | + "remote-viewer process was not running.") |
0 commit comments