hammer_cli_katello 0.3.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello.rb +0 -1
  3. data/lib/hammer_cli_katello/activation_key.rb +12 -29
  4. data/lib/hammer_cli_katello/composite_content_view_name_resolvable.rb +6 -8
  5. data/lib/hammer_cli_katello/content_override.rb +48 -0
  6. data/lib/hammer_cli_katello/content_view.rb +98 -5
  7. data/lib/hammer_cli_katello/content_view_name_resolvable.rb +4 -6
  8. data/lib/hammer_cli_katello/content_view_purge.rb +92 -0
  9. data/lib/hammer_cli_katello/content_view_version.rb +13 -0
  10. data/lib/hammer_cli_katello/erratum.rb +9 -0
  11. data/lib/hammer_cli_katello/filter_rule.rb +3 -4
  12. data/lib/hammer_cli_katello/host_collection.rb +8 -2
  13. data/lib/hammer_cli_katello/host_errata.rb +1 -1
  14. data/lib/hammer_cli_katello/host_subscription.rb +25 -0
  15. data/lib/hammer_cli_katello/hostgroup_extensions.rb +7 -6
  16. data/lib/hammer_cli_katello/id_resolver.rb +13 -4
  17. data/lib/hammer_cli_katello/katello_environment_name_resolvable.rb +4 -6
  18. data/lib/hammer_cli_katello/lifecycle_environment_name_resolvable.rb +4 -6
  19. data/lib/hammer_cli_katello/organization.rb +1 -0
  20. data/lib/hammer_cli_katello/package.rb +16 -3
  21. data/lib/hammer_cli_katello/package_group.rb +16 -2
  22. data/lib/hammer_cli_katello/product_content.rb +36 -0
  23. data/lib/hammer_cli_katello/repository.rb +48 -7
  24. data/lib/hammer_cli_katello/version.rb +1 -1
  25. data/test/data/3.4/foreman_api.json +1 -0
  26. data/test/functional/{activaton_key → activation_key}/add_host_collection_test.rb +0 -0
  27. data/test/functional/activation_key/content_override_test.rb +91 -0
  28. data/test/functional/{activaton_key → activation_key}/create_test.rb +0 -0
  29. data/test/functional/{activaton_key → activation_key}/list_test.rb +0 -0
  30. data/test/functional/{activaton_key → activation_key}/product_content_test.rb +0 -0
  31. data/test/functional/{activaton_key → activation_key}/remove_host_collection_test.rb +0 -0
  32. data/test/functional/{activaton_key → activation_key}/subscriptions_test.rb +0 -0
  33. data/test/functional/{activaton_key → activation_key}/update_test.rb +0 -0
  34. data/test/functional/content_view/add_content_view_version_test.rb +57 -3
  35. data/test/functional/content_view/add_repository_test.rb +1 -0
  36. data/test/functional/content_view/copy_test.rb +53 -0
  37. data/test/functional/content_view/delete_test.rb +62 -0
  38. data/test/functional/content_view/publish_test.rb +1 -0
  39. data/test/functional/content_view/puppet_module/add_test.rb +1 -0
  40. data/test/functional/content_view/purge_test.rb +72 -0
  41. data/test/functional/content_view/remove_content_view_version_test.rb +57 -3
  42. data/test/functional/content_view/remove_test.rb +78 -0
  43. data/test/functional/content_view/update_test.rb +53 -0
  44. data/test/functional/content_view/version/republish_repositories_test.rb +35 -0
  45. data/test/functional/erratum/list_test.rb +108 -0
  46. data/test/functional/host/subscription/content_override_test.rb +95 -0
  47. data/test/functional/host/subscription/product_content_test.rb +27 -0
  48. data/test/functional/host_collection/content_api_expectations.rb +35 -0
  49. data/test/functional/host_collection/content_install_test.rb +42 -17
  50. data/test/functional/host_collection/content_remove_test.rb +22 -12
  51. data/test/functional/host_collection/content_update_test.rb +22 -12
  52. data/test/functional/hostgroup/create_test.rb +6 -0
  53. data/test/functional/hostgroup/data/hostgroup.json +2 -2
  54. data/test/functional/hostgroup/info_test.rb +2 -1
  55. data/test/functional/hostgroup/update_test.rb +12 -0
  56. data/test/functional/package/list_test.rb +89 -18
  57. data/test/functional/package_group/list_test.rb +33 -0
  58. data/test/functional/repository/export_test.rb +121 -0
  59. data/test/functional/repository/remove_content_test.rb +98 -8
  60. data/test/functional/repository/update_test.rb +108 -0
  61. data/test/functional/repository/upload_test.rb +73 -3
  62. data/test/test_helper.rb +1 -1
  63. data/test/unit/id_resolver_test.rb +26 -0
  64. metadata +54 -21
