Skip to content

Commit

Permalink
Merge pull request #188 from OSC/lha-tcsh-fix
Browse files Browse the repository at this point in the history
lha bug fixes
  • Loading branch information
ericfranz authored May 11, 2020
2 parents b61555b + f53f2f1 commit 04e1e53
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
20 changes: 12 additions & 8 deletions lib/ood_core/job/adapters/linux_host/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def initialize(
# @param hostname [#to_s] The hostname to submit the work to
# @param script [OodCore::Job::Script] The script object defining the work
def start_remote_session(script)
cmd = ssh_cmd(submit_host(script))
cmd = ssh_cmd(submit_host(script), ['/usr/bin/env', 'bash'])

session_name = unique_session_name
output = call(*cmd, stdin: wrapped_script(script, session_name))
Expand All @@ -67,13 +67,13 @@ def start_remote_session(script)
end

def stop_remote_session(session_name, hostname)
cmd = ssh_cmd(hostname)
cmd = ssh_cmd(hostname, ['/usr/bin/env', 'bash'])

kill_cmd = <<~SCRIPT
# Get the tmux pane PID for the target session
pane_pid=$(tmux list-panes -aF '\#{session_name} \#{pane_pid}' | grep '#{session_name}' | cut -f 2 -d ' ')
# Find the Singularity sinit PID child of the pane process
pane_sinit_pid=$(pstree -p "$pane_pid" | grep -o 'sinit([[:digit:]]*' | grep -o '[[:digit:]]*')
pane_sinit_pid=$(pstree -p -l "$pane_pid" | grep -o 'sinit([[:digit:]]*' | grep -o '[[:digit:]]*')
# Kill sinit which stops both Singularity-based processes and the tmux session
kill "$pane_sinit_pid"
SCRIPT
Expand Down Expand Up @@ -116,27 +116,31 @@ def call(cmd, *args, env: {}, stdin: "")
s.success? ? o : raise(Error, e)
end

# The SSH invocation to send a command
# The full command to ssh into the destination host and execute the command.
# SSH options include:
# -t Force pseudo-terminal allocation (required to allow tmux to run)
# -o BatchMode=yes (set mode to be non-interactive)
# if ! strict_host_checking
# -o UserKnownHostsFile=/dev/null (do not update the user's known hosts file)
# -o StrictHostKeyChecking=no (do no check the user's known hosts file)
def ssh_cmd(destination_host)
#
# @param destination_host [#to_s] the destination host you wish to ssh into
# @param cmd [Array<#to_s>] the command to be executed on the destination host
def ssh_cmd(destination_host, cmd)
if strict_host_checking
[
'ssh', '-t',
'-o', 'BatchMode=yes',
"#{username}@#{destination_host}"
]
].concat(cmd)
else
[
'ssh', '-t',
'-o', 'BatchMode=yes',
'-o', 'UserKnownHostsFile=/dev/null',
'-o', 'StrictHostKeyChecking=no',
"#{username}@#{destination_host}"
]
].concat(cmd)
end
end

Expand Down Expand Up @@ -245,7 +249,7 @@ def list_remote_tmux_session(destination_host)
['#{session_name}', '#{session_created}', '#{pane_pid}'].join(UNIT_SEPARATOR)
)
keys = [:session_name, :session_created, :session_pid]
cmd = ssh_cmd(destination_host) + ['tmux', 'list-panes', '-aF', format_str]
cmd = ssh_cmd(destination_host, ['tmux', 'list-panes', '-aF', format_str])

call(*cmd).split(
"\n"
Expand Down
11 changes: 7 additions & 4 deletions spec/job/adapters/linux_host/launcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,26 @@ def content
describe "#ssh_cmd" do
let(:username) { Etc.getlogin }
context "when strict_host_checking is true" do
let(:ssh_cmd) { subject.send(:ssh_cmd, 'remote_host') }
let(:ssh_cmd) { subject.send(:ssh_cmd, 'remote_host', ['/bin/bash']) }

it "uses the correct SSH options" do
expect(ssh_cmd).to eq(['ssh', '-t', '-o', 'BatchMode=yes', "#{username}@remote_host"])
expect(ssh_cmd).to eq(['ssh', '-t', '-o', 'BatchMode=yes', "#{username}@remote_host", '/bin/bash'])
end
end

context "when strict_host_checking is false" do
let(:ssh_cmd) { described_class.new(**opts.merge({strict_host_checking: false})).send(:ssh_cmd, 'remote_host') }
let(:ssh_cmd) {
described_class.new(**opts.merge({strict_host_checking: false})).send(:ssh_cmd, 'remote_host', ['/bin/bash'])
}

it "uses the correct SSH options" do
expect(ssh_cmd).to eq([
'ssh', '-t',
'-o', 'BatchMode=yes',
'-o', 'UserKnownHostsFile=/dev/null',
'-o', 'StrictHostKeyChecking=no',
"#{username}@remote_host"
"#{username}@remote_host",
"/bin/bash"
])
end
end
Expand Down

0 comments on commit 04e1e53

Please sign in to comment.