[KVM-AUTOTEST PATCH 13/26] KVM test: beautify VM, shell, monitor and login exception messages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



- Separate different logical parts of the messages with 4 spaces.
- Add output info to all login and SCP messages.
- Add 'using arping' to VMAddressVerificationError.

Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx>
---
 client/tests/kvm/kvm_monitor.py    |    4 +-
 client/tests/kvm/kvm_subprocess.py |   23 ++++++------
 client/tests/kvm/kvm_utils.py      |   66 ++++++++++++++++++++---------------
 client/tests/kvm/kvm_vm.py         |   14 ++++----
 4 files changed, 59 insertions(+), 48 deletions(-)

diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py
index 23fbc45..5d3422e 100644
--- a/client/tests/kvm/kvm_monitor.py
+++ b/client/tests/kvm/kvm_monitor.py
@@ -45,8 +45,8 @@ class QMPCmdError(MonitorError):
         self.data = data
 
     def __str__(self):
-        return ("QMP command %r failed (arguments: %r, error message: %r)" %
-                (self.cmd, self.qmp_args, self.data))
+        return ("QMP command %r failed    (arguments: %r,    "
+                "error message: %r)" % (self.cmd, self.qmp_args, self.data))
 
 
 class Monitor:
diff --git a/client/tests/kvm/kvm_subprocess.py b/client/tests/kvm/kvm_subprocess.py
index c3e2dd7..0b8734f 100755
--- a/client/tests/kvm/kvm_subprocess.py
+++ b/client/tests/kvm/kvm_subprocess.py
@@ -202,13 +202,13 @@ class ExpectError(Exception):
             return "patterns %r" % self.patterns
 
     def __str__(self):
