hammer_cli_katello 0.23.1 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello.rb +20 -16
  3. data/lib/hammer_cli_katello/activation_key.rb +5 -5
  4. data/lib/hammer_cli_katello/capsule.rb +2 -3
  5. data/lib/hammer_cli_katello/command_extensions/lifecycle_environment.rb +10 -7
  6. data/lib/hammer_cli_katello/command_extensions/lifecycle_environments.rb +11 -8
  7. data/lib/hammer_cli_katello/content_credential.rb +20 -19
  8. data/lib/hammer_cli_katello/content_export.rb +73 -0
  9. data/lib/hammer_cli_katello/content_export_complete.rb +25 -0
  10. data/lib/hammer_cli_katello/content_export_helper.rb +181 -0
  11. data/lib/hammer_cli_katello/content_export_incremental.rb +25 -0
  12. data/lib/hammer_cli_katello/content_import.rb +63 -0
  13. data/lib/hammer_cli_katello/content_view.rb +19 -32
  14. data/lib/hammer_cli_katello/content_view_version.rb +4 -11
  15. data/lib/hammer_cli_katello/deb_package.rb +3 -3
  16. data/lib/hammer_cli_katello/erratum.rb +1 -1
  17. data/lib/hammer_cli_katello/erratum_info_command.rb +1 -1
  18. data/lib/hammer_cli_katello/file.rb +3 -3
  19. data/lib/hammer_cli_katello/filter.rb +2 -2
  20. data/lib/hammer_cli_katello/foreman_search_options_creators.rb +0 -12
  21. data/lib/hammer_cli_katello/host_collection.rb +2 -2
  22. data/lib/hammer_cli_katello/host_deb.rb +1 -1
  23. data/lib/hammer_cli_katello/host_errata.rb +1 -1
  24. data/lib/hammer_cli_katello/host_extensions.rb +5 -5
  25. data/lib/hammer_cli_katello/host_package.rb +1 -1
  26. data/lib/hammer_cli_katello/host_traces.rb +17 -0
  27. data/lib/hammer_cli_katello/hostgroup_extensions.rb +4 -4
  28. data/lib/hammer_cli_katello/id_resolver.rb +5 -6
  29. data/lib/hammer_cli_katello/lifecycle_environment.rb +2 -2
  30. data/lib/hammer_cli_katello/module_stream.rb +8 -8
  31. data/lib/hammer_cli_katello/organization_options.rb +8 -6
  32. data/lib/hammer_cli_katello/ostree_branch.rb +2 -2
  33. data/lib/hammer_cli_katello/package.rb +5 -5
  34. data/lib/hammer_cli_katello/package_group.rb +4 -4
  35. data/lib/hammer_cli_katello/ping.rb +2 -9
  36. data/lib/hammer_cli_katello/product.rb +3 -3
  37. data/lib/hammer_cli_katello/product_content.rb +2 -2
  38. data/lib/hammer_cli_katello/repository.rb +6 -37
  39. data/lib/hammer_cli_katello/repository_set.rb +4 -4
  40. data/lib/hammer_cli_katello/simple_content_access.rb +40 -0
  41. data/lib/hammer_cli_katello/srpm.rb +2 -2
  42. data/lib/hammer_cli_katello/subscription.rb +2 -3
  43. data/lib/hammer_cli_katello/sync_plan.rb +2 -2
  44. data/lib/hammer_cli_katello/version.rb +1 -1
  45. data/test/data/3.18/foreman_api.json +1 -0
  46. data/test/data/3.19/foreman_api.json +1 -0
  47. data/test/data/4.0/foreman_api.json +1 -0
  48. data/test/functional/capsule/content/info_test.rb +1 -2
  49. data/test/functional/content_credentials/create_test.rb +32 -0
  50. data/test/functional/{repository → content_credentials}/data/test_cert.json +0 -0
  51. data/test/functional/content_credentials/list_test.rb +6 -8
  52. data/test/functional/content_export/complete/library_test.rb +155 -0
  53. data/test/functional/content_export/complete/version_test.rb +217 -0
  54. data/test/functional/content_export/content_export_helpers.rb +26 -0
  55. data/test/functional/content_export/generate_metadata_test.rb +64 -0
  56. data/test/functional/content_export/incremental/library_test.rb +172 -0
  57. data/test/functional/content_export/incremental/version_test.rb +268 -0
  58. data/test/functional/content_export/list_test.rb +64 -0
  59. data/test/functional/content_import/library_test.rb +85 -0
  60. data/test/functional/content_import/metadata.json +1 -0
  61. data/test/functional/content_import/version_test.rb +85 -0
  62. data/test/functional/content_view/content_view_helpers.rb +3 -1
  63. data/test/functional/content_view/list_test.rb +0 -2
  64. data/test/functional/content_view/publish_test.rb +0 -21
  65. data/test/functional/content_view/version/promote_test.rb +1 -2
  66. data/test/functional/content_view/version/republish_repositories_test.rb +1 -2
  67. data/test/functional/host/errata/apply_test.rb +0 -2
  68. data/test/functional/host/errata/recalculate_test.rb +0 -2
  69. data/test/functional/host/extensions/update_test.rb +0 -1
  70. data/test/functional/host/traces/resolve_test.rb +31 -0
  71. data/test/functional/lifecycle_environment/lifecycle_environment_helpers.rb +1 -1
  72. data/test/functional/ping_test.rb +1 -2
  73. data/test/functional/repository/create_test.rb +0 -30
  74. data/test/functional/repository/info_test.rb +4 -4
  75. data/test/functional/repository/list_test.rb +0 -2
  76. data/test/functional/search_helpers.rb +11 -0
  77. data/test/functional/simple_content_access/disable_test.rb +48 -0
  78. data/test/functional/simple_content_access/enable_test.rb +46 -0
  79. data/test/test_helper.rb +1 -1
  80. metadata +45 -18
  81. data/lib/hammer_cli_katello/content_view_puppet_module.rb +0 -60
  82. data/lib/hammer_cli_katello/gpg_key.rb +0 -67
  83. data/lib/hammer_cli_katello/puppet_module.rb +0 -59
  84. data/test/functional/content_view/puppet_module/add_test.rb +0 -24
  85. data/test/functional/content_view/puppet_module/remove_test.rb +0 -54
  86. data/test/functional/gpg_test.rb +0 -39
  87. data/test/functional/repository/data/test_ca.json +0 -43
  88. data/test/functional/repository/data/test_key.json +0 -43
