hammer_cli_katello 0.22.3 → 0.24.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello.rb +19 -2
  3. data/lib/hammer_cli_katello/content_export.rb +72 -0
  4. data/lib/hammer_cli_katello/content_export_complete.rb +25 -0
  5. data/lib/hammer_cli_katello/content_export_helper.rb +172 -0
  6. data/lib/hammer_cli_katello/content_export_incremental.rb +25 -0
  7. data/lib/hammer_cli_katello/content_import.rb +63 -0
  8. data/lib/hammer_cli_katello/content_view.rb +3 -1
  9. data/lib/hammer_cli_katello/deb_package.rb +66 -0
  10. data/lib/hammer_cli_katello/host.rb +5 -0
  11. data/lib/hammer_cli_katello/host_deb.rb +20 -0
  12. data/lib/hammer_cli_katello/ping.rb +10 -3
  13. data/lib/hammer_cli_katello/repository.rb +60 -1
  14. data/lib/hammer_cli_katello/version.rb +1 -1
  15. data/test/data/3.16/foreman_api.json +1 -1
  16. data/test/data/3.17/foreman_api.json +1 -1
  17. data/test/data/3.18/foreman_api.json +1 -0
  18. data/test/functional/content_export/complete/library_test.rb +155 -0
  19. data/test/functional/content_export/complete/version_test.rb +185 -0
  20. data/test/functional/content_export/content_export_helpers.rb +21 -0
  21. data/test/functional/content_export/generate_metadata_test.rb +64 -0
  22. data/test/functional/content_export/incremental/library_test.rb +172 -0
  23. data/test/functional/content_export/incremental/version_test.rb +236 -0
  24. data/test/functional/content_export/list_test.rb +34 -0
  25. data/test/functional/content_import/library_test.rb +85 -0
  26. data/test/functional/content_import/metadata.json +1 -0
  27. data/test/functional/content_import/version_test.rb +85 -0
  28. data/test/functional/ping_test.rb +2 -1
  29. data/test/functional/repository/info_test.rb +133 -23
  30. data/test/functional/repository/update_test.rb +41 -1
  31. data/test/test_helper.rb +1 -1
  32. metadata +31 -2
