hammer_cli_katello 0.20.0 → 0.22.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello.rb +13 -2
  3. data/lib/hammer_cli_katello/content_credential.rb +67 -0
  4. data/lib/hammer_cli_katello/content_view_version.rb +2 -6
  5. data/lib/hammer_cli_katello/exception_handler.rb +15 -8
  6. data/lib/hammer_cli_katello/foreman_search_options_creators.rb +8 -0
  7. data/lib/hammer_cli_katello/host.rb +5 -0
  8. data/lib/hammer_cli_katello/host_errata.rb +3 -0
  9. data/lib/hammer_cli_katello/host_extensions.rb +4 -0
  10. data/lib/hammer_cli_katello/host_traces.rb +19 -0
  11. data/lib/hammer_cli_katello/id_resolver.rb +1 -0
  12. data/lib/hammer_cli_katello/ping.rb +16 -0
  13. data/lib/hammer_cli_katello/product.rb +19 -1
  14. data/lib/hammer_cli_katello/repository.rb +37 -1
  15. data/lib/hammer_cli_katello/sync_plan.rb +1 -0
  16. data/lib/hammer_cli_katello/version.rb +1 -1
  17. data/test/data/3.15/foreman_api.json +1 -0
  18. data/test/data/3.16/foreman_api.json +1 -0
  19. data/test/data/3.17/foreman_api.json +1 -0
  20. data/test/functional/content_credentials/info_test.rb +50 -0
  21. data/test/functional/content_credentials/list_test.rb +68 -0
  22. data/test/functional/content_view/version/promote_test.rb +1 -1
  23. data/test/functional/gpg_test.rb +39 -0
  24. data/test/functional/host/errata/list_test.rb +49 -0
  25. data/test/functional/host/extensions/data/host.json +1 -0
  26. data/test/functional/host/extensions/data/host_list.json +2 -0
  27. data/test/functional/host/extensions/info_test.rb +2 -1
  28. data/test/functional/host/extensions/list_test.rb +2 -2
  29. data/test/functional/host/extensions/update_test.rb +2 -2
  30. data/test/functional/host/traces/list_test.rb +37 -0
  31. data/test/functional/organization/delete_test.rb +26 -0
  32. data/test/functional/package/list_test.rb +3 -2
  33. data/test/functional/ping_test.rb +2 -0
  34. data/test/functional/product/update_proxy.rb +48 -0
  35. data/test/functional/repository/create_test.rb +51 -0
  36. data/test/functional/repository/data/test_ca.json +43 -0
  37. data/test/functional/repository/data/test_cert.json +43 -0
  38. data/test/functional/repository/data/test_key.json +43 -0
  39. data/test/functional/srpm/list_test.rb +1 -0
  40. data/test/test_helper.rb +2 -2
  41. data/test/unit/search_options_creators_test.rb +6 -0
  42. metadata +37 -8