-        return ("Unknown error occurred while looking for %s (output: %r)" %
+        return ("Unknown error occurred while looking for %s    (output: %r)" %
                 (self._pattern_str(), self.output))
 
 
 class ExpectTimeoutError(ExpectError):
     def __str__(self):
-        return ("Timeout expired while looking for %s (output: %r)" %
+        return ("Timeout expired while looking for %s    (output: %r)" %
                 (self._pattern_str(), self.output))
 
 
@@ -218,8 +218,9 @@ class ExpectProcessTerminatedError(ExpectError):
         self.status = status
 
     def __str__(self):
-        return ("Process terminated while looking for %s (status: %s, output: "
-                "%r)" % (self._pattern_str(), self.status, self.output))
+        return ("Process terminated while looking for %s    "
+                "(status: %s,    output: %r)" % (self._pattern_str(),
+                                                 self.status, self.output))
 
 
 class ShellError(Exception):
@@ -229,14 +230,14 @@ class ShellError(Exception):
         self.output = output
 
     def __str__(self):
-        return ("Could not execute shell command %r (output: %r)" %
+        return ("Could not execute shell command %r    (output: %r)" %
                 (self.cmd, self.output))
 
 
 class ShellTimeoutError(ShellError):
     def __str__(self):
-        return ("Timeout expired while waiting for shell command %r to "
-                "complete (output: %r)" % (self.cmd, self.output))
+        return ("Timeout expired while waiting for shell command to "
+                "complete: %r    (output: %r)" % (self.cmd, self.output))
 
 
 class ShellProcessTerminatedError(ShellError):
@@ -247,8 +248,8 @@ class ShellProcessTerminatedError(ShellError):
         self.status = status
 
     def __str__(self):
-        return ("Shell process terminated while waiting for command %r to "
-                "complete (status: %s, output: %r)" %
+        return ("Shell process terminated while waiting for command to "
+                "complete: %r    (status: %s,    output: %r)" %
                 (self.cmd, self.status, self.output))
 
 
@@ -260,14 +261,14 @@ class ShellCmdError(ShellError):
         self.status = status
 
     def __str__(self):
-        return ("Shell command %r failed with status %d (output: %r)" %
+        return ("Shell command failed: %r    (status: %s,    output: %r)" %
                 (self.cmd, self.status, self.output))
 
 
 class ShellStatusError(ShellError):
     # Raised when the command's exit status cannot be obtained
     def __str__(self):
-        return ("Could not get exit status of command %r (output: %r)" %
+        return ("Could not get exit status of command: %r    (output: %r)" %
                 (self.cmd, self.output))
 
 
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 6cfed3f..178a665 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -440,7 +440,13 @@ def check_kvm_source_dir(source_dir):
 # Functions and classes used for logging into guests and transferring files
 
 class LoginError(Exception):
-    pass
+    def __init__(self, msg, output):
+        Exception.__init__(self, msg, output)
+        self.msg = msg
+        self.output = output
+
+    def __str__(self):
+        return "%s    (output: %r)" % (self.msg, self.output)
 
 
 class LoginAuthenticationError(LoginError):
@@ -449,27 +455,22 @@ class LoginAuthenticationError(LoginError):
 
 class LoginTimeoutError(LoginError):
     def __init__(self, output):
-        LoginError.__init__(self, output)
-        self.output = output
-
-    def __str__(self):
-        return "Timeout expired (output so far: %r)" % self.output
+        LoginError.__init__(self, "Login timeout expired", output)
 
 
 class LoginProcessTerminatedError(LoginError):
     def __init__(self, status, output):
-        LoginError.__init__(self, status, output)
+        LoginError.__init__(self, None, output)
         self.status = status
-        self.output = output
 
     def __str__(self):
-        return ("Client process terminated (status: %s, output: %r)" %
+        return ("Client process terminated    (status: %s,    output: %r)" %
                 (self.status, self.output))
 
 
 class LoginBadClientError(LoginError):
     def __init__(self, client):
-        LoginError.__init__(self, client)
+        LoginError.__init__(self, None, None)
         self.client = client
 
     def __str__(self):
@@ -477,31 +478,38 @@ class LoginBadClientError(LoginError):
 
 
 class SCPError(Exception):
-    pass
+    def __init__(self, msg, output):
+        Exception.__init__(self, msg, output)
+        self.msg = msg
+        self.output = output
+
+    def __str__(self):
+        return "%s    (output: %r)" % (self.msg, self.output)
 
 
 class SCPAuthenticationError(SCPError):
     pass
 
 
-class SCPTransferTimeoutError(SCPError):
+class SCPAuthenticationTimeoutError(SCPAuthenticationError):
     def __init__(self, output):
-        SCPError.__init__(self, output)
-        self.output = output
+        SCPAuthenticationError.__init__(self, "Authentication timeout expired",
+                                        output)
 
-    def __str__(self):
-        return "Transfer timeout expired (output so far: %r)" % self.output
+
+class SCPTransferTimeoutError(SCPError):
+    def __init__(self, output):
+        SCPError.__init__(self, "Transfer timeout expired", output)
 
 
 class SCPTransferFailedError(SCPError):
     def __init__(self, status, output):
-        SCPError.__init__(self, status, output)
+        SCPError.__init__(self, None, output)
         self.status = status
-        self.output = output
 
     def __str__(self):
-        return "SCP transfer failed (status: %s, output: %r)" % (self.status,
-                                                                 self.output)
+        return ("SCP transfer failed    (status: %s,    output: %r)" %
+                (self.status, self.output))
 
 
 def _remote_login(session, username, password, prompt, timeout=10):
@@ -545,7 +553,8 @@ def _remote_login(session, username, password, prompt, timeout=10):
                     password_prompt_count += 1
                     continue
                 else:
-                    raise LoginAuthenticationError("Got password prompt twice")
+                    raise LoginAuthenticationError("Got password prompt twice",
+                                                   text)
             elif match == 2:  # "login:"
                 if login_prompt_count == 0:
                     logging.debug("Got username prompt; sending '%s'" % username)
@@ -553,11 +562,12 @@ def _remote_login(session, username, password, prompt, timeout=10):
                     login_prompt_count += 1
                     continue
                 else:
-                    raise LoginAuthenticationError("Got username prompt twice")
+                    raise LoginAuthenticationError("Got username prompt twice",
+                                                   text)
             elif match == 3:  # "Connection closed"
-                raise LoginError("Client said 'connection closed'")
+                raise LoginError("Client said 'connection closed'", text)
             elif match == 4:  # "Connection refused"
-                raise LoginError("Client said 'connection refused'")
+                raise LoginError("Client said 'connection refused'", text)
             elif match == 5:  # "Please wait"
                 logging.debug("Got 'Please wait'")
                 timeout = 30
@@ -689,15 +699,15 @@ def _remote_scp(session, password, transfer_timeout=600, login_timeout=10):
                     authentication_done = True
                     continue
                 else:
-                    raise SCPAuthenticationError("Got password prompt twice")
+                    raise SCPAuthenticationError("Got password prompt twice",
+                                                 text)
             elif match == 2:  # "lost connection"
-                raise SCPError("SCP client said 'lost connection'")
+                raise SCPError("SCP client said 'lost connection'", text)
         except kvm_subprocess.ExpectTimeoutError, e:
             if authentication_done:
                 raise SCPTransferTimeoutError(e.output)
             else:
-                raise SCPAuthenticationError("Authentication timeout expired "
-                                             "(output so far: %r)" % e.output)
+                raise SCPAuthenticationTimeoutError(e.output)
         except kvm_subprocess.ExpectProcessTerminatedError, e:
             if e.status == 0:
                 logging.debug("SCP process terminated with status 0")
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 525c065..98ad0c3 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -23,8 +23,8 @@ class VMCreateError(VMError):
         self.output = output
 
     def __str__(self):
-        return ("VM creation command failed: %r (status: %s, output: %r)" %
-                (self.cmd, self.status, self.output))
+        return ("VM creation command failed:    %r    (status: %s,    "
+                "output: %r)" % (self.cmd, self.status, self.output))
 
 
 class VMHashMismatchError(VMError):
@@ -75,13 +75,13 @@ class VMPostCreateError(VMError):
 
 class VMHugePageError(VMPostCreateError):
     def __str__(self):
-        return ("Cannot allocate hugepage memory (command: %r, output: %r)" %
-                (self.cmd, self.output))
+        return ("Cannot allocate hugepage memory    (command: %r,    "
+                "output: %r)" % (self.cmd, self.output))
 
 
 class VMKVMInitError(VMPostCreateError):
     def __str__(self):
-        return ("Cannot initialize KVM (command: %r, output: %r)" %
+        return ("Cannot initialize KVM    (command: %r,    output: %r)" %
                 (self.cmd, self.output))
 
 
@@ -109,8 +109,8 @@ class VMAddressVerificationError(VMAddressError):
         self.ip = ip
 
     def __str__(self):
-        return "Cannot verify MAC-IP address mapping: %s ---> %s" % (self.mac,
-                                                                     self.ip)
+        return ("Cannot verify MAC-IP address mapping using arping: "
+                "%s ---> %s" % (self.mac, self.ip))
 
 
 class VMMACAddressMissingError(VMAddressError):
-- 
1.7.3.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux