hammer_cli_katello 0.11.5.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello.rb +5 -0
  3. data/lib/hammer_cli_katello/content_view.rb +22 -8
  4. data/lib/hammer_cli_katello/file.rb +72 -0
  5. data/lib/hammer_cli_katello/foreman_search_options_creators.rb +34 -34
  6. data/lib/hammer_cli_katello/host_collection.rb +18 -0
  7. data/lib/hammer_cli_katello/host_content_source_options.rb +25 -0
  8. data/lib/hammer_cli_katello/host_extensions.rb +34 -3
  9. data/lib/hammer_cli_katello/host_kickstart_repository_options.rb +49 -0
  10. data/lib/hammer_cli_katello/hostgroup_extensions.rb +25 -3
  11. data/lib/hammer_cli_katello/id_resolver.rb +15 -9
  12. data/lib/hammer_cli_katello/repository.rb +47 -1
  13. data/lib/hammer_cli_katello/search_options_creators.rb +23 -16
  14. data/lib/hammer_cli_katello/sync_plan.rb +5 -0
  15. data/lib/hammer_cli_katello/version.rb +1 -1
  16. data/test/functional/capsule/content/add_lifecycle_environment_test.rb +3 -3
  17. data/test/functional/capsule/content/cancel_synchronization_test.rb +3 -3
  18. data/test/functional/capsule/content/info_test.rb +3 -3
  19. data/test/functional/capsule/content/lifecycle_environments_test.rb +1 -1
  20. data/test/functional/capsule/content/remove_lifecycle_environment_test.rb +3 -3
  21. data/test/functional/capsule/content/synchronization_status_test.rb +3 -3
  22. data/test/functional/content_view/content_view_helpers.rb +4 -0
  23. data/test/functional/content_view/create_test.rb +2 -2
  24. data/test/functional/content_view/filter/delete_test.rb +1 -4
  25. data/test/functional/content_view/filter/info_test.rb +1 -4
  26. data/test/functional/content_view/filter/list_test.rb +1 -1
  27. data/test/functional/content_view/filter/update_test.rb +1 -4
  28. data/test/functional/erratum/list_test.rb +1 -1
  29. data/test/functional/file/file_helpers.rb +13 -0
  30. data/test/functional/file/info_test.rb +162 -0
  31. data/test/functional/file/list_test.rb +112 -0
  32. data/test/functional/filter_rule/info_test.rb +1 -1
  33. data/test/functional/filter_rule/update_test.rb +1 -1
  34. data/test/functional/host/extensions/create_test.rb +95 -0
  35. data/test/functional/host/extensions/data/host.json +4 -0
  36. data/test/functional/host/extensions/info_test.rb +5 -3
  37. data/test/functional/host/extensions/update_test.rb +69 -0
  38. data/test/functional/host_collection/add_host_test.rb +36 -3
  39. data/test/functional/host_collection/copy_test.rb +4 -4
  40. data/test/functional/host_collection/delete_test.rb +3 -3
  41. data/test/functional/host_collection/hosts_test.rb +1 -2
  42. data/test/functional/host_collection/info_test.rb +3 -3
  43. data/test/functional/host_collection/remove_host_test.rb +36 -3
  44. data/test/functional/host_collection/update_test.rb +3 -3
  45. data/test/functional/hostgroup/create_test.rb +46 -1
  46. data/test/functional/hostgroup/data/hostgroup.json +48 -46
  47. data/test/functional/hostgroup/info_test.rb +5 -3
  48. data/test/functional/hostgroup/update_test.rb +48 -1
  49. data/test/functional/lifecycle_environment/create_test.rb +1 -1
  50. data/test/functional/package/list_test.rb +1 -1
  51. data/test/functional/product/product_helpers.rb +6 -4
  52. data/test/functional/repository/upload_test.rb +32 -14
  53. data/test/functional/sync_plan/info_test.rb +37 -0
  54. data/test/functional/sync_plan/list_test.rb +31 -0
  55. metadata +21 -18
@@ -74,6 +74,10 @@
74
74
  "content_view_name":"Default Organization View",
