Skip to content

Commit

Permalink
Merge pull request #8 from MaralAfris/add_ssh_cmd
Browse files Browse the repository at this point in the history
Add ssh cmd
  • Loading branch information
gijzelaerr authored Mar 3, 2017
2 parents 05c96eb + 5d06aa8 commit 4379ea9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit 4379ea9

Please sign in to comment.