@@ -0,0 +1,64 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_export'
3
+
4
+ describe 'content-export list' do
5
+ let(:empty_response) do
6
+ {
7
+ "total" => 0,
8
+ "subtotal" => 0,
9
+ "page" => "1",
10
+ "per_page" => "1000",
11
+ "error" => nil,
12
+ "search" => nil,
13
+ "sort" => {
14
+ "by" => nil,
15
+ "order" => nil
16
+ },
17
+ "results" => []
18
+ }
19
+ end
20
+
21
+ it 'allows minimal options' do
22
+ ex = api_expects(:content_exports, :index)
23
+
24
+ ex.returns(empty_response)
25
+ # rubocop:disable LineLength
26
+ expected_result = success_result('---|--------------------|------|------|----------------------|-------------------------|------------|-----------
27
+ ID | DESTINATION SERVER | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
28
+ ---|--------------------|------|------|----------------------|-------------------------|------------|-----------
29
+ ')
30
+ # rubocop:enable LineLength
31
+ result = run_cmd(%w(content-export list))
32
+ assert_cmd(expected_result, result)
33
+ end
34
+
35
+ it 'works with content-view-id only' do
36
+ api_expects(:content_view_versions, :index).returns(empty_response)
37
+
38
+ ex = api_expects(:content_exports, :index)
39
+
40
+ ex.returns(empty_response)
41
+ # rubocop:disable LineLength
42
+ expected_result = success_result('---|--------------------|------|------|----------------------|-------------------------|------------|-----------
43
+ ID | DESTINATION SERVER | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
44
+ ---|--------------------|------|------|----------------------|-------------------------|------------|-----------
45
+ ')
46
+ # rubocop:enable LineLength
47
+ result = run_cmd(%w(content-export list --content-view-id=1))
48
+ assert_cmd(expected_result, result)
49
+ end
50
+
51
+ it 'works with content-view-version-id only' do
52
+ ex = api_expects(:content_exports, :index)
53
+
54
+ ex.returns(empty_response)
55
+ # rubocop:disable LineLength
56
+ expected_result = success_result('---|--------------------|------|------|----------------------|-------------------------|------------|-----------
57
+ ID | DESTINATION SERVER | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
58
+ ---|--------------------|------|------|----------------------|-------------------------|------------|-----------
59
+ ')
60
+ # rubocop:enable LineLength
61
+ result = run_cmd(%w(content-export list --content-view-version-id=1))
62
+ assert_cmd(expected_result, result)
63
+ end
64
+ end
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_import'
3
+
4
+ describe 'content-import library' do
5
+ include ForemanTaskHelpers
6
+
7
+ before do
8
+ @cmd = %w(content-import library)
9
+ end
10
+
11
+ let(:task_id) { '5' }
12
+
13
+ let(:response) do
14
+ {
15
+ 'id' => task_id,
16
+ 'state' => 'planned'
17
+ }
18
+ end
19
+
20
+ let(:path) do
21
+ File.dirname(__FILE__)
22
+ end
23
+
24
+ let(:metadata) do
25
+ JSON.parse(File.read("#{path}/metadata.json"))
26
+ end
27
+
28
+ let(:organization_id) { 3 }
29
+
30
+ it "performs import with required options and async" do
31
+ params = [
32
+ "--organization-id=#{organization_id}",
33
+ "--path=#{path}",
34
+ '--async'
35
+ ]
36
+ api_expects(:content_imports, :library)
37
+ .with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
38
+ .returns(response)
39
+
40
+ result = run_cmd(@cmd + params)
41
+
42
+ assert_equal("Archive is being imported in task #{task_id}.\n", result.out)
43
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
44
+ end
45
+
46
+ it "performs import with required options" do
47
+ params = [
48
+ "--organization-id=#{organization_id}",
49
+ "--path=#{path}"
50
+ ]
51
+
52
+ api_expects(:content_imports, :library)
53
+ .with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
54
+ .returns(response)
55
+
56
+ expect_foreman_task(task_id)
57
+
58
+ result = run_cmd(@cmd + params)
59
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
60
+ end
61
+
62
+ it 'fails on missing required params' do
63
+ params = [
64
+ '--id=2'
65
+ ]
66
+
67
+ result = run_cmd(@cmd + params)
68
+ expected_error = "Could not import the archive."
69
+
70
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
71
+ assert_equal(result.err[/#{expected_error}/], expected_error)
72
+ end
73
+
74
+ it 'fails on missing metadata.json' do
75
+ bad_path = "/nosuchdir"
76
+ params = [
77
+ "--organization-id=#{organization_id}",
78
+ "--path=#{bad_path}"
79
+ ]
80
+ result = run_cmd(@cmd + params)
81
+ expected_error = "Unable to find '#{bad_path}/metadata.json'."
82
+
83
+ assert_match(/#{expected_error}/, result.err)
84
+ end
85
+ end
@@ -0,0 +1 @@
1
+ {"organization":"export-9697","repository_mapping":{"katello-15062":{"repository":"katello","product":"prod","redhat":false},"misc-28137":{"repository":"misc","product":"prod","redhat":false},"candlepin-37918":{"repository":"candlepin","product":"prod","redhat":false}},"content_view":"view","content_view_version":{"major":1,"minor":0},"incremental":false,"toc":"export-24d91ced-3d11-4fa2-b5ea-19a41f7b97a5-20201118_1523-toc.json"}
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_import'
3
+
4
+ describe 'content-import version' do
5
+ include ForemanTaskHelpers
6
+
7
+ before do
8
+ @cmd = %w(content-import version)
9
+ end
10
+
11
+ let(:task_id) { '5' }
12
+
13
+ let(:response) do
14
+ {
15
+ 'id' => task_id,
16
+ 'state' => 'planned'
17
+ }
18
+ end
19
+
20
+ let(:path) do
21
+ File.dirname(__FILE__)
22
+ end
23
+
24
+ let(:metadata) do
25
+ JSON.parse(File.read("#{path}/metadata.json"))
26
+ end
27
+
28
+ let(:content_view_id) { 3 }
29
+
30
+ it "performs import with required options and async" do
31
+ params = [
32
+ "--content-view-id=#{content_view_id}",
33
+ "--path=#{path}",
34
+ '--async'
35
+ ]
36
+ api_expects(:content_imports, :version)
37
+ .with_params('content_view_id' => content_view_id, 'path' => path, 'metadata' => metadata)
38
+ .returns(response)
39
+
40
+ result = run_cmd(@cmd + params)
41
+
42
+ assert_equal("Archive is being imported in task #{task_id}.\n", result.out)
43
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
44
+ end
45
+
46
+ it "performs import with required options" do
47
+ params = [
48
+ "--content-view-id=#{content_view_id}",
49
+ "--path=#{path}"
50
+ ]
51
+
52
+ api_expects(:content_imports, :version)
53
+ .with_params('content_view_id' => content_view_id, 'path' => path, 'metadata' => metadata)
54
+ .returns(response)
55
+
56
+ expect_foreman_task(task_id)
57
+
58
+ result = run_cmd(@cmd + params)
59
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
60
+ end
61
+
62
+ it 'fails on missing required params' do
63
+ params = [
64
+ '--id=2'
65
+ ]
66
+
67
+ result = run_cmd(@cmd + params)
68
+ expected_error = "Could not import the archive."
69
+
70
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
71
+ assert_equal(result.err[/#{expected_error}/], expected_error)
72
+ end
73
+
74
+ it 'fails on missing metadata.json' do
75
+ bad_path = "/nosuchdir"
76
+ params = [
77
+ "--content-view-id=#{content_view_id}",
78
+ "--path=#{bad_path}"
79
+ ]
80
+ result = run_cmd(@cmd + params)
81
+ expected_error = "Unable to find '#{bad_path}/metadata.json'."
82
+
83
+ assert_match(/#{expected_error}/, result.err)
84
+ end
85
+ end
@@ -13,6 +13,8 @@ module ContentViewHelpers
13
13
  end
14
14
 
15
15
  def expect_content_view_version_search(params, returns)
16
- expect_generic_search(:content_view_versions, params: params, returns: returns)
16
+ expect_lenient_search(:content_view_versions,
17
+ params: params,
18
+ returns: returns)
17
19
  end
18
20
  end
@@ -1,8 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), '../test_helper')
2
2
  require File.join(File.dirname(__FILE__), '../lifecycle_environment/lifecycle_environment_helpers')
3
3
 
4
- require 'hammer_cli_katello/content_view_puppet_module'
5
-
6
4
  describe 'listing content-views' do
7
5
  include LifecycleEnvironmentHelpers
8
6
 
@@ -1,5 +1,4 @@
1
1
  require_relative '../test_helper'
2
- require 'hammer_cli_katello/content_view_puppet_module'
3
2
  require 'hammer_cli_katello/content_view'
4
3
 
5
4
  module HammerCLIKatello
@@ -22,24 +21,4 @@ module HammerCLIKatello
22
21
  run_cmd(%w(content-view publish --major 5 --minor 1 --organization org1 --name cv --async))
23
22
  end
24
23
  end
25
-
26
- describe ContentViewPuppetModule do
27
- it 'allows adding a puppet module' do
28
- ex = api_expects(:organizations, :index) do |p|
29
- p[:search] == "name = \"org1\""
30
- end
31
- ex.returns(index_response([{'id' => 1}]))
32
-
33
- ex = api_expects(:content_views, :index) do |p|
34
- p['name'] == 'cv' && p['organization_id'] == 1
35
- end
36
- ex.returns(index_response([{'id' => 3}]))
37
-
38
- api_expects(:content_views, :publish) do |p|
39
- p['id'] == 3
40
- end
41
-
42
- run_cmd(%w(content-view publish --organization org1 --name cv --async))
43
- end
44
- end
45
24
  end
@@ -1,8 +1,7 @@
1
1
  require_relative '../../test_helper'
2
- require 'hammer_cli_katello/content_view_puppet_module'
3
2
 
4
3
  module HammerCLIKatello
5
- describe ContentViewPuppetModule do
4
+ describe ContentViewVersion::PromoteCommand do
6
5
  it 'allows promoting a content view' do
7
6
  ex = api_expects(:organizations, :index) do |p|
8
7
  p[:search] == "name = \"org1\""
@@ -1,8 +1,7 @@
1
1
  require_relative '../../test_helper'
2
- require 'hammer_cli_katello/content_view_puppet_module'
3
2
 
4
3
  module HammerCLIKatello
5
- describe ContentViewPuppetModule do
4
+ describe ContentViewVersion::RepublishRepositoriesCommand do
6
5
  include ForemanTaskHelpers
7
6
  include OrganizationHelpers
8
7
 
@@ -1,7 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), '../../test_helper')
2
2
 
3
- require 'hammer_cli_katello/content_view_puppet_module'
4
-
5
3
  describe 'apply an errata' do
6
4
  include ForemanTaskHelpers
7
5
 
@@ -1,7 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), '../../test_helper')
2
2
 
3
- require 'hammer_cli_katello/content_view_puppet_module'
4
-
5
3
  describe 'recalculate errata' do
6
4
  include ForemanTaskHelpers
7
5
 
@@ -29,7 +29,6 @@ module HammerCLIForeman
29
29
  with_params('id' => host_id.to_s,
30
30
  'organization_id' => organization_id,
31
31
  'host' => {
32
- 'compute_attributes' => {},
33
32
  'content_facet_attributes' => {
34
33
  'content_view_id' => cv_id,
35
34
  'lifecycle_environment_id' => env_id,
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+
3
+ describe 'host trace resolve' do
4
+ include ForemanTaskHelpers
5
+
6
+ before do
7
+ @cmd = %w(host traces resolve)
8
+ end
9
+
10
+ let(:host_id) { '2' }
11
+ let(:task_id) { '5' }
12
+ let(:response) do
13
+ {
14
+ 'id' => task_id,
15
+ 'state' => 'stopped'
16
+ }
17
+ end
18
+
19
+ it "resolves traces on a host" do
20
+ trace_ids = [3]
21
+ params = ["--host-id=#{host_id}", "--trace-ids=#{trace_ids}"]
22
+
23
+ ex = api_expects(:host_tracer, :resolve)
24
+
25
+ ex.returns(response)
26
+
27
+ expect_foreman_task(task_id)
28
+
29
+ run_cmd(@cmd + params)
30
+ end
31
+ end
@@ -4,7 +4,7 @@ module LifecycleEnvironmentHelpers
4
4
  include SearchHelpers
5
5
 
6
6
  def expect_lifecycle_environment_search(org_id, name, id)
7
- expect_generic_search(:lifecycle_environments,
7
+ expect_lenient_search(:lifecycle_environments,
8
8
  params: {'name' => name, 'organization_id' => org_id},
9
9
  returns: {'id' => id})
10
10
  end
@@ -11,8 +11,7 @@ describe 'ping' do
11
11
  'candlepin_events' => {'status' => 'ok', 'message' => '0 messages', 'duration_ms' => '34'},
12
12
  'candlepin_auth' => {'status' => 'ok', 'duration_ms' => '34'},
13
13
  'katello_events' => {'status' => 'ok', 'message' => '0 messages', 'duration_ms' => '34'},
14
- 'pulp' => {'status' => 'ok', 'duration_ms' => '34'},
15
- 'pulp_auth' => {'status' => 'ok', 'duration_ms' => '34'}
14
+ 'pulp3' => {'status' => 'ok', 'duration_ms' => '34'}
16
15
  }
17
16
  )
18
17
 
@@ -18,34 +18,4 @@ describe "create repository" do
18
18
 
19
19
  assert_equal(0, run_cmd(command).exit_code)
20
20
  end
21
-
22
- it 'with ssl options by name' do
23
- def stub_gpg_key(gpg_key_name)
24
- gpg_key_index = api_expects(:gpg_keys, :index)
25
- .with_params(
26
- name: gpg_key_name.to_s,
27
- organization_id: 1,
28
- per_page: 1000,
29
- page: 1)
30
- gpg_response = File.join(File.dirname(__FILE__), 'data', "#{gpg_key_name}.json")
31
- gpg_key_index.returns(JSON.parse(File.read(gpg_response)))
32
- end
33
-
34
- api_expects(:repositories, :create)
35
- .with_params(
36
- name: name,
37
- product_id: product_id,
38
- ssl_ca_cert_id: 1,
39
- ssl_client_cert_id: 2,
40
- ssl_client_key_id: 3,
41
- content_type: content_type)
42
-
43
- %w(test_cert test_key test_ca).each { |cred| stub_gpg_key(cred) }
44
-
45
- command = %W(repository create --organization-id #{org_id} --product-id #{product_id}
46
- --content-type #{content_type} --name #{name} --ssl-client-cert test_cert
47
- --ssl-client-key test_key --ssl-ca-cert test_ca)
48
-
49
- assert_equal(0, run_cmd(command).exit_code)
50
- end
51
21
  end
@@ -46,7 +46,7 @@ describe "get repository info" do
46
46
  )
47
47
  result = run_cmd(@cmd + params)
48
48
  # rubocop:disable Style/WordArray
49
- expected_fields = [['ID', '1'],
49
+ expected_fields = [['Id', '1'],
50
50
  ['Name', 'Test Repo'],
51
51
  ['Label', 'Test_Repo'],
52
52
  ['Description', 'hammertime'],
@@ -59,7 +59,7 @@ describe "get repository info" do
59
59
  ['Download Policy', 'immediate'],
60
60
  ['HTTP Proxy', ''],
61
61
  ['Product', ''],
62
- ['ID', '79'],
62
+ ['Id', '79'],
63
63
  ['Name', 'test'],
64
64
  ['GPG Key', ''],
65
65
  ['Sync', ''],
@@ -122,7 +122,7 @@ describe "get repository info" do
122
122
  )
123
123
  result = run_cmd(@cmd + params)
124
124
  # rubocop:disable Style/WordArray
125
- expected_fields = [['ID', '1'],
125
+ expected_fields = [['Id', '1'],
126
126
  ['Name', 'Test Repo'],
127
127
  ['Label', 'Test_Repo'],
128
128
  ['Description', 'hammertime'],
@@ -135,7 +135,7 @@ describe "get repository info" do
135
135
  ['Download Policy', 'immediate'],
136
136
  ['HTTP Proxy', ''],
137
137
  ['Product', ''],
138
- ['ID', '79'],
138
+ ['Id', '79'],
139
139
  ['Name', 'Test_Product'],
140
140
  ['GPG Key', ''],
141
141
  ['Sync', ''],