From 0caffdda48ebd1aa9721150f6def6d9bbd0935fa Mon Sep 17 00:00:00 2001 From: Samir Jha Date: Thu, 14 Sep 2023 20:04:46 +0000 Subject: [PATCH] Fixes #36750 - Add aggregated CV version content counts to count field and return via API (cherry picked from commit dbde8b46e4b80d18a4d46a25eee245b96509428f) --- .../katello/concerns/smart_proxy_extensions.rb | 15 ++++++++++++++- .../v2/capsule_content/sync_status.json.rabl | 3 ++- .../concerns/smart_proxy_extensions_test.rb | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/app/models/katello/concerns/smart_proxy_extensions.rb b/app/models/katello/concerns/smart_proxy_extensions.rb index 9261e647b0d..b01d46fd54c 100644 --- a/app/models/katello/concerns/smart_proxy_extensions.rb +++ b/app/models/katello/concerns/smart_proxy_extensions.rb @@ -145,12 +145,25 @@ def update_content_counts! translated_counts[::Katello::Pulp3::PulpContentUnit.katello_name_from_pulpcore_name(name, repo)] = count end end - new_content_counts[:content_view_versions][repo.content_view_version_id] ||= { repositories: {} } + new_content_counts[:content_view_versions][repo.content_view_version_id] ||= { repositories: {}, cv_version_content_counts: {}} new_content_counts[:content_view_versions][repo.content_view_version_id][:repositories][repo.id] = translated_counts + new_content_counts = aggregated_cv_version_count!(repo.content_view_version_id, new_content_counts, translated_counts) end update(content_counts: new_content_counts) end + def aggregated_cv_version_count!(cv_version_id, cvv_content_counts, repo_counts) + repo_counts.keys.each do |content_type| + cvv_content_counts[:content_view_versions][cv_version_id][:cv_version_content_counts][content_type] = + if cvv_content_counts[:content_view_versions][cv_version_id][:cv_version_content_counts][content_type] + cvv_content_counts[:content_view_versions][cv_version_id][:cv_version_content_counts][content_type] + repo_counts[content_type] + else + repo_counts[content_type] + end + end + cvv_content_counts + end + def sync_container_gateway if has_feature?(::SmartProxy::CONTAINER_GATEWAY_FEATURE) update_container_repo_list diff --git a/app/views/katello/api/v2/capsule_content/sync_status.json.rabl b/app/views/katello/api/v2/capsule_content/sync_status.json.rabl index 6b0904dcd6f..e499e14b328 100644 --- a/app/views/katello/api/v2/capsule_content/sync_status.json.rabl +++ b/app/views/katello/api/v2/capsule_content/sync_status.json.rabl @@ -43,7 +43,8 @@ child @lifecycle_environments => :lifecycle_environments do :up_to_date => @capsule.repos_pending_sync(env, content_view).empty?, :counts => { :repositories => ::Katello::ContentViewVersion.in_environment(env).find_by(:content_view => content_view)&.archived_repos&.count - } + }, + :content_counts => @capsule.content_counts } attributes end diff --git a/test/models/concerns/smart_proxy_extensions_test.rb b/test/models/concerns/smart_proxy_extensions_test.rb index 804c6d2b051..5f86d594d35 100644 --- a/test/models/concerns/smart_proxy_extensions_test.rb +++ b/test/models/concerns/smart_proxy_extensions_test.rb @@ -102,6 +102,24 @@ def test_update_content_counts ostree_repo.id.to_s => {"ostree_ref" => 30 }, deb_repo.id.to_s => { "deb" => 987 }, python_repo.id.to_s => { "python_package" => 42 } + }, + "cv_version_content_counts" => + { "erratum" => 4, + "srpm" => 1, + "rpm" => 31, + "rpm.modulemd" => 7, + "rpm.modulemd_defaults" => 3, + "package_group" => 7, + "rpm.packagecategory" => 1, + "file" => 100, + "ansible_collection" => 802, + "container.blob" => 30, + "docker_manifest_list" => 1, + "docker_manifest" => 9, + "docker_tag" => 5, + "ostree_ref" => 30, + "deb" => 987, + "python_package" => 42 } } }