Skip to content

Commit

Permalink
Fixes #36814 - add content counts to capsule content info
Browse files Browse the repository at this point in the history
* Add capsule content update-counts command
  • Loading branch information
ianballou committed Oct 10, 2023
1 parent 3bc7d4c commit aef0835
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 61 deletions.
57 changes: 48 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,44 @@ 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 :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|
repo["_content_counts"] = lce.dig("counts", "content_counts", "content_view_versions", cv["cvv_id"].to_s, "repositories", repo["id"].to_s)
end
end
end
data
end

build_options
end

Expand Down
70 changes: 29 additions & 41 deletions test/functional/capsule/content/data/library_env.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
{
"library": true,
"id": 3,
"name": "Library",
"label": "Library",
"description": null,
"organization": {
"name": "Default Organization",
"label": "Default_Organization",
"id": 1
"library":false,
"id":4,
"name":"Test",
"label":"Test",
"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":false,
"counts":{
"content_views":1,
"content_counts":{
"content_view_versions":{
"2":{"repositories":{"2":{"rpm":32,"erratum":4}}}}
}
},
"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}]
}
]
}
}
20 changes: 9 additions & 11 deletions test/functional/capsule/content/info_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@

output = OutputMatcher.new([
"Lifecycle Environments:",
" 1) Name: Library",
" 1) Name: Test",
" 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",
])
expected_result = success_result(output)

Expand Down

0 comments on commit aef0835

Please sign in to comment.