@@ -0,0 +1,91 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/activation_key'
3
+
4
+ describe 'activation-key content-override' do
5
+ before do
6
+ @cmd = %w(activation-key content-override)
7
+ end
8
+ it "attaches a content label" do
9
+ label = "foo"
10
+ value = 'default'
11
+ id = '20'
12
+ params = ["--id=#{id}", "--content-label=#{label}", "--value=#{value}"]
13
+ ex = api_expects(:activation_keys, :content_override) do |par|
14
+ par['id'] == id && par["content_overrides"][0]['content_label'] == label &&
15
+ par['content_overrides'][0]['value'] == value &&
16
+ par['content_overrides'][0]['name'] == "enabled"
17
+ end
18
+ ex.returns({})
19
+
20
+ expected_result = success_result("Updated content override\n")
21
+
22
+ result = run_cmd(@cmd + params)
23
+ assert_cmd(expected_result, result)
24
+ end
25
+
26
+ it "attaches a content label with name" do
27
+ label = "foo"
28
+ value = '1'
29
+ id = '20'
30
+ name = 'protected'
31
+ params = ["--id=#{id}", "--content-label=#{label}", "--value=#{value}", "--name=#{name}"]
32
+ ex = api_expects(:activation_keys, :content_override) do |par|
33
+ par['id'] == id && par["content_overrides"][0]['content_label'] == label &&
34
+ par['content_overrides'][0]['value'] == value &&
35
+ par['content_overrides'][0]['name'] == name
36
+ end
37
+ ex.returns({})
38
+
39
+ expected_result = success_result("Updated content override\n")
40
+
41
+ result = run_cmd(@cmd + params)
42
+ assert_cmd(expected_result, result)
43
+ end
44
+
45
+ it "removes override" do
46
+ label = "foo"
47
+ id = '20'
48
+ params = ["--id=#{id}", "--content-label=#{label}", "--remove"]
49
+ ex = api_expects(:activation_keys, :content_override) do |par|
50
+ par['id'] == id && par["content_overrides"][0]['content_label'] == label &&
51
+ par['content_overrides'][0]['remove'] == true &&
52
+ par['content_overrides'][0]['name'] == "enabled"
53
+ end
54
+ ex.returns({})
55
+
56
+ expected_result = success_result("Updated content override\n")
57
+
58
+ result = run_cmd(@cmd + params)
59
+ assert_cmd(expected_result, result)
60
+ end
61
+
62
+ it "removes override with name" do
63
+ label = "foo"
64
+ id = '20'
65
+ name = 'protected'
66
+ params = ["--id=#{id}", "--content-label=#{label}", "--name=#{name}", "--remove"]
67
+ ex = api_expects(:activation_keys, :content_override) do |par|
68
+ par['id'] == id && par["content_overrides"][0]['content_label'] == label &&
69
+ par['content_overrides'][0]['remove'] == true &&
70
+ par['content_overrides'][0]['name'] == name
71
+ end
72
+ ex.returns({})
73
+
74
+ expected_result = success_result("Updated content override\n")
75
+
76
+ result = run_cmd(@cmd + params)
77
+ assert_cmd(expected_result, result)
78
+ end
79
+
80
+ it "validation fails on no override value or remove" do
81
+ api_expects_no_call
82
+ label = "foo"
83
+ id = '20'
84
+ name = 'protected'
85
+ params = ["--id=#{id}", "--content-label=#{label}", "--name=#{name}"]
86
+ result = run_cmd(@cmd + params)
87
+
88
+ assert(result.err[/At least one of options --remove, --value is required/],
89
+ "Remove or Value must be provided")
90
+ end
91
+ end
@@ -1,8 +1,13 @@
1
1
  require_relative '../test_helper'
