Skip to content

Commit

Permalink
qemu_guest_agent: add new guest agent case
Browse files Browse the repository at this point in the history
1.frozen guest FS
2.send shutdown agent cmd to guest
3.send reboot agent cmd to guest
4.send reset HMP cmd to guest

Signed-off-by: Xiangchun Fu <xfu@redhat.com>
  • Loading branch information
xiangchunfu committed Aug 7, 2017
1 parent ea2f299 commit f03fce1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 40 deletions.
3 changes: 3 additions & 0 deletions qemu/tests/cfg/qemu_guest_agent.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
no Windows
gagent_check_type = fsfreeze
gagent_fs_test_cmd = "rm -f /tmp/foo; echo foo > /tmp/foo"
- check_reset_reboot_shutdown_fsfreeze:
no Windows
gagent_check_type = reset_reboot_shutdown
- check_snapshot:
# fsfreeze series commands can't run on windows guest.
type = qemu_guest_agent_snapshot
Expand Down
75 changes: 35 additions & 40 deletions qemu/tests/qemu_guest_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import aexpect

from autotest.client.shared import error
from autotest.client import utils
from avocado.utils import path as avo_path
from avocado.utils import process
Expand Down Expand Up @@ -102,12 +101,11 @@ def _cleanup_open_session(self):
except Exception:
pass

@error.context_aware
def gagent_install(self, params, vm, *args):
if args and isinstance(args, tuple):
gagent_install_cmd = args[0]
else:
raise error.TestError("Missing config 'gagent_install_cmd'")
raise test.error("Missing config 'gagent_install_cmd'")

if not gagent_install_cmd:
return
Expand All @@ -120,12 +118,11 @@ def gagent_install(self, params, vm, *args):
raise error.TestFail("Could not install qemu-guest-agent package"
" in VM '%s', detail: '%s'" % (vm.name, o))

@error.context_aware
def gagent_start(self, params, vm, *args):
if args and isinstance(args, tuple):
gagent_start_cmd = args[0]
else:
raise error.TestError("Missing config 'gagent_start_cmd'")
raise test.error("Missing config 'gagent_start_cmd'")

if not gagent_start_cmd:
return
Expand All @@ -137,14 +134,13 @@ def gagent_start(self, params, vm, *args):
raise error.TestFail("Could not start qemu-guest-agent in VM"
" '%s', detail: '%s'" % (vm.name, o))

@error.context_aware
def gagent_create(self, params, vm, *args):
if self.gagent:
return self.gagent

error.context("Create a QemuAgent object.", logging.info)
if not (args and isinstance(args, tuple) and len(args) == 2):
raise error.TestError("Got invalid arguments for guest agent")
raise test.error("Got invalid arguments for guest agent")

gagent_serial_type = args[0]
gagent_name = args[1]
Expand All @@ -162,20 +158,18 @@ def gagent_create(self, params, vm, *args):

return self.gagent

@error.context_aware
def setup_gagent_in_guest(self, params, vm):
error.context("Setup guest agent in VM '%s'" % vm.name)
self.gagent_install(params, vm, *[params.get("gagent_install_cmd")])
self.gagent_start(params, vm, *[params.get("gagent_start_cmd")])
args = [params.get("gagent_serial_type"), params.get("gagent_name")]
self.gagent_create(params, vm, *args)

@error.context_aware
def gagent_verify(self, params, vm):
error.context("Check if guest agent work.", logging.info)

