From: Michael Goldish <[email protected]> In VM.send_monitor_cmd(), kvm_spawn.get_command_status_output() and kvm_spawn.read_until_output_matches(), print some information upon failure (exit status and/or output so far). Also add function kvm_utils.format_str_for_message() which helps in formatting these debug messages. Also print the command being executed with get_command_status_output().
Signed-off-by: Michael Goldish <[email protected]> diff --git a/client/tests/kvm_runtest_2/kvm_utils.py b/client/tests/kvm_runtest_2/kvm_utils.py index 594105a..be8ad95 100644 --- a/client/tests/kvm_runtest_2/kvm_utils.py +++ b/client/tests/kvm_runtest_2/kvm_utils.py @@ -217,6 +217,7 @@ class kvm_spawn: """ match = None data = "" + end_time = time.time() + timeout while time.time() < end_time: # Read data from child @@ -238,6 +239,11 @@ class kvm_spawn: # Are we done? if done: break + # Print some debugging info + if match == None and self.poll() != 0: + kvm_log.debug("Timeout elapsed or process terminated; output so far:" \ + + format_str_for_message(data.strip())) + return (match, data) def get_last_word(self, str): @@ -325,8 +331,11 @@ class kvm_spawn: Return a tuple (status, output) where status is the exit status or None if no exit status is available (e.g. timeout elapsed), and output is the - output of command. + output of command. """ + # Print some debugging info + kvm_log.debug("Sending command: %s" % command) + # Read everything that's waiting to be read self.read_nonblocking(0.1) @@ -344,6 +353,11 @@ class kvm_spawn: return (None, output) status = int("\n".join(status.splitlines()[1:-1]).strip()) + # Print some debugging info + if status != 0: + kvm_log.debug("Command failed; status: %d, output:" % status \ + + format_str_for_message(output.strip())) + return (status, output) def get_command_status(self, command, timeout=30.0, internal_timeout=1.0, print_func=None): @@ -356,7 +370,7 @@ class kvm_spawn: (should take a string parameter) Return the exit status or None if no exit status is available (e.g. - timeout elapsed). + timeout elapsed). """ (status, output) = self.get_command_status_output(command, timeout, internal_timeout, print_func) return status @@ -688,6 +702,21 @@ def generate_random_string(length): return str +def format_str_for_message(str): + """Format str so that it can be appended to a message. + + If str consists of one line, prefix it with a space. + If str consists of multiple lines, prefix it with a newline. + """ + num_lines = len(str.splitlines()) + if num_lines == 0: + return "" + elif num_lines == 1: + return " " + str + else: + return "\n" + str + + def wait_for(func, timeout, first=0.0, step=1.0, text=None): """Wait until func() evaluates to True. diff --git a/client/tests/kvm_runtest_2/kvm_vm.py b/client/tests/kvm_runtest_2/kvm_vm.py index b3c46b6..0680f52 100644 --- a/client/tests/kvm_runtest_2/kvm_vm.py +++ b/client/tests/kvm_runtest_2/kvm_vm.py @@ -372,7 +372,8 @@ class VM: status, data = read_up_to_qemu_prompt(s, timeout) if not status: s.close() - kvm_log.debug("Could not find (qemu) prompt") + kvm_log.debug("Could not find (qemu) prompt; output so far:" \ + + kvm_utils.format_str_for_message(data)) return (1, "") # Send command s.sendall(command + "\n") @@ -383,7 +384,8 @@ class VM: data = "\n".join(data.splitlines()[1:]) if not status: s.close() - kvm_log.debug("Could not find (qemu) prompt after command") + kvm_log.debug("Could not find (qemu) prompt after command; output so far:" \ + + kvm_utils.format_str_for_message(data)) return (1, data) s.close() return (0, data) -- To unsubscribe from this list: send the line "unsubscribe kvm-commits" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
