Skip to content

Commit

Permalink
Fixes #31270 - Fix applicability with modular vs non-modular rpms (Ka…
Browse files Browse the repository at this point in the history
…tello#9107)

* Fixes #31270 - properly ignore non-modular rpms for modular-rpm applicability

* Refs #31270 - use enabled modules for modular rpm checking instead

(cherry picked from commit 56fb9e5)
  • Loading branch information
ianballou authored and jturel committed Mar 4, 2021
1 parent 4f9ea48 commit f4d650c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 28 deletions.
46 changes: 32 additions & 14 deletions app/services/katello/applicability/applicable_content_helper.rb
Expand Up @@ -60,17 +60,7 @@ def fetch_module_stream_content_ids
end

def fetch_rpm_content_ids
# Query for applicable RPM ids
# -> Include all non-modular rpms or rpms that exist within installed module streams
enabled_module_stream_ids = ::Katello::ModuleStream.
joins("inner join katello_available_module_streams on
katello_module_streams.name = katello_available_module_streams.name and
katello_module_streams.stream = katello_available_module_streams.stream").
joins("inner join katello_host_available_module_streams on
katello_available_module_streams.id = katello_host_available_module_streams.available_module_stream_id").
where("katello_host_available_module_streams.host_id = :content_facet_id and
katello_host_available_module_streams.status = 'enabled'",
:content_facet_id => self.content_facet.host.id).select(:id)
enabled_module_stream_ids = fetch_enabled_module_stream_ids

::Katello::Rpm.
joins("INNER JOIN katello_repository_rpms ON
Expand All @@ -88,9 +78,37 @@ def fetch_rpm_content_ids
:bound_library_repos => self.bound_library_instance_repos).
where("katello_host_installed_packages.host_id = :content_facet_id",
:content_facet_id => self.content_facet.host.id).
where("katello_module_stream_rpms.module_stream_id is null or
katello_module_stream_rpms.module_stream_id in (:enabled_module_streams)",
:enabled_module_streams => enabled_module_stream_ids).pluck(:id).uniq
where("(katello_module_stream_rpms.module_stream_id IS NULL AND
katello_installed_packages.id NOT IN (:locked_modular_installed_packages)) OR
(katello_module_stream_rpms.module_stream_id IN (:enabled_module_streams)
AND katello_installed_packages.id IN (:locked_modular_installed_packages))",
:enabled_module_streams => enabled_module_stream_ids,
:locked_modular_installed_packages => locked_modular_installed_packages(enabled_module_stream_ids)).pluck(:id).uniq
end

def fetch_enabled_module_stream_ids
# Query for applicable RPM ids
# -> Include all non-modular rpms or rpms that exist within installed module streams
::Katello::ModuleStream.
joins("inner join katello_available_module_streams on
katello_module_streams.name = katello_available_module_streams.name and
katello_module_streams.stream = katello_available_module_streams.stream").
joins("inner join katello_host_available_module_streams on
katello_available_module_streams.id = katello_host_available_module_streams.available_module_stream_id").
where("katello_host_available_module_streams.host_id = :content_facet_id and
katello_host_available_module_streams.status = 'enabled'",
:content_facet_id => self.content_facet.host.id).select(:id)
end

# Installed packages that are locked for the host due to enabled module stream membership
def locked_modular_installed_packages(enabled_module_streams)
rpms_in_enabled_module_streams = ::Katello::Rpm.
joins("INNER JOIN katello_module_stream_rpms ON katello_rpms.id = katello_module_stream_rpms.rpm_id").
where("katello_module_stream_rpms.module_stream_id IN (:enabled_module_streams)",
:enabled_module_streams => enabled_module_streams).select(:nvra, :epoch)

::Katello::InstalledPackage.where(nvra: rpms_in_enabled_module_streams.map(&:nvra),
epoch: rpms_in_enabled_module_streams.map(&:epoch)).select(:id)
end

def newest_distinct_installed_packages_query
Expand Down
Expand Up @@ -31,8 +31,7 @@ def setup
@rpm_three = katello_rpms(:three)
@rpm_one_two = katello_rpms(:one_two)

@rpm1 = Rpm.where(nvra: "one-1.0-1.el7.x86_64").first
@rpm2 = Rpm.where(nvra: "one-1.0-2.el7.x86_64").first
@rpm_one_v2 = Rpm.where(nvra: "one-1.0-2.el7.x86_64").first

@erratum = Erratum.find_by(errata_id: "RHBA-2014-013")

Expand All @@ -42,23 +41,23 @@ def setup
available_module_stream_id: AvailableModuleStream.find_by(name: "Ohio").id,
status: "enabled")

@installed_package1 = InstalledPackage.create(name: @rpm1.name, nvra: @rpm1.nvra, epoch: @rpm1.epoch,
version: @rpm1.version, release: @rpm1.release,
arch: @rpm1.arch, nvrea: @rpm1.nvrea)
@installed_package1 = InstalledPackage.create(name: @rpm_one.name, nvra: @rpm_one.nvra, epoch: @rpm_one.epoch,
version: @rpm_one.version, release: @rpm_one.release,
arch: @rpm_one.arch, nvrea: @rpm_one.nvrea)

trigger_evrs([@rpm_one, @rpm_two, @rpm_three, @rpm1, @rpm2, @installed_package1])
trigger_evrs([@rpm_one, @rpm_two, @rpm_three, @rpm_one, @rpm_one_v2, @installed_package1])

HostInstalledPackage.create(host_id: @host.id, installed_package_id: @installed_package1.id)

ErratumPackage.create(erratum_id: @erratum.id,
nvrea: @rpm2.nvra, name: @rpm2.name, filename: @rpm2.filename)
nvrea: @rpm_one_v2.nvra, name: @rpm_one_v2.name, filename: @rpm_one_v2.filename)

Katello::ContentFacetRepository.create(content_facet_id: @host.content_facet.id, repository_id: @repo.id)
Katello::RepositoryErratum.create(erratum_id: @erratum.id, repository_id: @repo.id)
end

def teardown
::Katello::Applicability::ApplicableContentHelper.new(@host.content_facet, ::Katello::Rpm, bound_repos(@host)).remove(@rpm2.id)
::Katello::Applicability::ApplicableContentHelper.new(@host.content_facet, ::Katello::Rpm, bound_repos(@host)).remove(@rpm_one_v2.id)
::Katello::Applicability::ApplicableContentHelper.new(@host.content_facet, ::Katello::Rpm, bound_repos(@host)).remove(@erratum.id)

@rpm_one.update(modular: false)
Expand All @@ -68,9 +67,9 @@ def teardown
end

def test_older_dup_installed_rpms_are_ignored
installed_package2 = InstalledPackage.create(name: @rpm2.name, nvra: @rpm2.nvra, epoch: @rpm2.epoch,
version: @rpm2.version, release: @rpm2.release,
arch: @rpm2.arch, nvrea: @rpm2.nvrea)
installed_package2 = InstalledPackage.create(name: @rpm_one_v2.name, nvra: @rpm_one_v2.nvra, epoch: @rpm_one_v2.epoch,
version: @rpm_one_v2.version, release: @rpm_one_v2.release,
arch: @rpm_one_v2.arch, nvrea: @rpm_one_v2.nvrea)
trigger_evrs([installed_package2])
HostInstalledPackage.create(host_id: @host.id, installed_package_id: installed_package2.id)
rpm_differences = ::Katello::Applicability::ApplicableContentHelper.new(@host.content_facet, ::Katello::Rpm, bound_repos(@host)).applicable_differences
Expand All @@ -79,7 +78,7 @@ def test_older_dup_installed_rpms_are_ignored

def test_rpm_content_ids_returns_something
package_content_ids = ::Katello::Applicability::ApplicableContentHelper.new(@host.content_facet, ::Katello::Rpm, bound_repos(@host)).fetch_content_ids
assert_equal [@rpm2.id], package_content_ids
assert_equal [@rpm_one_v2.id], package_content_ids
end

def test_rpm_content_ids_returns_nothing
Expand All @@ -102,7 +101,7 @@ def test_erratum_content_ids_returns_nothing

def test_applicable_differences_adds_rpm_id
rpm_differences = ::Katello::Applicability::ApplicableContentHelper.new(@host.content_facet, ::Katello::Rpm, bound_repos(@host)).applicable_differences
assert_equal [[@rpm2.id], []], rpm_differences
assert_equal [[@rpm_one_v2.id], []], rpm_differences
end

def test_applicable_differences_adds_and_removes_no_rpm_ids
Expand All @@ -115,7 +114,7 @@ def test_applicable_differences_removes_rpm_id
::Katello::Applicability::ApplicableContentHelper.new(@host.content_facet, ::Katello::Rpm, bound_repos(@host)).calculate_and_import
@installed_package1.destroy
rpm_differences = ::Katello::Applicability::ApplicableContentHelper.new(@host.content_facet, ::Katello::Rpm, bound_repos(@host)).applicable_differences
assert_equal [[], [@rpm2.id]], rpm_differences
assert_equal [[], [@rpm_one_v2.id]], rpm_differences
end

def test_applicable_differences_adds_erratum_id
Expand Down Expand Up @@ -185,6 +184,12 @@ def test_applicable_differences_removes_module_id
module_differences = ::Katello::Applicability::ApplicableContentHelper.new(@host.content_facet, ::Katello::ModuleStream, bound_repos(@host)).applicable_differences
assert_equal [[], [@module_stream.id]], module_differences
end

def test_non_modular_rpm_ignored_if_module_enabled
ModuleStreamRpm.create(module_stream_id: @module_stream.id, rpm_id: @rpm_one.id)
rpm_applicable_differences = ::Katello::Applicability::ApplicableContentHelper.new(@host.content_facet, ::Katello::Rpm, bound_repos(@host)).applicable_differences
assert_equal [[], []], rpm_applicable_differences
end
end
end
end
Expand Down

0 comments on commit f4d650c

Please sign in to comment.