2
+ require_relative '../organization/organization_helpers'
3
+ require_relative '../content_view/content_view_helpers'
2
4
  require 'hammer_cli_katello/content_view'
3
5
 
4
6
  module HammerCLIKatello
5
7
  describe ContentView::AddContentViewVersionCommand do
8
+ include OrganizationHelpers
9
+ include ContentViewHelpers
10
+
6
11
  it 'allows minimal options' do
7
12
  ex = api_expects(:content_views, :show) do |p|
8
13
  p[:id] == '1'
@@ -16,7 +21,7 @@ module HammerCLIKatello
16
21
 
17
22
  it 'resolves content view version ID' do
18
23
  ex = api_expects(:content_view_versions, :index) do |p|
19
- p['content_view_id'] == '3' && p['version'] == '2.1'
24
+ p['content_view_id'] == 3 && p['version'] == '2.1'
20
25
  end
21
26
  ex.returns(index_response([{'id' => 6}]))
22
27
  ex.returns('id' => 1, 'component_ids' => [1, 3])
@@ -27,8 +32,57 @@ module HammerCLIKatello
27
32
  api_expects(:content_views, :update) do |p|
28
33
  p['id'] == '1' && p['component_ids'] == %w(1 3 6)
29
34
  end
30
- run_cmd(%w(content-view add-version --id 1 --content-view-version-content-view-id 3
31
- --content-view-version 2.1))
35
+ run_cmd(%w(content-view add-version --id 1 --content-view-id 3 --content-view-version 2.1))
36
+ end
37
+
38
+ describe 'OrganizationOptions' do
39
+ it 'requires organization if content view name is supplied' do
40
+ api_expects_no_call
41
+ result = run_cmd(%w(content-view add-version --name cv1))
42
+ assert(result.err[/--organization-id, --organization, --organization-label is required/],
43
+ "Organization option requirements are validated")
44
+ end
45
+
46
+ it 'allows organization id' do
47
+ expect_content_view_search('1', 'cv2', 2)
48
+ ex = api_expects(:content_views, :show) do |p|
49
+ p[:id] == 2
50
+ end
51
+ ex.returns('id' => 2, 'component_ids' => [1, 2])
52
+ api_expects(:content_views, :update) do |p|
53
+ p['id'] == 2 && p['component_ids'] == %w(1 2 3)
54
+ end
55
+ run_cmd(%w(content-view add-version --name cv2 --organization-id 1
56
+ --content-view-version-id 3))
57
+ end
58
+
59
+ it 'allows organization name' do
60
+ expect_organization_search('org1', 1)
61
+ expect_content_view_search(1, 'cv2', 2)
62
+ ex = api_expects(:content_views, :show) do |p|
63
+ p[:id] == 2
64
+ end
65
+ ex.returns('id' => 2, 'component_ids' => [1, 2])
66
+ api_expects(:content_views, :update) do |p|
67
+ p['id'] == 2 && p['component_ids'] == %w(1 2 3)
68
+ end
69
+ run_cmd(%w(content-view add-version --name cv2 --organization org1
70
+ --content-view-version-id 3))
71
+ end
72
+
73
+ it 'allows organization label' do
74
+ expect_organization_search('org1', 1, field: 'label')
75
+ expect_content_view_search(1, 'cv2', 2)
76
+ ex = api_expects(:content_views, :show) do |p|
77
+ p[:id] == 2
78
+ end
79
+ ex.returns('id' => 2, 'component_ids' => [1, 2])
80
+ api_expects(:content_views, :update) do |p|
81
+ p['id'] == 2 && p['component_ids'] == %w(1 2 3)
82
+ end
83
+ run_cmd(%w(content-view add-version --name cv2 --organization-label org1
84
+ --content-view-version-id 3))
85
+ end
32
86
  end
33
87
  end
