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 #36814 - add content counts to capsule content info #913

Merged
merged 1 commit into from
Oct 25, 2023
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
72 changes: 63 additions & 9 deletions lib/hammer_cli_katello/capsule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
66 changes: 25 additions & 41 deletions test/functional/capsule/content/data/library_env.json
Original file line number Diff line number Diff line change
@@ -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}]
}
]
}
}
6 changes: 5 additions & 1 deletion test/functional/capsule/content/data/sync_status.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}}}
}
}
31 changes: 31 additions & 0 deletions test/functional/capsule/content/data/unsynced_env.json
Original file line number Diff line number Diff line change
@@ -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}]
}
]
}
32 changes: 21 additions & 11 deletions test/functional/capsule/content/info_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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)

Expand Down
Loading