From: Lucas Meneghel Rodrigues <lmr@redhat.com>
To: Michael Goldish <mgoldish@redhat.com>
Cc: autotest@test.kernel.org, kvm@vger.kernel.org
Subject: Re: [KVM-AUTOTEST PATCH 5/5] [RFC] KVM test: kvm_subprocess: rename kvm_shell_session and friends
Date: Wed, 27 Oct 2010 19:07:25 -0200 [thread overview]
Message-ID: <1288213645.2516.160.camel@freedom> (raw)
In-Reply-To: <1288111784-10188-5-git-send-email-mgoldish@redhat.com>
On Tue, 2010-10-26 at 18:49 +0200, Michael Goldish wrote:
> PEP 8 states that class names should use the CapWords convention.
>
> kvm_spawn -> Spawn
> kvm_tail -> Tail
> kvm_expect -> Expect
> kvm_shell_session -> ShellSession
>
> This is an RFC because I wonder if the proposed names are too general, even
> though they are usually prefixed by 'kvm_subprocess.'.
No, the names are good. The namespace takes care of disambiguation.
>
> Signed-off-by: Michael Goldish <mgoldish@redhat.com>
> ---
> client/tests/kvm/kvm_preprocessing.py | 2 +-
> client/tests/kvm/kvm_scheduler.py | 2 +-
> client/tests/kvm/kvm_subprocess.py | 60 ++++++++++++++++----------------
> client/tests/kvm/kvm_utils.py | 15 ++++----
> client/tests/kvm/kvm_vm.py | 6 ++--
> 5 files changed, 42 insertions(+), 43 deletions(-)
>
> 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", "")
prev parent reply other threads:[~2010-10-27 21:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-26 16:49 [KVM-AUTOTEST PATCH 1/5] KVM test: kvm_subprocess: raise exceptions in kvm_shell_session and kvm_expect Michael Goldish
2010-10-26 16:49 ` [KVM-AUTOTEST PATCH 2/5] KVM test: kvm_monitor.py: store attributes in QMPCmdError Michael Goldish
2010-10-26 16:49 ` [KVM-AUTOTEST PATCH 3/5] KVM test: add utility functions start_windows_service() and stop_windows_service() Michael Goldish
2010-10-26 16:49 ` [KVM-AUTOTEST PATCH 4/5] KVM test: kvm_subprocess: rename get_command_status_output() and friends Michael Goldish
2010-10-26 16:49 ` [KVM-AUTOTEST PATCH 5/5] [RFC] KVM test: kvm_subprocess: rename kvm_shell_session " Michael Goldish
2010-10-27 21:07 ` Lucas Meneghel Rodrigues [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1288213645.2516.160.camel@freedom \
--to=lmr@redhat.com \
--cc=autotest@test.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=mgoldish@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox