hammer_cli_katello 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello/acs.rb +79 -0
  3. data/lib/hammer_cli_katello/repository.rb +1 -1
  4. data/lib/hammer_cli_katello/version.rb +1 -1
  5. data/lib/hammer_cli_katello.rb +5 -0
  6. data/test/data/2.5/foreman_api.json +1 -0
  7. data/test/data/3.0/foreman_api.json +1 -0
  8. data/test/data/3.10/foreman_api.json +1 -0
  9. data/test/data/3.11/foreman_api.json +1 -0
  10. data/test/data/3.12/foreman_api.json +1 -0
  11. data/test/data/3.13/foreman_api.json +1 -0
  12. data/test/data/3.14/foreman_api.json +1 -0
  13. data/test/data/3.15/foreman_api.json +1 -0
  14. data/test/data/3.16/foreman_api.json +1 -0
  15. data/test/data/3.17/foreman_api.json +1 -0
  16. data/test/data/3.18/foreman_api.json +1 -0
  17. data/test/data/3.19/foreman_api.json +1 -0
  18. data/test/data/3.2/foreman_api.json +1 -0
  19. data/test/data/3.4/foreman_api.json +1 -0
  20. data/test/data/3.5/foreman_api.json +1 -0
  21. data/test/data/3.6/foreman_api.json +1 -0
  22. data/test/data/3.7/foreman_api.json +1 -0
  23. data/test/data/3.8/foreman_api.json +1 -0
  24. data/test/data/3.9/foreman_api.json +1 -0
  25. data/test/data/4.0/foreman_api.json +1 -0
  26. data/test/data/4.1/foreman_api.json +1 -0
  27. data/test/data/4.3/foreman_api.json +1 -0
  28. data/test/data/4.4/foreman_api.json +1 -0
  29. data/test/data/4.5/foreman_api.json +1 -0
  30. data/test/data/4.6/foreman_api.json +1 -0
  31. data/test/data/Readme.md +5 -0
  32. data/test/functional/acs/create_test.rb +27 -0
  33. data/test/functional/acs/delete_test.rb +13 -0
  34. data/test/functional/acs/info_test.rb +55 -0
  35. data/test/functional/acs/list_test.rb +62 -0
  36. data/test/functional/acs/update_test.rb +23 -0
  37. data/test/functional/activation_key/add_host_collection_test.rb +62 -0
  38. data/test/functional/activation_key/content_override_test.rb +92 -0
  39. data/test/functional/activation_key/create_test.rb +33 -0
  40. data/test/functional/activation_key/data/activation_key.json +17 -0
  41. data/test/functional/activation_key/info_test.rb +29 -0
  42. data/test/functional/activation_key/list_test.rb +68 -0
  43. data/test/functional/activation_key/product_content_test.rb +23 -0
  44. data/test/functional/activation_key/remove_host_collection_test.rb +62 -0
  45. data/test/functional/activation_key/subscriptions_test.rb +74 -0
  46. data/test/functional/activation_key/update_test.rb +26 -0
  47. data/test/functional/apipie_helper_test.rb +31 -0
  48. data/test/functional/capsule/capsule_helpers.rb +13 -0
  49. data/test/functional/capsule/content/add_lifecycle_environment_test.rb +40 -0
  50. data/test/functional/capsule/content/cancel_synchronization_test.rb +42 -0
  51. data/test/functional/capsule/content/capsule_content_helpers.rb +24 -0
  52. data/test/functional/capsule/content/data/library_env.json +47 -0
  53. data/test/functional/capsule/content/data/sync_status.json +6 -0
  54. data/test/functional/capsule/content/data/sync_tasks.json +62 -0
  55. data/test/functional/capsule/content/info_test.rb +61 -0
  56. data/test/functional/capsule/content/lifecycle_environments_test.rb +19 -0
  57. data/test/functional/capsule/content/remove_lifecycle_environment_test.rb +40 -0
  58. data/test/functional/capsule/content/synchronization_status_test.rb +107 -0
  59. data/test/functional/capsule/info_test.rb +25 -0
  60. data/test/functional/capsule/list_test.rb +24 -0
  61. data/test/functional/content_credentials/create_test.rb +32 -0
  62. data/test/functional/content_credentials/data/test_cert.json +43 -0
  63. data/test/functional/content_credentials/info_test.rb +50 -0
  64. data/test/functional/content_credentials/list_test.rb +66 -0
  65. data/test/functional/content_export/complete/library_test.rb +155 -0
  66. data/test/functional/content_export/complete/repository_test.rb +226 -0
  67. data/test/functional/content_export/complete/version_test.rb +252 -0
  68. data/test/functional/content_export/content_export_helpers.rb +33 -0
  69. data/test/functional/content_export/generate_metadata_test.rb +64 -0
  70. data/test/functional/content_export/incremental/library_test.rb +172 -0
  71. data/test/functional/content_export/incremental/repository_test.rb +212 -0
  72. data/test/functional/content_export/incremental/version_test.rb +268 -0
  73. data/test/functional/content_export/list_test.rb +64 -0
  74. data/test/functional/content_import/library_test.rb +85 -0
  75. data/test/functional/content_import/list_test.rb +65 -0
  76. data/test/functional/content_import/metadata.json +1 -0
  77. data/test/functional/content_import/version_test.rb +85 -0
  78. data/test/functional/content_units/info_test.rb +29 -0
  79. data/test/functional/content_units/list_test.rb +106 -0
  80. data/test/functional/content_view/add_content_view_version_test.rb +88 -0
  81. data/test/functional/content_view/add_repository_test.rb +21 -0
  82. data/test/functional/content_view/component/add_test.rb +177 -0
  83. data/test/functional/content_view/component/list_test.rb +55 -0
  84. data/test/functional/content_view/component/remove_test.rb +107 -0
  85. data/test/functional/content_view/component/update_test.rb +134 -0
  86. data/test/functional/content_view/content_view_helpers.rb +20 -0
  87. data/test/functional/content_view/copy_test.rb +53 -0
  88. data/test/functional/content_view/create_test.rb +34 -0
  89. data/test/functional/content_view/delete_test.rb +62 -0
  90. data/test/functional/content_view/filter/create_test.rb +57 -0
  91. data/test/functional/content_view/filter/delete_test.rb +90 -0
  92. data/test/functional/content_view/filter/info_test.rb +89 -0
  93. data/test/functional/content_view/filter/list_test.rb +98 -0
  94. data/test/functional/content_view/filter/update_test.rb +91 -0
  95. data/test/functional/content_view/list_test.rb +68 -0
  96. data/test/functional/content_view/publish_test.rb +24 -0
  97. data/test/functional/content_view/purge_test.rb +97 -0
  98. data/test/functional/content_view/remove_content_view_version_test.rb +88 -0
  99. data/test/functional/content_view/remove_test.rb +79 -0
  100. data/test/functional/content_view/update_test.rb +53 -0
  101. data/test/functional/content_view/version/incremental_update_test.rb +108 -0
  102. data/test/functional/content_view/version/list_test.rb +44 -0
  103. data/test/functional/content_view/version/promote_test.rb +75 -0
  104. data/test/functional/content_view/version/republish_repositories_test.rb +34 -0
  105. data/test/functional/content_view/version/update_test.rb +48 -0
  106. data/test/functional/erratum/erratum_helpers.rb +91 -0
  107. data/test/functional/erratum/info_test.rb +29 -0
  108. data/test/functional/erratum/list_test.rb +108 -0
  109. data/test/functional/file/file_helpers.rb +13 -0
  110. data/test/functional/file/info_test.rb +162 -0
  111. data/test/functional/file/list_test.rb +112 -0
  112. data/test/functional/filter_rule/create_test.rb +99 -0
  113. data/test/functional/filter_rule/delete_test.rb +104 -0
  114. data/test/functional/filter_rule/filter_rule_helpers.rb +12 -0
  115. data/test/functional/filter_rule/info_test.rb +104 -0
  116. data/test/functional/filter_rule/list_test.rb +91 -0
  117. data/test/functional/filter_rule/update_test.rb +104 -0
  118. data/test/functional/host/errata/apply_test.rb +45 -0
  119. data/test/functional/host/errata/info_test.rb +27 -0
  120. data/test/functional/host/errata/list_test.rb +49 -0
  121. data/test/functional/host/errata/recalculate_test.rb +26 -0
  122. data/test/functional/host/extensions/create_test.rb +95 -0
  123. data/test/functional/host/extensions/data/host.json +320 -0
  124. data/test/functional/host/extensions/data/host_list.json +117 -0
  125. data/test/functional/host/extensions/info_test.rb +35 -0
  126. data/test/functional/host/extensions/list_test.rb +21 -0
  127. data/test/functional/host/extensions/update_test.rb +70 -0
  128. data/test/functional/host/host_helpers.rb +8 -0
  129. data/test/functional/host/subscription/attach_test.rb +54 -0
  130. data/test/functional/host/subscription/auto_attach_test.rb +35 -0
  131. data/test/functional/host/subscription/content_override_test.rb +96 -0
  132. data/test/functional/host/subscription/product_content_test.rb +27 -0
  133. data/test/functional/host/subscription/register_test.rb +53 -0
  134. data/test/functional/host/subscription/remove_test.rb +52 -0
  135. data/test/functional/host/subscription/unregister_test.rb +37 -0
  136. data/test/functional/host/traces/list_test.rb +37 -0
  137. data/test/functional/host/traces/resolve_test.rb +31 -0
  138. data/test/functional/host_collection/add_host_test.rb +90 -0
  139. data/test/functional/host_collection/content_api_expectations.rb +35 -0
  140. data/test/functional/host_collection/content_install_test.rb +62 -0
  141. data/test/functional/host_collection/content_remove_test.rb +37 -0
  142. data/test/functional/host_collection/content_update_test.rb +37 -0
  143. data/test/functional/host_collection/copy_test.rb +64 -0
  144. data/test/functional/host_collection/create_test.rb +54 -0
  145. data/test/functional/host_collection/delete_test.rb +57 -0
  146. data/test/functional/host_collection/hosts_test.rb +39 -0
  147. data/test/functional/host_collection/info_test.rb +57 -0
  148. data/test/functional/host_collection/list_test.rb +63 -0
  149. data/test/functional/host_collection/remove_host_test.rb +90 -0
  150. data/test/functional/host_collection/update_test.rb +57 -0
  151. data/test/functional/hostgroup/create_test.rb +112 -0
  152. data/test/functional/hostgroup/data/hostgroup.json +50 -0
  153. data/test/functional/hostgroup/info_test.rb +33 -0
  154. data/test/functional/hostgroup/update_test.rb +120 -0
  155. data/test/functional/lifecycle_environment/create_test.rb +14 -0
  156. data/test/functional/lifecycle_environment/lifecycle_environment_helpers.rb +18 -0
  157. data/test/functional/lifecycle_environment/list_test.rb +38 -0
  158. data/test/functional/lifecycle_environment/update_test.rb +14 -0
  159. data/test/functional/local_helper_test.rb +30 -0
  160. data/test/functional/module_stream/info_test.rb +58 -0
  161. data/test/functional/module_stream/list_test.rb +53 -0
  162. data/test/functional/organization/cdn_configuration_test.rb +45 -0
  163. data/test/functional/organization/delete_test.rb +26 -0
  164. data/test/functional/organization/info_test.rb +45 -0
  165. data/test/functional/organization/organization_helpers.rb +10 -0
  166. data/test/functional/package/list_test.rb +160 -0
  167. data/test/functional/package_group/list_test.rb +38 -0
  168. data/test/functional/ping_test.rb +61 -0
  169. data/test/functional/product/create_test.rb +54 -0
  170. data/test/functional/product/delete_test.rb +41 -0
  171. data/test/functional/product/info_test.rb +33 -0
  172. data/test/functional/product/list_test.rb +58 -0
  173. data/test/functional/product/product_helpers.rb +24 -0
  174. data/test/functional/product/remove_sync_plan_test.rb +35 -0
  175. data/test/functional/product/set_sync_plan_test.rb +49 -0
  176. data/test/functional/product/update_proxy.rb +48 -0
  177. data/test/functional/product/update_test.rb +46 -0
  178. data/test/functional/repository/create_test.rb +21 -0
  179. data/test/functional/repository/delete_test.rb +95 -0
  180. data/test/functional/repository/info_test.rb +156 -0
  181. data/test/functional/repository/list_test.rb +68 -0
  182. data/test/functional/repository/reclaim_space_test.rb +105 -0
  183. data/test/functional/repository/remove_content_test.rb +108 -0
  184. data/test/functional/repository/repository_helpers.rb +18 -0
  185. data/test/functional/repository/republish_test.rb +37 -0
  186. data/test/functional/repository/synchronize_test.rb +57 -0
  187. data/test/functional/repository/update_test.rb +150 -0
  188. data/test/functional/repository/upload_test.rb +368 -0
  189. data/test/functional/repository_set/available_repositories_test.rb +18 -0
  190. data/test/functional/repository_set/disable_test.rb +48 -0
  191. data/test/functional/repository_set/enable_test.rb +42 -0
  192. data/test/functional/repository_set/info_test.rb +17 -0
  193. data/test/functional/repository_set/list_test.rb +18 -0
  194. data/test/functional/repository_set/repository_set_helpers.rb +20 -0
  195. data/test/functional/search_helpers.rb +17 -0
  196. data/test/functional/simple_content_access/disable_test.rb +48 -0
  197. data/test/functional/simple_content_access/enable_test.rb +46 -0
  198. data/test/functional/srpm/list_test.rb +92 -0
  199. data/test/functional/subscription/list_test.rb +86 -0
  200. data/test/functional/sync_plan/create_test.rb +60 -0
  201. data/test/functional/sync_plan/delete_test.rb +46 -0
  202. data/test/functional/sync_plan/info_test.rb +37 -0
  203. data/test/functional/sync_plan/list_test.rb +31 -0
  204. data/test/functional/sync_plan/sync_plan_helpers.rb +8 -0
  205. data/test/functional/sync_plan/update_test.rb +44 -0
  206. data/test/functional/test_helper.rb +24 -0
  207. data/test/task_helper.rb +7 -0
  208. data/test/test_helper.rb +38 -0
  209. data/test/unit/id_name_options_validator_test.rb +96 -0
  210. data/test/unit/id_resolver_test.rb +58 -0
  211. data/test/unit/messages_test.rb +7 -0
  212. data/test/unit/search_options_creators_test.rb +145 -0
  213. metadata +419 -4
