libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1454771 - in /libcloud/trunk/libcloud: compute/ssh.py test/compute/test_ssh_client.py
Date Sat, 09 Mar 2013 23:23:03 GMT
Author: tomaz
Date: Sat Mar  9 23:23:03 2013
New Revision: 1454771

URL: http://svn.apache.org/r1454771
Log:
Add some preliminary tests for ShellOutSSHClient.

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=1454771&r1=1454770&r2=1454771&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/ssh.py (original)
+++ libcloud/trunk/libcloud/compute/ssh.py Sat Mar  9 23:23:03 2013
@@ -300,6 +300,15 @@ class ShellOutSSHClient(BaseSSHClient):
         return cmd
 
     def _run_remote_shell_command(self, cmd):
+        """
+        Run a command on a remote server.
+
+        @param      cmd: Command to run.
+        @type       cmd: C{list} of C{str}
+
+        @return: Command stdout, stderr and status code.
+        @rtype: C{tuple}
+        """
         base_cmd = self._get_base_ssh_command()
         full_cmd = base_cmd + [' '.join(cmd)]
 

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=1454771&r1=1454770&r2=1454771&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/compute/test_ssh_client.py (original)
+++ libcloud/trunk/libcloud/test/compute/test_ssh_client.py Sat Mar  9 23:23:03 2013
@@ -18,6 +18,7 @@ import sys
 import unittest
 
 from libcloud.compute.ssh import ParamikoSSHClient
+from libcloud.compute.ssh import ShellOutSSHClient
 from libcloud.compute.ssh import have_paramiko
 
 from mock import patch, Mock
@@ -164,10 +165,69 @@ class ParamikoSSHClientTests(unittest.Te
 
         mock.close()
 
+
 if not ParamikoSSHClient:
     class ParamikoSSHClientTests(unittest.TestCase):
         pass
 
 
+class ShellOutSSHClientTests(unittest.TestCase):
+    def test_password_auth_not_supported(self):
+        try:
+            ShellOutSSHClient(hostname='localhost', username='foo',
+                              password='bar')
+        except ValueError:
+            e = sys.exc_info()[1]
+            msg = str(e)
+            self.assertTrue('ShellOutSSHClient only supports key auth' in msg)
+        else:
+            self.fail('Exception was not thrown')
+
+    def test_ssh_executable_not_available(self):
+        class MockChild(object):
+            returncode = 127
+
+            def communicate(*args, **kwargs):
+                pass
+
+        def mock_popen(*args, **kwargs):
+            return MockChild()
+
+        with patch('subprocess.Popen', mock_popen):
+            try:
+                ShellOutSSHClient(hostname='localhost', username='foo')
+            except ValueError:
+                e = sys.exc_info()[1]
+                msg = str(e)
+                self.assertTrue('ssh client is not available' in msg)
+            else:
+                self.fail('Exception was not thrown')
+
+    def test_connect_success(self):
+        client = ShellOutSSHClient(hostname='localhost', username='root')
+        self.assertTrue(client.connect())
+
+    def test_close_success(self):
+        client = ShellOutSSHClient(hostname='localhost', username='root')
+        self.assertEqual(client.close(), None)
+
+    def test_get_base_ssh_command(self):
+        client1 = ShellOutSSHClient(hostname='localhost', username='root')
+        client2 = ShellOutSSHClient(hostname='localhost', username='root',
+                                    key='/home/my.key')
+        client3 = ShellOutSSHClient(hostname='localhost', username='root',
+                                    key='/home/my.key', timeout=5)
+
+        cmd1 = client1._get_base_ssh_command()
+        cmd2 = client2._get_base_ssh_command()
+        cmd3 = client3._get_base_ssh_command()
+
+        self.assertEquals(cmd1, ['ssh', 'root@localhost'])
+        self.assertEquals(cmd2, ['ssh', '-i', '/home/my.key',
+                                 'root@localhost'])
+        self.assertEquals(cmd3, ['ssh', '-i', '/home/my.key',
+                                 '-oConnectTimeout=5', 'root@localhost'])
+
+
 if __name__ == '__main__':
     sys.exit(unittest.main())



Mime
View raw message