Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submit commands on another host via ssh #204

Merged
merged 17 commits into from
Aug 5, 2020
Merged

Submit commands on another host via ssh #204

merged 17 commits into from
Aug 5, 2020

Conversation

matthu017
Copy link
Contributor

Made Adapters::Helper.ssh_wrap to return commands wrapped in ssh

Matthew Hu added 2 commits June 19, 2020 16:01
Made Adapters::Helper.ssh_wrap to return this command wrapped in ssh
@matthu017 matthu017 linked an issue Jun 19, 2020 that may be closed by this pull request
@ericfranz
Copy link
Contributor

I mentioned one example inline, but for each adapter we want to keep both host and submit host as they are different values.

  • host is the host of the batch server we are submitting the job to
  • submit_host is the host where we are executing the job submission command

For example, I could specify the submit_host as being ruby.osc.edu and the host as being owens.osc.edu. Then I would be ssh-ing to ruby.osc.edu and executing qsub with the batch server specified as owens.osc.edu to submit a batch job running on owens.

Added commands to ssh
Made rspec tests for ssh wrapper
-defaults to yes

use to_s to guard against nil objects
@johrstrom
Copy link
Contributor

With the realization in #201 we may have to rethink how the job_environment works for this feature.

Instead of just passing the command, we may have to template a small script that can inline the correct environment variables (like the linux host adapter does). I don't believe we want to get involved with SendEnv and AcceptEnv just because that would require admins to go through some pain, then realize there's missing sshd configuration.

Let's look at how this would work for PBSPro.
job_environment is OK because it's a part of the command.

envvars = script.job_environment.to_h
args.concat ["-v", envvars.map{|k,v| "#{k}=#{v}"}.join(",")] unless envvars.empty?

But these two environment variables need to be passed to the destination. Anything that is set in the environment to the call or Open3 functions needs to be passed to the submit_host.

env["PBS_DEFAULT"] = host.to_s if host
env["PBS_EXEC"] = pbs_exec.to_s if pbs_exec

Maybe instead of templating a script (because that would require all the adapters to toggle the cmd or stdin - the script), we just inline the variables in the command.

Something to this affect:
ssh johrstrom@owens.osc.edu 'export FOO=BAR; echo $FOO'

The ssh_wrap interface probably expands to include environment you want to pass, and you prepend exports to it.

So submitting to owens with PBSPro adapter ends up resulting in a command like this:
ssh johrstrom@owens.osc.edu 'export PBS_DEFAULT=owens; qsub myscript.sh'

(Note that the quotes are important becuase the shell will see the ; as the terminating command which it isn't. At least not on the source side).

@johrstrom
Copy link
Contributor

Also, I thought adapters like Torque had some restriction because they use shared libraries (FFI) that may not be on the destination hosts?

@ericfranz
Copy link
Contributor

Torque does not use FFI for qsub

@johrstrom
Copy link
Contributor

Is that the behavior we want, where some things are executing on the submit_host and others on the webhost?

@ericfranz
Copy link
Contributor

#170 Addresses that. This PR is the first half, enabling only qsub by specifying submit_host: "some_other_host". Another feature would be adding use_submit_host_for_all_commands: true to enable the rest of the commands executed on the submit host. In Torque and SGE's cases this second step is problematic because of their use of FFI. We could drop FFI then.

command = ""
env.each {|key, value| command += "export #{key}=#{value}; "} # exports env vars
command += cmd_args.unshift(cmd).join(' ')
args.push(command)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does the same thing:

args.push(env.map {|k,v| "export #{key}=#{value};" } + [cmd] + cmd_args).join(' '))

though env.map {|k,v| "export #{key}=#{value};" } should be a separate method

Copy link
Contributor Author

@matthu017 matthu017 Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should a new method still be made for this with the current commit? There are quite a few params in this method already, but everything in this command deals with ssh wrapping.

@matthu017 matthu017 added the ready label Jul 8, 2020
check_host = strict_host_checking ? "yes" : "no"
args = ['-o', 'BatchMode=yes', '-o', 'UserKnownHostsFile=/dev/null', '-o', "StrictHostKeyChecking=#{check_host}", "#{submit_host}"]
env.each{|key, value| args.push("export #{key}=#{value};")}
args.concat(cmd_args.unshift(cmd))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd_args.unshift(cmd) modifies the argument cmd_args which should not happen. I know you just changed a bunch of + to concats, but in this case + may improve readability.

return 'ssh', args + [cmd] + cmd_args

@ericfranz ericfranz merged commit 1b3cdc8 into master Aug 5, 2020
@ericfranz ericfranz deleted the ssh_wrapper branch August 5, 2020 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the "ssh wrapper" pattern a first class citizen
3 participants