|
| 1 | +import time |
| 2 | +from autotest.client.shared import error |
| 3 | +from virttest import utils_misc |
| 4 | + |
| 5 | + |
| 6 | +@error.context_aware |
| 7 | +def run_client_guest_shutdown(test, params, env): |
| 8 | + """ |
| 9 | + KVM shutdown test: |
| 10 | + For a test with two VMs: client & guest |
| 11 | + 1) Log into the VMS(guests) that represent the client &guest |
| 12 | + 2) Send a shutdown command to the guest, or issue a system_powerdown |
| 13 | + monitor command (depending on the value of shutdown_method) |
| 14 | + 3) Wait until the guest is down |
| 15 | +
|
| 16 | + @param test: kvm test object |
| 17 | + @param params: Dictionary with the test parameters |
| 18 | + @param env: Dictionary with test environment |
| 19 | + """ |
| 20 | + client_vm = env.get_vm(params["client_vm"]) |
| 21 | + client_vm.verify_alive() |
| 22 | + guest_vm = env.get_vm(params["guest_vm"]) |
| 23 | + guest_vm.verify_alive() |
| 24 | + |
| 25 | + timeout = int(params.get("login_timeout", 360)) |
| 26 | + |
| 27 | + #shutdown both of the sessions |
| 28 | + for vm in [client_vm, guest_vm]: |
| 29 | + vm_session = vm.wait_for_login(timeout=timeout, username="root", |
| 30 | + password="123456") |
| 31 | + try: |
| 32 | + error.base_context("shutting down the VM") |
| 33 | + if params.get("shutdown_method") == "shell": |
| 34 | + # Send a shutdown command to the guest's shell |
| 35 | + vm_session.sendline(vm.get_params().get("shutdown_command")) |
| 36 | + error.context("waiting VM to go down (shutdown shell cmd)") |
| 37 | + elif params.get("shutdown_method") == "system_powerdown": |
| 38 | + # Sleep for a while -- give the guest a chance to finish booting |
| 39 | + time.sleep(float(params.get("sleep_before_powerdown", 10))) |
| 40 | + # Send a system_powerdown monitor command |
| 41 | + vm.monitor.cmd("system_powerdown") |
| 42 | + error.context("waiting VM to go down " |
| 43 | + "(system_powerdown monitor cmd)") |
| 44 | + |
| 45 | + if not utils_misc.wait_for(vm.is_dead, 240, 0, 1): |
| 46 | + raise error.TestFail("Guest refuses to go down") |
| 47 | + |
| 48 | + finally: |
| 49 | + vm_session.close() |
0 commit comments