From 614b41d8fc99903c3cd91a6eb90793d0e569a05f Mon Sep 17 00:00:00 2001 From: ianballou Date: Tue, 10 Oct 2023 19:37:59 +0000 Subject: [PATCH] Fixes #36814 - add content counts to capsule content info * Add capsule content update-counts command --- lib/hammer_cli_katello/capsule.rb | 72 ++++++++++++++++--- .../capsule/content/data/library_env.json | 66 +++++++---------- .../capsule/content/data/sync_status.json | 6 +- .../capsule/content/data/unsynced_env.json | 31 ++++++++ test/functional/capsule/content/info_test.rb | 32 ++++++--- 5 files changed, 145 insertions(+), 62 deletions(-) create mode 100644 test/functional/capsule/content/data/unsynced_env.json diff --git a/lib/hammer_cli_katello/capsule.rb b/lib/hammer_cli_katello/capsule.rb index cec5c014d..286579733 100644 --- a/lib/hammer_cli_katello/capsule.rb +++ b/lib/hammer_cli_katello/capsule.rb @@ -105,6 +105,22 @@ class SyncCommand < HammerCLIKatello::SingleResourceCommand extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new) end + class UpdateCountsCommand < HammerCLIKatello::SingleResourceCommand + include HammerCLIForemanTasks::Async + + resource :capsule_content, :update_counts + command_name "update-counts" + + success_message _("Capsule content counts are being updated in task %{id}.") + failure_message _("Could not update capsule content counts") + + option "--organization-id", "ID", _("Organization ID"), + :attribute_name => :option_organization_id + option "--organization", "NAME", _("Organization name"), + :attribute_name => :option_organization_name + build_options + end + class SyncStatusCommand < HammerCLIKatello::InfoCommand resource :capsule_content, :sync_status command_name "synchronization-status" @@ -170,21 +186,59 @@ class InfoCommand < HammerCLIKatello::InfoCommand field nil, _("Name"), Fields::Reference field :composite, _('Composite'), Fields::Boolean field :last_published, _('Last Published'), Fields::Date - label _('Content') do - from :counts do - field :content_hosts, _('Hosts') - field :products, _('Products') - field :yum_repositories, _('Yum repos') - field :docker_repositories, _('Container Image repos') - field :packages, _('Packages') - field :package_groups, _('Package groups') - field :errata, _('Errata') + collection :repositories, _('Repositories') do + field :id, _("Repository ID") + field :name, _("Repository Name") + label _('Content Counts') do + from :_content_counts do + field :warning, _('Warning') + field :rpm, _('Packages') + field :srpm, _('SRPMs') + field :module_stream, _('Module Streams') + field :package_group, _('Package Groups') + field :erratum, _('Errata') + field :deb, _('Debian Packages') + field :docker_tag, _('Container Tags') + field :docker_manifest, _('Container Manifests') + field :docker_manifest_list, _('Container Manifest Lists') + field :file, _('Files') + field :ansible_collection, _('Ansible Collections') + field :ostree_ref, _('OSTree Refs') + field :python_package, _('Python Packages') + end end end end end end + private + + def extend_data(data) + data["lifecycle_environments"].each do |lce| + lce["content_views"].each do |cv| + cv["repositories"].each do |repo| + if cv["up_to_date"] + cvv_count_repos = data.dig("content_counts", "content_view_versions", + cv["cvv_id"].to_s, "repositories") + cvv_count_repos.each do |_repo_id, counts_and_metadata| + if counts_and_metadata. + dig("metadata", "library_instance_id") == repo["library_id"] && + counts_and_metadata.dig("metadata", "env_id") == lce["id"] + repo["_content_counts"] = counts_and_metadata["counts"] + end + end + else + repo["_content_counts"] = {} + repo["_content_counts"]["warning"] = + _("Content view must be synced to see content counts") + end + end + end + end + data + end + build_options end diff --git a/test/functional/capsule/content/data/library_env.json b/test/functional/capsule/content/data/library_env.json index 116d89dec..ea6c2800e 100644 --- a/test/functional/capsule/content/data/library_env.json +++ b/test/functional/capsule/content/data/library_env.json @@ -1,47 +1,31 @@ { - "library": true, - "id": 3, - "name": "Library", - "label": "Library", - "description": null, - "organization": { - "name": "Default Organization", - "label": "Default_Organization", - "id": 1 + "library":true, + "id":4, + "name":"Library", + "label":"Library", + "description":null, + "organization_id":1, + "organization":{ + "name":"Default Organization", + "label":"Default_Organization", + "id":1 }, - "syncable": true, - "counts": { - "content_hosts": 0, - "content_views": 1, - "products": 3, - "yum_repositories": 1, - "packages": 32, - "package_groups": 2, - "errata": 4, - "puppet_repositories": 0, - "puppet_modules": 0, - "docker_repositories": 0, - "docker_images": 0 + "syncable":true, + "counts":{ + "content_views":1 }, - "content_views": [ + "content_views": + [ { - "id": 3, - "label": "CV1", - "name": "CV1", - "composite": false, - "last_published": "2016-01-08 15:44:10 +0100", - "counts": { - "content_hosts": 0, - "products": 3, - "yum_repositories": 1, - "packages": 32, - "package_groups": 2, - "errata": 4, - "puppet_repositories": 0, - "puppet_modules": 0, - "docker_repositories": 0, - "docker_images": 0 - } + "id":2, + "cvv_id":2, + "label":"Zoo_View", + "name":"Zoo View", + "composite":false, + "last_published":"2023-10-09 19:18:15 UTC", + "default":false,"up_to_date":true, + "counts":{"repositories":1}, + "repositories":[{"id":2,"name":"Zoo","library_id":1}] } ] -} +} \ No newline at end of file diff --git a/test/functional/capsule/content/data/sync_status.json b/test/functional/capsule/content/data/sync_status.json index 28ca1490e..4ce258bea 100644 --- a/test/functional/capsule/content/data/sync_status.json +++ b/test/functional/capsule/content/data/sync_status.json @@ -2,5 +2,9 @@ "last_sync_time": "2016-01-10 00:27:51 +0100", "active_sync_tasks": [], "last_failed_sync_tasks": [], - "lifecycle_environments": [] + "lifecycle_environments": [], + "content_counts": { + "content_view_versions":{ + "2":{"repositories":{"42":{"metadata":{"env_id":4,"product_id":1,"content_type":"yum","library_instance_id":1},"counts":{"rpm":32,"erratum":4}}}}} + } } diff --git a/test/functional/capsule/content/data/unsynced_env.json b/test/functional/capsule/content/data/unsynced_env.json new file mode 100644 index 000000000..b22751f80 --- /dev/null +++ b/test/functional/capsule/content/data/unsynced_env.json @@ -0,0 +1,31 @@ +{ + "library":false, + "id":5, + "name":"Test", + "label":"Test", + "description":null, + "organization_id":1, + "organization":{ + "name":"Default Organization", + "label":"Default_Organization", + "id":1 + }, + "syncable":true, + "counts":{ + "content_views":1 + }, + "content_views": + [ + { + "id":2, + "cvv_id":2, + "label":"Zoo_View", + "name":"Zoo View", + "composite":false, + "last_published":"2023-10-09 19:18:15 UTC", + "default":false,"up_to_date":false, + "counts":{"repositories":1}, + "repositories":[{"id":2,"name":"Zoo","library_id":1}] + } + ] +} \ No newline at end of file diff --git a/test/functional/capsule/content/info_test.rb b/test/functional/capsule/content/info_test.rb index 8399df561..f1b63c861 100644 --- a/test/functional/capsule/content/info_test.rb +++ b/test/functional/capsule/content/info_test.rb @@ -12,7 +12,8 @@ it "lists content counts" do @sync_status = load_json('./data/sync_status.json', __FILE__) @sync_status['lifecycle_environments'] = [ - load_json('./data/library_env.json', __FILE__) + load_json('./data/library_env.json', __FILE__), + load_json('./data/unsynced_env.json', __FILE__) ] ex = api_expects(:capsule_content, :sync_status, 'Get sync info') do |par| @@ -25,17 +26,26 @@ " 1) Name: Library", " Organization: Default Organization", " Content Views:", - " 1) Name: CV1", + " 1) Name: Zoo View", " Composite: no", - " Last Published: 2016/01/08 15:44:10", - " Content:", - " Hosts: 0", - " Products: 3", - " Yum repos: 1", - " Container Image repos: 0", - " Packages: 32", - " Package groups: 2", - " Errata: 4" + " Last Published: 2023/10/09 19:18:15", + " Repositories:", + " 1) Repository ID: 2", + " Repository Name: Zoo", + " Content Counts:", + " Packages: 32", + " Errata: 4", + " 2) Name: Test", + " Organization: Default Organization", + " Content Views:", + " 1) Name: Zoo View", + " Composite: no", + " Last Published: 2023/10/09 19:18:15", + " Repositories:", + " 1) Repository ID: 2", + " Repository Name: Zoo", + " Content Counts:", + " Warning: Content view must be synced to see content counts" ]) expected_result = success_result(output)