From 11b82ea0da92a70765f02d3994032e7778cee210 Mon Sep 17 00:00:00 2001 From: Markus Bucher Date: Fri, 8 Nov 2024 15:52:55 +0100 Subject: [PATCH] Fixes #37998 - deb-repos not shown on host repo-set --- .../katello/product_content_finder.rb | 3 +- .../katello_content_view_repositories.yml | 4 +++ test/fixtures/models/katello_contents.yml | 34 +++++++++++++++++- .../fixtures/models/katello_pool_products.yml | 6 +++- .../models/katello_product_contents.yml | 20 +++++++++++ test/fixtures/models/katello_repositories.yml | 12 +++++++ test/services/product_content_finder_test.rb | 36 ++++++++++++++++++- 7 files changed, 111 insertions(+), 4 deletions(-) diff --git a/app/services/katello/product_content_finder.rb b/app/services/katello/product_content_finder.rb index 0cadd4f898f..70c8cd5d7ca 100644 --- a/app/services/katello/product_content_finder.rb +++ b/app/services/katello/product_content_finder.rb @@ -26,7 +26,8 @@ def product_content structured_apt_roots = roots.where(:content_id => nil) if structured_apt_roots.any? deb_repos_query = Katello::Repository.where(root: structured_apt_roots) - deb_repos = match_environment ? deb_repos_query.where(content_view_version: versions, environment: consumable.environment) : deb_repos_query.where(:library_instance_id => nil) + environment = consumable.respond_to?(:environment) ? consumable.environment : consumable.content_view_environments.select(:environment_id).map(&:environment_id) + deb_repos = match_environment ? deb_repos_query.where(content_view_version: versions, environment: environment) : deb_repos_query.where(:library_instance_id => nil) content_ids += deb_repos.pluck(:content_id) end diff --git a/test/fixtures/models/katello_content_view_repositories.yml b/test/fixtures/models/katello_content_view_repositories.yml index 137b1e61bcd..7e80607c1b5 100644 --- a/test/fixtures/models/katello_content_view_repositories.yml +++ b/test/fixtures/models/katello_content_view_repositories.yml @@ -6,6 +6,10 @@ library_view_debian_10_amd64: content_view_id: <%= ActiveRecord::FixtureSet.identify(:library_view) %> repository_id: <%= ActiveRecord::FixtureSet.identify(:debian_10_amd64) %> +library_view_acme_debian_10_amd64: + content_view_id: <%= ActiveRecord::FixtureSet.identify(:acme_default) %> + repository_id: <%= ActiveRecord::FixtureSet.identify(:debian_10_amd64_dev) %> + library_view_rhel_6_x86_64: content_view_id: <%= ActiveRecord::FixtureSet.identify(:acme_default) %> repository_id: <%= ActiveRecord::FixtureSet.identify(:rhel_6_x86_64) %> diff --git a/test/fixtures/models/katello_contents.yml b/test/fixtures/models/katello_contents.yml index 04deeb7a666..7534889692c 100644 --- a/test/fixtures/models/katello_contents.yml +++ b/test/fixtures/models/katello_contents.yml @@ -1,3 +1,35 @@ +deb_content: + name: debian + label: debian + cp_content_id: 110 + organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %> + content_url: /custom/Debian_12/Debian_12_amd64_main/?comp=main&rel=bookworm + content_type: "deb" + +deb_content_v1: + name: debian + label: debian + cp_content_id: 111 + organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %> + content_url: /custom/Debian_12/Debian_12_amd64_main/?comp=main&rel=bookworm + content_type: "deb" + +deb_content_v2: + name: debian + label: debian + cp_content_id: 112 + organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %> + content_url: /custom/Debian_12/Debian_12_amd64_main/?comp=main&rel=bookworm + content_type: "deb" + +deb_content_v3: + name: debian + label: debian + cp_content_id: 113 + organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %> + content_url: /custom/Debian_12/Debian_10_amd64_main/?comp=main&rel=buster + content_type: "deb" + some_content: name: Fedora cp_content_id: 1 @@ -12,4 +44,4 @@ rhel_content: cp_content_id: 69 organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %> content_url: /content/dist/rhel/server/$releasever/$basearch/os - content_type: "yum" \ No newline at end of file + content_type: "yum" diff --git a/test/fixtures/models/katello_pool_products.yml b/test/fixtures/models/katello_pool_products.yml index 2591ca53850..e405e0f2504 100644 --- a/test/fixtures/models/katello_pool_products.yml +++ b/test/fixtures/models/katello_pool_products.yml @@ -6,6 +6,10 @@ basic_redhat: pool_id: <%= ActiveRecord::FixtureSet.identify(:pool_one) %> product_id: <%= ActiveRecord::FixtureSet.identify(:redhat) %> +basic_debian: + pool_id: <%= ActiveRecord::FixtureSet.identify(:pool_one) %> + product_id: <%= ActiveRecord::FixtureSet.identify(:debian) %> + other_sub_fedora: pool_id: <%= ActiveRecord::FixtureSet.identify(:pool_two) %> - product_id: <%= ActiveRecord::FixtureSet.identify(:fedora) %> \ No newline at end of file + product_id: <%= ActiveRecord::FixtureSet.identify(:fedora) %> diff --git a/test/fixtures/models/katello_product_contents.yml b/test/fixtures/models/katello_product_contents.yml index b15542c2de3..d066c2bbf4e 100644 --- a/test/fixtures/models/katello_product_contents.yml +++ b/test/fixtures/models/katello_product_contents.yml @@ -7,3 +7,23 @@ rhel_content: content_id: <%= ActiveRecord::FixtureSet.identify(:rhel_content) %> product_id: <%= ActiveRecord::FixtureSet.identify(:redhat) %> enabled: false + +debian_content: + content_id: <%= ActiveRecord::FixtureSet.identify(:deb_content) %> + product_id: <%= ActiveRecord::FixtureSet.identify(:debian) %> + enabled: false + +debian_content_v1: + content_id: <%= ActiveRecord::FixtureSet.identify(:deb_content_v1) %> + product_id: <%= ActiveRecord::FixtureSet.identify(:debian) %> + enabled: false + +debian_content_v2: + content_id: <%= ActiveRecord::FixtureSet.identify(:deb_content_v2) %> + product_id: <%= ActiveRecord::FixtureSet.identify(:debian) %> + enabled: false + +debian_content_v3: + content_id: <%= ActiveRecord::FixtureSet.identify(:deb_content_v3) %> + product_id: <%= ActiveRecord::FixtureSet.identify(:debian) %> + enabled: false diff --git a/test/fixtures/models/katello_repositories.yml b/test/fixtures/models/katello_repositories.yml index a706767cfc1..06e9e53db38 100644 --- a/test/fixtures/models/katello_repositories.yml +++ b/test/fixtures/models/katello_repositories.yml @@ -15,6 +15,7 @@ debian_9_amd64: debian_10_amd64: root_id: <%= ActiveRecord::FixtureSet.identify(:debian_10_amd64_root) %> pulp_id: Debian_10 + content_id: 110 relative_path: 'ACME_Corporation/library/debian_10_label' environment_id: <%= ActiveRecord::FixtureSet.identify(:library) %> content_view_version_id: <%= ActiveRecord::FixtureSet.identify(:library_default_version) %> @@ -36,6 +37,7 @@ debian_10_dev_library_view: library_instance: debian_10_amd64 root_id: <%= ActiveRecord::FixtureSet.identify(:debian_10_amd64_root) %> pulp_id: debian_10_dev_library_view + content_id: 112 relative_path: 'ACME_Corporation/dev/debian_10_library_library_view_label' environment_id: <%= ActiveRecord::FixtureSet.identify(:dev) %> content_view_version_id: <%= ActiveRecord::FixtureSet.identify(:library_view_version_2) %> @@ -44,6 +46,7 @@ debian_10_amd64_dev: library_instance: debian_10_amd64 root_id: <%= ActiveRecord::FixtureSet.identify(:debian_10_amd64_root) %> pulp_id: 12 + content_id: 111 relative_path: 'ACME_Corporation/dev/debian_10_dev_label' environment_id: <%= ActiveRecord::FixtureSet.identify(:dev) %> content_view_version_id: <%= ActiveRecord::FixtureSet.identify(:library_dev_view_version) %> @@ -310,6 +313,15 @@ busybox_view2: environment_id: content_view_version_id: <%= ActiveRecord::FixtureSet.identify(:library_view_version_2) %> +debian_10_amd64_composite_view_version_1: + library_instance: debian_10_amd64 + root_id: <%= ActiveRecord::FixtureSet.identify(:debian_10_amd64_root) %> + pulp_id: 8_deb_composite_version1 + content_id: 113 + relative_path: 'ACME_Corporation/library/composite/debian_10_label' + environment_id: <%= ActiveRecord::FixtureSet.identify(:library) %> + content_view_version_id: <%= ActiveRecord::FixtureSet.identify(:composite_view_version_1) %> + rhel_6_x86_64_composite_view_version_1: library_instance: rhel_6_x86_64 root_id: <%= ActiveRecord::FixtureSet.identify(:rhel_6_x86_64_root) %> diff --git a/test/services/product_content_finder_test.rb b/test/services/product_content_finder_test.rb index b24a6226a9f..d0fbd8e6be4 100644 --- a/test/services/product_content_finder_test.rb +++ b/test/services/product_content_finder_test.rb @@ -5,10 +5,13 @@ class ProductContentFinderTestBase < ActiveSupport::TestCase def setup @product1 = katello_products(:fedora) @product2 = katello_products(:redhat) + @product3 = katello_products(:debian) @repo1 = katello_repositories(:fedora_17_x86_64) @repo2 = katello_repositories(:rhel_7_x86_64) @repo2_cv = katello_repositories(:rhel_6_x86_64_composite_view_version_1) + @repo3 = katello_repositories(:debian_10_amd64) + @repo4 = katello_repositories(:debian_10_amd64_dev) #@repo1's content is already in fixtures [@repo2].each do |repo| @@ -31,16 +34,20 @@ def test_all assert product_content.any? { |pc| pc.content.cp_content_id == @repo1.content_id } assert product_content.any? { |pc| pc.content.cp_content_id == @repo2.content_id } + assert product_content.any? { |pc| pc.content.cp_content_id == @repo3.content_id } + refute product_content.any? { |pc| pc.content.cp_content_id == @repo4.content_id } end def test_match_subs - @key.expects(:products).returns([@product1]) + @key.expects(:products).returns([@product1, @product3]) pcf = Katello::ProductContentFinder.new(:consumable => @key, :match_subscription => true) product_content = pcf.product_content assert product_content.any? { |pc| pc.content.cp_content_id == @repo1.content_id } refute product_content.any? { |pc| pc.content.cp_content_id == @repo2.content_id } + assert product_content.any? { |pc| pc.content.cp_content_id == @repo3.content_id } + refute product_content.any? { |pc| pc.content.cp_content_id == @repo4.content_id } end def test_match_environments @@ -59,4 +66,31 @@ def test_match_environments assert product_content.any? { |pc| pc.content.cp_content_id == @repo2.content_id } end end + + class ProductContentFinderHostSubscriptionTest < ProductContentFinderActivationKeyTest + def setup + super + @key = katello_subscription_facets(:one) + end + + def test_match_environments + repo5 = katello_repositories(:debian_10_amd64_composite_view_version_1) + cves = ::Katello::ContentViewEnvironment.where(environment_id: @repo2_cv.environment, + content_view_id: @repo2_cv.content_view) + + @key.stubs(:content_view_environments).returns(cves) + + #Katello::Repository.where(:root => Katello::RootRepository.where(:content_id => @repo1.content_id), + # :content_view_version_id => @key.content_view.version(@key.environment)).destroy_all + + pcf = Katello::ProductContentFinder.new(:consumable => @key, :match_environment => true) + product_content = pcf.product_content + + refute product_content.any? { |pc| pc.content.cp_content_id == @repo1.content_id } + assert product_content.any? { |pc| pc.content.cp_content_id == @repo2.content_id } + refute product_content.any? { |pc| pc.content.cp_content_id == @repo3.content_id } + refute product_content.any? { |pc| pc.content.cp_content_id == @repo4.content_id } + assert product_content.any? { |pc| pc.content.cp_content_id == repo5.content_id } + end + end end