From patchwork Tue Oct 26 16:49:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 283112 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9QHpLS2005165 for ; Tue, 26 Oct 2010 17:51:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760207Ab0JZRvS (ORCPT ); Tue, 26 Oct 2010 13:51:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3250 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760167Ab0JZRvR (ORCPT ); Tue, 26 Oct 2010 13:51:17 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9QHp9sa030898 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Oct 2010 13:51:14 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9QGnrY4032444; Tue, 26 Oct 2010 12:49: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 o9QGnjvI022482; Tue, 26 Oct 2010 12:49:52 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 5/5] [RFC] KVM test: kvm_subprocess: rename kvm_shell_session and friends Date: Tue, 26 Oct 2010 18:49:44 +0200 Message-Id: <1288111784-10188-5-git-send-email-mgoldish@redhat.com> In-Reply-To: <1288111784-10188-4-git-send-email-mgoldish@redhat.com> References: <1288111784-10188-1-git-send-email-mgoldish@redhat.com> <1288111784-10188-2-git-send-email-mgoldish@redhat.com> <1288111784-10188-3-git-send-email-mgoldish@redhat.com> <1288111784-10188-4-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 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 (demeter1.kernel.org [140.211.167.41]); Tue, 26 Oct 2010 17:51:21 +0000 (UTC) diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py index 1ddf99b..5ec38fb 100644 --- a/client/tests/kvm/kvm_preprocessing.py +++ b/client/tests/kvm/kvm_preprocessing.py @@ -204,7 +204,7 @@ def preprocess(test, params, env): if "tcpdump" not in env and params.get("run_tcpdump", "yes") == "yes": cmd = "%s -npvi any 'dst port 68'" % kvm_utils.find_command("tcpdump") logging.debug("Starting tcpdump (%s)...", cmd) - env["tcpdump"] = kvm_subprocess.kvm_tail( + env["tcpdump"] = kvm_subprocess.Tail( command=cmd, output_func=_update_address_cache, output_params=(env["address_cache"],)) diff --git a/client/tests/kvm/kvm_scheduler.py b/client/tests/kvm/kvm_scheduler.py index f1adb39..aa581ad 100644 --- a/client/tests/kvm/kvm_scheduler.py +++ b/client/tests/kvm/kvm_scheduler.py @@ -78,7 +78,7 @@ class scheduler: for obj in env.values(): if isinstance(obj, kvm_vm.VM): obj.destroy() - elif isinstance(obj, kvm_subprocess.kvm_spawn): + elif isinstance(obj, kvm_subprocess.Spawn): obj.close() kvm_utils.dump_env(env, env_filename) w.write("cleanup_done\n") diff --git a/client/tests/kvm/kvm_subprocess.py b/client/tests/kvm/kvm_subprocess.py index c8caab2..e0723bb 100755 --- a/client/tests/kvm/kvm_subprocess.py +++ b/client/tests/kvm/kvm_subprocess.py @@ -292,12 +292,12 @@ def run_bg(command, termination_func=None, output_func=None, output_prefix="", @param timeout: Time duration (in seconds) to wait for the subprocess to terminate before returning - @return: A kvm_tail object. + @return: A Tail object. """ - process = kvm_tail(command=command, - termination_func=termination_func, - output_func=output_func, - output_prefix=output_prefix) + process = Tail(command=command, + termination_func=termination_func, + output_func=output_func, + output_prefix=output_prefix) end_time = time.time() + timeout while time.time() < end_time and process.is_alive(): @@ -338,7 +338,7 @@ def run_fg(command, output_func=None, output_prefix="", timeout=1.0): return (status, output) -class kvm_spawn: +class Spawn: """ This class is used for spawning and controlling a child process. @@ -350,7 +350,7 @@ class kvm_spawn: The text file can be accessed at any time using get_output(). In addition, the server opens as many pipes as requested by the client and writes the output to them. - The pipes are requested and accessed by classes derived from kvm_spawn. + The pipes are requested and accessed by classes derived from Spawn. These pipes are referred to as "readers". The server also receives input from the client and sends it to the child process. @@ -634,7 +634,7 @@ _thread_kill_requested = False def kill_tail_threads(): """ - Kill all kvm_tail threads. + Kill all Tail threads. After calling this function no new threads should be started. """ @@ -646,12 +646,12 @@ def kill_tail_threads(): _thread_kill_requested = False -class kvm_tail(kvm_spawn): +class Tail(Spawn): """ This class runs a child process in the background and sends its output in real time, line-by-line, to a callback function. - See kvm_spawn's docstring. + See Spawn's docstring. This class uses a single pipe reader to read data in real time from the child process and report it to a given callback function. @@ -692,10 +692,10 @@ class kvm_tail(kvm_spawn): """ # Add a reader and a close hook self._add_reader("tail") - self._add_close_hook(kvm_tail._join_thread) + self._add_close_hook(Tail._join_thread) # Init the superclass - kvm_spawn.__init__(self, command, id, auto_close, echo, linesep) + Spawn.__init__(self, command, id, auto_close, echo, linesep) # Remember some attributes self.termination_func = termination_func @@ -711,11 +711,11 @@ 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) + return Spawn.__getinitargs__(self) + (self.termination_func, + self.termination_params, + self.output_func, + self.output_params, + self.output_prefix) def set_termination_func(self, termination_func): @@ -847,12 +847,12 @@ class kvm_tail(kvm_spawn): t.join() -class kvm_expect(kvm_tail): +class Expect(Tail): """ This class runs a child process in the background and provides expect-like services. - It also provides all of kvm_tail's functionality. + It also provides all of Tail's functionality. """ def __init__(self, command=None, id=None, auto_close=True, echo=False, @@ -888,13 +888,13 @@ class kvm_expect(kvm_tail): self._add_reader("expect") # Init the superclass - kvm_tail.__init__(self, command, id, auto_close, echo, linesep, - termination_func, termination_params, - output_func, output_params, output_prefix) + Tail.__init__(self, command, id, auto_close, echo, linesep, + termination_func, termination_params, + output_func, output_params, output_prefix) def __getinitargs__(self): - return kvm_tail.__getinitargs__(self) + return Tail.__getinitargs__(self) def read_nonblocking(self, timeout=None): @@ -1061,12 +1061,12 @@ class kvm_expect(kvm_tail): print_func) -class kvm_shell_session(kvm_expect): +class ShellSession(Expect): """ This class runs a child process in the background. It it suited for processes that provide an interactive shell, such as SSH and Telnet. - It provides all services of kvm_expect and kvm_tail. In addition, it + It provides all services of Expect and Tail. In addition, it provides command running services, and a utility function to test the process for responsiveness. """ @@ -1106,9 +1106,9 @@ class kvm_shell_session(kvm_expect): cmd_status_output() and friends). """ # Init the superclass - kvm_expect.__init__(self, command, id, auto_close, echo, linesep, - termination_func, termination_params, - output_func, output_params, output_prefix) + Expect.__init__(self, command, id, auto_close, echo, linesep, + termination_func, termination_params, + output_func, output_params, output_prefix) # Remember some attributes self.prompt = prompt @@ -1116,8 +1116,8 @@ class kvm_shell_session(kvm_expect): def __getinitargs__(self): - return kvm_expect.__getinitargs__(self) + (self.prompt, - self.status_test_command) + return Expect.__getinitargs__(self) + (self.prompt, + self.status_test_command) def set_prompt(self, prompt): diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index c87e908..b4f1419 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -437,7 +437,7 @@ def _remote_login(session, username, password, prompt, timeout=10): @brief: Log into a remote host (guest) using SSH or Telnet. - @param session: A kvm_expect or kvm_shell_session instance to operate on + @param session: An Expect or ShellSession instance to operate on @param username: The username to send in reply to a login prompt @param password: The password to send in reply to a password prompt @param prompt: The shell prompt that indicates a successful login @@ -509,7 +509,7 @@ def _remote_scp(session, password, transfer_timeout=600, login_timeout=10): @brief: Transfer files using SCP, given a command line. - @param session: A kvm_expect or kvm_shell_session instance to operate on + @param session: An Expect or ShellSession instance to operate on @param password: The password to send in reply to a password prompt. @param transfer_timeout: The time duration (in seconds) to wait for the transfer to complete. @@ -570,7 +570,7 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n", each step of the login procedure (i.e. the "Are you sure" prompt or the password prompt) - @return: kvm_shell_session object on success and None on failure. + @return: ShellSession object on success and None on failure. """ if client == "ssh": cmd = ("ssh -o UserKnownHostsFile=/dev/null " @@ -585,8 +585,7 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n", return logging.debug("Trying to login with command '%s'" % cmd) - session = kvm_subprocess.kvm_shell_session(cmd, linesep=linesep, - prompt=prompt) + session = kvm_subprocess.ShellSession(cmd, linesep=linesep, prompt=prompt) if _remote_login(session, username, password, prompt, timeout): if log_filename: session.set_output_func(log_line) @@ -625,9 +624,9 @@ def remote_scp(command, password, log_filename=None, transfer_timeout=600, output_func = None output_params = () - session = kvm_subprocess.kvm_expect(command, - output_func=output_func, - output_params=output_params) + session = kvm_subprocess.Expect(command, + output_func=output_func, + output_params=output_params) try: return _remote_scp(session, password, transfer_timeout, login_timeout) finally: diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index 267b45b..bb24c6a 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -733,7 +733,7 @@ class VM: # Establish a session with the serial console -- requires a version # of netcat that supports -U - self.serial_console = kvm_subprocess.kvm_shell_session( + self.serial_console = kvm_subprocess.ShellSession( "nc -U %s" % self.get_serial_console_filename(), auto_close=False, output_func=kvm_utils.log_line, @@ -1040,7 +1040,7 @@ class VM: @param nic_index: The index of the NIC to connect to. @param timeout: Time (seconds) before giving up logging into the guest. - @return: kvm_spawn object on success and None on failure. + @return: ShellSession object on success and None on failure. """ username = self.params.get("username", "") password = self.params.get("password", "") @@ -1139,7 +1139,7 @@ class VM: password prompt or a shell prompt) -- fail. @param timeout: Time (seconds) before giving up logging into the guest. - @return: kvm_spawn object on success and None on failure. + @return: ShellSession object on success and None on failure. """ username = self.params.get("username", "") password = self.params.get("password", "")