Bug #31135

foreman-maintain package lock check indicates false failure

Added by Eric Helms 3 months ago. Updated about 2 months ago.

foreman-installer script
Target version:
Bugzilla link:
Fixed in Releases:
Found in Releases:


Cloned from


We have logic that attempts to detect if foreman-maintain is installed and package locking is enabled but the output isn't being interpreted correctly.

if !app_value(:noop) && [0, 2].include?(@kafo.exit_code) && foreman_server?
execute('foreman-rake upgrade:run')
which appears to kick off if the kafo-puppet run had a "bad" exit code.

Looking back at that puppet run, the only error I see is
[ INFO 2020-09-18T18:21:00 verbose] Executing hooks in group pre_commit
[ERROR 2020-09-18T18:21:05 verbose] foreman-maintain packages is-locked --assumeyes failed! Check the output for error!
[ INFO 2020-09-18T18:21:05 verbose] All hooks in group pre_commit finished
There are a number of warnings though.

Running that command gives:
root@tstr000047:/var/log/foreman-installer $ foreman-maintain packages is-locked --assumeyes; echo $?
Packages are not locked

I ran it again with debug and captured this:
[ INFO 2020-09-18T19:03:39 main] Executing hooks in group pre_commit
[DEBUG 2020-09-18T19:03:39 main] Hook /usr/share/foreman-installer/katello/hooks/pre_commit/05-puppet_certs_exist.rb returned nil
[DEBUG 2020-09-18T19:03:39 main] Executing: foreman-maintain packages -h
[DEBUG 2020-09-18T19:03:41 main] Usage:
[DEBUG 2020-09-18T19:03:41 main] foreman-maintain packages [OPTIONS] SUBCOMMAND [ARG] ...
[DEBUG 2020-09-18T19:03:41 main]
[DEBUG 2020-09-18T19:03:41 main] Parameters:
[DEBUG 2020-09-18T19:03:41 main] SUBCOMMAND subcommand
[DEBUG 2020-09-18T19:03:41 main] [ARG] ... subcommand arguments
[DEBUG 2020-09-18T19:03:41 main]
[DEBUG 2020-09-18T19:03:41 main] Subcommands:
[DEBUG 2020-09-18T19:03:41 main] lock Prevent packages from automatic update
[DEBUG 2020-09-18T19:03:41 main] unlock Enable packages for automatic update
[DEBUG 2020-09-18T19:03:41 main] status Check if packages are protected against update
[DEBUG 2020-09-18T19:03:41 main] install Install packages in an unlocked session
[DEBUG 2020-09-18T19:03:41 main] update Update packages in an unlocked session
[DEBUG 2020-09-18T19:03:41 main] is-locked Check if update of packages is allowed
[DEBUG 2020-09-18T19:03:41 main]
[DEBUG 2020-09-18T19:03:41 main] Options:
[DEBUG 2020-09-18T19:03:41 main] -h, --help print help
[DEBUG 2020-09-18T19:03:41 main] foreman-maintain packages -h finished successfully!
[DEBUG 2020-09-18T19:03:41 main] Executing: foreman-maintain packages is-locked --assumeyes
[DEBUG 2020-09-18T19:03:43 main] Packages are not locked
[ERROR 2020-09-18T19:03:43 main] foreman-maintain packages is-locked --assumeyes failed! Check the output for error!
[DEBUG 2020-09-18T19:03:43 main] Hook /usr/share/foreman-installer/katello/hooks/pre_commit/09-version_locking.rb returned nil

It looks like that's ultimately coming from
def package_lock_feature?
foreman_maintain('packages -h')

Associated revisions

Revision d5e079d0 (diff)
Added by Eric Helms 2 months ago

Fixes #31135: Introduce execute! and execute for fatal and non-fatal commands

Introduce two separate functions that run a command. execute! will
run a command and exit if the status indicates failure. execute will
run a command and return the status of the command to let the hook
take further action. execute is intended for actions that require
information to decide what further action to take or if the action
is non-fatal.

This present previously seen errors where detecting foreman-maintain
exists on the system or foreman-maintain checks for a feature
from presenting as an error incorrectly to the user.


#1 Updated by The Foreman Bot 3 months ago

  • Assignee set to Eric Helms
  • Status changed from New to Ready For Testing
  • Pull request added

#2 Updated by The Foreman Bot 2 months ago

  • Fixed in Releases 2.4.0 added

#3 Updated by Eric Helms 2 months ago

  • Status changed from Ready For Testing to Closed

#4 Updated by Tomer Brisker 2 months ago

  • Category set to foreman-installer script
  • Fixed in Releases 2.3.0 added
  • Fixed in Releases deleted (2.4.0)

#5 Updated by Ewoud Kohl van Wijngaarden about 2 months ago

  • Triaged changed from No to Yes
  • Target version set to 2.3.0

Also available in: Atom PDF