kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Autotest PATCH] KVM-test: Simple stop/continue test
@ 2011-04-21  6:21 Amos Kong
  2011-04-29  5:05 ` [Autotest] " Lucas Meneghel Rodrigues
  0 siblings, 1 reply; 5+ messages in thread
From: Amos Kong @ 2011-04-21  6:21 UTC (permalink / raw)
  To: autotest; +Cc: kvm

Change guest state by monitor cmd, verify guest status,
and try to login guest by network.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Amos Kong <akong@redhat.com>
---
 client/tests/kvm/tests/stop_continue.py |   52 +++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample  |    4 ++
 2 files changed, 56 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/stop_continue.py

diff --git a/client/tests/kvm/tests/stop_continue.py b/client/tests/kvm/tests/stop_continue.py
new file mode 100644
index 0000000..c7d8025
--- /dev/null
+++ b/client/tests/kvm/tests/stop_continue.py
@@ -0,0 +1,52 @@
+import logging
+from autotest_lib.client.common_lib import error
+
+
+def run_stop_continue(test, params, env):
+    """
+    Suspend a running Virtual Machine and verify its state.
+
+    1) Boot the vm
+    2) Suspend the vm through stop command
+    3) Verify the state through info status command
+    4) Check is the ssh session to guest is still responsive,
+       if succeed, fail the test.
+
+    @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"])
+    vm.verify_alive()
+    timeout = float(params.get("login_timeout", 240))
+    session = vm.wait_for_login(timeout=timeout)
+
+    try:
+        logging.info("Suspend the virtual machine")
+        vm.monitor.cmd("stop")
+
+        logging.info("Verifying the status of virtual machine through monitor")
+        o = vm.monitor.info("status")
+        if 'paused' not in o and ( "u'running': False" not in str(o)):
+            logging.error(o)
+            raise error.TestFail("Fail to suspend through monitor command line")
+
+        logging.info("Check the session responsiveness")
+        if session.is_responsive():
+            raise error.TestFail("Session is still responsive after stop")
+
+        logging.info("Try to resume the guest")
+        vm.monitor.cmd("cont")
+
+        o = vm.monitor.info("status")
+        m_type = params.get("monitor_type", "human")
+        if ('human' in m_type and 'running' not in o) or\
+           ('qmp' in m_type and "u'running': True" not in str(o)):
+            logging.error(o)
+            raise error.TestFail("Could not continue the execution")
+
+        logging.info("Try to re-log into guest")
+        session = vm.wait_for_login(timeout=timeout)
+
+    finally:
+        session.close()
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index 5d274f8..7333ed0 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -260,6 +260,10 @@ variants:
             - systemtap:
                 test_control_file = systemtap.control
 
+    - stop_continue:
+        type = stop_continue
+        kill_vm_on_error = yes
+
     - linux_s3:     install setup unattended_install.cdrom
         only Linux
         type = linux_s3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Autotest] [Autotest PATCH] KVM-test: Simple stop/continue test
  2011-04-21  6:21 [Autotest PATCH] KVM-test: Simple stop/continue test Amos Kong
@ 2011-04-29  5:05 ` Lucas Meneghel Rodrigues
  2011-05-06 15:03   ` [PATCH 1/3] KVM-test: introduce a verify_status method Amos Kong
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Lucas Meneghel Rodrigues @ 2011-04-29  5:05 UTC (permalink / raw)
  To: Amos Kong; +Cc: autotest, kvm

On Thu, Apr 21, 2011 at 3:21 AM, Amos Kong <akong@redhat.com> wrote:
> Change guest state by monitor cmd, verify guest status,
> and try to login guest by network.

I don't like the way you're handling human monitor and QMP monitors in
this tests...  comments below:

> Signed-off-by: Jason Wang <jasowang@redhat.com>
> Signed-off-by: Amos Kong <akong@redhat.com>
> ---
>  client/tests/kvm/tests/stop_continue.py |   52 +++++++++++++++++++++++++++++++
>  client/tests/kvm/tests_base.cfg.sample  |    4 ++
>  2 files changed, 56 insertions(+), 0 deletions(-)
>  create mode 100644 client/tests/kvm/tests/stop_continue.py
>
> diff --git a/client/tests/kvm/tests/stop_continue.py b/client/tests/kvm/tests/stop_continue.py
> new file mode 100644
> index 0000000..c7d8025
> --- /dev/null
> +++ b/client/tests/kvm/tests/stop_continue.py
> @@ -0,0 +1,52 @@
> +import logging
> +from autotest_lib.client.common_lib import error
> +
> +
> +def run_stop_continue(test, params, env):
> +    """
> +    Suspend a running Virtual Machine and verify its state.
> +
> +    1) Boot the vm
> +    2) Suspend the vm through stop command
> +    3) Verify the state through info status command
> +    4) Check is the ssh session to guest is still responsive,
> +       if succeed, fail the test.
> +
> +    @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"])
> +    vm.verify_alive()
> +    timeout = float(params.get("login_timeout", 240))
> +    session = vm.wait_for_login(timeout=timeout)
> +
> +    try:
> +        logging.info("Suspend the virtual machine")
> +        vm.monitor.cmd("stop")
> +
> +        logging.info("Verifying the status of virtual machine through monitor")
> +        o = vm.monitor.info("status")
> +        if 'paused' not in o and ( "u'running': False" not in str(o)):

^ Here, it's not clear what means a paused qmp monitor or a hmp
monitor. this statement is unnecessarily confusing. Here

'paused' not in o -> Is what would define a 'not paused hmp monitor'

"u'running': False" not in str(o) -> This defines a 'not paused qmp monitor'

why we are checking one _and_ the other, as one monitor can't be hmp
and qmp at the same time? It would be at least _or_. And like I said,
it's non trivial to flow this assertion made.

It seems to me that a better (although involving more code changes) approach is:

1) Introduce VM methods is_paused and verify_paused, which would
internally for the kvm vm class, call monitor methods also called
is_paused and verify_paused, with implementations for both hmp and
qmp. verify_paused would throw an exception in case of a failure,
while is_paused would return a boolean.

> +            logging.error(o)
> +            raise error.TestFail("Fail to suspend through monitor command line")
> +
> +        logging.info("Check the session responsiveness")
> +        if session.is_responsive():
> +            raise error.TestFail("Session is still responsive after stop")
> +
> +        logging.info("Try to resume the guest")
> +        vm.monitor.cmd("cont")
> +
> +        o = vm.monitor.info("status")
> +        m_type = params.get("monitor_type", "human")
> +        if ('human' in m_type and 'running' not in o) or\
> +           ('qmp' in m_type and "u'running': True" not in str(o)):

^ same here, we should have is_running and verify_running methods on
VM that would call monitor methods with the same names.

Now, of course I might be really mistaken here, would like to hear
your opinion on that subject.

-- 
Lucas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] KVM-test: introduce a verify_status method
  2011-04-29  5:05 ` [Autotest] " Lucas Meneghel Rodrigues