34
88
  end
@@ -1,4 +1,5 @@
1
1
  require_relative '../test_helper'
2
+ require 'hammer_cli_katello/content_view'
2
3
 
3
4
  module HammerCLIKatello
4
5
  describe ContentView do
@@ -0,0 +1,53 @@
1
+ require_relative '../test_helper'
2
+ require_relative '../organization/organization_helpers'
3
+ require_relative '../content_view/content_view_helpers'
4
+ require 'hammer_cli_katello/content_view'
5
+
6
+ module HammerCLIKatello
7
+ describe ContentView::CopyCommand do
8
+ include OrganizationHelpers
9
+ include ContentViewHelpers
10
+
11
+ it 'allows minimal options' do
12
+ api_expects(:content_views, :copy) do |p|
13
+ p['id'] == '2' && p['name'] == 'cv2-dup'
14
+ end
15
+ run_cmd(%w(content-view copy --id 2 --new-name cv2-dup))
16
+ end
17
+
18
+ describe 'OrganizationOptions' do
19
+ it 'requires organization if content view name is supplied' do
20
+ api_expects_no_call
21
+ result = run_cmd(%w(content-view copy --new-name cv2-dup --name cv2))
22
+ assert(result.err[/--organization-id, --organization, --organization-label is required/],
23
+ "Organization option requirements are validated")
24
+ end
25
+
26
+ it 'allows organization id' do
27
+ expect_content_view_search('1', 'cv2', 2)
28
+ api_expects(:content_views, :copy) do |p|
29
+ p['id'] == 2 && p['name'] == 'cv2-dup'
30
+ end
31
+ run_cmd(%w(content-view copy --name cv2 --new-name cv2-dup --organization-id 1))
32
+ end
33
+
34
+ it 'allows organization name' do
35
+ expect_organization_search('org1', 1)
36
+ expect_content_view_search(1, 'cv2', 2)
37
+ api_expects(:content_views, :copy) do |p|
38
+ p['id'] == 2 && p['name'] == 'cv2-dup'
39
+ end
40
+ run_cmd(%w(content-view copy --name cv2 --new-name cv2-dup --organization org1))
41
+ end
42
+
43
+ it 'allows organization label' do
44
+ expect_organization_search('org1', 1, field: 'label')
45
+ expect_content_view_search(1, 'cv2', 2)
46
+ api_expects(:content_views, :copy) do |p|
47
+ p['id'] == 2 && p['name'] == 'cv2-dup'
48
+ end
49
+ run_cmd(%w(content-view copy --name cv2 --new-name cv2-dup --organization-label org1))
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,62 @@
1
+ require_relative '../test_helper'
2
+ require_relative '../organization/organization_helpers'
3
+ require_relative '../content_view/content_view_helpers'
4
+ require 'hammer_cli_katello/content_view'
5
+
6
+ module HammerCLIKatello
7
+ describe ContentView::DeleteCommand do
8
+ include OrganizationHelpers
9
+ include ContentViewHelpers
10
+ include ForemanTaskHelpers
11
+
12
+ it 'allows minimal options' do
13
+ ex = api_expects(:content_views, :destroy) do |p|
14
+ p['id'] == 2
15
+ end
16
+ ex.returns(id: '8')
17
+ expect_foreman_task('8')
18
+ run_cmd(%w(content-view delete --id 2))
19
+ end
20
+
21
+ describe 'OrganizationOptions' do
22
+ it 'requires organization if content view name is supplied' do
23
+ api_expects_no_call
24
+ result = run_cmd(%w(content-view delete --name cv2))
25
+ assert(result.err[/--organization-id, --organization, --organization-label is required/],
26
+ "Organization option requirements are validated")
27
+ end
28
+
29
+ it 'allows organization id' do
30
+ expect_content_view_search('1', 'cv2', 2)
31
+ ex = api_expects(:content_views, :destroy) do |p|
32
+ p['id'] == 2
33
+ end
34
+ ex.returns(id: '8')
35
+ expect_foreman_task('8')
36
+ run_cmd(%w(content-view delete --name cv2 --organization-id 1))
37
+ end
38
+
39
+ it 'allows organization name' do
40
+ expect_organization_search('org1', 1)
41
+ expect_content_view_search(1, 'cv2', 2)
42
+ ex = api_expects(:content_views, :destroy) do |p|
43
+ p['id'] == 2
44
+ end
45
+ ex.returns(id: '8')
46
+ expect_foreman_task('8')
47
+ run_cmd(%w(content-view delete --name cv2 --organization org1))
48
+ end
49
+
50
+ it 'allows organization label' do
51
+ expect_organization_search('org1', 1, field: 'label')
52
+ expect_content_view_search(1, 'cv2', 2)
53
+ ex = api_expects(:content_views, :destroy) do |p|
54
+ p['id'] == 2
55
+ end
56
+ ex.returns(id: '8')
57
+ expect_foreman_task('8')
58
+ run_cmd(%w(content-view delete --name cv2 --organization-label org1))
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,4 +1,5 @@
1
1
  require_relative '../test_helper'