@@ -0,0 +1,21 @@
1
+ module ContentExportHelpers
2
+ def expects_repositories_in_library(organization_id, returns = [])
3
+ export_task = api_expects(:repositories, :index) do |p|
4
+ assert_equal organization_id.to_s, p[:organization_id].to_s
5
+ assert p[:library]
6
+ assert_equal "download_policy != immediate", p[:search]
7
+ assert_equal "yum", p[:content_type]
8
+ end
9
+ export_task.returns(index_response(returns))
10
+ end
11
+
12
+ def expects_repositories_in_version(version_id, returns = [])
13
+ export_task = api_expects(:repositories, :index) do |p|
14
+ assert_equal version_id.to_s, p[:content_view_version_id].to_s
15
+ assert p[:library]
16
+ assert_equal "download_policy != immediate", p[:search]
17
+ assert_equal "yum", p[:content_type]
18
+ end
19
+ export_task.returns(index_response(returns))
20
+ end
21
+ 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 generate-metadata') do
5
+ include ForemanTaskHelpers
6
+
7
+ before do
8
+ @cmd = %w(content-export generate-metadata)
9
+ @params = []
10
+ @export_history_id = 100
11
+ @export_history = {
12
+ 'id' => @export_history_id,
13
+ 'path' => '/tmp',
14
+ 'metadata' => {}
15
+ }
16
+ @task_id = SecureRandom.uuid
17
+ end
18
+
19
+ let(:cmd) { @cmd + @params }
20
+ let(:result) { run_cmd(cmd) }
21
+
22
+ describe('given an export history id') do
23
+ it('loads export history by id') do
24
+ @params = ["--id=#{@export_history_id}"]
25
+
26
+ HammerCLIKatello::ContentExport::GenerateMetadataCommand.
27
+ any_instance.
28
+ expects(:fetch_export_history).
29
+ returns(@export_history)
30
+
31
+ expected = success_result("Generated /tmp/metadata.json\n")
32
+
33
+ assert_cmd(expected, result)
34
+ end
35
+ end
36
+
37
+ describe('given a task id') do
38
+ it('loads export history based on the task') do
39
+ @params = ["--task-id=#{@task_id}"]
40
+
41
+ HammerCLIKatello::ContentExport::GenerateMetadataCommand.
42
+ any_instance.
43
+ expects(:reload_task).
44
+ returns('id' => 'taskid')
45
+
46
+ HammerCLIKatello::ContentExport::GenerateMetadataCommand.
47
+ any_instance.
48
+ expects(:fetch_export_history).
49
+ returns(@export_history)
50
+
51
+ expected = success_result("Generated /tmp/metadata.json\n")
52
+
53
+ assert_cmd(expected, result)
54
+ end
55
+ end
56
+
57
+ describe('given no arguments') do
58
+ it('tells the user to verify the arguments') do
59
+ expected = "Error: No export history was found. Verify the value given for "\
60
+ + "--task-id or --id\n"
61
+ assert_equal(expected, result.err)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,172 @@
1
+ require File.join(File.dirname(__FILE__), '../../../test_helper')
2
+ require_relative '../../organization/organization_helpers'
3
+ require_relative '../content_export_helpers'
4
+ require 'hammer_cli_katello/content_export'
5
+
6
+ describe 'content-export incremental library' do
7
+ include ForemanTaskHelpers
8
+ include OrganizationHelpers
9
+ include ContentExportHelpers
10
+
11
+ before do
12
+ @cmd = %w(content-export incremental library)
13
+ end
14
+
15
+ let(:task_id) { '5' }
16
+ let(:response) do
17
+ {
18
+ 'id' => task_id,
19
+ 'state' => 'planned',
20
+ 'output' => {
21
+ 'export_history_id' => 2
22
+ }
23
+ }
24
+ end
25
+
26
+ let(:export_history_id) { 1000 }
27
+
28
+ let(:export_history) do
29
+ {
30
+ "id": export_history_id,
31
+ "path": "/tmp",
32
+ "metadata": {}
33
+ }
34
+ end
35
+
36
+ let(:organization_id) { 77 }
37
+ let(:organization_name) { 'Foo' }
38
+ let(:destination_server) { "dream.example.com" }
39
+
40
+ it "performs export with required options and async" do
41
+ params = [
42
+ "--organization-id=#{organization_id}",
43
+ '--destination-server=foo',
44
+ '--async'
45
+ ]
46
+ expects_repositories_in_library(organization_id)
47
+ ex = api_expects(:content_export_incrementals, :library)
48
+ ex.returns(response)
49
+
50
+ result = run_cmd(@cmd + params)
51
+
52
+ assert_equal("Library environment is being exported in task #{task_id}.\n"\
53
+ + "Once the task completes the export metadata must be generated with the "\
54
+ + "command:\n hammer content-export generate-metadata --task-id #{task_id}\n", result.out)
55
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
56
+ end
57
+
58
+ it "performs export with required options" do
59
+ params = [
60
+ "--organization-id=#{organization_id}"
61
+ ]
62
+ expects_repositories_in_library(organization_id)
63
+ ex = api_expects(:content_export_incrementals, :library)
64
+ ex.returns(response)
65
+
66
+ expect_foreman_task(task_id).at_least_once
67
+
68
+ HammerCLIKatello::ContentExportIncremental::LibraryCommand.
69
+ any_instance.
70
+ expects(:fetch_export_history).
71
+ returns(export_history)
72
+
73
+ result = run_cmd(@cmd + params)
74
+ assert_match(/Generated .*metadata.*json/, result.out)
75
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
76
+ end
77
+
78
+ it "performs export with history id" do
79
+ params = [
80
+ "--organization-id=#{organization_id}",
81
+ "--destination-server=#{destination_server}",
82
+ "--from-history-id=#{export_history_id}"
83
+ ]
84
+ expects_repositories_in_library(organization_id)
85
+ api_expects(:content_export_incrementals, :library)
86
+ .with_params('organization_id' => organization_id,
87
+ 'destination_server' => destination_server,
88
+ 'from_history_id' => export_history_id)
89
+ .returns(response)
90
+
91
+ expect_foreman_task(task_id).at_least_once
92
+
93
+ HammerCLIKatello::ContentExportIncremental::LibraryCommand.
94
+ any_instance.
95
+ expects(:fetch_export_history).
96
+ returns(export_history)
97
+
98
+ result = run_cmd(@cmd + params)
99
+ assert_match(/Generated .*metadata.*json/, result.out)
100
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
101
+ end
102
+
103
+ it 'fails on missing required params' do
104
+ params = [
105
+ '--id=2'
106
+ ]
107
+
108
+ result = run_cmd(@cmd + params)
109
+ expected_error = "Could not export the library:\n"
110
+
111
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
112
+ assert_equal(result.err[/#{expected_error}/], expected_error)
113
+ end
114
+
115
+ it 'correctly resolves organization id from name' do
116
+ params = ["--organization=#{organization_name}",
117
+ "--async"]
118
+ expects_repositories_in_library(organization_id)
119
+ expect_organization_search(organization_name, organization_id)
120
+
121
+ ex = api_expects(:content_export_incrementals, :library) do |p|
122
+ assert_equal p['organization_id'].to_s, organization_id.to_s
123
+ end
124
+ ex.returns(response)
125
+
126
+ run_cmd(@cmd + params)
127
+ end
128
+
129
+ it 'warns of lazy repositories' do
130
+ params = ["--organization-id=#{organization_id}"]
131
+ expects_repositories_in_library(organization_id, [{id: 200}])
132
+
133
+ ex = api_expects(:content_export_incrementals, :library)
134
+ ex.returns(response)
135
+
136
+ expect_foreman_task(task_id).at_least_once
137
+
138
+ HammerCLIKatello::ContentExportIncremental::LibraryCommand.
139
+ any_instance.
140
+ expects(:fetch_export_history).
141
+ returns(export_history)
142
+
143
+ result = run_cmd(@cmd + params)
144
+ assert_match(/Unable to fully export this organization's library/, result.out)
145
+ assert_match(/200/, result.out)
146
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
147
+ end
148
+
149
+ it 'Errors out on lazy repositories if --fail-on-missing-content' do
150
+ params = ["--organization-id=#{organization_id}",
151
+ "--fail-on-missing-content"]
152
+ expects_repositories_in_library(organization_id, [{id: 200}])
153
+
154
+ ex = api_expects(:content_export_incrementals, :library)
155
+ ex.returns(response)
156
+
157
+ expect_foreman_task(task_id).at_least_once
158
+
159
+ HammerCLIKatello::ContentExportIncremental::LibraryCommand.
160
+ any_instance.
161
+ expects(:fetch_export_history).
162
+ returns(export_history)
163
+
164
+ HammerCLIKatello::ContentExportIncremental::LibraryCommand.
165
+ any_instance.
166
+ expects(:exit).with(HammerCLI::EX_SOFTWARE)
167
+
168
+ result = run_cmd(@cmd + params)
169
+ assert_match(/Unable to fully export this organization's library/, result.out)
170
+ assert_match(/200/, result.out)
171
+ end
172
+ end
@@ -0,0 +1,236 @@
1
+ require File.join(File.dirname(__FILE__), '../../../test_helper')
2
+ require_relative '../content_export_helpers'
3
+ require 'hammer_cli_katello/content_export'
4
+
5
+ describe 'content-export incremental version' do
6
+ include ForemanTaskHelpers
7
+ include ContentExportHelpers
8
+
9
+ before do
10
+ @cmd = %w(content-export incremental version)
11
+ end
12
+
13
+ let(:task_id) { '5' }
14
+ let(:response) do
15
+ {
16
+ 'id' => task_id,
17
+ 'state' => 'planned',
18
+ 'output' => {
19
+ 'export_history_id' => 2
20
+ }
21
+ }
22
+ end
23
+
24
+ let(:export_history_id) { 1000 }
25
+
26
+ let(:export_history) do
27
+ {
28
+ "id": export_history_id,
29
+ "path": "/tmp",
30
+ "metadata": {}
31
+ }
32
+ end
33
+
34
+ let(:content_view_id) { '77' }
35
+ let(:content_view_version_id) { 100 }
36
+
37
+ let(:version) { '10.0' }
38
+ let(:destination_server) { "dream.example.com" }
39
+
40
+ it "performs export with required options and async" do
41
+ params = [
42
+ "--id=#{content_view_version_id}",
43
+ '--destination-server=foo',
44
+ '--async'
45
+ ]
46
+ expects_repositories_in_version(content_view_version_id)
47
+
48
+ ex = api_expects(:content_export_incrementals, :version)
49
+ ex.returns(response)
50
+
51
+ result = run_cmd(@cmd + params)
52
+
53
+ assert_equal("Content view version is being exported in task #{task_id}.\n"\
54
+ + "Once the task completes the export metadata must be generated with the "\
55
+ + "command:\n hammer content-export generate-metadata --task-id #{task_id}\n", result.out)
56
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
57
+ end
58
+
59
+ it "performs export with required options" do
60
+ params = [
61
+ "--id=#{content_view_version_id}",
62
+ '--destination-server=foo'
63
+ ]
64
+
65
+ expects_repositories_in_version(content_view_version_id)
66
+ ex = api_expects(:content_export_incrementals, :version)
67
+ ex.returns(response)
68
+
69
+ expect_foreman_task(task_id).at_least_once
70
+
71
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
72
+ any_instance.
73
+ expects(:fetch_export_history).
74
+ returns(export_history)
75
+
76
+ result = run_cmd(@cmd + params)
77
+ assert_match(/Generated .*metadata.*json/, result.out)
78
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
79
+ end
80
+
81
+ it "performs export with history id" do
82
+ params = [
83
+ "--id=#{content_view_version_id}",
84
+ "--destination-server=#{destination_server}",
85
+ "--from-history-id=#{export_history_id}"
86
+ ]
87
+ expects_repositories_in_version(content_view_version_id)
88
+ api_expects(:content_export_incrementals, :version)
89
+ .with_params('id' => content_view_version_id,
90
+ 'destination_server' => destination_server,
91
+ 'from_history_id' => export_history_id)
92
+ .returns(response)
93
+
94
+ expect_foreman_task(task_id).at_least_once
95
+
96
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
97
+ any_instance.
98
+ expects(:fetch_export_history).
99
+ returns(export_history)
100
+
101
+ result = run_cmd(@cmd + params)
102
+ assert_match(/Generated .*metadata.*json/, result.out)
103
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
104
+ end
105
+
106
+ it 'fails on missing required params' do
107
+ params = [
108
+ '--boo-id=2'
109
+ ]
110
+
111
+ result = run_cmd(@cmd + params)
112
+ expected_error = "Could not export the content view version:\n"
113
+
114
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
115
+ assert_equal(result.err[/#{expected_error}/], expected_error)
116
+ end
117
+
118
+ it 'correctly resolves content-view-id and content view version number' do
119
+ params = ["--content-view-id=#{content_view_id}",
120
+ "--version=#{version}",
121
+ "--destination-server=#{destination_server}",
122
+ "--async"]
123
+ expects_repositories_in_version(content_view_version_id)
124
+ cvv_expect = api_expects(:content_view_versions, :index) do |p|
125
+ assert_equal p['content_view_id'].to_s, content_view_id.to_s
126
+ assert_equal p["version"], version
127
+ end
128
+
129
+ cvv_expect.at_least_once.
130
+ returns(index_response([{'id' => content_view_version_id}]))
131
+
132
+ ex = api_expects(:content_export_incrementals, :version) do |p|
133
+ assert_equal p['id'], content_view_version_id
134
+ assert_equal p["destination_server"], destination_server
135
+ end
136
+ ex.returns(response)
137
+
138
+ run_cmd(@cmd + params)
139
+ end
140
+
141
+ it 'fails on missing content-view name/id' do
142
+ params = []
143
+
144
+ result = run_cmd(@cmd + params)
145
+ expected_error = " At least one of options --id, --content-view, --content-view-id is required"
146
+
147
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
148
+ assert_match(/#{expected_error}/, result.err)
149
+ end
150
+
151
+ it 'fails on missing content-view version' do
152
+ params = ["--content-view-id=2"]
153
+ result = run_cmd(@cmd + params)
154
+ expected_error = "Option --version is required"
155
+
156
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
157
+ assert_match(/#{expected_error}/, result.err)
158
+ end
159
+
160
+ it 'fails on missing content-view missing org' do
161
+ params = ["--content-view=lol", "--version=4.0"]
162
+ result = run_cmd(@cmd + params)
163
+ expected_error = "At least one of options --organization-id, "\
164
+ "--organization, --organization-label is required."
165
+
166
+ assert_equal(result.exit_code, HammerCLI::EX_USAGE)
167
+ assert_match(/#{expected_error}/, result.err)
168
+ end
169
+
170
+ it 'correctly resolves content-view-id and content view version number' do
171
+ params = ["--content-view-id=#{content_view_id}",
172
+ "--version=#{version}",
173
+ "--destination-server=#{destination_server}",
174
+ "--async"]
175
+
176
+ cvv_expect = api_expects(:content_view_versions, :index) do |p|
177
+ assert_equal p['content_view_id'].to_s, content_view_id.to_s
178
+ assert_equal p["version"], version
179
+ end
180
+
181
+ cvv_expect.at_least_once.
182
+ returns(index_response([{'id' => content_view_version_id}]))
183
+
184
+ api_expects(:content_export_incrementals, :version)
185
+ .with_params('id' => content_view_version_id)
186
+ .returns(response)
187
+
188
+ expects_repositories_in_version(content_view_version_id)
189
+ run_cmd(@cmd + params)
190
+ end
191
+
192
+ it 'warns of lazy repositories' do
193
+ params = ["--id=#{content_view_version_id}"]
194
+ expects_repositories_in_version(content_view_version_id, [{id: 200}])
195
+
196
+ api_expects(:content_export_incrementals, :version)
197
+ .with_params('id' => content_view_version_id)
198
+ .returns(response)
199
+
200
+ expect_foreman_task(task_id).at_least_once
201
+
202
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
203
+ any_instance.
204
+ expects(:fetch_export_history).
205
+ returns(export_history)
206
+
207
+ result = run_cmd(@cmd + params)
208
+ assert_match(/Unable to fully export this version because/, result.out)
209
+ assert_match(/200/, result.out)
210
+ assert_equal(HammerCLI::EX_OK, result.exit_code)
211
+ end
212
+
213
+ it 'Errors out on lazy repositories if --fail-on-missing-content' do
214
+ params = ["--id=#{content_view_version_id}",
215
+ "--fail-on-missing-content"]
216
+ expects_repositories_in_version(content_view_version_id, [{id: 200}])
217
+
218
+ ex = api_expects(:content_export_incrementals, :version)
219
+ ex.returns(response)
220
+
221
+ expect_foreman_task(task_id).at_least_once
222
+
223
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
224
+ any_instance.
225
+ expects(:fetch_export_history).
226
+ returns(export_history)
227
+
228
+ HammerCLIKatello::ContentExportIncremental::VersionCommand.
229
+ any_instance.
230
+ expects(:exit).with(HammerCLI::EX_SOFTWARE)
231
+
232
+ result = run_cmd(@cmd + params)
233
+ assert_match(/Unable to fully export this version because/, result.out)
234
+ assert_match(/200/, result.out)
235
+ end
236
+ end