Skip to contentSkip to conversation

KVM test: VM.send_monitor_cmd() minor cleanup

PATCH New Michael Goldish 1 participant 3 messages Oct 15, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 KVM test: VM.send_monitor_cmd() minor cleanup

- Move some of the code into a try..finally block
- Shutdown the socket before closing it

---
 client/tests/kvm/kvm_vm.py |   45 ++++++++++++++++++++++++-------------------
 1 files changed, 25 insertions(+), 20 deletions(-)
client/tests/kvm/kvm_vm.py +25 -20
index 82f1eb4..a8d96ca 100755
@@ -465,7 +465,7 @@ class VM:
             end_time = time.time() + timeout
             while time.time() < end_time:
                 try:
-                    o += s.recv(16384)
+                    o += s.recv(1024)
                     if o.splitlines()[-1].split()[-1] == "(qemu)":
                         return (True, o)
                 except:
@@ -481,27 +481,32 @@ class VM:
         except:
             logging.debug("Could not connect to monitor socket")
             return (1, "")
-        status, data = read_up_to_qemu_prompt(s, timeout)
-        if not status:
-            s.close()
-            logging.debug("Could not find (qemu) prompt; output so far:" \
-                    + kvm_utils.format_str_for_message(data))
-            return (1, "")
-        # Send command
-        s.sendall(command + "\n")
-        # Receive command output
-        data = ""
-        if block:
+
+        # Send the command and get the resulting output
+        try:
             status, data = read_up_to_qemu_prompt(s, timeout)
-            data = "\n".join(data.splitlines()[1:])
             if not status:
-                s.close()
-                logging.debug("Could not find (qemu) prompt after command;"
-                              " output so far: %s",
-                               kvm_utils.format_str_for_message(data))
-                return (1, data)
-        s.close()
-        return (0, data)
+                logging.debug("Could not find (qemu) prompt; output so far:" +
+                              kvm_utils.format_str_for_message(data))
+                return (1, "")
+            # Send command
+            s.sendall(command + "\n")
+            # Receive command output
+            data = ""
+            if block:
+                status, data = read_up_to_qemu_prompt(s, timeout)
+                data = "\n".join(data.splitlines()[1:])
+                if not status:
+                    logging.debug("Could not find (qemu) prompt after command; "
+                                  "output so far:" +
+                                  kvm_utils.format_str_for_message(data))
+                    return (1, data)
+            return (0, data)
+
+        # Clean up before exiting
+        finally:
+            s.shutdown(socket.SHUT_RDWR)
+            s.close()
 
 
     def destroy(self, gracefully=True):
Signature · 1 line
1.5.4.1
#1 lore raw

PATCH 2/3 KVM test: corrections to guest_s4