if not self.gagent:
raise error.TestError("Could not find guest agent object"
raise test.error("Could not find guest agent object"
"for VM '%s'" % vm.name)

self.gagent.verify_responsive()
Expand Down Expand Up @@ -213,7 +207,6 @@ def __init__(self, test, params, env):
def gagent_check_install(self, test, params, env):
pass

@error.context_aware
def gagent_check_sync(self, test, params, env):
"""
Execute "guest-sync" command to guest agent
Expand All @@ -228,12 +221,11 @@ def gagent_check_sync(self, test, params, env):
error.context("Check guest agent command 'guest-sync'", logging.info)
self.gagent.sync()

@error.context_aware
def __gagent_check_shutdown(self, shutdown_mode):
error.context("Check guest agent command 'guest-shutdown'"
", shutdown mode '%s'" % shutdown_mode, logging.info)
if not self.env or not self.params:
raise error.TestError("You should run 'setup' method before test")
raise test.error("You should run 'setup' method before test")

if not (self.vm and self.vm.is_alive()):
vm = self.env.get_vm(self.params["main_vm"])
Expand All @@ -260,7 +252,6 @@ def gagent_check_powerdown(self, test, params, env):
if not utils_misc.wait_for(self.vm.is_dead, self.vm.REBOOT_TIMEOUT):
raise error.TestFail("Could not shutdown VM via guest agent'")

@error.context_aware
def gagent_check_reboot(self, test, params, env):
"""
Reboot guest with guest agent command "guest-shutdown"
Expand All @@ -283,7 +274,6 @@ def gagent_check_reboot(self, test, params, env):
raise error.TestFail("Could not login to guest,"
" detail: '%s'" % detail)

@error.context_aware
def gagent_check_halt(self, test, params, env):
"""
Halt guest with guest agent command "guest-shutdown"
Expand All @@ -305,7 +295,6 @@ def gagent_check_halt(self, test, params, env):
logging.warn("Got an exception when force destroying guest:"
" '%s'", detail)

@error.context_aware
def gagent_check_sync_delimited(self, test, params, env):
"""
Execute "guest-sync-delimited" command to guest agent
Expand All @@ -318,14 +307,12 @@ def gagent_check_sync_delimited(self, test, params, env):
logging.info)
self.gagent.sync("guest-sync-delimited")

@error.context_aware
def _gagent_verify_password(self, vm, new_password):
"""
check if the password works well for the specific user
"""
vm.wait_for_login(password=new_password)

@error.context_aware
def gagent_check_set_user_password(self, test, params, env):
"""
Execute "guest-set-user-password" command to guest agent
Expand All @@ -346,13 +333,12 @@ def gagent_check_set_user_password(self, test, params, env):
self._gagent_verify_password(self.vm, new_password)

except guest_agent.VAgentCmdError:
raise error.TestError("Failed to set the new password for guest")
raise test.error("Failed to set the new password for guest")

finally:
error.context("reset back the password of guest", logging.info)
self.gagent.set_user_password(old_password)

@error.context_aware
def gagent_check_get_vcpus(self, test, params, env):
"""
Execute "guest-set-vcpus" command to guest agent
Expand All @@ -362,7 +348,6 @@ def gagent_check_get_vcpus(self, test, params, env):
"""
self.gagent.get_vcpus()

@error.context_aware
def gagent_check_set_vcpus(self, test, params, env):
"""
Execute "guest-set-vcpus" command to guest agent
Expand All @@ -386,7 +371,6 @@ def gagent_check_set_vcpus(self, test, params, env):
if vcpus_info[vcpus_num - 1]["online"] is not False:
raise error.TestFail("the vcpu status is not changed as expected")

@error.context_aware
def gagent_check_get_time(self, test, params, env):
"""
Execute "guest-get-time" command to guest agent
Expand All @@ -403,15 +387,14 @@ def gagent_check_get_time(self, test, params, env):
% nanoseconds_time, logging.info)
guest_time = session.cmd_output(get_guest_time_cmd)
if not guest_time:
raise error.TestError("can't get the guest time for contrast")
raise test.error("can't get the guest time for contrast")
error.context("the time get inside guest by shell cmd is '%d' "
% int(guest_time), logging.info)
delta = abs(int(guest_time) - nanoseconds_time / 1000000000)
if delta > 3:
raise error.TestFail("the time get by guest agent is not the same "
"with that by time check cmd inside guest")

@error.context_aware
def gagent_check_set_time(self, test, params, env):
"""
Execute "guest-set-time" command to guest agent
Expand All @@ -425,7 +408,7 @@ def gagent_check_set_time(self, test, params, env):
error.context("get the time of the guest", logging.info)
guest_time_before = session.cmd_output(get_guest_time_cmd)
if not guest_time_before:
raise error.TestError("can't get the guest time for contrast")
raise test.error("can't get the guest time for contrast")
error.context("the time before being moved back into past is '%d' "
% int(guest_time_before), logging.info)
# Need to move the guest time one week into the past
Expand Down Expand Up @@ -461,7 +444,6 @@ def gagent_check_set_time(self, test, params, env):
raise error.TestFail("The guest time can't be set from hwclock"
" on host")

@error.context_aware
def _get_mem_used(self, session, cmd):

"""
Expand All @@ -480,7 +462,6 @@ def _get_mem_used(self, session, cmd):
raise exceptions.TestError("Get invalid memory usage by "
"cmd '%s' (%s)" % (cmd, output))

@error.context_aware
def gagent_check_memory_leak(self, test, params, env):

"""
Expand Down Expand Up @@ -520,7 +501,6 @@ def gagent_check_memory_leak(self, test, params, env):
" run command is %skb" % (memory_usage_before,
memory_usage_after))

