From 216892949621974b794eec5d9b892924ec31cc80 Mon Sep 17 00:00:00 2001 From: Ian Ballou Date: Tue, 17 Sep 2024 21:18:21 +0000 Subject: [PATCH] Fixes #37831 - Don't filter job template install content by bound repos --- .../concerns/host_managed_extensions.rb | 34 ++++++++++--------- .../install_errata_by_search_query.erb | 2 +- ...search_query_-_katello_ansible_default.erb | 2 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/models/katello/concerns/host_managed_extensions.rb b/app/models/katello/concerns/host_managed_extensions.rb index e9d411171f5..e3aebe2b7ad 100644 --- a/app/models/katello/concerns/host_managed_extensions.rb +++ b/app/models/katello/concerns/host_managed_extensions.rb @@ -511,17 +511,17 @@ def yum_names_for_job_template(action:, search:, versions: nil) actions = %w(install remove update).freeze case action when 'install' - yum_installable = ::Katello::Rpm.yum_installable_for_host(self).search_for(search).distinct.pluck(:name) + yum_installable = ::Katello::Rpm.search_for(search).distinct.pluck(:name) if yum_installable.empty? - fail N_("No available packages found for search term '%s'. Check the host's content view environments and already-installed packages.") % search + fail N_("No available packages found for search term '%s'.") % search end yum_installable when 'remove' return [] if search.empty? - yum_removable = installed_packages.search_for(search).distinct.pluck(:name) + yum_removable = ::Katello::InstalledPackage.search_for(search).distinct.pluck(:name) if yum_removable.empty? - fail N_("Cannot remove package(s): This host does not have any installed packages matching the search term '%s'.") % search + fail N_("Cannot remove package(s): No installed packages found for search term '%s'.") % search end yum_removable when 'update' @@ -536,14 +536,15 @@ def yum_names_for_job_template(action:, search:, versions: nil) end pkg_name_archs = installed_packages.search_for(search).distinct.pluck(:name, :arch) if pkg_name_archs.empty? - fail _("Cannot upgrade packages: No installed packages found for search term '%s'") % search + fail _("Cannot upgrade packages: No installed packages found for search term '%s'.") % search end - upgrades = ::Katello::Rpm.installable_for_hosts([self]).select(:id, :name, :arch, :nvra, :evr).order(evr: :desc).group_by { |i| [i.name, i.arch] } - result = pkg_name_archs.map { |name, arch| versions_by_name_arch[[name, arch]] || upgrades[[name, arch]]&.first&.nvra }.compact - if result.empty? - fail _("No upgradable packages found for search term '%s'. The host may already have the latest version(s) installed.") % search + versionless_upgrades = ::Katello::Rpm.where(name: pkg_name_archs.map(&:first)).select(:id, :name, :arch, :evr).order(evr: :desc).group_by { |i| [i.name, i.arch] } + # Use versions_by_name_arch if a version is specified, otherwise use the latest version. If using the latest version, upgrade by name only, not by name and arch. + pkg_names_and_nvras = pkg_name_archs.map { |name, arch| versions_by_name_arch[[name, arch]] || versionless_upgrades[[name, arch]]&.first&.name }.compact + if pkg_names_and_nvras.empty? + fail _("No upgradable packages found for search term '%s'.") % search end - result + pkg_names_and_nvras else fail ::Foreman::Exception.new(N_("package_names_for_job_template: Action must be one of %s"), actions.join(', ')) end @@ -554,7 +555,7 @@ def deb_names_for_job_template(action:, search:) actions = %w(install remove update).freeze case action when 'install' - deb_installable = ::Katello::Deb.apt_installable_for_host(self).search_for(search).distinct.pluck(:name) + deb_installable = ::Katello::Deb.search_for(search).distinct.pluck(:name) if deb_installable.empty? fail _("No available debs found for search term '%s'. Check the host's content view environments and already-installed debs.") % search end @@ -562,10 +563,10 @@ def deb_names_for_job_template(action:, search:) when 'remove' return [] if search.empty? - installed_debs.search_for(search).distinct.pluck(:name) + ::Katello::InstalledDeb.search_for(search).distinct.pluck(:name) when 'update' return [] if search.empty? - deb_results = installed_debs.search_for(search).distinct.pluck(:name) + deb_results = ::Katello::InstalledDeb.search_for(search).distinct.pluck(:name) if deb_results.empty? fail _("No installed debs found for search term '%s'") % search end @@ -575,10 +576,11 @@ def deb_names_for_job_template(action:, search:) end end - def advisory_ids(search:) - ids = ::Katello::Erratum.installable_for_hosts([self]).search_for(search).pluck(:errata_id) + def advisory_ids(search:, check_installable_for_host: true) + errata_scope = check_installable_for_host ? ::Katello::Erratum.installable_for_hosts([self]) : ::Katello::Erratum + ids = errata_scope.search_for(search).pluck(:errata_id) if ids.empty? - fail _("Cannot install errata: No installable errata found for search term '%s'") % search + fail _("Cannot install errata: No errata found for search term '%s'") % search end ids end diff --git a/app/views/foreman/job_templates/install_errata_by_search_query.erb b/app/views/foreman/job_templates/install_errata_by_search_query.erb index 3ef5a1bf809..fc86535b933 100644 --- a/app/views/foreman/job_templates/install_errata_by_search_query.erb +++ b/app/views/foreman/job_templates/install_errata_by_search_query.erb @@ -15,7 +15,7 @@ foreign_input_sets: exclude: action,package %> -<% advisory_ids = @host.advisory_ids(search: input("Errata search query")) -%> +<% advisory_ids = @host.advisory_ids(search: input("Errata search query"), check_installable_for_host: false) -%> <% render_error(N_("No errata matching given search query")) if !input("Errata search query").blank? && advisory_ids.blank? -%> # RESOLVED_ERRATA_IDS=<%= advisory_ids.join(',') %> diff --git a/app/views/foreman/job_templates/install_errata_by_search_query_-_katello_ansible_default.erb b/app/views/foreman/job_templates/install_errata_by_search_query_-_katello_ansible_default.erb index 5cbb894bc82..b440d63c310 100644 --- a/app/views/foreman/job_templates/install_errata_by_search_query_-_katello_ansible_default.erb +++ b/app/views/foreman/job_templates/install_errata_by_search_query_-_katello_ansible_default.erb @@ -12,7 +12,7 @@ template_inputs: required: false %> -<% advisory_ids = @host.advisory_ids(search: input("Errata search query")) -%> +<% advisory_ids = @host.advisory_ids(search: input("Errata search query"), check_installable_for_host: false) -%> <% render_error(N_("No errata matching given search query")) if !input("Errata search query").blank? && advisory_ids.blank? -%> # RESOLVED_ERRATA_IDS=<%= advisory_ids.join(',') %>