75
75
  "lifecycle_environment_id":1,
76
76
  "lifecycle_environment_name":"Library",
77
+ "content_source_id":2,
78
+ "content_source_name":"capsule",
79
+ "kickstart_repository_id":10000,
80
+ "kickstart_repository_name":"Rhel 7",
77
81
  "content_view":{
78
82
  "id":1,
79
83
  "name":"Default Organization View"
@@ -15,10 +15,12 @@ describe 'host info' do
15
15
  ex.returns(JSON.parse(File.read(json_file)))
16
16
 
17
17
  result = run_cmd(@cmd + params)
18
-
19
- expected_fields = [['Lifecycle Environment', 'Library'],
20
- ['Content View', 'Default Organization View'],
18
+ # rubocop:disable Style/WordArray
19
+ expected_fields = [['Name', 'Library'],
20
+ ['Name', 'Default Organization View'],
21
21
  ['Release Version', '7Server'],
22
+ ['Name', 'Rhel 7'],
23
+ ['Name', 'capsule'],
22
24
  ['Bug Fix', '0'],
23
25
  ['Name', 'my host collection'],
24
26
  ['Applicable Packages', '5'],
@@ -0,0 +1,69 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_foreman/host'
3
+
4
+ module HammerCLIForeman
5
+ describe Host do
6
+ # These tests are only for the extensions Katello adds to the hostgroup command
7
+ # See hammer-cli-foreman for the core hostgroup tests
8
+ describe UpdateCommand do
9
+ it 'allows kickstart repository name' do
10
+ env_name = "world"
11
+ env_id = 100
12
+ cv_id = 200
13
+ repo_name = "life_of_kickstart"
14
+ repo_id = 111
15
+ host_id = 777
16
+ organization_id = 329
17
+ api_expects(:lifecycle_environments, :index).
18
+ with_params('name' => env_name,
19
+ 'organization_id' => organization_id).
20
+ returns(index_response([{'id' => env_id}]))
21
+
22
+ api_expects(:repositories, :index).
23
+ with_params('name' => repo_name,
24
+ 'environment_id' => env_id,
25
+ 'content_view_id' => cv_id).
26
+ returns(index_response([{'id' => repo_id}]))
27
+
28
+ api_expects(:hosts, :update).
29
+ with_params('id' => host_id.to_s,
30
+ 'host' => {
31
+ 'organization_id' => organization_id,
32
+ 'content_facet_attributes' => {
33
+ 'lifecycle_environment_id' => env_id,
34
+ 'content_view_id' => cv_id,
35
+ 'kickstart_repository_id' => repo_id
36
+ }
37
+ })
38
+
39
+ cmd = "host update --id=#{host_id}"\
40
+ " --content-view-id=#{cv_id}"\
41
+ " --lifecycle-environment=#{env_name}"\
42
+ " --kickstart-repository=#{repo_name}"\
43
+ " --organization-id=#{organization_id}"
44
+ run_cmd(cmd.split)
45
+ end
46
+
47
+ it 'allows content source name' do
48
+ content_source_name = "life_of_cs"
49
+ content_source_id = 111
50
+ host_id = 441
51
+
52
+ api_expects(:smart_proxies, :index).
53
+ with_params(:search => "name = \"#{content_source_name}\"").
54
+ returns(index_response([{'id' => content_source_id}]))
55
+
56
+ api_expects(:hosts, :update).
57
+ with_params('id' => host_id.to_s,
58
+ 'host' => {
59
+ 'content_facet_attributes' => {
60
+ 'content_source_id' => content_source_id
61
+ }
62
+ })
63
+
64
+ cmd = "host update --id #{host_id} --content-source #{content_source_name}"
65
+ run_cmd(cmd.split)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -3,6 +3,39 @@ require 'hammer_cli_katello/host_collection'
3
3
 
4
4
  module HammerCLIKatello
5
5
  describe HostCollection::AddHostCommand do
6
+ describe 'handles individual host errors' do
7
+ it 'for successful results' do
8
+ api_expects(:host_collections, :add_hosts)
9
+ .with_params('id' => 1, 'host_ids' => %w(2 3))
10
+ .returns("displayMessages" => {"success" => ["Successfully added 2 Host(s)."],
11
+ "error" => []})
12
+ result = run_cmd(%w(host-collection add-host --id 1 --host-ids 2,3))
13
+ assert_match("The host(s) has been added", result.out)
14
+ end
15
+
16
+ it 'for mixed results' do
17
+ api_expects(:host_collections, :add_hosts)
18
+ .with_params('id' => 1, 'host_ids' => %w(2 3))
19
+ .returns("displayMessages" => {"success" => ["Successfully added 1 Host(s)."],
20
+ "error" => ["Host with ID 3 not found."]})
21
+ result = run_cmd(%w(host-collection add-host --id 1 --host-ids 2,3))
22
+ assert_match("Could not add host(s)", result.out)
23
+ assert_match("Host with ID 3 not found.", result.out)
24
+ end
25
+
26
+ it 'for errored results' do
27
+ api_expects(:host_collections, :add_hosts)
28
+ .with_params('id' => 1, 'host_ids' => %w(2 3))
29
+ .returns("displayMessages" => {"success" => [], "error" => [
30
+ "Host with ID 1 already exists in the host collection.",
31
+ "Host with ID 3 not found."]})
32
+ result = run_cmd(%w(host-collection add-host --id 1 --host-ids 2,3))
33
+ assert_match("Could not add host(s)", result.out)
34
+ assert_match("Host with ID 1 already exists in the host collection.", result.out)
35
+ assert_match("Host with ID 3 not found.", result.out)
36
+ end
37
+ end
38
+
6
39
  it 'does not require organization options if id is specified' do
7
40
  api_expects(:host_collections, :add_hosts)
8
41
  run_cmd(%w(host-collection add-host --id 1))
@@ -10,9 +43,9 @@ module HammerCLIKatello
10
43
 
11
44
  it 'requires organization options if name is specified' do
12
45
  result = run_cmd(%w(host-collection add-host --name hc1))
13
- expected_error = "Could not find organization"
14
- assert_equal(result.exit_code, HammerCLI::EX_SOFTWARE)
15
- assert_equal(result.err[/#{expected_error}/], expected_error)
46
+ expected_error = "Missing options to search organization"
47
+ assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
48
+ assert_equal(expected_error, result.err[/#{expected_error}/])
16
49
  end
17
50
 
18
51
  it 'allows organization id' do
@@ -5,7 +5,7 @@ module HammerCLIKatello
5
5
  describe HostCollection::CopyCommand do
6
6
  it 'requires a new name' do
7
7
  result = run_cmd(%w(host-collection copy --id 1))
8
- expected_error = "option '--new-name' is required"
8
+ expected_error = "Option '--new-name' is required."
9
9
  assert_equal(result.exit_code, HammerCLI::EX_USAGE)
10
10
  assert_equal(result.err[/#{expected_error}/], expected_error)
11
11
  end
@@ -17,9 +17,9 @@ module HammerCLIKatello
17
17
 
18
18
  it 'requires organization options if name is specified' do
19
19
  result = run_cmd(%w(host-collection copy --name hc1 --new-name foo))
20
- expected_error = "Could not find organization"
21
- assert_equal(result.exit_code, HammerCLI::EX_SOFTWARE)
22
- assert_equal(result.err[/#{expected_error}/], expected_error)
20
+ expected_error = "Missing options to search organization"
21
+ assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
22
+ assert_equal(expected_error, result.err[/#{expected_error}/])
23
23
  end
24
24
 
25
25
  it 'allows organization id' do
@@ -10,9 +10,9 @@ module HammerCLIKatello
10
10
 
11
11
  it 'requires organization options if name is specified' do
12
12
  result = run_cmd(%w(host-collection delete --name hc1))
13
- expected_error = "Could not find organization"
14
- assert_equal(result.exit_code, HammerCLI::EX_SOFTWARE)
15
- assert_equal(result.err[/#{expected_error}/], expected_error)
13
+ expected_error = "Missing options to search organization"
14
+ assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
15
+ assert_equal(expected_error, result.err[/#{expected_error}/])
16
16
  end
17
17
 
18
18
  it 'allows organization id' do
@@ -24,8 +24,7 @@ module HammerCLIKatello
24
24
 
25
25
  it 'requires organization with host collection name' do
26
26
  result = run_cmd(%w(host-collection hosts --name collection))
27
- expected_error = "Error: Could not find organization, please set one of options " \
28
- "--organization, --organization-label, --organization-id."
27
+ expected_error = "Missing options to search organization"
29
28
  assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
30
29
  assert_equal(expected_error, result.err[/#{expected_error}/])
31
30
  end
@@ -10,9 +10,9 @@ module HammerCLIKatello
10
10
 
11
11
  it 'requires organization options if id is not specified' do
12
12
  result = run_cmd(%w(host-collection info --name hc1))
13
- expected_error = "Could not find organization"
14
- assert_equal(result.exit_code, HammerCLI::EX_SOFTWARE)
15
- assert_equal(result.err[/#{expected_error}/], expected_error)
13
+ expected_error = "Missing options to search organization"
14
+ assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
15
+ assert_equal(expected_error, result.err[/#{expected_error}/])
16
16
  end
17
17
 
18
18
  it 'allows organization id' do
@@ -3,6 +3,39 @@ require 'hammer_cli_katello/host_collection'
3
3
 
4
4
  module HammerCLIKatello
5
5
  describe HostCollection::RemoveHostCommand do
6
+ describe 'handles individual host errors' do
7
+ it 'for successful results' do
8
+ api_expects(:host_collections, :remove_hosts)
9
+ .with_params('id' => 1, 'host_ids' => %w(2 3))
10
+ .returns("displayMessages" => {"success" => ["Successfully removed 2 Host(s)."],
11
+ "error" => []})
12
+ result = run_cmd(%w(host-collection remove-host --id 1 --host-ids 2,3))
13
+ assert_match("The host(s) has been removed", result.out)
14
+ end
15
+
16
+ it 'for mixed results' do
17
+ api_expects(:host_collections, :remove_hosts)
18
+ .with_params('id' => 1, 'host_ids' => %w(2 3))
19
+ .returns("displayMessages" => {"success" => ["Successfully removed 1 Host(s)."],
20
+ "error" => ["Host with ID 3 not found."]})
21
+ result = run_cmd(%w(host-collection remove-host --id 1 --host-ids 2,3))
22
+ assert_match("Could not remove host(s)", result.out)
23
+ assert_match("Host with ID 3 not found.", result.out)
24
+ end
25
+
26
+ it 'for errored results' do
27
+ api_expects(:host_collections, :remove_hosts)
28
+ .with_params('id' => 1, 'host_ids' => %w(2 3))
29
+ .returns("displayMessages" => {"success" => [], "error" => [
30
+ "Host with ID 1 does not exist in the host collection.",
31
+ "Host with ID 3 not found."]})
32
+ result = run_cmd(%w(host-collection remove-host --id 1 --host-ids 2,3))
33
+ assert_match("Could not remove host(s)", result.out)
34
+ assert_match("Host with ID 1 does not exist in the host collection.", result.out)
35
+ assert_match("Host with ID 3 not found.", result.out)
36
+ end
37
+ end
38
+
6
39
  it 'does not require organization options if id is specified' do
7
40
  api_expects(:host_collections, :remove_hosts)
8
41
  run_cmd(%w(host-collection remove-host --id 1))
@@ -10,9 +43,9 @@ module HammerCLIKatello
10
43
 
11
44
  it 'requires organization options if name is specified' do
12
45
  result = run_cmd(%w(host-collection remove-host --name hc1))
13
- expected_error = "Could not find organization"
14
- assert_equal(result.exit_code, HammerCLI::EX_SOFTWARE)
15
- assert_equal(result.err[/#{expected_error}/], expected_error)
46
+ expected_error = "Missing options to search organization"
47
+ assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
48
+ assert_equal(expected_error, result.err[/#{expected_error}/])
16
49
  end
17
50
 
18
51
  it 'allows organization id' do
@@ -10,9 +10,9 @@ module HammerCLIKatello
10
10
 
11
11
  it 'requires organization options if name is specified' do
12
12
  result = run_cmd(%w(host-collection update --name hc1))
13
- expected_error = "Could not find organization"
14
- assert_equal(result.exit_code, HammerCLI::EX_SOFTWARE)
15
- assert_equal(result.err[/#{expected_error}/], expected_error)
13
+ expected_error = "Missing options to search organization"
14
+ assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
15
+ assert_equal(expected_error, result.err[/#{expected_error}/])
16
16
  end
17
17
 
18
18
  it 'allows organization id' do
@@ -13,6 +13,24 @@ module HammerCLIForeman
13
13
  run_cmd(%w(hostgroup create --name hg1 --content-source-id 1))
14
14
  end
15
15
 
16
+ it 'allows content source name' do
17
+ content_source_name = "life_of_cs"
18
+ content_source_id = 111
19
+ hg_name = "mercury"
20
+
21
+ api_expects(:smart_proxies, :index).
22
+ with_params(:search => "name = \"#{content_source_name}\"").
23
+ returns(index_response([{'id' => content_source_id}]))
24
+
25
+ api_expects(:hostgroups, :create).
26
+ with_params('hostgroup' => {'name' => hg_name,
27
+ 'content_source_id' => content_source_id
28
+ })
29
+
30
+ cmd = "hostgroup create --name #{hg_name} --content-source #{content_source_name}"
31
+ run_cmd(cmd.split)
32
+ end
33
+
16
34
  it 'allows content view id' do
17
35
  api_expects(:hostgroups, :create) do |p|
18
36
  p['hostgroup']['name'] == 'hg1' && p['hostgroup']['content_view_id'] == 1
@@ -47,7 +65,7 @@ module HammerCLIForeman
47
65
 
48
66
  it 'allows lifecycle environment name' do
49
67
  ex = api_expects(:lifecycle_environments, :index) do |p|
50
- p[:name] = 'le1' && p['organization_id'] == '1'
68
+ p['name'] == 'le1' && p['organization_id'] == '1'
51
69
  end
52
70
  ex.returns(index_response([{'id' => 1}]))
53
71
  api_expects(:hostgroups, :create) do |p|
@@ -62,6 +80,33 @@ module HammerCLIForeman
62
80
  result = run_cmd(%w(hostgroup create --name hg1 --lifecycle-environment le1))
63
81
  assert_match(/--query-organization/, result.err)
64
82
  end
83
+
84
+ it 'allows kickstart repository name' do
85
+ env_id = 100
86
+ cv_id = 200
87
+ repo_name = "life_of_kickstart"
88
+ repo_id = 111
89
+ hg_name = "mercury"
90
+
91
+ api_expects(:repositories, :index).
92
+ with_params('name' => repo_name,
93
+ 'environment_id' => env_id,
94
+ 'content_view_id' => cv_id).
95
+ returns(index_response([{'id' => repo_id}]))
96
+
97
+ expected_params = {'hostgroup' => {
98
+ 'name' => hg_name,
99
+ 'lifecycle_environment_id' => env_id,
100
+ 'content_view_id' => cv_id,
101
+ 'kickstart_repository_id' => repo_id
102
+ }
103
+ }
104
+ api_expects(:hostgroups, :create).with_params(expected_params)
105
+
106
+ cmd = "hostgroup create --name #{hg_name} --lifecycle-environment-id #{env_id}"\
107
+ " --content-view-id #{cv_id} --kickstart-repository #{repo_name}"
108
+ run_cmd(cmd.split)
109
+ end
65
110
  end
66
111
  end
67
112
  end
@@ -1,48 +1,50 @@
1
1
  {
2
- "content_source_id":1,
3
- "content_source_name":"foreman.example.com",
4
- "content_view_id":1,
5
- "content_view_name":"Default Organization View",
6
- "lifecycle_environment_id":1,
7
- "lifecycle_environment_name":"Library",
8
- "subnet_id":null,
9
- "subnet_name":null,
10
- "operatingsystem_id":null,
11
- "operatingsystem_name":null,
12
- "domain_id":null,
13
- "domain_name":null,
14
- "environment_id":1,
15
- "environment_name":"Production Env",
16
- "compute_profile_id":null,
17
- "compute_profile_name":null,
18
- "ancestry":null,
19
- "parent_id":null,
20
- "parent_name":null,
21
- "puppet_proxy_id":null,
22
- "puppet_ca_proxy_id":null,
23
- "ptable_id":null,
24
- "ptable_name":null,
25
- "medium_id":null,
26
- "medium_name":null,
27
- "architecture_id":null,
28
- "architecture_name":null,
29
- "realm_id":null,
30
- "realm_name":null,
31
- "created_at":"2016-08-09 04:18:32 UTC",
32
- "updated_at":"2016-08-09 04:18:32 UTC",
33
- "id":1,
34
- "parameters":[],
35
- "template_combinations":[],
36
- "puppetclasses":[],
37
- "config_groups":[],
38
- "all_puppetclasses":[],
39
- "locations":[],
40
- "organizations":[
41
- {
42
- "id":1,
43
- "name":"Redhat",
44
- "title":"Redhat",
45
- "description":null
46
- }
47
- ]
2
+ "content_source_id":1,
3
+ "content_source_name":"foreman.example.com",
4
+ "content_view_id":1,
5
+ "content_view_name":"Default Organization View",
6
+ "lifecycle_environment_id":1,
7
+ "lifecycle_environment_name":"Library",
8
+ "kickstart_repository_id":10000,
9
+ "kickstart_repository_name":"Rhel 7",
10
+ "subnet_id":null,
11
+ "subnet_name":null,
12
+ "operatingsystem_id":null,
13
+ "operatingsystem_name":null,
14
+ "domain_id":null,
15
+ "domain_name":null,
16
+ "environment_id":1,
17
+ "environment_name":"Production Env",
18
+ "compute_profile_id":null,
19
+ "compute_profile_name":null,
20
+ "ancestry":null,
21
+ "parent_id":null,
22
+ "parent_name":null,
23
+ "puppet_proxy_id":null,
24
+ "puppet_ca_proxy_id":null,
25
+ "ptable_id":null,
26
+ "ptable_name":null,
27
+ "medium_id":null,
28
+ "medium_name":null,
29
+ "architecture_id":null,
30
+ "architecture_name":null,
31
+ "realm_id":null,
32
+ "realm_name":null,
33
+ "created_at":"2016-08-09 04:18:32 UTC",
34
+ "updated_at":"2016-08-09 04:18:32 UTC",
35
+ "id":1,
36
+ "parameters":[],
37
+ "template_combinations":[],
38
+ "puppetclasses":[],
39
+ "config_groups":[],
40
+ "all_puppetclasses":[],
41
+ "locations":[],
42
+ "organizations":[
43
+ {
44
+ "id":1,
45
+ "name":"Redhat",
46
+ "title":"Redhat",
47
+ "description":null
48
+ }
49
+ ]
48
50
  }
@@ -20,9 +20,11 @@ module HammerCLIForeman
20
20
  ex.returns(JSON.parse(File.read(json_file)))
21
21
 
22
22
  result = run_cmd(@cmd + params)
23
- expected_fields = [['Lifecycle Environment', 'Library'],
24
- ['Content View', 'Default Organization View'],
25
- ['Content Source', 'foreman.example.com']]
23
+ # rubocop:disable Style/WordArray
24
+ expected_fields = [['Name', 'Library'],
25
+ ['Name', 'Default Organization View'],
26
+ ['Name', 'foreman.example.com'],
27
+ ['Name', 'Rhel 7']]
26
28
  expected_results = expected_fields.map { |field| success_result(FieldMatcher.new(*field)) }
27
29
  expected_results.each { |expected| assert_cmd(expected, result) }
28
30
  end