@error.context_aware
def gagent_check_fstrim(self, test, params, env):
"""
Execute "guest-fstrim" command to guest agent
Expand Down Expand Up @@ -582,7 +562,7 @@ def get_allocation_bitmap():
bitmap = get_allocation_bitmap()
if bitmap:
logging.debug("block allocation bitmap: %s" % bitmap)
raise error.TestError("block allocation bitmap"
raise test.error("block allocation bitmap"
" not empty before test.")
vm_name = params["main_vm"]
test_image = "scsi_debug"
Expand Down Expand Up @@ -655,7 +635,6 @@ def get_allocation_bitmap():
if self.vm:
self.vm.destroy()

@error.context_aware
def gagent_check_get_interfaces(self, test, params, env):
"""
Execute "guest-network-get-interfaces" command to guest agent
Expand Down Expand Up @@ -698,19 +677,17 @@ def find_interface_by_name(interface_list, target_interface):
error.TestFail("the interface list info after interface was down"
" was not as expected")

@error.context_aware
def _action_before_fsfreeze(self, *args):
session = self._get_session(self.params, None)
self._open_session_list.append(session)

@error.context_aware
def _action_after_fsfreeze(self, *args):
error.context("Verfiy FS is frozen in guest.")
if not isinstance(args, tuple):
return

if not self._open_session_list:
raise error.TestError("Could not find any opened session")
raise test.error("Could not find any opened session")
# Use the last opened session to send cmd.
session = self._open_session_list[-1]
try:
Expand All @@ -721,15 +698,35 @@ def _action_after_fsfreeze(self, *args):
raise error.TestFail("FS freeze failed, guest still can"
" write file")

@error.context_aware
def gagent_check_reset_reboot_shutdown(self, test, params, env):

"""
Execute "system_reset" and send "shutdown,reboot" command to guest agent after FS freezed
:param test: kvm test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
vm = env.get_vm(params["main_vm"])
if not vm.is_alive():
test.skip("VM died,can't continue the test loop.")
self.gagent.fsfreeze()
self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_FROZEN)

if self.gagent.shutdown(self.gagent.SHUTDOWN_MODE_POWERDOWN):
self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_FROZEN)

if self.gagent.shutdown(self.gagent.SHUTDOWN_MODE_REBOOT):
self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_FROZEN)

if vm.monitor.cmd("system_reset"):
self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_THAWED)

def _action_before_fsthaw(self, *args):
pass

@error.context_aware
def _action_after_fsthaw(self, *args):
pass

@error.context_aware
def gagent_check_fsfreeze(self, test, params, env):
"""
Test guest agent commands "guest-fsfreeze-freeze/status/thaw"
Expand Down Expand Up @@ -786,7 +783,7 @@ def run_once(self, test, params, env):
func = getattr(self, chk_type)
func(test, params, env)
else:
raise error.TestError("Could not find matching test, check your"
raise test.error("Could not find matching test, check your"
" config file")


Expand All @@ -795,7 +792,6 @@ class QemuGuestAgentBasicCheckWin(QemuGuestAgentBasicCheck):
"""
Qemu guest agent test class for windows guest.
"""
@error.context_aware
def gagent_install(self, params, vm, *args):
"""
Check if the installation process is finished and successfully
Expand All @@ -815,7 +811,6 @@ def gagent_install(self, params, vm, *args):
else:
raise error.TestFail("Failed to install qemu-ga in guest")

@error.context_aware
def setup_gagent_in_host(self, params, vm):
error.context("download qemu-ga.msi to host", logging.info)
deps = params["deps"]
Expand All @@ -834,7 +829,7 @@ def setup_gagent_in_host(self, params, vm):
# gagent_remove_service_cmd = params["gagent_remove_service_cmd"]
s, o = session.cmd_status_output("mkdir %s" % gagent_guest_dir)
if bool(s) and str(s) != "1":
raise error.TestError("Could not create qemu-ga directory in "
raise test.error("Could not create qemu-ga directory in "
"VM '%s', detail: '%s'" % (vm.name, o))
error.context("Copy qemu guest agent program to guest", logging.info)
vm.copy_files_to(gagent_host_path, gagent_guest_dir)
Expand Down

0 comments on commit f03fce1

Please sign in to comment.