diff --git a/lib/beaker/host/unix/exec.rb b/lib/beaker/host/unix/exec.rb index 08ea8d677..7542981e4 100644 --- a/lib/beaker/host/unix/exec.rb +++ b/lib/beaker/host/unix/exec.rb @@ -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/ @@ -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 diff --git a/spec/beaker/host/unix/exec_spec.rb b/spec/beaker/host/unix/exec_spec.rb index 04ea84055..15eaef7d7 100644 --- a/spec/beaker/host/unix/exec_spec.rb +++ b/spec/beaker/host/unix/exec_spec.rb @@ -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 @@ -104,7 +106,7 @@ 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) @@ -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 diff --git a/spec/helpers.rb b/spec/helpers.rb index b95960d00..b6d918582 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -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