All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Goldish <mgoldish@redhat.com>
To: autotest@test.kernel.org, kvm@vger.kernel.org
Subject: [KVM-AUTOTEST PATCH 02/17] KVM test: kvm_utils.py: reorder remote_login(), remote_scp(), copy_files_to(), etc
Date: Mon,  3 Jan 2011 20:27:03 +0200	[thread overview]
Message-ID: <1294079238-21239-2-git-send-email-mgoldish@redhat.com> (raw)
In-Reply-To: <1294079238-21239-1-git-send-email-mgoldish@redhat.com>

Reorder the definition of these functions so that login functions are clustered
together, and higher level functions are further down in the file.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
 client/tests/kvm/kvm_utils.py |  180 ++++++++++++++++++++--------------------
 1 files changed, 90 insertions(+), 90 deletions(-)

diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 41117e3..c2918c9 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -575,6 +575,49 @@ def _remote_login(session, username, password, prompt, timeout=10):
             return False
 
 
+def remote_login(client, host, port, username, password, prompt, linesep="\n",
+                 log_filename=None, timeout=10):
+    """
+    Log into a remote host (guest) using SSH/Telnet/Netcat.
+
+    @param client: The client to use ('ssh', 'telnet' or 'nc')
+    @param host: Hostname or IP address
+    @param port: Port to connect to
+    @param username: Username (if required)
+    @param password: Password (if required)
+    @param prompt: Shell prompt (regular expression)
+    @param linesep: The line separator to use when sending lines
+            (e.g. '\\n' or '\\r\\n')
+    @param log_filename: If specified, log all output to this file
+    @param timeout: The maximal time duration (in seconds) to wait for
+            each step of the login procedure (i.e. the "Are you sure" prompt
+            or the password prompt)
+
+    @return: ShellSession object on success and None on failure.
+    """
+    if client == "ssh":
+        cmd = ("ssh -o UserKnownHostsFile=/dev/null "
+               "-o PreferredAuthentications=password -p %s %s@%s" %
+               (port, username, host))
+    elif client == "telnet":
+        cmd = "telnet -l %s %s %s" % (username, host, port)
+    elif client == "nc":
+        cmd = "nc %s %s" % (host, port)
+    else:
+        logging.error("Unknown remote shell client: %s" % client)
+        return
+
+    logging.debug("Trying to login with command '%s'" % cmd)
+    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)
+            session.set_output_params((log_filename,))
+        return session
+    else:
+        session.close()
+
+
 def _remote_scp(session, password, transfer_timeout=600, login_timeout=10):
     """
     Transfer file(s) to a remote host (guest) using SCP.  Wait for questions
@@ -627,49 +670,6 @@ def _remote_scp(session, password, transfer_timeout=600, login_timeout=10):
             return e.status == 0
 
 
-def remote_login(client, host, port, username, password, prompt, linesep="\n",
-                 log_filename=None, timeout=10):
-    """
-    Log into a remote host (guest) using SSH/Telnet/Netcat.
-
-    @param client: The client to use ('ssh', 'telnet' or 'nc')
-    @param host: Hostname or IP address
-    @param port: Port to connect to
-    @param username: Username (if required)
-    @param password: Password (if required)
-    @param prompt: Shell prompt (regular expression)
-    @param linesep: The line separator to use when sending lines
-            (e.g. '\\n' or '\\r\\n')
-    @param log_filename: If specified, log all output to this file
-    @param timeout: The maximal time duration (in seconds) to wait for
-            each step of the login procedure (i.e. the "Are you sure" prompt
-            or the password prompt)
-
-    @return: ShellSession object on success and None on failure.
-    """
-    if client == "ssh":
-        cmd = ("ssh -o UserKnownHostsFile=/dev/null "
-               "-o PreferredAuthentications=password -p %s %s@%s" %
-               (port, username, host))
-    elif client == "telnet":
-        cmd = "telnet -l %s %s %s" % (username, host, port)
-    elif client == "nc":
-        cmd = "nc %s %s" % (host, port)
-    else:
-        logging.error("Unknown remote shell client: %s" % client)
-        return
-
-    logging.debug("Trying to login with command '%s'" % cmd)
-    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)
-            session.set_output_params((log_filename,))
-        return session
-    else:
-        session.close()
-
-
 def remote_scp(command, password, log_filename=None, transfer_timeout=600,
                login_timeout=10):
     """
