Return-Path: X-Original-To: apmail-libcloud-notifications-archive@www.apache.org Delivered-To: apmail-libcloud-notifications-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E161A18E3F for ; Wed, 27 Jan 2016 10:39:35 +0000 (UTC) Received: (qmail 50568 invoked by uid 500); 27 Jan 2016 10:39:29 -0000 Delivered-To: apmail-libcloud-notifications-archive@libcloud.apache.org Received: (qmail 50519 invoked by uid 500); 27 Jan 2016 10:39:29 -0000 Mailing-List: contact notifications-help@libcloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@libcloud.apache.org Delivered-To: mailing list notifications@libcloud.apache.org Received: (qmail 50463 invoked by uid 500); 27 Jan 2016 10:39:29 -0000 Delivered-To: apmail-libcloud-commits@libcloud.apache.org Received: (qmail 50413 invoked by uid 99); 27 Jan 2016 10:39:29 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Jan 2016 10:39:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3A899E00DC; Wed, 27 Jan 2016 10:39:29 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tomaz@apache.org To: commits@libcloud.apache.org Date: Wed, 27 Jan 2016 10:39:33 -0000 Message-Id: <098d136293fc4f6bb1b27684fac33a56@git.apache.org> In-Reply-To: <8bf647b21add423bbb68ec0e3b2607ac@git.apache.org> References: <8bf647b21add423bbb68ec0e3b2607ac@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [5/9] libcloud git commit: Fix a bug, add some tests. 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 Authored: Tue Jan 26 21:31:54 2016 +0100 Committer: Tomaz Muraus 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())