@@ -0,0 +1,68 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper')
2
+ require File.join(File.dirname(__FILE__), '../lifecycle_environment/lifecycle_environment_helpers')
3
+
4
+ require 'hammer_cli_katello/content_view_puppet_module'
5
+
6
+ describe 'listing content credentials' do
7
+ include LifecycleEnvironmentHelpers
8
+
9
+ before do
10
+ @cmd = %w(content-credentials list)
11
+ end
12
+
13
+ let(:org_id) { 1 }
14
+ let(:lifecycle_env_id) { 1 }
15
+ let(:empty_response) do
16
+ {
17
+ "total" => 0,
18
+ "subtotal" => 0,
19
+ "page" => "1",
20
+ "per_page" => "1000",
21
+ "error" => nil,
22
+ "search" => nil,
23
+ "sort" => {
24
+ "by" => nil,
25
+ "order" => nil
26
+ },
27
+ "results" => []
28
+ }
29
+ end
30
+
31
+ it "lists an organizations keys" do
32
+ params = ["--organization-id=#{org_id}"]
33
+
34
+ ex = api_expects(:content_credentials, :index, 'Organization content credentials list') do |par|
35
+ par['organization_id'] == org_id && par['page'] == 1 &&
36
+ par['per_page'] == 1000
37
+ end
38
+
39
+ ex.returns(empty_response)
40
+
41
+ expected_result = success_result("---|-----
42
+ ID | NAME
43
+ ---|-----
44
+ ")
45
+
46
+ result = run_cmd(@cmd + params)
47
+ assert_cmd(expected_result, result)
48
+ end
49
+
50
+ it "lists the keys by content-type" do
51
+ params = ['--content-type=gpg', "--organization-id=#{org_id}"]
52
+
53
+ ex = api_expects(:content_credentials, :index, 'content-type') do |par|
54
+ par['organization_id'] == org_id && par['page'] == 1 &&
55
+ par['per_page'] == 1000
56
+ end
57
+
58
+ ex.returns(empty_response)
59
+
60
+ expected_result = CommandExpectation.new("---|-----
61
+ ID | NAME
62
+ ---|-----
63
+ ")
64
+
65
+ result = run_cmd(@cmd + params)
66
+ assert_cmd(expected_result, result)
67
+ end
68
+ end
@@ -25,7 +25,7 @@ module HammerCLIKatello
25
25
  ex.returns(index_response([{'id' => 9}]))
26
26
 
27
27
  api_expects(:content_view_versions, :promote) do |p|
28
- p['id'] == 6 && p['environment_id'] == 9
28
+ p['id'] == 6 && p['environment_ids'] == [9]
29
29
  end
30
30
 
31
31
  run_cmd(%w(content-view version promote --organization org1 --content-view cv
@@ -0,0 +1,39 @@
1
+ require_relative 'test_helper'
2
+ require 'hammer_cli_katello/gpg_key'
3
+
4
+ module HammerCLIKatello
5
+ describe GpgKeyCommand::ListCommand do
6
+ it 'warns of deprecation' do
7
+ result = run_cmd(%w(gpg list))
8
+ assert_match(/deprecated/, result.err)
9
+ end
10
+ end
11
+
12
+ describe GpgKeyCommand::InfoCommand do
13
+ it 'warns of deprecation' do
14
+ result = run_cmd(%w(gpg info))
15
+ assert_match(/deprecated/, result.err)
16
+ end
17
+ end
18
+
19
+ describe GpgKeyCommand::CreateCommand do
20
+ it 'warns of deprecation' do
21
+ result = run_cmd(%w(gpg create))
22
+ assert_match(/deprecated/, result.err)
23
+ end
24
+ end
25
+
26
+ describe GpgKeyCommand::UpdateCommand do
27
+ it 'warns of deprecation' do
28
+ result = run_cmd(%w(gpg update))
29
+ assert_match(/deprecated/, result.err)
30
+ end
31
+ end
32
+
33
+ describe GpgKeyCommand::DeleteCommand do
34
+ it 'warns of deprecation' do
35
+ result = run_cmd(%w(gpg delete))
36
+ assert_match(/deprecated/, result.err)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require_relative '../../lifecycle_environment/lifecycle_environment_helpers'
3
+
4
+ describe 'host errata listing' do
5
+ include LifecycleEnvironmentHelpers
6
+
7
+ before do
8
+ @cmd = %w(host errata list)
9
+ end
10
+
11
+ let(:org_id) { 1 }
12
+ let(:host_id) { 2 }
13
+ let(:lifecycle_env_id) { 3 }
14
+ let(:empty_response) do
15
+ {
16
+ "total" => 0,
17
+ "subtotal" => 0,
18
+ "page" => "1",
19
+ "per_page" => "1000",
20
+ "error" => nil,
21
+ "search" => nil,
22
+ "sort" => {
23
+ "by" => nil,
24
+ "order" => nil
25
+ },
26
+ "results" => []
27
+ }
28
+ end
29
+
30
+ it "lists the host errata belonging to a lifecycle-environment by name" do
31
+ params = ["--host-id=#{host_id}", "--organization-id=#{org_id}", '--lifecycle-environment=test']
32
+
33
+ expect_lifecycle_environment_search(org_id.to_s, 'test', lifecycle_env_id)
34
+
35
+ ex = api_expects(:host_errata, :index, 'host errata list').
36
+ with_params('host_id': host_id,
37
+ 'environment_id': lifecycle_env_id,
38
+ 'page': 1,
39
+ 'per_page': 1000)
40
+
41
+ ex.returns(empty_response)
42
+ expected_result = success_result("---|------------|------|-------|------------
43
+ ID | ERRATUM ID | TYPE | TITLE | INSTALLABLE
44
+ ---|------------|------|-------|------------
45
+ ")
46
+ result = run_cmd(@cmd + params)
47
+ assert_cmd(expected_result, result)
48
+ end
49
+ end
@@ -100,6 +100,7 @@
100
100
  "applicable_package_count": 5,
101
101
  "upgradable_package_count": 4
102
102
  },
103
+ "traces_status_label":"Updated",
103
104
  "subscription_facet_attributes":{
104
105
  "id":2,
105
106
  "uuid":"179834bf-779a-457f-a1fa-b06ae0acb21a",
@@ -74,6 +74,8 @@
74
74
  "errata_status_label":"Could not calculate errata status, ensure host is registered and katello-agent is installed",
75
75
  "subscription_status":0,
76
76
  "subscription_status_label":"Fully entitled",
77
+ "traces_status":0,
78
+ "traces_status_label":"updated",
77
79
  "name":"robot.example.com",
78
80
  "id":1,
79
81
  "hostgroup_name":null,
@@ -27,7 +27,8 @@ describe 'host info' do
27
27
  ['Upgradable Packages', '4'],
28
28
  ['Purpose Usage', 'Production'],
29
29
  ['Purpose Role', 'Role'],
30
- ['Purpose Addons', 'Test Addon1, Test Addon2']]
30
+ ['Purpose Addons', 'Test Addon1, Test Addon2'],
31
+ ['Trace Status', 'Updated']]
31
32
  expected_results = expected_fields.map { |field| success_result(FieldMatcher.new(*field)) }
32
33
  expected_results.each { |expected| assert_cmd(expected, result) }
33
34
  end
@@ -13,8 +13,8 @@ describe 'host list' do
13
13
 
14
14
  result = run_cmd(@cmd)
15
15
 
16
- fields = ['CONTENT VIEW', 'LIFECYCLE ENVIRONMENT']
17
- values = ['Default Organization View', 'Library']
16
+ fields = ['CONTENT VIEW', 'LIFECYCLE ENVIRONMENT', 'TRACE STATUS']
17
+ values = ['Default Organization View', 'Library', 'updated']
18
18
  expected_result = success_result(IndexMatcher.new([fields, values]))
19
19
  assert_cmd(expected_result, result)
20
20
  end
@@ -29,13 +29,13 @@ module HammerCLIForeman
29
29
  with_params('id' => host_id.to_s,
30
30
  'organization_id' => organization_id,
31
31
  'host' => {
32
- 'puppetclass_ids' => [],
33
32
  'compute_attributes' => {},
34
33
  'content_facet_attributes' => {
35
34
  'content_view_id' => cv_id,
36
35
  'lifecycle_environment_id' => env_id,
37
36
  'kickstart_repository_id' => repo_id
38
- }
37
+ },
38
+ 'subscription_facet_attributes' => {}
39
39
  })
40
40
 
41
41
  cmd = "host update --id=#{host_id}"\
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+
3
+ describe 'host trace listing' do
4
+ before do
5
+ @cmd = %w(host traces list)
6
+ end
7
+
8
+ let(:host_id) { 2 }
9
+ let(:empty_response) do
10
+ {
11
+ "total" => 0,
12
+ "subtotal" => 0,
13
+ "page" => "1",
14
+ "per_page" => "1000",
15
+ "error" => nil,
16
+ "search" => nil,
17
+ "sort" => {
18
+ "by" => nil,
19
+ "order" => nil
20
+ },
21
+ "results" => []
22
+ }
23
+ end
24
+
25
+ it 'allows listing by host' do
26
+ params = ["--host-id=#{host_id}"]
27
+ ex = api_expects(:host_tracer, :index, 'host traces list')
28
+
29
+ ex.returns(empty_response)
30
+ expected_result = success_result("---------|-------------|--------|-----
31
+ TRACE ID | APPLICATION | HELPER | TYPE
32
+ ---------|-------------|--------|-----
33
+ ")
34
+ result = run_cmd(@cmd + params)
35
+ assert_cmd(expected_result, result)
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../test_helper'
2
+
3
+ module HammerCLIKatello
4
+ describe 'Organization::DeleteCommand' do
5
+ it 'it requires the organization ID and must be resolved from name' do
6
+ api_expects(:organizations, :index).with_params(
7
+ :search => "name = \"my_org\"", :per_page => 1000, :page => 1
8
+ )
9
+ run_cmd(%w(organization delete --name my_org))
10
+ end
11
+
12
+ it 'it requires the organization ID and must be resolved from name' do
13
+ api_expects(:organizations, :index).with_params(
14
+ :search => "label = \"my_org\"", :per_page => 1000, :page => 1
15
+ )
16
+ run_cmd(%w(organization delete --label my_org))
17
+ end
18
+
19
+ it 'it requires the organization ID and must be resolved from name' do
20
+ api_expects(:organizations, :index).with_params(
21
+ :search => "title = \"my_org\"", :per_page => 1000, :page => 1
22
+ )
23
+ run_cmd(%w(organization delete --title my_org))
24
+ end
25
+ end
26
+ end
@@ -86,8 +86,9 @@ module HammerCLIKatello
86
86
  it 'may be specified environment name no org fails' do
87
87
  api_expects_no_call
88
88
  r = run_cmd(%w(package list --environment Library))
89
- expected_error = "--organization, --organization-label, --organization-id"
90
- assert(r.err.include?(expected_error), "Invalid error message")
89
+ expec_err = "--organization, --organization-title, --organization-label, --organization-id"
90
+ puts r.err
91
+ assert(r.err.include?(expec_err), "Invalid error message")
91
92
  end
92
93
  end
93
94
 
@@ -8,7 +8,9 @@ describe 'ping' do
8
8
  'foreman_tasks' => {'status' => 'ok', 'duration_ms' => '34'},
9
9
  'foreman_auth' => {'status' => 'ok', 'duration_ms' => '34'},
10
10
  'candlepin' => {'status' => 'ok', 'duration_ms' => '34'},
11
+ 'candlepin_events' => {'status' => 'ok', 'message' => '0 messages', 'duration_ms' => '34'},
11
12
  'candlepin_auth' => {'status' => 'ok', 'duration_ms' => '34'},
13
+ 'katello_events' => {'status' => 'ok', 'message' => '0 messages', 'duration_ms' => '34'},
12
14
  'pulp' => {'status' => 'ok', 'duration_ms' => '34'},
13
15
  'pulp_auth' => {'status' => 'ok', 'duration_ms' => '34'}
14
16
  }
@@ -0,0 +1,48 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper')
2
+
3
+ describe 'update an http proxy on a product' do
4
+ include ForemanTaskHelpers
5
+
6
+ before do
7
+ @cmd = %w(product update-proxy)
8
+ end
9
+
10
+ let(:sync_response) do
11
+ {
12
+ 'id' => 1,
13
+ 'state' => 'planned',
14
+ 'action' => 'Update http proxy'
15
+ }
16
+ end
17
+
18
+ it 'updates product proxy policy' do
19
+ params = [
20
+ '--ids=1',
21
+ '--http-proxy-policy=use_selected_http_proxy',
22
+ '--http-proxy-id=1'
23
+ ]
24
+
25
+ ex = api_expects(:products_bulk_actions, :update_http_proxy, 'update an http-proxy')
26
+ .with_params('ids' => '1', 'http_proxy_policy' => 'use_selected_http_proxy',
27
+ 'http_proxy_id' => '1')
28
+ ex.returns(sync_response)
29
+
30
+ expect_foreman_task('3')
31
+
32
+ result = run_cmd(@cmd + params)
33
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
34
+ end
35
+
36
+ it 'fails with missing required params' do
37
+ params = ['--proxy-id=1']
38
+
39
+ ex = api_expects(:products_bulk_actions, :update_http_proxy, 'update an http-proxy')
40
+ .with_params('proxy_id' => '1')
41
+ ex.returns(
42
+ 'proxy_id' => '1'
43
+ )
44
+
45
+ result = run_cmd(@cmd + params)
46
+ assert_equal(result.exit_code, 70)
47
+ end
48
+ end
@@ -0,0 +1,51 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe "create repository" do
4
+ let(:org_id) { 1 }
5
+ let(:product_id) { 2 }
6
+ let(:name) { "repo1" }
7
+ let(:content_type) { "yum" }
8
+
9
+ it 'with basic options' do
10
+ api_expects(:repositories, :create)
11
+ .with_params(
12
+ name: name,
13
+ product_id: product_id,
14
+ content_type: content_type)
15
+
16
+ command = %W(repository create --organization-id #{org_id} --product-id #{product_id}
17
+ --content-type #{content_type} --name #{name})
18
+
19
+ assert_equal(0, run_cmd(command).exit_code)
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
+ end
@@ -0,0 +1,43 @@
1
+ {
2
+ "name":"test_ca",
3
+ "content_type":"cert",
4
+ "content":"hi",
5
+ "id":1,
6
+ "organization_id":1,
7
+ "organization":{
8
+ "name":"org2",
9
+ "label":"org2",
10
+ "id":1
11
+ },
12
+ "created_at":"2020-01-28 09:30:54 -0500",
13
+ "updated_at":"2020-01-28 09:30:54 -0500",
14
+ "gpg_key_products":[
15
+
16
+ ],
17
+ "gpg_key_repos":[
18
+
19
+ ],
20
+ "ssl_ca_products":[
21
+
22
+ ],
23
+ "ssl_ca_root_repos":[
24
+
25
+ ],
26
+ "ssl_client_products":[
27
+
28
+ ],
29
+ "ssl_client_root_repos":[
30
+
31
+ ],
32
+ "ssl_key_products":[
33
+
34
+ ],
35
+ "ssl_key_root_repos":[
36
+
37
+ ],
38
+ "permissions":{
39
+ "view_content_credenials":true,
40
+ "edit_content_credenials":true,
41
+ "destroy_content_credenials":true
42
+ }
43
+ }