2
+ require 'hammer_cli_katello/content_view_puppet_module'
2
3
 
3
4
  module HammerCLIKatello
4
5
  describe ContentViewPuppetModule do
@@ -1,4 +1,5 @@
1
1
  require_relative '../../test_helper'
2
+ require 'hammer_cli_katello/content_view_puppet_module'
2
3
 
3
4
  module HammerCLIKatello
4
5
  describe ContentViewPuppetModule do
@@ -0,0 +1,72 @@
1
+ require_relative '../test_helper'
2
+ require_relative '../organization/organization_helpers'
3
+ require_relative '../content_view/content_view_helpers'
4
+ require 'hammer_cli_katello/content_view'
5
+ require 'hammer_cli_katello/content_view_purge'
6
+
7
+ module HammerCLIKatello
8
+ describe ContentViewPurgeCommand do
9
+ include ForemanTaskHelpers
10
+
11
+ let(:versions) do
12
+ {'versions' => [
13
+ {"id" => '2', "version" => "1.0", "published" => "2017-03-09 19:48:25 UTC",
14
+ "environment_ids" => []},
15
+ {"id" => '4', "version" => "2.2", "published" => "2017-03-09 19:50:29 UTC",
16
+ "environment_ids" => [1]},
17
+ {"id" => '6', "version" => "2.10", "published" => "2017-03-09 19:50:29 UTC",
18
+ "environment_ids" => []}
19
+ ]}
20
+ end
21
+
22
+ it 'fails gracefully if count <= 0' do
23
+ api_expects_no_call
24
+
25
+ r = run_cmd(%w(content-view purge --id 2 --count -1))
26
+ assert(r.err.include?('Invalid value for --count option'), 'Incorrect error message')
27
+ end
28
+
29
+ it 'fails gracefully when there are no versions to delete' do
30
+ ex = api_expects(:content_views, :show) do |p|
31
+ p['id'] == '2'
32
+ end
33
+ ex.returns(versions)
34
+
35
+ r = run_cmd(%w(content-view purge --id 2 --count 3))
36
+ assert(r.err.include?('No versions to delete.'), 'Incorrect error message')
37
+ end
38
+
39
+ it 'only deletes versions not associated with an environment' do
40
+ ex = api_expects(:content_views, :show) do |p|
41
+ p['id'] == '2'
42
+ end
43
+ ex.returns(versions)
44
+
45
+ %w(2 6).each do |id|
46
+ ex = api_expects(:content_view_versions, :destroy) do |p|
47
+ p['id'] == id
48
+ end
49
+ ex.returns('id' => '3', 'state' => 'stopped')
50
+ expect_foreman_task('3')
51
+ end
52
+
53
+ run_cmd(%w(content-view purge --id 2 --count 0))
54
+ end
55
+
56
+ it 'allows for async purge of versions' do
57
+ ex = api_expects(:content_views, :show) do |p|
58
+ p['id'] == '2'
59
+ end
60
+ ex.returns(versions)
61
+
62
+ %w(2 6).each do |id|
63
+ ex = api_expects(:content_view_versions, :destroy) do |p|
64
+ p['id'] == id
65
+ end
66
+ ex.returns('id' => '3')
67
+ end
68
+
69
+ run_cmd(%w(content-view purge --id 2 --count 0 --async))
70
+ end
71
+ end
72
+ end
@@ -1,8 +1,13 @@
1
1
  require_relative '../test_helper'
