From patchwork Wed Aug 12 15:59:59 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 40911 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 n7CFwLLV005478 for ; Wed, 12 Aug 2009 15:58:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754034AbZHLP52 (ORCPT ); Wed, 12 Aug 2009 11:57:28 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754024AbZHLP52 (ORCPT ); Wed, 12 Aug 2009 11:57:28 -0400 Received: from mx2.redhat.com ([66.187.237.31]:42768 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754018AbZHLP50 (ORCPT ); Wed, 12 Aug 2009 11:57:26 -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 n7CFvRsY005558; Wed, 12 Aug 2009 11:57:27 -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 n7CFvQGo004557; Wed, 12 Aug 2009 11:57:26 -0400 Received: from localhost.localdomain (dhcp-1-31.tlv.redhat.com [10.35.1.31]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n7CFvFCJ029667; Wed, 12 Aug 2009 11:57:25 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH v2 07/11] KVM test: kvm_subprocess: send user specified parameters to kvm_tail callbacks Date: Wed, 12 Aug 2009 18:59:59 +0300 Message-Id: <40e596a8c1d099f0afdd2ad18f2f4a0908b89f20.1250091576.git.mgoldish@redhat.com> In-Reply-To: <5fbc30f0d24e3d4b12b93f40fe14264e5963048c.1250091576.git.mgoldish@redhat.com> References: <1250092803-32477-1-git-send-email-mgoldish@redhat.com> <10a541e518180735e86a4dbc8e759912d0ec314c.1250091576.git.mgoldish@redhat.com> <42ceeed70c7c1ec9f4d78d91d67a290f3ac11e6e.1250091576.git.mgoldish@redhat.com> <8284ff0173612b63412132bb8c864f2c8a258b55.1250091576.git.mgoldish@redhat.com> <05eac6f84757616309273b01ac4d8800efbdb083.1250091576.git.mgoldish@redhat.com> <5fbc30f0d24e3d4b12b93f40fe14264e5963048c.1250091576.git.mgoldish@redhat.com> In-Reply-To: <10a541e518180735e86a4dbc8e759912d0ec314c.1250091576.git.mgoldish@redhat.com> References: <10a541e518180735e86a4dbc8e759912d0ec314c.1250091576.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 (A mistake was made in the first version of this patch -- this is a corrected version.) 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 | 60 +++++++++++++++++++++++++++++++---- 1 files changed, 53 insertions(+), 7 deletions(-) diff --git a/client/tests/kvm/kvm_subprocess.py b/client/tests/kvm/kvm_subprocess.py index 6362856..41b9d80 100644 --- a/client/tests/kvm/kvm_subprocess.py +++ b/client/tests/kvm/kvm_subprocess.py @@ -470,7 +470,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. @@ -485,10 +487,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 @@ -500,7 +506,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 @@ -510,7 +518,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) @@ -524,6 +534,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. @@ -534,6 +554,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. @@ -552,7 +582,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 @@ -593,7 +624,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 @@ -613,7 +645,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. @@ -628,10 +662,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 @@ -639,7 +677,8 @@ class kvm_expect(kvm_tail): # Init the superclass kvm_tail.__init__(self, command, id, echo, linesep, - termination_func, output_func, output_prefix) + termination_func, termination_params, + output_func, output_params, output_prefix) def __getinitargs__(self): @@ -813,7 +852,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. @@ -829,10 +870,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 @@ -841,7 +886,8 @@ class kvm_shell_session(kvm_expect): """ # Init the superclass kvm_expect.__init__(self, command, id, echo, linesep, - termination_func, output_func, output_prefix) + termination_func, termination_params, + output_func, output_params, output_prefix) # Remember some attributes self.prompt = prompt