Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ Common
Compute
~~~~~~~

- [SSH] Fix ``ShellOutSSHClient.run()`` returning the command's standard output in
place of its standard error.
(#2259)
[Abed Alawiyeh - @abedalawieh]

- [OVH] Remove the static location mapping and use the location code returned
by the API as both the location ID and name, avoiding failures for codes not
known to Libcloud.
Expand Down
2 changes: 1 addition & 1 deletion libcloud/compute/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ def _run_remote_shell_command(self, cmd):
stdout, stderr = child.communicate()

stdout_str = cast(str, stdout)
stderr_str = cast(str, stdout)
stderr_str = cast(str, stderr)

return (stdout_str, stderr_str, child.returncode)

Expand Down
18 changes: 18 additions & 0 deletions libcloud/test/compute/test_ssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,24 @@ def test_get_base_ssh_command(self):
cmd3, ["ssh", "-i", "/home/my.key", "-oConnectTimeout=5", "root@localhost"]
)

def test_run_returns_stdout_and_stderr(self):
class MockChild:
returncode = 0

def communicate(*args, **kwargs):
return (b"out", b"err")

def mock_popen(*args, **kwargs):
return MockChild()

with patch("subprocess.Popen", mock_popen):
client = ShellOutSSHClient(hostname="localhost", username="root")
stdout, stderr, status = client.run("ls")

self.assertEqual(stdout, b"out")
self.assertEqual(stderr, b"err")
self.assertEqual(status, 0)


if __name__ == "__main__":
sys.exit(unittest.main())