Skip to content

Commit

Permalink
Using service ssh restart for Ubuntu, Debian
Browse files Browse the repository at this point in the history
Fix Rubocop
  • Loading branch information
skyamgarp committed May 23, 2024
1 parent 7053494 commit 4d172f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/beaker/host/unix/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ def clear_env_var key
# @return [Result] result of restarting the SSH service
def ssh_service_restart
case self['platform']
when /debian|ubuntu/
exec(Beaker::Command.new("systemctl restart ssh"))
when /(el|centos|redhat|oracle|scientific)-[0-6]/
exec(Beaker::Command.new("/sbin/service sshd restart"))
when /solaris/
Expand All @@ -302,7 +304,7 @@ def ssh_permit_user_environment
directory = tmpdir
exec(Beaker::Command.new("echo 'PermitUserEnvironment yes' | cat - /etc/ssh/sshd_config > #{directory}/sshd_config.permit"))
exec(Beaker::Command.new("mv #{directory}/sshd_config.permit /etc/ssh/sshd_config"))
exec(Beaker::Command.new("echo '' >/etc/environment")) if /ubuntu-2(0|2).04/.match?(self['platform'])
exec(Beaker::Command.new("echo '' >/etc/environment")) if self['platform'].include?('ubuntu')
when /(free|open)bsd/
exec(Beaker::Command.new("sudo perl -pi -e 's/^#?PermitUserEnvironment no/PermitUserEnvironment yes/' /etc/ssh/sshd_config"), { :pty => true })
else
Expand Down
13 changes: 12 additions & 1 deletion spec/beaker/host/unix/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def to_s
let(:ssh_command) { "echo 'PermitUserEnvironment yes' | cat - /etc/ssh/sshd_config > #{directory}/sshd_config.permit" }
let(:ssh_move) { "mv #{directory}/sshd_config.permit /etc/ssh/sshd_config" }

PlatformHelpers::SYSTEMDPLATFORMS.each do |platform|
platforms = PlatformHelpers::SYSTEMDPLATFORMS + PlatformHelpers::DEBIANPLATFORMS

platforms.each do |platform|
it "calls the correct commands for #{platform}" do
opts['platform'] = platform
expect(instance).to receive(:exec).twice
Expand Down Expand Up @@ -112,6 +114,15 @@ def to_s
expect { instance.ssh_service_restart }.not_to raise_error
end
end

PlatformHelpers::DEBIANPLATFORMS.each do |platform|
it "calls the ssh service restart command for #{platform}" do
opts['platform'] = platform
expect(instance).to receive(:exec)
expect(Beaker::Command).to receive(:new).with("systemctl restart ssh")
expect { instance.ssh_service_restart }.not_to raise_error
end
end
end

describe '#prepend_commands' do
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,5 @@ module PlatformHelpers
redhat
oracle
scientific
archlinux].concat(DEBIANPLATFORMS)
archlinux]
end

0 comments on commit 4d172f3

Please sign in to comment.