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

Add ssh restart for Ubuntu #1885

Merged
merged 1 commit into from
May 24, 2024
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
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"))
joshcooper marked this conversation as resolved.
Show resolved Hide resolved
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
15 changes: 13 additions & 2 deletions 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::REDHATPLATFORMS + PlatformHelpers::DEBIANPLATFORMS

platforms.each do |platform|
it "calls the correct commands for #{platform}" do
opts['platform'] = platform
expect(instance).to receive(:exec).twice
Expand All @@ -104,14 +106,23 @@ def to_s
end

describe '#ssh_service_restart' do
PlatformHelpers::SYSTEMDPLATFORMS.each do |platform|
PlatformHelpers::REDHATPLATFORMS.each do |platform|
it "calls the correct command for #{platform}" do
opts['platform'] = platform
expect(instance).to receive(:exec)
expect(Beaker::Command).to receive(:new).with("systemctl restart sshd.service")
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
18 changes: 10 additions & 8 deletions spec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ def make_instance instance_data = {}
module PlatformHelpers
DEBIANPLATFORMS = %w[debian ubuntu]

SYSTEMDPLATFORMS = %w[amazon-2023
fedora
el-
centos
redhat
oracle
scientific
archlinux].concat(DEBIANPLATFORMS)
REDHATPLATFORMS = %w[
amazon-2023
fedora
el-
centos
redhat
oracle
scientific
archlinux
]
end