Skip to content
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

Fixes #37831 - Don't filter job template install content by bound repos #11150

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions app/models/katello/concerns/host_managed_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line above this still searches the host's installed_packages, and then errors if an installed package is not found. Doesn't this need updating as well?

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
Expand All @@ -554,18 +555,18 @@ 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
deb_installable
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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(',') %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(',') %>

Expand Down
Loading