Skip to content

Commit

Permalink
Refs #30193 - always execute commands outside the SCL context
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Jun 24, 2020
1 parent 0045820 commit 2cfd052
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
22 changes: 4 additions & 18 deletions hooks/boot/01-kafo-hook-extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,16 @@ def execute(commands, do_say = true, do_log = true)
end

def execute_command(command, do_say, do_log)
IO.popen("#{command} 2>&1") do |io|
while (line = io.gets)
line.chomp!
log_and_say(:debug, line, do_say, do_log)
end
io.close
if $CHILD_STATUS.success?
log_and_say(:debug, "#{command} finished successfully!", do_say, do_log)
else
log_and_say(:error, "#{command} failed! Check the output for error!", do_say, do_log)
end
$CHILD_STATUS.success?
end
end

def execute_command_nonscl(command, do_say, do_log)
log_and_say(:debug, "Executing: #{command}", do_say, do_log)

_stdout, stderr, status = Open3.capture3(*Kafo::PuppetCommand.format_command(command))
stdout_stderr, status = Open3.capture2e(*Kafo::PuppetCommand.format_command(command))
stdout_stderr.lines.map(&:chomp).each do |line|
log_and_say(:debug, line, do_say, do_log)
end

if status.success?
log_and_say(:debug, "#{command} finished successfully!", do_say, do_log)
else
log_and_say(:debug, stderr, do_say, do_log)
log_and_say(:error, "#{command} failed! Check the output for error!", do_say, do_log)
end
status.success?
Expand Down
2 changes: 1 addition & 1 deletion hooks/boot/03-foreman-maintain-extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def stop_services(services = nil)

def foreman_maintain(command, exit_on_fail = false)
command = "foreman-maintain #{command}"
status = execute_command_nonscl(command, false, true)
status = execute_command(command, false, true)

exit 1 if exit_on_fail && !status
status
Expand Down
4 changes: 2 additions & 2 deletions hooks/pre_validations/31-puppet-agent-oauth.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
unless app_value(:noop)
if File.exist?('/opt/puppetlabs/puppet/bin/ruby') && execute_command("rpm -q puppet-agent-oauth", false, false)
unless execute_command_nonscl("/opt/puppetlabs/puppet/bin/ruby -e \"require 'oauth'\"", false, false)
execute_command_nonscl("yum -y reinstall puppet-agent-oauth", false, true)
unless execute_command("/opt/puppetlabs/puppet/bin/ruby -e \"require 'oauth'\"", false, false)
execute_command("yum -y reinstall puppet-agent-oauth", false, true)
end
end
end

0 comments on commit 2cfd052

Please sign in to comment.