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

Systemd fixups #868

Merged
merged 3 commits into from
Feb 7, 2025
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
23 changes: 7 additions & 16 deletions lib/ood_core/job/adapters/systemd/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,20 @@ def call(cmd, *args, env: {}, stdin: "")
# @param cmd [Array<#to_s>] the command to be executed on the destination host
def ssh_cmd(destination_host, cmd)

sshcmd=[
sshcmd = [
'ssh', '-t',
'-p', OodCore::Job::Adapters::Helper.ssh_port,
'-o', 'Batchmode=yes',
]

if !strict_host_checking
sshcmd.concat([
'-o','StrictHostKeyChecking=no',
'-o','UserKnownHostsFile=/dev/null',
])
end

if (!ssh_keyfile.to_s.empty?)
sshcmd.concat([
'-i',ssh_keyfile.to_s,
])
end

sshcmd.concat([
"#{username}@#{destination_host}"
]).concat(cmd)
'-o','StrictHostKeyChecking=no',
'-o','UserKnownHostsFile=/dev/null',
]) unless strict_host_checking

sshcmd.concat(['-i',ssh_keyfile.to_s,]) unless ssh_keyfile.to_s.empty?

sshcmd.concat(["#{username}@#{destination_host}"]).concat(cmd)
end

def shell
Expand Down
51 changes: 51 additions & 0 deletions test/job/adapters/systemd_launcher_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'test_helper'
require 'ood_core/job/adapters/systemd'
require 'ood_core/job/adapters/systemd/launcher'

class SystemdLauncherTest < Minitest::Test
include TestHelper

def launcher_instance(config = {})
default = { ssh_hosts: ['foo'], submit_host: 'localhost' }
OodCore::Job::Adapters::LinuxSystemd::Launcher.new(**default.merge(config))
end

def setup
Etc.stubs(:getlogin).returns('testuser')
end

def test_instantiation
launcher = launcher_instance

refute_nil(launcher)
end

def test_ssh_cmd_default
launcher = launcher_instance
expected = [ 'ssh', '-t', '-p', '22', '-o',
'Batchmode=yes', '-o', 'StrictHostKeyChecking=no', '-o', 'UserKnownHostsFile=/dev/null',
'testuser@localhost', '/bin/bash'
]

assert_equal(expected, launcher.send(:ssh_cmd, 'localhost', ['/bin/bash']))
end

def test_ssh_cmd_with_host_checking
launcher = launcher_instance({ strict_host_checking: true })
expected = [ 'ssh', '-t', '-p', '22', '-o',
'Batchmode=yes', 'testuser@localhost', '/bin/bash'
]

assert_equal(expected, launcher.send(:ssh_cmd, 'localhost', ['/bin/bash']))
end

def test_ssh_cmd_with_keyfile
launcher = launcher_instance({ ssh_keyfile: "~/.ssh/my_key" })
expected = [ 'ssh', '-t', '-p', '22', '-o',
'Batchmode=yes', '-o', 'StrictHostKeyChecking=no', '-o', 'UserKnownHostsFile=/dev/null',
'-i', '~/.ssh/my_key', 'testuser@localhost', '/bin/bash'
]

assert_equal(expected, launcher.send(:ssh_cmd, 'localhost', ['/bin/bash']))
end
end
15 changes: 15 additions & 0 deletions test/job/adapters/systemd_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'test_helper'

class SystemdTest < Minitest::Test
include TestHelper

def systemd_instance(config = { })
OodCore::Job::Factory.build({ adapter: 'systemd' }.merge(config))
end

def test_instantiation
sysd = systemd_instance

refute_nil(sysd)
end
end