libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1454785 - in /libcloud/trunk/libcloud: compute/ssh.py test/compute/test_ssh_client.py
Date Sun, 10 Mar 2013 04:42:36 GMT
Author: tomaz
Date: Sun Mar 10 04:42:36 2013
New Revision: 1454785

URL: http://svn.apache.org/r1454785
Log:
Change SSHClient interface a bit and make "put" method return a full path to the
location where a file has been saved.

Modified:
    libcloud/trunk/libcloud/compute/ssh.py
    libcloud/trunk/libcloud/test/compute/test_ssh_client.py

Modified: libcloud/trunk/libcloud/compute/ssh.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/ssh.py?rev=1454785&r1=1454784&r2=1454785&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/ssh.py (original)
+++ libcloud/trunk/libcloud/compute/ssh.py Sun Mar 10 04:42:36 2013
@@ -70,7 +70,9 @@ class BaseSSHClient(object):
         """
         Connect to the remote node over SSH.
 
-        @return: C{bool}
+        @return: True if the connection has been successfuly established, False
+                 otherwise.
+        @rtype: C{bool}
         """
         raise NotImplementedError(
             'connect not implemented for this ssh client')
@@ -90,6 +92,9 @@ class BaseSSHClient(object):
 
         @type mode: C{str}
         @keyword mode: Mode in which the file is opened.
+
+        @return: Full path to the location where a file has been saved.
+        @rtype: C{str}
         """
         raise NotImplementedError(
             'put not implemented for this ssh client')
@@ -100,6 +105,10 @@ class BaseSSHClient(object):
 
         @type path: C{str}
         @keyword path: File path on the remote node.
+
+        @return: True if the file has been successfuly deleted, False
+                 otherwise.
+        @rtype: C{bool}
         """
         raise NotImplementedError(
             'delete not implemented for this ssh client')
@@ -119,6 +128,10 @@ class BaseSSHClient(object):
     def close(self):
         """
         Shutdown connection to the remote node.
+
+        @return: True if the connection has been successfuly closed, False
+                 otherwise.
+        @rtype: C{bool}
         """
         raise NotImplementedError(
             'close not implemented for this ssh client')
@@ -178,6 +191,8 @@ class ParamikoSSHClient(BaseSSHClient):
                     pass
                 sftp.chdir(part)
 
+        cwd = sftp.getcwd()
+
         ak = sftp.file(tail, mode=mode)
         ak.write(contents)
         if chmod is not None:
@@ -185,6 +200,13 @@ class ParamikoSSHClient(BaseSSHClient):
         ak.close()
         sftp.close()
 
+        if path[0] == '/':
+            file_path = path
+        else:
+            file_path = pjoin(cwd, path)
+
+        return file_path
+
     def delete(self, path):
         sftp = self.client.open_sftp()
         sftp.unlink(path)
@@ -208,6 +230,7 @@ class ParamikoSSHClient(BaseSSHClient):
 
     def close(self):
         self.client.close()
+        return True
 
 
 class ShellOutSSHClient(BaseSSHClient):
@@ -260,7 +283,7 @@ class ShellOutSSHClient(BaseSSHClient):
         self._run_remote_shell_command(cmd)
 
     def close(self):
-        pass
+        return True
 
     def _get_and_setup_logger(self):
         logger = logging.getLogger('libcloud.compute.ssh')

Modified: libcloud/trunk/libcloud/test/compute/test_ssh_client.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/compute/test_ssh_client.py?rev=1454785&r1=1454784&r2=1454785&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/compute/test_ssh_client.py (original)
+++ libcloud/trunk/libcloud/test/compute/test_ssh_client.py Sun Mar 10 04:42:36 2013
@@ -211,7 +211,7 @@ class ShellOutSSHClientTests(unittest.Te
 
     def test_close_success(self):
         client = ShellOutSSHClient(hostname='localhost', username='root')
-        self.assertEqual(client.close(), None)
+        self.assertTrue(client.close())
 
     def test_get_base_ssh_command(self):
         client1 = ShellOutSSHClient(hostname='localhost', username='root')



Mime
View raw message