Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justinjfu committed Jan 26, 2019
1 parent 1cbcf6e commit 7bc56e4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
8 changes: 3 additions & 5 deletions doodad/credentials/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ def get_ssh_bash_cmd(self, cmd):
prefix = self.get_ssh_cmd_prefix()
return prefix + " '%s'"%cmd

def get_ssh_script_cmd(self, script_name):
cmd = 'ssh %s@%s' % (self.username, self.hostname)
if self.identity_file:
cmd += ' -i %s' % self.identity_file
cmd += " 'bash -s' < %s" % script_name
def get_ssh_script_cmd(self, script_name, shell_interpreter='bash'):
cmd = self.get_ssh_cmd_prefix()
cmd += "'%s -s' < %s" % (shell_interpreter, script_name)
return cmd

def get_scp_cmd(self, source, destination, src_remote=True, recursive=True):
Expand Down
13 changes: 13 additions & 0 deletions doodad/credentials/test_ssh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest

from doodad.credentials import ssh

class TestSSHCreds(unittest.TestCase):
def test_user_host(self):
creds = ssh.get_credentials(username='a', hostname='b.com')
self.assertEqual(creds.user_host, '[email protected]')

def test_global_set(self):
ssh.set_identity_file('mykey')
creds = ssh.get_credentials(username='a', hostname='b.com')
self.assertEqual(creds.identity_file, 'mykey')
2 changes: 1 addition & 1 deletion doodad/darchive/test_archive_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_gcp(self):
"""
mnts = []
mnts.append(mount.MountGCP(
local_dir='test_dir',
gcp_path='test_dir',
dry=True,
))
payload_script = 'echo hello123'
Expand Down
3 changes: 2 additions & 1 deletion doodad/launch/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def __init__(self, ssh_credentials, **kwargs):
self.ssh_cred = ssh_credentials

def _get_run_command(self, script_filename):
return self.ssh_cred.get_ssh_script_cmd(script_filename)
return self.ssh_cred.get_ssh_script_cmd(script_filename,
shell_interpreter=self.shell_interpreter)


class GCPMode(LaunchMode):
Expand Down
2 changes: 1 addition & 1 deletion doodad/launch/test_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def test_mode(self):
launcher = mode.SSHMode(credentials, shell_interpreter='bashy')
self.assertEqual(
launcher._get_run_command('myscript.sh'),
'ssh [email protected] -s \'bashy -s \' < myscript.sh'
'ssh [email protected] \'bashy -s\' < myscript.sh'
)
2 changes: 1 addition & 1 deletion scripts/gcp/gcp_shutdown_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bucket_name=$(query_metadata bucket_name)
gcp_bucket_path=$(query_metadata gcp_bucket_path)
instance_name=$(curl http://metadata/computeMetadata/v1/instance/name -H "Metadata-Flavor: Google")

gsutil cp -r /doodad gs://$bucket_name/$gcp_bucket_path/logs
gsutil cp -r /doodad/* gs://$bucket_name/$gcp_bucket_path/logs
# sync stdout
gcp_bucket_path=${gcp_bucket_path%/} # remove trailing slash if present
gsutil cp /home/ubuntu/user_data.log gs://$bucket_name/$gcp_bucket_path/${instance_name}_stdout.log

0 comments on commit 7bc56e4

Please sign in to comment.