@ 2011-05-06 15:03   ` Amos Kong
  2011-05-06 15:03   ` [PATCH 2/3] KVM-test: Simple stop/continue test Amos Kong
  2011-05-06 15:04   ` [PATCH 3/3] KVM-test: Check if guest bootable after reseting several times Amos Kong
  2 siblings, 0 replies; 5+ messages in thread
From: Amos Kong @ 2011-05-06 15:03 UTC (permalink / raw)
  To: autotest; +Cc: lmr, kvm

This method is used to check if VM status is same as
we expected.

Signed-off-by: Amos Kong <akong@redhat.com>
---
 0 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/client/virt/kvm_monitor.py b/client/virt/kvm_monitor.py
index 7934b07..aff716a 100644
--- a/client/virt/kvm_monitor.py
+++ b/client/virt/kvm_monitor.py
@@ -282,6 +282,18 @@ class HumanMonitor(Monitor):
         self.cmd("info status", debug=False)
 
 
+    def verify_status(self, status):
+        """
+        Verify VM status
+
+        @param status: Optional VM status, 'running' or 'paused'
+        @return: return True if VM status is same as we expected
+        """
+        o = self.cmd("info status", debug=False)
+        if status=='paused' or status=='running':
+            return (status in o)
+
+
     # Command wrappers
     # Notes:
     # - All of the following commands raise exceptions in a similar manner to
@@ -650,6 +662,20 @@ class QMPMonitor(Monitor):
         self.cmd(cmd="query-status", debug=False)
 
 
+    def verify_status(self, status):
+        """
+        Verify VM status
+
+        @param status: Optional VM status, 'running' or 'paused'
+        @return: return True if VM status is same as we expected
+        """
+        o = str(self.cmd(cmd="query-status", debug=False))
+        if (status=='paused' and "u'running': False" in o):
+            return True
+        if (status=='running' and "u'running': True" in o):
+            return True
+
+
     def get_events(self):
         """
         Return a list of the asynchronous events received since the last
diff --git a/client/virt/kvm_vm.py b/client/virt/kvm_vm.py
index 57fc61b..830ab2e 100644
--- a/client/virt/kvm_vm.py
+++ b/client/virt/kvm_vm.py
@@ -82,6 +82,15 @@ class VM(virt_vm.BaseVM):
         return not self.process or not self.process.is_alive()
 
 
+    def verify_status(self, status):
+        """
+        Check VM status
+
+        @param status: Optional VM status, 'running' or 'paused'
+        @raise VMStatusError: If the VM status is not same as parameter
+        """
+        if not self.monitor.verify_status(status):
+            raise virt_vm.VMStatusError("VM status is unexpected.")
 
 
     def clone(self, name=None, params=None, root_dir=None, address_cache=None,
diff --git a/client/virt/virt_vm.py b/client/virt/virt_vm.py
index fd28966..5e9838a 100644
--- a/client/virt/virt_vm.py
+++ b/client/virt/virt_vm.py
@@ -185,6 +185,8 @@ class VMMigrateStateMismatchError(VMMigrateError):
 class VMRebootError(VMError):
     pass
 
+class VMStatusError(VMError):
+    pass
 
 def get_image_filename(params, root_dir):
     """


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] KVM-test: Simple stop/continue test
  2011-04-29  5:05 ` [Autotest] " Lucas Meneghel Rodrigues
  2011-05-06 15:03   ` [PATCH 1/3] KVM-test: introduce a verify_status method Amos Kong
@ 2011-05-06 15:03   ` Amos Kong
  2011-05-06 15:04   ` [PATCH 3/3] KVM-test: Check if guest bootable after reseting several times Amos Kong
  2 siblings, 0 replies; 5+ messages in thread
From: Amos Kong @ 2011-05-06 15:03 UTC (permalink / raw)
  To: autotest; +Cc: kvm

Change guest state by monitor cmd, verify guest status,
and try to login guest by network.

Changes from v1:
- use new method verify_status() to check vm status

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Amos Kong <akong@redhat.com>
---
 client/tests/kvm/tests/stop_continue.py |   43 +++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample  |    4 +++
 2 files changed, 47 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/stop_continue.py

diff --git a/client/tests/kvm/tests/stop_continue.py b/client/tests/kvm/tests/stop_continue.py
new file mode 100644
index 0000000..62df48e
--- /dev/null
+++ b/client/tests/kvm/tests/stop_continue.py
@@ -0,0 +1,43 @@
+import logging
+from autotest_lib.client.common_lib import error
+
+
+def run_stop_continue(test, params, env):
+    """
+    Suspend a running Virtual Machine and verify its state.
+
+    1) Boot the vm
+    2) Suspend the vm through stop command
+    3) Verify the state through info status command
+    4) Check is the ssh session to guest is still responsive,
+       if succeed, fail the test.
+
+    @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"])
+    vm.verify_alive()
+    timeout = float(params.get("login_timeout", 240))
+    session = vm.wait_for_login(timeout=timeout)
+
+    try:
+        logging.info("Stop the VM")
+        vm.monitor.cmd("stop")
+        logging.info("Verifying the status of VM is 'paused'")
+        vm.verify_status("paused")
+
+        logging.info("Check the session is responsive")
+        if session.is_responsive():
+            raise error.TestFail("Session is still responsive after stop")
+
+        logging.info("Try to resume the guest")
+        vm.monitor.cmd("cont")
+        logging.info("Verifying the status of VM is 'running'")
+        vm.verify_status("running")
+
+        logging.info("Try to re-log into guest")
+        session = vm.wait_for_login(timeout=timeout)
+
+    finally:
+        session.close()
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index 78c84c6..1e659bc 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -261,6 +261,10 @@ variants:
             - systemtap:
                 test_control_file = systemtap.control
 
+    - stop_continue:
+        type = stop_continue
+        kill_vm_on_error = yes
+
     - linux_s3:     install setup unattended_install.cdrom
         only Linux
         type = linux_s3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] KVM-test: Check if guest bootable after reseting several times
  2011-04-29  5:05 ` [Autotest] " Lucas Meneghel Rodrigues
  2011-05-06 15:03   ` [PATCH 1/3] KVM-test: introduce a verify_status method Amos Kong
  2011-05-06 15:03   ` [PATCH 2/3] KVM-test: Simple stop/continue test Amos Kong
