@@ -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:
@@ -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))
@@ -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")
@@ -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):