- Log into the guest again after it resumes from S4 ('session2' doesn't survive S4 in user networking mode).
- Use != 0 when checking the status returned by get_command_status(), because when things go wrong, it can also return None.
- Use time.sleep(float(params.get(...))) instead of time.sleep(params.get(...)) (time.sleep() doesn't accept strings).
- Do not check that the VM is alive after vm.create() because vm.create() already does that.
- Use get_command_output(kill_test_s4_cmd) instead of sendline(kill_test_s4_cmd), because get_command_output() waits for the prompt to return, and allows us to be sure that the command got delivered to the guest. This is especially important if the session is closed immediately after sending the command. In the case of the command that performs suspend to disk (set_s4_cmd), and the test_s4_cmd for Linux (nohup ...), it is OK to use sendline() because the prompt may never return. In the latter case, sleep(5) after the sendline() call should ensure that the command got delivered before the test proceeds.
- Change the timeouts in the wait_for(vm.is_dead, ...) call.
- For Windows guests modify test_s4_cmd to 'start ping -t localhost'. Using start /B isn't safe because then ping's output is redirected to a dead shell session.
- For Windows guests mdify check_s4_cmd to 'tasklist | find /I "ping.exe"'. (It's a little more specific than just "ping".)
- Run guest_s4 after autoit tests because it can leave Windows guests with an annoying welcome screen.
- Make the logging messages more consistent with the style of other tests.

---
 client/tests/kvm/kvm_tests.cfg.sample |   23 ++++++++---------
 client/tests/kvm/tests/guest_s4.py    |   45 +++++++++++++++++++-------------
 2 files changed, 38 insertions(+), 30 deletions(-)
client/tests/kvm/kvm_tests.cfg.sample +11 -12
index 9ccc9b5..296449d 100644
@@ -118,15 +118,6 @@ variants:
     - linux_s3:     install setup
         type = linux_s3
 
-    - guest_s4:
-        type = guest_s4
-        check_s4_support_cmd = grep -q disk /sys/power/state
-        test_s4_cmd = "cd /tmp/;nohup tcpdump -q -t ip host localhost"
-        check_s4_cmd = pgrep tcpdump
-        set_s4_cmd = echo disk > /sys/power/state
-        kill_test_s4_cmd = pkill tcpdump
-        services_up_timeout = 30
-
     - timedrift:    install setup
         extra_params += " -rtc-td-hack"
         variants:
@@ -166,7 +157,6 @@ variants:
         used_cpus = 5
         used_mem = 2560
 
-
     - autoit:       install setup
         type = autoit
         autoit_binary = D:\AutoIt3.exe
@@ -176,6 +166,15 @@ variants:
             - notepad:
                 autoit_script = autoit/notepad1.au3
 
+    - guest_s4:
+        type = guest_s4
+        check_s4_support_cmd = grep -q disk /sys/power/state
+        test_s4_cmd = "cd /tmp; nohup tcpdump -q -t ip host localhost"
+        check_s4_cmd = pgrep tcpdump
+        set_s4_cmd = echo disk > /sys/power/state
+        kill_test_s4_cmd = pkill tcpdump
+        services_up_timeout = 30
+
     - nic_hotplug:       install setup
         type = pci_hotplug
         pci_type = nic
@@ -518,8 +517,8 @@ variants:
             host_load_instances = 8
         guest_s4:
             check_s4_support_cmd = powercfg /hibernate on
-            test_s4_cmd = start /B ping -n 3000 localhost
-            check_s4_cmd = tasklist | find /I "ping"
+            test_s4_cmd = start ping -t localhost
+            check_s4_cmd = tasklist | find /I "ping.exe"
             set_s4_cmd = rundll32.exe PowrProf.dll, SetSuspendState
             kill_test_s4_cmd = taskkill /IM ping.exe /F
             services_up_timeout = 30
client/tests/kvm/tests/guest_s4.py +27 -18

87 lines not on this page · raw message

Signature · 1 line
1.5.4.1
#2 lore raw

PATCH 3/3 KVM test: modify messages in kvm_test_utils.wait_for_login()

Use "logged into guest" instead of "logged in guest". AFAIK this is more correct.

---
 client/tests/kvm/kvm_test_utils.py |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
client/tests/kvm/kvm_test_utils.py +2 -2
index e51520a..bf8aed2 100644
@@ -52,12 +52,12 @@ def wait_for_login(vm, nic_index=0, timeout=240, start=0, step=2):
     @param timeout: Time to wait before giving up.
     @return: A shell session object.
     """
-    logging.info("Try to login to guest '%s'..." % vm.name)
+    logging.info("Trying to log into guest '%s'..." % vm.name)
     session = kvm_utils.wait_for(lambda: vm.remote_login(nic_index=nic_index),
                                  timeout, start, step)
     if not session:
         raise error.TestFail("Could not log into guest '%s'" % vm.name)
-    logging.info("Logged in '%s'" % vm.name)
+    logging.info("Logged into guest '%s'" % vm.name)
     return session
 
 
Signature · 1 line
1.5.4.1