@ 2011-05-06 15:04   ` Amos Kong
  2 siblings, 0 replies; 5+ messages in thread
From: Amos Kong @ 2011-05-06 15:04 UTC (permalink / raw)
  To: autotest; +Cc: lmr, kvm

This test comes from a regression bug:
Guest can not found bootable device after reseting several times by
monitor command.

https://bugzilla.redhat.com/show_bug.cgi?id=531026

Changes from v1:
- add bug id to commitlog
- remove unnecessary imports
- add some log message

Signed-off-by: Amos Kong <akong@redhat.com>
---
 client/tests/kvm/tests/system_reset_bootable.py |   31 +++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample          |    7 +++++
 2 files changed, 38 insertions(+), 0 deletions(-)
 create mode 100755 client/tests/kvm/tests/system_reset_bootable.py

diff --git a/client/tests/kvm/tests/system_reset_bootable.py b/client/tests/kvm/tests/system_reset_bootable.py
new file mode 100755
index 0000000..54536dc
--- /dev/null
+++ b/client/tests/kvm/tests/system_reset_bootable.py
@@ -0,0 +1,31 @@
+import logging, time
+from autotest_lib.client.common_lib import error
+
+def run_system_reset_bootable(test, params, env):
+    """
+    KVM reset test:
+    1) Boot guest.
+    2) Reset system by monitor command for several times.
+    3) Log into the guest to verify it could normally boot.
+
+    @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"])
+    vm.verify_alive()
+    timeout = float(params.get("login_timeout", 240))
+    reset_times = int(params.get("reset_times",20))
+    interval = int(params.get("reset_interval",10))
+    wait_time = int(params.get("wait_time_for_reset",60))
+
+    logging.info("Wait for %d seconds before reset" % wait_time)
+    time.sleep(wait_time)
+
+    for i in range(reset_times):
+        logging.info("Reset the system by monitor cmd")
+        vm.monitor.cmd("system_reset")
+        time.sleep(interval)
+
+    logging.info("Try to login guest after reset")
+    session = vm.wait_for_login(timeout=timeout)
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index 1e659bc..3b69b37 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -962,6 +962,13 @@ variants:
         sleep_before_reset = 20
         kill_vm_on_error = yes
 
+    - system_reset_bootable:
+        type = system_reset_bootable
+        interval = 1
+        reset_times = 20
+        wait_time_for_reset = 120
+        kill_vm_on_error = yes
+
     - shutdown:     install setup unattended_install.cdrom
         type = shutdown
         shutdown_method = shell


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-05-06 15:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-21  6:21 [Autotest PATCH] KVM-test: Simple stop/continue test Amos Kong
2011-04-29  5:05 ` [Autotest] " Lucas Meneghel Rodrigues
2011-05-06 15:03   ` [PATCH 1/3] KVM-test: introduce a verify_status method Amos Kong
2011-05-06 15:03   ` [PATCH 2/3] KVM-test: Simple stop/continue test Amos Kong
2011-05-06 15:04   ` [PATCH 3/3] KVM-test: Check if guest bootable after reseting several times Amos Kong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).