Skip to content
Merged
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
15 changes: 15 additions & 0 deletions machine/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,18 @@ def scp(self, source, destination, recursive=False):
cmd = ["scp"] + r + [source, destination]
stdout, _, _ = self._run(cmd)
return stdout.split()

def ssh(self, machine, cmd):
"""
Run a command on a machine through docker-machine ssh

Args:
machine (str): machine name
cmd (str): command to run

Returns:
List[str]: output of the ssh command
"""
ssh_cmd = ['ssh', machine, cmd]
stdout, _, _ = self._run(ssh_cmd)
return stdout.split()
6 changes: 5 additions & 1 deletion tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def tearDownClass(cls):
cls.machine.rm(machine=TEMPORARY_MACHINE)
except RuntimeError:
pass

def setUp(self):
if not self.machine.status(machine=TEST_MACHINE):
self.machine.start(machine=TEST_MACHINE)
Expand Down Expand Up @@ -81,6 +81,10 @@ def test_scp(self):
destination = "%s:." % TEST_MACHINE
self.machine.scp(source, destination)

def test_ssh_echo(self):
self.assertTrue(self.machine.exists(machine=TEST_MACHINE))
self.assertEqual(self.machine.ssh(TEST_MACHINE, 'echo \"Hi\"'), ['Hi'])

def test_start(self):
self.machine.stop(machine=TEST_MACHINE)
self.machine.start(machine=TEST_MACHINE)
Expand Down