2
+ require_relative '../organization/organization_helpers'
3
+ require_relative '../content_view/content_view_helpers'
2
4
  require 'hammer_cli_katello/content_view'
3
5
 
4
6
  module HammerCLIKatello
5
7
  describe ContentView::RemoveContentViewVersionCommand do
8
+ include OrganizationHelpers
9
+ include ContentViewHelpers
10
+
6
11
  it 'allows minimal options' do
7
12
  ex = api_expects(:content_views, :show) do |p|
8
13
  p[:id] == '1'
@@ -16,7 +21,7 @@ module HammerCLIKatello
16
21
 
17
22
  it 'resolves content view version ID' do
18
23
  ex = api_expects(:content_view_versions, :index) do |p|
19
- p['content_view_id'] == '3' && p['version'] == '2.1'
24
+ p['content_view_id'] == 3 && p['version'] == '2.1'
20
25
  end
21
26
  ex.returns(index_response([{'id' => 6}]))
22
27
  ex.returns('id' => 1, 'component_ids' => [1, 3, 6])
@@ -27,8 +32,57 @@ module HammerCLIKatello
27
32
  api_expects(:content_views, :update) do |p|
28
33
  p['id'] == '1' && p['component_ids'] == %w(1 3)
29
34
  end
30
- run_cmd(%w(content-view remove-version --id 1 --content-view-version-content-view-id 3
31
- --content-view-version 2.1))
35
+ run_cmd(%w(content-view remove-version --id 1 --content-view-id 3 --content-view-version 2.1))
36
+ end
37
+
38
+ describe 'OrganizationOptions' do
39
+ it 'requires organization if content view name is supplied' do
40
+ api_expects_no_call
41
+ result = run_cmd(%w(content-view remove-version --name cv1))
42
+ assert(result.err[/--organization-id, --organization, --organization-label is required/],
43
+ "Organization option requirements are validated")
44
+ end
45
+
46
+ it 'allows organization id' do
47
+ expect_content_view_search('1', 'cv2', 2)
48
+ ex = api_expects(:content_views, :show) do |p|
49
+ p[:id] == 2
50
+ end
51
+ ex.returns('id' => 2, 'component_ids' => [1, 2, 3])
52
+ api_expects(:content_views, :update) do |p|
53
+ p['id'] == 2 && p['component_ids'] == %w(1 2)
54
+ end
55
+ run_cmd(%w(content-view remove-version --name cv2 --organization-id 1
56
+ --content-view-version-id 3))
57
+ end
58
+
59
+ it 'allows organization name' do
60
+ expect_organization_search('org1', 1)
61
+ expect_content_view_search(1, 'cv2', 2)
62
+ ex = api_expects(:content_views, :show) do |p|
63
+ p[:id] == 2
64
+ end
65
+ ex.returns('id' => 2, 'component_ids' => [1, 2, 3])
66
+ api_expects(:content_views, :update) do |p|
67
+ p['id'] == 2 && p['component_ids'] == %w(1 2)
68
+ end
69
+ run_cmd(%w(content-view remove-version --name cv2 --organization org1
70
+ --content-view-version-id 3))
71
+ end
72
+
73
+ it 'allows organization label' do
74
+ expect_organization_search('org1', 1, field: 'label')
75
+ expect_content_view_search(1, 'cv2', 2)
76
+ ex = api_expects(:content_views, :show) do |p|
77
+ p[:id] == 2
78
+ end
79
+ ex.returns('id' => 2, 'component_ids' => [1, 2, 3])
80
+ api_expects(:content_views, :update) do |p|
81
+ p['id'] == 2 && p['component_ids'] == %w(1 2)
82
+ end
83
+ run_cmd(%w(content-view remove-version --name cv2 --organization-label org1
84
+ --content-view-version-id 3))
85
+ end
32
86
  end
33
87
  end
34
88
  end