From f1f747679d597f0ee716f9d0df2a43e0ee615a22 Mon Sep 17 00:00:00 2001 From: ianballou Date: Thu, 4 Jan 2024 23:35:32 +0000 Subject: [PATCH] Fixes #37031 - hammer proxy content info fails when DB has no content counts --- lib/hammer_cli_katello/capsule.rb | 2 +- .../content/data/sync_status_no_counts.json | 6 +++ test/functional/capsule/content/info_test.rb | 43 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/functional/capsule/content/data/sync_status_no_counts.json diff --git a/lib/hammer_cli_katello/capsule.rb b/lib/hammer_cli_katello/capsule.rb index 6f620f50e..a66b3ac4d 100644 --- a/lib/hammer_cli_katello/capsule.rb +++ b/lib/hammer_cli_katello/capsule.rb @@ -232,7 +232,7 @@ 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"] + if cv["up_to_date"] && !data.dig("content_counts").nil? 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| diff --git a/test/functional/capsule/content/data/sync_status_no_counts.json b/test/functional/capsule/content/data/sync_status_no_counts.json new file mode 100644 index 000000000..28ca1490e --- /dev/null +++ b/test/functional/capsule/content/data/sync_status_no_counts.json @@ -0,0 +1,6 @@ +{ + "last_sync_time": "2016-01-10 00:27:51 +0100", + "active_sync_tasks": [], + "last_failed_sync_tasks": [], + "lifecycle_environments": [] +} diff --git a/test/functional/capsule/content/info_test.rb b/test/functional/capsule/content/info_test.rb index f1b63c861..13f7fced2 100644 --- a/test/functional/capsule/content/info_test.rb +++ b/test/functional/capsule/content/info_test.rb @@ -53,6 +53,49 @@ assert_cmd(expected_result, result) end + it "works with no content counts" do + @sync_status = load_json('./data/sync_status_no_counts.json', __FILE__) + @sync_status['lifecycle_environments'] = [ + 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| + par['id'] == 3 + end + ex.returns(@sync_status) + + output = OutputMatcher.new([ + "Lifecycle Environments:", + " 1) Name: Library", + " 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", + " 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) + + result = run_cmd(@cmd + params) + assert_cmd(expected_result, result) + end + it "resolves id from name" do params = ['--name=capsule1']