hammer_cli_katello 0.17.0 → 0.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/hammer_cli_katello/content_view_version.rb +19 -4
- data/lib/hammer_cli_katello/cv_import_export_helper.rb +27 -0
- data/lib/hammer_cli_katello/ostree_branch.rb +0 -1
- data/lib/hammer_cli_katello/version.rb +1 -1
- data/test/functional/content_view/version/export_test.rb +43 -4
- data/test/functional/content_view/version/import_test.rb +97 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 53e2f4ceb875e5146dc941c0c2f6ba8a00095e525c1a8a99ad0252ed92f8cf60
|
4
|
+
data.tar.gz: '01080c7f6a9e503fcf2446d41f20b131ca2293aeb849e08243da25ccfc1e5cbc'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d4ce299d3e164363f6209a127d8425bbbfdf7571fc38771e8ce52c671e2b550659fb6af5cc97fd066f50b3af81935802c832e585aa7c280136e75b0acc561b5
|
7
|
+
data.tar.gz: 666a449b3d17c960642fdbb498cc8367e6049dab07a58d640322672798d8937338a78bf089e2e59c5db42d68afa652db1af2fa861ac1b5e54a5470e05a95bd09
|
@@ -301,6 +301,7 @@ module HammerCLIKatello
|
|
301
301
|
export_json_options[:repositories] = []
|
302
302
|
else
|
303
303
|
repositories = fetch_cvv_repositories(cvv)
|
304
|
+
check_repo_type(repositories)
|
304
305
|
check_repo_download_policy(repositories)
|
305
306
|
|
306
307
|
repositories.each do |repo|
|
@@ -316,7 +317,7 @@ module HammerCLIKatello
|
|
316
317
|
end
|
317
318
|
|
318
319
|
def create_tar(cv, cvv, repositories, json)
|
319
|
-
export_prefix = "export-#{cv['label']}-#{cvv['
|
320
|
+
export_prefix = "export-#{cv['label']}-#{cvv['major']}.#{cvv['minor']}"
|
320
321
|
export_file = "#{export_prefix}.json"
|
321
322
|
export_repos_tar = "#{export_prefix}-repos.tar"
|
322
323
|
export_tar = "#{export_prefix}.tar"
|
@@ -349,6 +350,17 @@ module HammerCLIKatello
|
|
349
350
|
end
|
350
351
|
end
|
351
352
|
|
353
|
+
def check_repo_type(repositories)
|
354
|
+
repositories.select do |repo|
|
355
|
+
if repo['content_type'] != 'yum'
|
356
|
+
raise _("The Repository '#{repo['name']}' is a non-yum repository."\
|
357
|
+
" Only Yum is supported at this time."\
|
358
|
+
" Please remove the repository from the Content View,"\
|
359
|
+
" republish and try the export again.")
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
352
364
|
def check_repo_download_policy(repositories)
|
353
365
|
non_immediate = repositories.select do |repo|
|
354
366
|
show(:repositories, 'id' => repo['library_instance_id'])['download_policy'] != 'immediate'
|
@@ -378,7 +390,7 @@ module HammerCLIKatello
|
|
378
390
|
command_name "import"
|
379
391
|
|
380
392
|
success_message _("Content view imported.")
|
381
|
-
failure_message _("Could not import the content view
|
393
|
+
failure_message _("Could not import the content view")
|
382
394
|
|
383
395
|
option "--organization-id", "ORGANIZATION_ID", _("Organization numeric identifier")
|
384
396
|
option(
|
@@ -393,6 +405,7 @@ module HammerCLIKatello
|
|
393
405
|
|
394
406
|
build_options
|
395
407
|
|
408
|
+
# rubocop:disable Metrics/AbcSize
|
396
409
|
def execute
|
397
410
|
unless File.exist?(options['option_export_tar'])
|
398
411
|
raise _("Export tar #{options['option_export_tar']} does not exist.")
|
@@ -403,18 +416,19 @@ module HammerCLIKatello
|
|
403
416
|
|
404
417
|
export_json = read_json(import_tar_params)
|
405
418
|
cv = content_view(export_json['name'], options['option_organization_id'])
|
419
|
+
major = export_json['major'].to_s
|
420
|
+
minor = export_json['minor'].to_s
|
421
|
+
import_checks(export_json, cv, major, minor)
|
406
422
|
|
407
423
|
if export_json['composite_components']
|
408
424
|
composite_version_ids = export_json['composite_components'].map do |component|
|
409
425
|
find_local_component_id(component)
|
410
426
|
end
|
411
|
-
|
412
427
|
update(:content_views, 'id' => cv['id'], 'component_ids' => composite_version_ids)
|
413
428
|
publish(cv['id'], export_json['major'], export_json['minor'])
|
414
429
|
else
|
415
430
|
sync_repositories(export_json['repositories'], options['option_organization_id'],
|
416
431
|
import_tar_params)
|
417
|
-
|
418
432
|
publish(
|
419
433
|
cv['id'], export_json['major'],
|
420
434
|
export_json['minor'], repos_units(export_json['repositories'])
|
@@ -422,6 +436,7 @@ module HammerCLIKatello
|
|
422
436
|
end
|
423
437
|
return HammerCLI::EX_OK
|
424
438
|
end
|
439
|
+
# rubocop:enable Metrics/AbcSize
|
425
440
|
|
426
441
|
def sync_repositories(repositories, organization_id, options)
|
427
442
|
export_tar_dir = options[:dirname]
|
@@ -22,6 +22,33 @@ module HammerCLIKatello
|
|
22
22
|
found_composite_version.first['id']
|
23
23
|
end
|
24
24
|
|
25
|
+
def import_checks(cv, import_cv, major, minor)
|
26
|
+
version = "#{major}.#{minor}".to_f
|
27
|
+
|
28
|
+
if import_cv.nil?
|
29
|
+
raise _("The Content View #{cv['name']} is not present on this server,"\
|
30
|
+
" please create the Content View and try the import again.")
|
31
|
+
end
|
32
|
+
|
33
|
+
if import_cv['latest_version'].to_f >= version
|
34
|
+
raise _("The latest version (#{import_cv['latest_version']}) of"\
|
35
|
+
" the Content View '#{cv['name']}'"\
|
36
|
+
" is greater or equal to the version you are trying to import (#{version})")
|
37
|
+
end
|
38
|
+
|
39
|
+
unless import_cv['repository_ids'].nil?
|
40
|
+
repositories = import_cv['repository_ids'].collect do |repo_id|
|
41
|
+
show(:repositories, 'id' => repo_id)
|
42
|
+
end
|
43
|
+
repositories.each do |repo|
|
44
|
+
if repo['mirror_on_sync'] == true
|
45
|
+
raise _("The Repository '#{repo['name']}' is set with Mirror-on-Sync to YES."\
|
46
|
+
" Please change Mirror-on-Sync to NO and try the import again.")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
25
52
|
def untar_export(options)
|
26
53
|
export_tar_file = options[:filename]
|
27
54
|
export_tar_dir = options[:dirname]
|
@@ -51,9 +51,9 @@ describe 'content-view version export' do
|
|
51
51
|
File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
|
52
52
|
|
53
53
|
Dir.expects(:chdir).with("/var/lib/pulp/published/yum/https/repos/").returns(true)
|
54
|
-
Dir.expects(:mkdir).with('/tmp/exports/export-cv-
|
54
|
+
Dir.expects(:mkdir).with('/tmp/exports/export-cv-1.0').returns(0)
|
55
55
|
Dir.expects(:chdir).with('/tmp/exports').returns(0)
|
56
|
-
Dir.expects(:chdir).with('/tmp/exports/export-cv-
|
56
|
+
Dir.expects(:chdir).with('/tmp/exports/export-cv-1.0').returns(0)
|
57
57
|
|
58
58
|
result = run_cmd(@cmd + params)
|
59
59
|
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
@@ -87,9 +87,9 @@ describe 'content-view version export' do
|
|
87
87
|
File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
|
88
88
|
|
89
89
|
Dir.expects(:chdir).with("/var/lib/pulp/published/yum/https/repos/").never
|
90
|
-
Dir.expects(:mkdir).with('/tmp/exports/export-cv-
|
90
|
+
Dir.expects(:mkdir).with('/tmp/exports/export-cv-1.0').returns(0)
|
91
91
|
Dir.expects(:chdir).with('/tmp/exports').returns(0)
|
92
|
-
Dir.expects(:chdir).with('/tmp/exports/export-cv-
|
92
|
+
Dir.expects(:chdir).with('/tmp/exports/export-cv-1.0').returns(0)
|
93
93
|
|
94
94
|
result = run_cmd(@cmd + params)
|
95
95
|
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
@@ -182,4 +182,43 @@ describe 'content-view version export' do
|
|
182
182
|
result = run_cmd(@cmd + params)
|
183
183
|
assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
|
184
184
|
end
|
185
|
+
|
186
|
+
it "fails export if any repository is not yum" do
|
187
|
+
params = [
|
188
|
+
'--id=5',
|
189
|
+
'--export-dir=/tmp/exports'
|
190
|
+
]
|
191
|
+
|
192
|
+
ex = api_expects(:content_view_versions, :show)
|
193
|
+
ex.returns(
|
194
|
+
'id' => '5',
|
195
|
+
'repositories' => [{'id' => '2'}],
|
196
|
+
'major' => 1,
|
197
|
+
'minor' => 0,
|
198
|
+
'content_view' => {'name' => 'cv'},
|
199
|
+
'content_view_id' => 4321
|
200
|
+
)
|
201
|
+
|
202
|
+
ex = api_expects(:content_views, :show)
|
203
|
+
ex.returns(
|
204
|
+
'id' => '4321',
|
205
|
+
'composite' => false
|
206
|
+
)
|
207
|
+
|
208
|
+
ex = api_expects(:repositories, :show).with_params('id' => '2')
|
209
|
+
ex.returns(
|
210
|
+
'id' => '2',
|
211
|
+
'label' => 'Test_Repo',
|
212
|
+
'content_type' => 'file',
|
213
|
+
'backend_identifier' => 'Default_Organization-Library-Test_Repo',
|
214
|
+
'relative_path' => 'Default_Organization/Library/Test_Repo',
|
215
|
+
'library_instance_id' => '1'
|
216
|
+
)
|
217
|
+
|
218
|
+
File.expects(:exist?).with('/usr/share/foreman').returns(true)
|
219
|
+
File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
|
220
|
+
|
221
|
+
result = run_cmd(@cmd + params)
|
222
|
+
assert_equal(result.exit_code, 70)
|
223
|
+
end
|
185
224
|
end
|
@@ -183,6 +183,100 @@ describe 'content-view version import' do
|
|
183
183
|
assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
|
184
184
|
end
|
185
185
|
|
186
|
+
it "fails import if cv has not been created" do
|
187
|
+
params = [
|
188
|
+
'--export-tar=/tmp/exports/export-2.tar',
|
189
|
+
'--organization-id=1'
|
190
|
+
]
|
191
|
+
|
192
|
+
File.expects(:exist?).with('/usr/share/foreman').returns(true)
|
193
|
+
File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
|
194
|
+
|
195
|
+
File.expects(:exist?).with("/tmp/exports/export-2.tar").returns(true)
|
196
|
+
Dir.expects(:chdir).with('/tmp/exports').returns(0)
|
197
|
+
Dir.expects(:chdir).with('/tmp/exports/export-2').returns(0)
|
198
|
+
File.expects(:read).with("/tmp/exports/export-2/export-2.json").returns(
|
199
|
+
JSON.dump(
|
200
|
+
'name' => 'Foo View'
|
201
|
+
)
|
202
|
+
)
|
203
|
+
|
204
|
+
ex = api_expects(:content_views, :index)
|
205
|
+
ex = ex.with_params('name' => 'Foo View', 'organization_id' => '1')
|
206
|
+
ex.returns([])
|
207
|
+
|
208
|
+
result = run_cmd(@cmd + params)
|
209
|
+
assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
|
210
|
+
end
|
211
|
+
|
212
|
+
it "fails import if repo is set to mirror-on-sync" do
|
213
|
+
params = [
|
214
|
+
'--export-tar=/tmp/exports/export-2.tar',
|
215
|
+
'--organization-id=1'
|
216
|
+
]
|
217
|
+
|
218
|
+
File.expects(:exist?).with('/usr/share/foreman').returns(true)
|
219
|
+
File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
|
220
|
+
|
221
|
+
File.expects(:exist?).with("/tmp/exports/export-2.tar").returns(true)
|
222
|
+
Dir.expects(:chdir).with('/tmp/exports').returns(0)
|
223
|
+
Dir.expects(:chdir).with('/tmp/exports/export-2').returns(0)
|
224
|
+
File.expects(:read).with("/tmp/exports/export-2/export-2.json").returns(
|
225
|
+
JSON.dump(
|
226
|
+
'name' => 'Foo View',
|
227
|
+
'major' => '2',
|
228
|
+
'minor' => '1'
|
229
|
+
)
|
230
|
+
)
|
231
|
+
|
232
|
+
ex = api_expects(:content_views, :index)
|
233
|
+
ex = ex.with_params('name' => 'Foo View', 'organization_id' => '1')
|
234
|
+
ex.returns(
|
235
|
+
'results' => [{
|
236
|
+
'id' => '5',
|
237
|
+
'repositories' => [{'id' => '2', 'label' => 'foo', 'mirror_on_sync' => 'true'}],
|
238
|
+
'content_view' => {'name' => 'cv'}
|
239
|
+
}]
|
240
|
+
)
|
241
|
+
|
242
|
+
result = run_cmd(@cmd + params)
|
243
|
+
assert_equal(result.exit_code, 70)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "fails import if cv version already exists" do
|
247
|
+
params = [
|
248
|
+
'--export-tar=/tmp/exports/export-2.tar',
|
249
|
+
'--organization-id=1'
|
250
|
+
]
|
251
|
+
|
252
|
+
File.expects(:exist?).with('/usr/share/foreman').returns(true)
|
253
|
+
File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
|
254
|
+
|
255
|
+
File.expects(:exist?).with("/tmp/exports/export-2.tar").returns(true)
|
256
|
+
Dir.expects(:chdir).with('/tmp/exports').returns(0)
|
257
|
+
Dir.expects(:chdir).with('/tmp/exports/export-2').returns(0)
|
258
|
+
File.expects(:read).with("/tmp/exports/export-2/export-2.json").returns(
|
259
|
+
JSON.dump(
|
260
|
+
'name' => 'Foo View',
|
261
|
+
'major' => '2',
|
262
|
+
'minor' => '1'
|
263
|
+
)
|
264
|
+
)
|
265
|
+
|
266
|
+
ex = api_expects(:content_views, :index)
|
267
|
+
ex = ex.with_params('name' => 'Foo View', 'organization_id' => '1')
|
268
|
+
ex.returns(
|
269
|
+
'results' => [{
|
270
|
+
'id' => '5',
|
271
|
+
'content_view' => {'name' => 'cv'},
|
272
|
+
'versions' => [{'version' => '2.1', 'id' => '654'}]
|
273
|
+
}]
|
274
|
+
)
|
275
|
+
|
276
|
+
result = run_cmd(@cmd + params)
|
277
|
+
assert_equal(result.exit_code, 70)
|
278
|
+
end
|
279
|
+
|
186
280
|
it "fails import if any repository does not exist" do
|
187
281
|
params = [
|
188
282
|
'--export-tar=/tmp/exports/export-2.tar',
|
@@ -198,7 +292,9 @@ describe 'content-view version import' do
|
|
198
292
|
File.expects(:read).with("/tmp/exports/export-2/export-2.json").returns(
|
199
293
|
JSON.dump(
|
200
294
|
'name' => 'Foo View',
|
201
|
-
'repositories' => ['label' => 'foo']
|
295
|
+
'repositories' => ['label' => 'foo'],
|
296
|
+
'major' => '2',
|
297
|
+
'minor' => '1'
|
202
298
|
)
|
203
299
|
)
|
204
300
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hammer_cli_katello
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.17.
|
4
|
+
version: 0.17.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Price
|
@@ -34,7 +34,7 @@ authors:
|
|
34
34
|
autorequire:
|
35
35
|
bindir: bin
|
36
36
|
cert_chain: []
|
37
|
-
date: 2019-
|
37
|
+
date: 2019-04-22 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: hammer_cli_foreman
|
@@ -485,8 +485,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
485
485
|
- !ruby/object:Gem::Version
|
486
486
|
version: '0'
|
487
487
|
requirements: []
|
488
|
-
|
489
|
-
rubygems_version: 2.6.14
|
488
|
+
rubygems_version: 3.0.2
|
490
489
|
signing_key:
|
491
490
|
specification_version: 4
|
492
491
|
summary: Katello commands for Hammer
|