From patchwork Fri Jun 18 00:14:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 106785 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5I0FjxI016071 for ; Fri, 18 Jun 2010 00:15:45 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760753Ab0FRAPL (ORCPT ); Thu, 17 Jun 2010 20:15:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58711 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760861Ab0FRAPE (ORCPT ); Thu, 17 Jun 2010 20:15:04 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5I0F3eq005893 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 17 Jun 2010 20:15:03 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5I0F16P030580; Thu, 17 Jun 2010 20:15:01 -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 o5I0EljQ005733; Thu, 17 Jun 2010 20:15:00 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 10/18] KVM test: add the auto_close option to all kvm_subprocess classes Date: Fri, 18 Jun 2010 03:14:27 +0300 Message-Id: <1276820075-31310-10-git-send-email-mgoldish@redhat.com> In-Reply-To: <1276820075-31310-9-git-send-email-mgoldish@redhat.com> References: <1276820075-31310-1-git-send-email-mgoldish@redhat.com> <1276820075-31310-2-git-send-email-mgoldish@redhat.com> <1276820075-31310-3-git-send-email-mgoldish@redhat.com> <1276820075-31310-4-git-send-email-mgoldish@redhat.com> <1276820075-31310-5-git-send-email-mgoldish@redhat.com> <1276820075-31310-6-git-send-email-mgoldish@redhat.com> <1276820075-31310-7-git-send-email-mgoldish@redhat.com> <1276820075-31310-8-git-send-email-mgoldish@redhat.com> <1276820075-31310-9-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 18 Jun 2010 00:15:45 +0000 (UTC) diff --git a/client/tests/kvm/kvm_subprocess.py b/client/tests/kvm/kvm_subprocess.py index 2d70146..73edc5d 100755 --- a/client/tests/kvm/kvm_subprocess.py +++ b/client/tests/kvm/kvm_subprocess.py @@ -285,7 +285,8 @@ class kvm_spawn: resumes _tail() if needed. """ - def __init__(self, command=None, id=None, echo=False, linesep="\n"): + def __init__(self, command=None, id=None, auto_close=False, echo=False, + linesep="\n"): """ Initialize the class and run command as a child process. @@ -293,6 +294,8 @@ class kvm_spawn: server. @param id: ID of an already running server, if accessing a running server, or None if starting a new one. + @param auto_close: If True, close() the instance automatically when its + reference count drops to zero (default False). @param echo: Boolean indicating whether echo should be initially enabled for the pseudo terminal running the subprocess. This parameter has an effect only when starting a new server. @@ -316,6 +319,7 @@ class kvm_spawn: self.id) # Remember some attributes + self.auto_close = auto_close self.echo = echo self.linesep = linesep @@ -378,7 +382,12 @@ class kvm_spawn: def __getinitargs__(self): # Save some information when pickling -- will be passed to the # constructor upon unpickling - return (None, self.id, self.echo, self.linesep) + return (None, self.id, self.auto_close, self.echo, self.linesep) + + + def __del__(self): + if self.auto_close: + self.close() def _add_reader(self, reader): @@ -554,10 +563,9 @@ class kvm_tail(kvm_spawn): When this class is unpickled, it automatically resumes reporting output. """ - def __init__(self, command=None, id=None, echo=False, linesep="\n", - termination_func=None, termination_params=(), - output_func=None, output_params=(), - output_prefix=""): + def __init__(self, command=None, id=None, auto_close=False, echo=False, + linesep="\n", termination_func=None, termination_params=(), + output_func=None, output_params=(), output_prefix=""): """ Initialize the class and run command as a child process. @@ -565,6 +573,8 @@ class kvm_tail(kvm_spawn): server. @param id: ID of an already running server, if accessing a running server, or None if starting a new one. + @param auto_close: If True, close() the instance automatically when its + reference count drops to zero (default False). @param echo: Boolean indicating whether echo should be initially enabled for the pseudo terminal running the subprocess. This parameter has an effect only when starting a new server. @@ -587,7 +597,7 @@ class kvm_tail(kvm_spawn): self._add_close_hook(kvm_tail._join_thread) # Init the superclass - kvm_spawn.__init__(self, command, id, echo, linesep) + kvm_spawn.__init__(self, command, id, auto_close, echo, linesep) # Remember some attributes self.termination_func = termination_func @@ -751,10 +761,9 @@ class kvm_expect(kvm_tail): It also provides all of kvm_tail's functionality. """ - def __init__(self, command=None, id=None, echo=False, linesep="\n", - termination_func=None, termination_params=(), - output_func=None, output_params=(), - output_prefix=""): + def __init__(self, command=None, id=None, auto_close=False, echo=False, + linesep="\n", termination_func=None, termination_params=(), + output_func=None, output_params=(), output_prefix=""): """ Initialize the class and run command as a child process. @@ -762,6 +771,8 @@ class kvm_expect(kvm_tail): server. @param id: ID of an already running server, if accessing a running server, or None if starting a new one. + @param auto_close: If True, close() the instance automatically when its + reference count drops to zero (default False). @param echo: Boolean indicating whether echo should be initially enabled for the pseudo terminal running the subprocess. This parameter has an effect only when starting a new server. @@ -783,7 +794,7 @@ class kvm_expect(kvm_tail): self._add_reader("expect") # Init the superclass - kvm_tail.__init__(self, command, id, echo, linesep, + kvm_tail.__init__(self, command, id, auto_close, echo, linesep, termination_func, termination_params, output_func, output_params, output_prefix) @@ -967,10 +978,9 @@ class kvm_shell_session(kvm_expect): process for responsiveness. """ - def __init__(self, command=None, id=None, echo=False, linesep="\n", - termination_func=None, termination_params=(), - output_func=None, output_params=(), - output_prefix="", + def __init__(self, command=None, id=None, auto_close=True, echo=False, + linesep="\n", 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. @@ -979,6 +989,8 @@ class kvm_shell_session(kvm_expect): server. @param id: ID of an already running server, if accessing a running server, or None if starting a new one. + @param auto_close: If True, close() the instance automatically when its + reference count drops to zero (default True). @param echo: Boolean indicating whether echo should be initially enabled for the pseudo terminal running the subprocess. This parameter has an effect only when starting a new server. @@ -1001,7 +1013,7 @@ class kvm_shell_session(kvm_expect): get_command_status_output() and friends). """ # Init the superclass - kvm_expect.__init__(self, command, id, echo, linesep, + kvm_expect.__init__(self, command, id, auto_close, echo, linesep, termination_func, termination_params, output_func, output_params, output_prefix) @@ -1015,10 +1027,6 @@ class kvm_shell_session(kvm_expect): self.status_test_command) - def __del__(self): - self.close() - - def set_prompt(self, prompt): """ Set the prompt attribute for later use by read_up_to_prompt.