Skip to content

Commit f8c2f25

Browse files
committed
improved feedback from ssh command process
1 parent 748536f commit f8c2f25

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

juju/machine.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,13 @@ async def ssh(
164164
cmd.extend(ssh_opts.split() if isinstance(ssh_opts, str) else ssh_opts)
165165
cmd.extend([command])
166166
loop = self.model.loop
167-
process = await asyncio.create_subprocess_exec(*cmd, loop=loop)
168-
await process.wait()
167+
process = await asyncio.create_subprocess_exec(
168+
*cmd, loop=loop, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
169+
stdout, stderr = await process.communicate()
169170
if process.returncode != 0:
170-
raise JujuError("command failed: %s" % cmd)
171+
raise JujuError("command failed: %s with %s" % (cmd, stderr.decode()))
172+
# stdout is a bytes-like object, returning a string might be more useful
173+
return stdout.decode()
171174

172175
def status_history(self, num=20, utc=False):
173176
"""Get status history for this machine.

0 commit comments

Comments
 (0)