@@ -708,10 +708,54 @@ def remote_scp(command, password, log_filename=None, transfer_timeout=600,
         session.close()
 
 
+def scp_to_remote(host, port, username, password, local_path, remote_path,
+                  log_filename=None, timeout=600):
+    """
+    Copy files to a remote host (guest) through scp.
+
+    @param host: Hostname or IP address
+    @param username: Username (if required)
+    @param password: Password (if required)
+    @param local_path: Path on the local machine where we are copying from
+    @param remote_path: Path on the remote machine where we are copying to
+    @param log_filename: If specified, log all output to this file
+    @param timeout: The time duration (in seconds) to wait for the transfer
+            to complete.
+
+    @return: True on success and False on failure.
+    """
+    command = ("scp -v -o UserKnownHostsFile=/dev/null "
+               "-o PreferredAuthentications=password -r -P %s %s %s@%s:%s" %
+               (port, local_path, username, host, remote_path))
+    return remote_scp(command, password, log_filename, timeout)
+
+
+def scp_from_remote(host, port, username, password, remote_path, local_path,
+                    log_filename=None, timeout=600):
+    """
+    Copy files from a remote host (guest).
+
+    @param host: Hostname or IP address
+    @param username: Username (if required)
+    @param password: Password (if required)
+    @param local_path: Path on the local machine where we are copying from
+    @param remote_path: Path on the remote machine where we are copying to
+    @param log_filename: If specified, log all output to this file
+    @param timeout: The time duration (in seconds) to wait for the transfer
+            to complete.
+
+    @return: True on success and False on failure.
+    """
+    command = ("scp -v -o UserKnownHostsFile=/dev/null "
+               "-o PreferredAuthentications=password -r -P %s %s@%s:%s %s" %
+               (port, username, host, remote_path, local_path))
+    return remote_scp(command, password, log_filename, timeout)
+
+
 def copy_files_to(address, client, username, password, port, local_path,
                   remote_path, log_filename=None, timeout=600):
     """
-    Decide the transfer cleint and copy file to a remote host (guest).
+    Copy files to a remote host (guest) using the selected client.
 
     @param client: Type of transfer client
     @param username: Username (if required)
@@ -741,9 +785,9 @@ def copy_files_to(address, client, username, password, port, local_path,
 
 
 def copy_files_from(address, client, username, password, port, local_path,
-                  remote_path, log_filename=None, timeout=600):
+                    remote_path, log_filename=None, timeout=600):
     """
-    Decide the transfer cleint and copy file from a remote host (guest).
+    Copy files from a remote host (guest) using the selected client.
 
     @param client: Type of transfer client
     @param username: Username (if required)
@@ -772,50 +816,6 @@ def copy_files_from(address, client, username, password, port, local_path,
         return True
 
 
-def scp_to_remote(host, port, username, password, local_path, remote_path,
-                  log_filename=None, timeout=600):
-    """
-    Copy files to a remote host (guest) through scp.
-
-    @param host: Hostname or IP address
-    @param username: Username (if required)
-    @param password: Password (if required)
-    @param local_path: Path on the local machine where we are copying from
-    @param remote_path: Path on the remote machine where we are copying to
-    @param log_filename: If specified, log all output to this file
-    @param timeout: The time duration (in seconds) to wait for the transfer
-            to complete.
-
-    @return: True on success and False on failure.
-    """
-    command = ("scp -v -o UserKnownHostsFile=/dev/null "
-               "-o PreferredAuthentications=password -r -P %s %s %s@%s:%s" %
-               (port, local_path, username, host, remote_path))
-    return remote_scp(command, password, log_filename, timeout)
-
-
-def scp_from_remote(host, port, username, password, remote_path, local_path,
-                    log_filename=None, timeout=600):
-    """
-    Copy files from a remote host (guest).
-
-    @param host: Hostname or IP address
-    @param username: Username (if required)
-    @param password: Password (if required)
-    @param local_path: Path on the local machine where we are copying from
-    @param remote_path: Path on the remote machine where we are copying to
-    @param log_filename: If specified, log all output to this file
-    @param timeout: The time duration (in seconds) to wait for the transfer
-            to complete.
-
-    @return: True on success and False on failure.
-    """
-    command = ("scp -v -o UserKnownHostsFile=/dev/null "
-               "-o PreferredAuthentications=password -r -P %s %s@%s:%s %s" %
-               (port, username, host, remote_path, local_path))
-    return remote_scp(command, password, log_filename, timeout)
-
-
 # The following are utility functions related to ports.
 
 def is_port_free(port, address):
-- 
1.7.3.4

  reply	other threads:[~2011-01-03 18:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
2011-01-03 18:27 ` Michael Goldish [this message]
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 03/17] KVM test: use the new LoginError and SCPError exceptions Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 04/17] KVM test: add VM.wait_for_login() and kvm_utils.wait_for_login() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 05/17] KVM test: use the new wait_for_login() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 06/17] KVM test: rename VM.remote_login() to VM.login() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 07/17] KVM test: introduce VM exceptions Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 08/17] KVM test: let kvm_vm.create_image() raise a CmdError if qemu-img fails Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 09/17] KVM test: use the new VM exceptions Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 10/17] KVM test: add VM.verify_alive() and Monitor.verify_responsive() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 11/17] KVM test: use VM.verify_alive() instead of kvm_test_utils.get_living_vm() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 12/17] KVM test: kvm_preprocessing.py: simplify handling of params['migration_mode'] Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 13/17] KVM test: make migrate() a VM method Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 14/17] KVM test: simplify migration_with_reboot and migration_with_file_transfer Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 15/17] KVM test: use VM.migrate() instead of kvm_test_utils.migrate() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 16/17] KVM test: reorder kvm_utils.copy_files_from() path parameters Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 17/17] KVM test: rename path parameters in kvm_vm.copy_files_*() Michael Goldish

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=1294079238-21239-2-git-send-email-mgoldish@redhat.com \
    --to=mgoldish@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.