libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [5/9] libcloud git commit: Fix a bug, add some tests.
Date Wed, 27 Jan 2016 10:39:33 GMT
Fix a bug, add some tests.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/a14d27f9
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/a14d27f9
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/a14d27f9

Branch: refs/heads/trunk
Commit: a14d27f9b903a4a6b124945dda122cabece540e0
Parents: 5d55aad
Author: Tomaz Muraus <tomaz@apache.org>
Authored: Tue Jan 26 21:31:54 2016 +0100
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Tue Jan 26 21:31:54 2016 +0100

----------------------------------------------------------------------
 libcloud/compute/ssh.py                  |  1 +
 libcloud/test/compute/test_ssh_client.py | 82 +++++++++++++++++++++++++++
 2 files changed, 83 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/a14d27f9/libcloud/compute/ssh.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/ssh.py b/libcloud/compute/ssh.py
index 5013835..c65aab2 100644
--- a/libcloud/compute/ssh.py
+++ b/libcloud/compute/ssh.py
@@ -440,6 +440,7 @@ class ParamikoSSHClient(BaseSSHClient):
                     break
 
                 data = recv_method(self.CHUNK_SIZE)
+                result_bytes += b(data)
 
         # We only decode data at the end because a single chunk could contain
         # a part of multi byte UTF-8 character (whole multi bytes character

http://git-wip-us.apache.org/repos/asf/libcloud/blob/a14d27f9/libcloud/test/compute/test_ssh_client.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ssh_client.py b/libcloud/test/compute/test_ssh_client.py
index 772e175..5936eb2 100644
--- a/libcloud/test/compute/test_ssh_client.py
+++ b/libcloud/test/compute/test_ssh_client.py
@@ -320,6 +320,88 @@ class ShellOutSSHClientTests(LibcloudTestCase):
         self.assertEqual(cmd3, ['ssh', '-i', '/home/my.key',
                                 '-oConnectTimeout=5', 'root@localhost'])
 
+    def test_consume_stdout(self):
+        conn_params = {'hostname': 'dummy.host.org',
+                       'username': 'ubuntu'}
+        client = ParamikoSSHClient(**conn_params)
+        client.CHUNK_SIZE = 1024
+
+        chan = Mock()
+        chan.recv_ready.side_effect = [True, True, False]
+        chan.recv.side_effect = ['123', '456']
+
+        stdout = client._consume_stdout(chan).getvalue()
+        self.assertEqual(u'123456', stdout)
+        self.assertEqual(len(stdout), 6)
+
+        conn_params = {'hostname': 'dummy.host.org',
+                       'username': 'ubuntu'}
+        client = ParamikoSSHClient(**conn_params)
+        client.CHUNK_SIZE = 1024
+
+        chan = Mock()
+        chan.recv_ready.side_effect = [True, True, False]
+        chan.recv.side_effect = ['987', '6543210']
+
+        stdout = client._consume_stdout(chan).getvalue()
+        self.assertEqual(u'9876543210', stdout)
+        self.assertEqual(len(stdout), 10)
+
+    def test_consume_stderr(self):
+        conn_params = {'hostname': 'dummy.host.org',
+                       'username': 'ubuntu'}
+        client = ParamikoSSHClient(**conn_params)
+        client.CHUNK_SIZE = 1024
+
+        chan = Mock()
+        chan.recv_stderr_ready.side_effect = [True, True, False]
+        chan.recv_stderr.side_effect = ['123', '456']
+
+        stderr = client._consume_stderr(chan).getvalue()
+        self.assertEqual(u'123456', stderr)
+        self.assertEqual(len(stderr), 6)
+
+        conn_params = {'hostname': 'dummy.host.org',
+                       'username': 'ubuntu'}
+        client = ParamikoSSHClient(**conn_params)
+        client.CHUNK_SIZE = 1024
+
+        chan = Mock()
+        chan.recv_stderr_ready.side_effect = [True, True, False]
+        chan.recv_stderr.side_effect = ['987', '6543210']
+
+        stderr = client._consume_stderr(chan).getvalue()
+        self.assertEqual(u'9876543210', stderr)
+        self.assertEqual(len(stderr), 10)
+
+    def test_consume_stdout_chunk_contains_part_of_multi_byte_utf8_character(self):
+        conn_params = {'hostname': 'dummy.host.org',
+                       'username': 'ubuntu'}
+        client = ParamikoSSHClient(**conn_params)
+        client.CHUNK_SIZE = 1
+
+        chan = Mock()
+        chan.recv_ready.side_effect = [True, True, True, True, False]
+        chan.recv.side_effect = ['\xF0', '\x90', '\x8D', '\x88']
+
+        stdout = client._consume_stdout(chan).getvalue()
+        self.assertEqual(u'\U00010348', stdout)
+        self.assertEqual(len(stdout), 1)
+
+    def test_consume_stderr_chunk_contains_part_of_multi_byte_utf8_character(self):
+        conn_params = {'hostname': 'dummy.host.org',
+                       'username': 'ubuntu'}
+        client = ParamikoSSHClient(**conn_params)
+        client.CHUNK_SIZE = 1
+
+        chan = Mock()
+        chan.recv_stderr_ready.side_effect = [True, True, True, True, False]
+        chan.recv_stderr.side_effect = ['\xF0', '\x90', '\x8D', '\x88']
+
+        stderr = client._consume_stderr(chan).getvalue()
+        self.assertEqual(u'\U00010348', stderr)
+        self.assertEqual(len(stderr), 1)
+
 
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message