From patchwork Sun Aug 2 23:58:17 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 38813 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n72Nsweu009571 for ; Sun, 2 Aug 2009 23:54:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753982AbZHBXy4 (ORCPT ); Sun, 2 Aug 2009 19:54:56 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753978AbZHBXy4 (ORCPT ); Sun, 2 Aug 2009 19:54:56 -0400 Received: from mx2.redhat.com ([66.187.237.31]:37219 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753933AbZHBXyy (ORCPT ); Sun, 2 Aug 2009 19:54:54 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n72Ns47c016639; Sun, 2 Aug 2009 19:54:14 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n72Nrq40022167; Sun, 2 Aug 2009 19:53:53 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n72Nre6O017975; Sun, 2 Aug 2009 19:53:51 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 08/12] KVM test: kvm_subprocess: send user specified parameters to kvm_tail callbacks Date: Mon, 3 Aug 2009 02:58:17 +0300 Message-Id: In-Reply-To: <603d8e9011205d1586b36dffead3823a2a61a745.1249257056.git.mgoldish@redhat.com> References: <1249257501-19337-1-git-send-email-mgoldish@redhat.com> <7845d2fd228ec0232af10e48dbb29e1076a265d6.1249257056.git.mgoldish@redhat.com> <9ec0626f3ca8c20d08cfd2448dbf249632ed969a.1249257056.git.mgoldish@redhat.com> <30ddf2ae0b04eb29d55dcece97fd956b75563045.1249257056.git.mgoldish@redhat.com> <3e87b54663c4483d10912231945fc37741087b8f.1249257056.git.mgoldish@redhat.com> <9d4ca96f1445db6df176825a494d6504a3bddeba.1249257056.git.mgoldish@redhat.com> <8a2d08b846334a5eb097c2f32348d0c04a6789fb.1249257056.git.mgoldish@redhat.com> <603d8e9011205d1586b36dffead3823a2a61a745.1249257056.git.mgoldish@redhat.com> In-Reply-To: <7845d2fd228ec0232af10e48dbb29e1076a265d6.1249257056.git.mgoldish@redhat.com> References: <7845d2fd228ec0232af10e48dbb29e1076a265d6.1249257056.git.mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Allow the user to specify parameters to send to output_func and termination_func in addition to the regular output string and exit status. The user specified parameters will be pre-pended to the other parameters. This is mainly meant to bypass Python's refusal to pickle instance methods. Signed-off-by: Michael Goldish --- client/tests/kvm/kvm_subprocess.py | 54 ++++++++++++++++++++++++++++++++--- 1 files changed, 49 insertions(+), 5 deletions(-) diff --git a/client/tests/kvm/kvm_subprocess.py b/client/tests/kvm/kvm_subprocess.py index c15e779..df1d562 100644 --- a/client/tests/kvm/kvm_subprocess.py +++ b/client/tests/kvm/kvm_subprocess.py @@ -464,7 +464,9 @@ class kvm_tail(kvm_spawn): """ def __init__(self, command=None, id=None, echo=False, linesep="\n", - termination_func=None, output_func=None, output_prefix=""): + termination_func=None, termination_params=(), + output_func=None, output_params=(), + output_prefix=""): """ Initialize the class and run command as a child process. @@ -479,10 +481,14 @@ class kvm_tail(kvm_spawn): child process by sendline(). @param termination_func: Function to call when the process exits. The function must accept a single exit status parameter. + @param termination_params: Parameters to send to termination_func + before the exit status. @param output_func: Function to call whenever a line of output is available from the STDOUT or STDERR streams of the process. The function must accept a single string parameter. The string does not include the final newline. + @param output_params: Parameters to send to output_func before the + output line. @param output_prefix: String to prepend to lines sent to output_func. """ # Add a reader and a close hook @@ -494,7 +500,9 @@ class kvm_tail(kvm_spawn): # Remember some attributes self.termination_func = termination_func + self.termination_params = termination_params self.output_func = output_func + self.output_params = output_params self.output_prefix = output_prefix # Start the thread in the background @@ -504,7 +512,9 @@ class kvm_tail(kvm_spawn): def __getinitargs__(self): return kvm_spawn.__getinitargs__(self) + (self.termination_func, + self.termination_params, self.output_func, + self.output_params, self.output_prefix) @@ -518,6 +528,16 @@ class kvm_tail(kvm_spawn): self.termination_func = termination_func + def set_termination_params(self, termination_params): + """ + Set the termination_params attribute. See __init__() for details. + + @param termination_params: Parameters to send to termination_func + before the exit status. + """ + self.termination_params = termination_params + + def set_output_func(self, output_func): """ Set the output_func attribute. See __init__() for details. @@ -528,6 +548,16 @@ class kvm_tail(kvm_spawn): self.output_func = output_func + def set_output_params(self, output_params): + """ + Set the output_params attribute. See __init__() for details. + + @param output_params: Parameters to send to output_func before the + output line. + """ + self.output_params = output_params + + def set_output_prefix(self, output_prefix): """ Set the output_prefix attribute. See __init__() for details. @@ -546,7 +576,8 @@ class kvm_tail(kvm_spawn): text = text.decode("utf-8", "replace") # Pass it to output_func try: - self.output_func(text) + params = self.output_params + (text,) + self.output_func(*params) except TypeError: pass @@ -587,7 +618,8 @@ class kvm_tail(kvm_spawn): return print_line("(Process terminated with status %s)" % status) try: - self.termination_func(status) + params = self.termination_params + (status,) + self.termination_func(*params) except TypeError: pass @@ -607,7 +639,9 @@ class kvm_expect(kvm_tail): """ def __init__(self, command=None, id=None, echo=False, linesep="\n", - termination_func=None, output_func=None, output_prefix=""): + termination_func=None, termination_params=(), + output_func=None, output_params=(), + output_prefix=""): """ Initialize the class and run command as a child process. @@ -622,10 +656,14 @@ class kvm_expect(kvm_tail): child process by sendline(). @param termination_func: Function to call when the process exits. The function must accept a single exit status parameter. + @param termination_params: Parameters to send to termination_func + before the exit status. @param output_func: Function to call whenever a line of output is available from the STDOUT or STDERR streams of the process. The function must accept a single string parameter. The string does not include the final newline. + @param output_params: Parameters to send to output_func before the + output line. @param output_prefix: String to prepend to lines sent to output_func. """ # Add a reader @@ -807,7 +845,9 @@ class kvm_shell_session(kvm_expect): """ def __init__(self, command=None, id=None, echo=False, linesep="\n", - termination_func=None, output_func=None, output_prefix="", + termination_func=None, termination_params=(), + output_func=None, output_params=(), + output_prefix="", prompt=r"[\#\$]\s*$", status_test_command="echo $?"): """ Initialize the class and run command as a child process. @@ -823,10 +863,14 @@ class kvm_shell_session(kvm_expect): child process by sendline(). @param termination_func: Function to call when the process exits. The function must accept a single exit status parameter. + @param termination_params: Parameters to send to termination_func + before the exit status. @param output_func: Function to call whenever a line of output is available from the STDOUT or STDERR streams of the process. The function must accept a single string parameter. The string does not include the final newline. + @param output_params: Parameters to send to output_func before the + output line. @param output_prefix: String to prepend to lines sent to output_func. @param prompt: Regular expression describing the shell's prompt line. @param status_test_command: Command to be used for getting the last