From a7848ad40d81f32d143013da0c1463a78dc75fcf Mon Sep 17 00:00:00 2001 From: skyamgarp <130442619+skyamgarp@users.noreply.github.com> Date: Fri, 17 May 2024 21:20:58 +0530 Subject: [PATCH] Using service ssh restart for Ubuntu, Debian Fix Rubocop Fixed failing test --- lib/beaker/host/unix/exec.rb | 4 +++- spec/beaker/host/unix/exec_spec.rb | 13 ++++++++++++- spec/helpers.rb | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) 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..32d03c20f 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::SYSTEMDPLATFORMS + PlatformHelpers::DEBIANPLATFORMS + + platforms.each do |platform| it "calls the correct commands for #{platform}" do opts['platform'] = platform expect(instance).to receive(:exec).twice @@ -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..6b1916b78 100644 --- a/spec/helpers.rb +++ b/spec/helpers.rb @@ -129,5 +129,5 @@ module PlatformHelpers redhat oracle scientific - archlinux].concat(DEBIANPLATFORMS) + archlinux] end