@@ -0,0 +1,212 @@
1
+ require_relative '../../test_helper'
2
+ require 'hammer_cli_katello/content_export'
3
+ require_relative '../../product/product_helpers'
4
+ require_relative '../../repository/repository_helpers'
5
+ require_relative '../content_export_helpers'
6
+
7
+ describe 'content-export incremental version' do
8
+ include ForemanTaskHelpers
9
+ include ContentExportHelpers
10
+ include ProductHelpers
11
+ include RepositoryHelpers
12
+
13
+ before do
14
+ @cmd = %w(content-export incremental repository)
15
+ end
16
+
17
+ let(:task_id) { '5' }
18
+ let(:response) do
19
+ {
20
+ 'id' => task_id,
21
+ 'state' => 'planned',
22
+ 'output' => {
23
+ 'export_history_id' => 2
24
+ }
25
+ }
26
+ end
27
+
28
+ let(:export_history_id) { 1000 }
29
+
30
+ let(:export_history) do
31
+ {
32
+ "id": export_history_id,
33
+ "path": "/tmp",
34
+ "metadata": {}
35
+ }
36
+ end
37
+
38
+ let(:default_repository_options) do
39
+ {"download_policy" => "immediate", "id" => repository_id}
40
+ end
41
+
42
+ let(:product_id) { '77' }
43
+ let(:repository_id) { 100 }
44
+
45
+ let(:name) { 'great' }
46
+
47
+ it "performs export with required options and async" do
48
+ params = [
49
+ "--id=#{repository_id}",
50
+ '--async'
51
+ ]
52
+ expects_repository(repository_id, default_repository_options)
53
+
54
+ ex = api_expects(:content_export_incrementals, :repository)
55
+ ex.returns(response)
56
+
57
+ result = run_cmd(@cmd + params)
58
+
59
+ assert_equal("Repository is being exported in task #{task_id}.\n"\
60
+ + "Once the task completes the export metadata must be generated with the "\
61
+ + "command:\n hammer content-export generate-metadata --task-id #{task_id}\n", result.out)
62
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
63
+ end
64
+
65
+ it "performs export with required options" do
66
+ params = [
67
+ "--id=#{repository_id}"
68
+ ]
69
+
70
+ expects_repository(repository_id, default_repository_options)
71
+ ex = api_expects(:content_export_incrementals, :repository)
72
+ ex.returns(response)
73
+
74
+ expect_foreman_task(task_id).at_least_once
75
+
76
+ HammerCLIKatello::ContentExportIncremental::RepositoryCommand.
77
+ any_instance.
78
+ expects(:fetch_export_history).
79
+ returns(export_history)
80
+
81
+ result = run_cmd(@cmd + params)
82
+ assert_match(/Generated .*metadata.*json/, result.out)
83
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
84
+ end
85
+
86
+ it "performs export with history id" do
87
+ params = [
88
+ "--id=#{repository_id}",
89
+ "--from-history-id=#{export_history_id}"
90
+ ]
91
+ expects_repository(repository_id, default_repository_options)
92
+ api_expects(:content_export_incrementals, :repository)
93
+ .with_params('id' => repository_id,
94
+ 'from_history_id' => export_history_id)
95
+ .returns(response)
96
+
97
+ expect_foreman_task(task_id).at_least_once
98
+
99
+ HammerCLIKatello::ContentExportIncremental::RepositoryCommand.
100
+ any_instance.
101
+ expects(:fetch_export_history).
102
+ returns(export_history)
103
+
104
+ result = run_cmd(@cmd + params)
105
+ assert_match(/Generated .*metadata.*json/, result.out)
106
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
107
+ end
108
+
109
+ it 'fails on missing required params' do
110
+ params = [
111
+ '--boo-id=2'
112
+ ]
113
+
114
+ result = run_cmd(@cmd + params)
115
+ expected_error = "Could not export the repository:\n"
116
+
117
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
118
+ assert_equal(result.err[/#{expected_error}/], expected_error)
119
+ end
120
+
121
+ it 'correctly resolves product_id and repository name' do
122
+ params = ["--product-id=#{product_id}",
123
+ "--name=#{name}",
124
+ "--async"]
125
+ expects_repository(repository_id, default_repository_options)
126
+
127
+ cvv_expect = api_expects(:repositories, :index) do |p|
128
+ assert_equal p['product_id'].to_s, product_id.to_s
129
+ assert_equal p["name"], name
130
+ end
131
+
132
+ cvv_expect.at_least_once.
133
+ returns(index_response([{'id' => repository_id}]))
134
+
135
+ ex = api_expects(:content_export_incrementals, :repository) do |p|
136
+ assert_equal p['id'], repository_id
137
+ end
138
+ ex.returns(response)
139
+ run_cmd(@cmd + params)
140
+ end
141
+
142
+ it 'fails on missing product name/id' do
143
+ params = ["--name=foo"]
144
+ result = run_cmd(@cmd + params)
145
+ expected_error = "At least one of options --product-id, --product is required"
146
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
147
+ assert_match(/#{expected_error}/, result.err)
148
+ end
149
+
150
+ it 'fails on missing repository' do
151
+ params = ["--product-id=2"]
152
+ result = run_cmd(@cmd + params)
153
+ expected_error = "--name is required."
154
+
155
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
156
+ assert_match(/#{expected_error}/, result.err)
157
+ end
158
+
159
+ it 'fails on missing product missing org' do
160
+ params = ["--product=lol", "--name=#{name}"]
161
+ result = run_cmd(@cmd + params)
162
+ expected_error = "At least one of options --organization-id,"\
163
+ " --organization, --organization-label is required"
164
+
165
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
166
+ assert_match(/#{expected_error}/, result.err)
167
+ end
168
+
169
+ it 'correctly resolves product_id and repository name' do
170
+ params = ["--product-id=#{product_id}",
171
+ "--name=#{name}",
172
+ "--async"]
173
+ expects_repository(repository_id, default_repository_options)
174
+
175
+ cvv_expect = api_expects(:repositories, :index) do |p|
176
+ assert_equal p['product_id'].to_s, product_id.to_s
177
+ assert_equal p["name"], name
178
+ end
179
+
180
+ cvv_expect.at_least_once.
181
+ returns(index_response([{'id' => repository_id}]))
182
+
183
+ ex = api_expects(:content_export_incrementals, :repository) do |p|
184
+ assert_equal p['id'], repository_id
185
+ end
186
+ ex.returns(response)
187
+ run_cmd(@cmd + params)
188
+ end
189
+
190
+ it 'Errors out on lazy repositories' do
191
+ params = ["--id=#{repository_id}"]
192
+ expects_repository(repository_id, "download_policy" => "on_demand", "id" => repository_id)
193
+
194
+ ex = api_expects(:content_export_incrementals, :repository)
195
+ ex.returns(response)
196
+
197
+ expect_foreman_task(task_id).at_least_once
198
+
199
+ HammerCLIKatello::ContentExportIncremental::RepositoryCommand.
200
+ any_instance.
201
+ expects(:fetch_export_history).
202
+ returns(export_history)
203
+
204
+ HammerCLIKatello::ContentExportIncremental::RepositoryCommand.
205
+ any_instance.
206
+ expects(:exit).with(HammerCLI::EX_SOFTWARE)
207
+
208
+ result = run_cmd(@cmd + params)
209
+ assert_match(/Unable to fully export this repository because/, result.out)
210
+ assert_match(/#{repository_id}/, result.out)
211
+ end
212
+ end
@@ -0,0 +1,268 @@
1
+ require_relative '../../test_helper'
2
+ require 'hammer_cli_katello/content_export'
3
+ require_relative '../../lifecycle_environment/lifecycle_environment_helpers'
4
+ require_relative '../../content_view/content_view_helpers'
5
+ require_relative '../content_export_helpers'
6
+
7
+ describe 'content-export incremental version' do
8
+ include ForemanTaskHelpers
9
+ include ContentExportHelpers
10
+ include ContentViewHelpers
11
+ include LifecycleEnvironmentHelpers
12
+
13
+ before do
14
+ @cmd = %w(content-export incremental version)
15
+ end
16
+
17
+ let(:task_id) { '5' }
18
+ let(:response) do
19
+ {
20
+ 'id' => task_id,
21
+ 'state' => 'planned',
22
+ 'output' => {
23
+ 'export_history_id' => 2
24
+ }
25
+ }
26
+ end
27
+
28
+ let(:export_history_id) { 1000 }
29
+
30
+ let(:export_history) do
31
+ {
32
+ "id": export_history_id,
33
+ "path": "/tmp",
34
+ "metadata": {}
35
+ }
36
+ end
37
+
38
+ let(:content_view_id) { '77' }
39
+ let(:content_view_version_id) { 100 }
40
+
41
+ let(:version) { '10.0' }
42
+ let(:destination_server) { "dream.example.com" }
43
+
44
+ it "performs export with required options and async" do
45
+ params = [
46
+ "--id=#{content_view_version_id}",
47
+ '--destination-server=foo',
48
+ '--async'
49
+ ]
50
+ expects_repositories_in_version(content_view_version_id)
51
+
52
+ ex = api_expects(:content_export_incrementals, :version)
53
+ ex.returns(response)
54
+
55
+ result = run_cmd(@cmd + params)
56
+
57
+ assert_equal("Content view version is being exported in task #{task_id}.\n"\
58
+ + "Once the task completes the export metadata must be generated with the "\
59
+ + "command:\n hammer content-export generate-metadata --task-id #{task_id}\n", result.out)
60
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
61
+ end
62
+
63
+ it "performs export with required options" do
64
+ params = [
65
+ "--id=#{content_view_version_id}",
66
+ '--destination-server=foo'
67
+ ]
68
+
69
+ expects_repositories_in_version(content_view_version_id)
70
+ ex = api_expects(:content_export_incrementals, :version)
71
+ ex.returns(response)
72
+
73
+ expect_foreman_task(task_id).at_least_once
74
+
75
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
76
+ any_instance.
77
+ expects(:fetch_export_history).
78
+ returns(export_history)
79
+
80
+ result = run_cmd(@cmd + params)
81
+ assert_match(/Generated .*metadata.*json/, result.out)
82
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
83
+ end
84
+
85
+ it "performs export with history id" do
86
+ params = [
87
+ "--id=#{content_view_version_id}",
88
+ "--destination-server=#{destination_server}",
89
+ "--from-history-id=#{export_history_id}"
90
+ ]
91
+ expects_repositories_in_version(content_view_version_id)
92
+ api_expects(:content_export_incrementals, :version)
93
+ .with_params('id' => content_view_version_id,
94
+ 'destination_server' => destination_server,
95
+ 'from_history_id' => export_history_id)
96
+ .returns(response)
97
+
98
+ expect_foreman_task(task_id).at_least_once
99
+
100
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
101
+ any_instance.
102
+ expects(:fetch_export_history).
103
+ returns(export_history)
104
+
105
+ result = run_cmd(@cmd + params)
106
+ assert_match(/Generated .*metadata.*json/, result.out)
107
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
108
+ end
109
+
110
+ it 'fails on missing required params' do
111
+ params = [
112
+ '--boo-id=2'
113
+ ]
114
+
115
+ result = run_cmd(@cmd + params)
116
+ expected_error = "Could not export the content view version:\n"
117
+
118
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
119
+ assert_equal(result.err[/#{expected_error}/], expected_error)
120
+ end
121
+
122
+ it 'correctly resolves content-view-id and content view version number' do
123
+ params = ["--content-view-id=#{content_view_id}",
124
+ "--version=#{version}",
125
+ "--destination-server=#{destination_server}",
126
+ "--async"]
127
+ expects_repositories_in_version(content_view_version_id)
128
+ cvv_expect = api_expects(:content_view_versions, :index) do |p|
129
+ assert_equal p['content_view_id'].to_s, content_view_id.to_s
130
+ assert_equal p["version"], version
131
+ end
132
+
133
+ cvv_expect.at_least_once.
134
+ returns(index_response([{'id' => content_view_version_id}]))
135
+
136
+ ex = api_expects(:content_export_incrementals, :version) do |p|
137
+ assert_equal p['id'], content_view_version_id
138
+ assert_equal p["destination_server"], destination_server
139
+ end
140
+ ex.returns(response)
141
+
142
+ run_cmd(@cmd + params)
143
+ end
144
+
145
+ it 'fails on missing content-view name/id' do
146
+ params = []
147
+
148
+ result = run_cmd(@cmd + params)
149
+ expected_error = " At least one of options --id, --content-view, --content-view-id is required"
150
+
151
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
152
+ assert_match(/#{expected_error}/, result.err)
153
+ end
154
+
155
+ it 'fails on missing content-view version' do
156
+ params = ["--content-view-id=2"]
157
+ result = run_cmd(@cmd + params)
158
+
159
+ expected_error = "--version, --lifecycle-environment-id, --lifecycle-environment is required."
160
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
161
+ assert_match(/#{expected_error}/, result.err)
162
+ end
163
+
164
+ it 'fails on missing content-view missing org' do
165
+ params = ["--content-view=lol", "--version=4.0"]
166
+ result = run_cmd(@cmd + params)
167
+ expected_error = "At least one of options --organization-id, "\
168
+ "--organization, --organization-label is required."
169
+
170
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
171
+ assert_match(/#{expected_error}/, result.err)
172
+ end
173
+
174
+ it 'correctly resolves content-view-id and content view version number' do
175
+ params = ["--content-view-id=#{content_view_id}",
176
+ "--version=#{version}",
177
+ "--destination-server=#{destination_server}",
178
+ "--async"]
179
+
180
+ cvv_expect = api_expects(:content_view_versions, :index) do |p|
181
+ assert_equal p['content_view_id'].to_s, content_view_id.to_s
182
+ assert_equal p["version"], version
183
+ end
184
+
185
+ cvv_expect.at_least_once.
186
+ returns(index_response([{'id' => content_view_version_id}]))
187
+
188
+ api_expects(:content_export_incrementals, :version)
189
+ .with_params('id' => content_view_version_id)
190
+ .returns(response)
191
+
192
+ expects_repositories_in_version(content_view_version_id)
193
+ run_cmd(@cmd + params)
194
+ end
195
+
196
+ it 'warns of lazy repositories' do
197
+ params = ["--id=#{content_view_version_id}"]
198
+ expects_repositories_in_version(content_view_version_id, [{id: 200}])
199
+
200
+ api_expects(:content_export_incrementals, :version)
201
+ .with_params('id' => content_view_version_id)
202
+ .returns(response)
203
+
204
+ expect_foreman_task(task_id).at_least_once
205
+
206
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
207
+ any_instance.
208
+ expects(:fetch_export_history).
209
+ returns(export_history)
210
+
211
+ result = run_cmd(@cmd + params)
212
+ assert_match(/Unable to fully export this version because/, result.out)
213
+ assert_match(/200/, result.out)
214
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
215
+ end
216
+
217
+ it 'Errors out on lazy repositories if --fail-on-missing-content' do
218
+ params = ["--id=#{content_view_version_id}",
219
+ "--fail-on-missing-content"]
220
+ expects_repositories_in_version(content_view_version_id, [{id: 200}])
221
+
222
+ ex = api_expects(:content_export_incrementals, :version)
223
+ ex.returns(response)
224
+
225
+ expect_foreman_task(task_id).at_least_once
226
+
227
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
228
+ any_instance.
229
+ expects(:fetch_export_history).
230
+ returns(export_history)
231
+
232
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
233
+ any_instance.
234
+ expects(:exit).with(HammerCLI::EX_SOFTWARE)
235
+
236
+ result = run_cmd(@cmd + params)
237
+ assert_match(/Unable to fully export this version because/, result.out)
238
+ assert_match(/200/, result.out)
239
+ end
240
+
241
+ it 'should accept content view and lifecycle environment and get the right version' do
242
+ env = "foo"
243
+ org_id = '100'
244
+ env_id = '223'
245
+ params = ["--content-view-id=#{content_view_id}",
246
+ "--lifecycle-environment=#{env}",
247
+ "--organization-id=#{org_id}"]
248
+ expect_lifecycle_environment_search(org_id, env, env_id)
249
+ expect_content_view_version_search({'environment_id' => env_id,
250
+ 'content_view_id' => content_view_id},
251
+ 'id' => content_view_version_id).at_least_once
252
+
253
+ expects_repositories_in_version(content_view_version_id)
254
+ ex = api_expects(:content_export_incrementals, :version)
255
+ ex.returns(response)
256
+
257
+ expect_foreman_task(task_id).at_least_once
258
+
259
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
260
+ any_instance.
261
+ expects(:fetch_export_history).
262
+ returns(export_history)
263
+
264
+ result = run_cmd(@cmd + params)
265
+ assert_match(/Generated .*metadata.*json/, result.out)
266
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
267
+ end
268
+ end
@@ -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,65 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+ require 'hammer_cli_katello/content_import'
3
+
4
+ describe 'content-import 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_imports, :index)
23
+
24
+ ex.returns(empty_response)
25
+
26
+ # rubocop:disable LineLength
27
+ expected_result = success_result('---|------|------|----------------------|-------------------------|------------|-----------
28
+ ID | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
29
+ ---|------|------|----------------------|-------------------------|------------|-----------
30
+ ')
31
+ # rubocop:enable LineLength
32
+ result = run_cmd(%w(content-import list))
33
+ assert_cmd(expected_result, result)
34
+ end
35
+
36
+ it 'works with content-view-id only' do
37
+ api_expects(:content_view_versions, :index).returns(empty_response)
38
+
39
+ ex = api_expects(:content_imports, :index)
40
+
41
+ ex.returns(empty_response)
42
+ # rubocop:disable LineLength
43
+ expected_result = success_result('---|------|------|----------------------|-------------------------|------------|-----------
44
+ ID | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
45
+ ---|------|------|----------------------|-------------------------|------------|-----------
46
+ ')
47
+ # rubocop:enable LineLength
48
+ result = run_cmd(%w(content-import list --content-view-id=1))
49
+ assert_cmd(expected_result, result)
50
+ end
51
+
52
+ it 'works with content-view-version-id only' do
53
+ ex = api_expects(:content_imports, :index)
54
+
55
+ ex.returns(empty_response)
56
+ # rubocop:disable LineLength
57
+ expected_result = success_result('---|------|------|----------------------|-------------------------|------------|-----------
58
+ ID | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
59
+ ---|------|------|----------------------|-------------------------|------------|-----------
60
+ ')
61
+ # rubocop:enable LineLength
62
+ result = run_cmd(%w(content-import list --content-view-version-id=1))
63
+ assert_cmd(expected_result, result)
64
+ end
65
+ 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"}