Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #29798 - Move --lock-package-versions to hooks/
The primary goal of this PR is to move the hook from Katello to a shared one. An accidental move in 6e1a07b resulted on this being executed on Debian which showed some flaws. Additional improvements are made to make it robust. This uses the package_lock_feature? helper to determine whether locking is available. It then uses the newly introduced app_option? to determine if the option is available. This means it doesn't have to execute package_lock_feature? within the pre_commit hook again which saves an exec() of an external process. In case locking could not be performed, the preference is cleared to allow the user to proceed. This saves them from having to edit the scenario manually. Instructions are printed to restore functionality. This also reduces the size of ForemanMaintainHookContextExtension to just the minimal wrapper. Methods that are only used once are moved into their particular hook file. This makes it easier to understand a single file. There helper itself is split into two methods. The one with bang exits on failure while the one without only returns the status.
- Loading branch information
Showing
5 changed files
with
50 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
katello/hooks/boot/09-version_locking.rb → hooks/boot/09-version_locking.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
katello/hooks/post/99-version_locking.rb → hooks/post/99-version_locking.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
def packages_locked? | ||
foreman_maintain('packages is-locked --assumeyes') | ||
end | ||
|
||
def unlock_packages | ||
foreman_maintain!('packages unlock --assumeyes') | ||
end | ||
|
||
if app_option?(:lock_package_versions) | ||
# evaluate version locking settings | ||
cli_param = app_value(:lock_package_versions) | ||
custom_config_value = get_custom_config(:lock_package_versions) | ||
lock_versions = cli_param.nil? ? !!custom_config_value : cli_param # rubocop:disable Style/DoubleNegation | ||
|
||
if lock_versions != custom_config_value | ||
store_custom_config(:lock_package_versions, lock_versions) | ||
kafo.config.configure_application | ||
end | ||
|
||
if packages_locked? | ||
log_and_say :info, "Package versions are locked. Continuing with unlock." | ||
unlock_packages | ||
end | ||
elsif get_custom_config(:lock_package_versions) | ||
# This case can happen if previously packages were locked but this is no | ||
# longer supported. For example, if foreman-maintain was removed. Clearing | ||
# this ensures the post hook works properly | ||
store_custom_config(:lock_package_versions, nil) | ||
kafo.config.configure_application | ||
fail_and_exit <<~MESSAGE | ||
Locking of package versions was requested but foreman-maintain couldn't be used for locking. | ||
The locking preference was cleared. Rerun the installer with the same arguments to proceed. | ||
If locking is desired, ensure foreman-maintain can be used and rerun with --lock-package-versions. | ||
MESSAGE | ||
end |
This file was deleted.
Oops, something went wrong.