Repository navigation
Fixes #39717 - Prepare for the upcoming remediation changes #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
adamruzicka
merged 1 commit into
theforeman:master
from
michalgritzbach:39717-remediation-command-changes
Oct 14, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,49 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'shellwords' | ||
|
|
||
| module ForemanLeapp | ||
| # Assembles the shell script out of the command remediations found in a leapp report. | ||
| # | ||
| # Leapp changed the way remediation commands are quoted. Up to leapp 0.21 the | ||
| # arguments in the "context" list were already quoted by leapp itself, so they | ||
| # were meant to be joined verbatim. Starting with leapp 0.22 the arguments are | ||
| # reported as they are and have to be escaped by the consumer of the report. | ||
| # See https://github.com/oamg/leapp-repository/pull/1520 | ||
| # | ||
| # The new quoting is shipped by leapp-upgrade-el<X>toel<Y> 0.25, which is released | ||
| # together with leapp 0.22, so the version of the leapp package tells the two | ||
| # formats apart. | ||
| module RemediationPlan | ||
| # The first leapp version that reports remediation command arguments unquoted. | ||
| UNQUOTED_ARGUMENTS_SINCE = Gem::Version.new('0.22') | ||
|
|
||
| class << self | ||
| def build(detail, leapp_version) | ||
| quoted = quoted_by_leapp?(leapp_version) | ||
| Array.wrap(detail) | ||
| .flat_map { |d| d['remediations'] } | ||
| .compact | ||
| .select { |remediation| remediation['type'] == 'command' } | ||
| .map { |remediation| "#{command_line(remediation['context'], quoted)}\n" } | ||
| .join | ||
| end | ||
|
|
||
| def command_line(context, quoted) | ||
| arguments = Array.wrap(context) | ||
| return arguments.join(' ') if quoted | ||
|
|
||
| arguments.map { |argument| Shellwords.escape(argument) }.join(' ') | ||
| end | ||
|
|
||
| # Unknown versions are treated as old leapp, so that reports collected | ||
| # before the version was recorded keep rendering the way they used to. | ||
| def quoted_by_leapp?(leapp_version) | ||
| version = Gem::Version.new(leapp_version.to_s[/\A[0-9][0-9.]*/].to_s.chomp('.')) | ||
| version < UNQUOTED_ARGUMENTS_SINCE | ||
| rescue ArgumentError | ||
| true | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| object @preupgrade_report_entry | ||
|
|
||
| attributes :id, :detail, :preupgrade_report_id, :host_id, :hostname, :title, :actor, :audience, | ||
| :severity, :leapp_run_id, :summary, :tags, :flags, :created_at, :updated_at | ||
| :severity, :leapp_run_id, :leapp_version, :summary, :tags, :flags, :created_at, | ||
| :updated_at |
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
db/migrate/20260825120000_add_leapp_version_to_report_entries.rb
This file contains hidden or 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,7 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddLeappVersionToReportEntries < ActiveRecord::Migration[7.0] | ||
| def change | ||
| add_column :preupgrade_report_entries, :leapp_version, :string | ||
| end | ||
| end |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.