hammer_cli_katello 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hammer_cli_katello/content_import.rb +16 -1
- data/lib/hammer_cli_katello/content_view_version.rb +0 -273
- data/lib/hammer_cli_katello/docker.rb +13 -0
- data/lib/hammer_cli_katello/docker_manifest.rb +53 -0
- data/lib/hammer_cli_katello/docker_tag.rb +40 -0
- data/lib/hammer_cli_katello/id_resolver.rb +3 -1
- data/lib/hammer_cli_katello/organization.rb +10 -0
- data/lib/hammer_cli_katello/ping.rb +13 -5
- data/lib/hammer_cli_katello/repository.rb +21 -0
- data/lib/hammer_cli_katello/simple_content_access.rb +2 -0
- data/lib/hammer_cli_katello/version.rb +1 -1
- data/lib/hammer_cli_katello.rb +5 -1
- data/locale/hammer-cli-katello.pot +0 -25
- data/test/data/4.0/foreman_api.json +1 -1
- data/test/data/4.1/foreman_api.json +1 -0
- data/test/functional/activation_key/subscriptions_test.rb +5 -2
- data/test/functional/content_import/list_test.rb +65 -0
- data/test/functional/content_import/version_test.rb +6 -6
- data/test/functional/organization/info_test.rb +22 -0
- data/test/functional/ping_test.rb +52 -13
- data/test/test_helper.rb +1 -1
- metadata +11 -39
- data/lib/hammer_cli_katello/cv_import_export_helper.rb +0 -187
- data/test/functional/content_view/version/cv_import_export_helper_test.rb +0 -20
- data/test/functional/content_view/version/default_export_test.rb +0 -40
- data/test/functional/content_view/version/export_test.rb +0 -148
- data/test/functional/content_view/version/import_test.rb +0 -346
@@ -54,11 +54,14 @@ module HammerCLIKatello
|
|
54
54
|
run_cmd(%w(activation-key add-subscription --id 1 --subscription-id 3))
|
55
55
|
end
|
56
56
|
|
57
|
-
it 'allows a subscription to be added by name to an activation key' do
|
57
|
+
it 'allows a subscription to be added by name to an activation key with org label' do
|
58
|
+
api_expects(:organizations, :index) { |par| par[:search] == "label = \"org1\"" }
|
59
|
+
.returns(index_response([{'id' => 1}]))
|
58
60
|
api_expects(:subscriptions, :index) { |p| p['name'] == 'sub' }
|
59
61
|
.returns(index_response([{'name' => 'sub'}]))
|
60
62
|
api_expects(:activation_keys, :add_subscriptions) { |p| p['id'] == 1 }
|
61
|
-
run_cmd(%w(activation-key add-subscription --id 1 --subscription sub
|
63
|
+
run_cmd(%w(activation-key add-subscription --id 1 --subscription sub
|
64
|
+
--organization-label org1))
|
62
65
|
end
|
63
66
|
|
64
67
|
it 'allows multiple subscriptions to be added to an activation key' do
|
@@ -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
|
@@ -25,16 +25,16 @@ describe 'content-import version' do
|
|
25
25
|
JSON.parse(File.read("#{path}/metadata.json"))
|
26
26
|
end
|
27
27
|
|
28
|
-
let(:
|
28
|
+
let(:organization_id) { 3 }
|
29
29
|
|
30
30
|
it "performs import with required options and async" do
|
31
31
|
params = [
|
32
|
-
"--
|
32
|
+
"--organization-id=#{organization_id}",
|
33
33
|
"--path=#{path}",
|
34
34
|
'--async'
|
35
35
|
]
|
36
36
|
api_expects(:content_imports, :version)
|
37
|
-
.with_params('
|
37
|
+
.with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
|
38
38
|
.returns(response)
|
39
39
|
|
40
40
|
result = run_cmd(@cmd + params)
|
@@ -45,12 +45,12 @@ describe 'content-import version' do
|
|
45
45
|
|
46
46
|
it "performs import with required options" do
|
47
47
|
params = [
|
48
|
-
"--
|
48
|
+
"--organization-id=#{organization_id}",
|
49
49
|
"--path=#{path}"
|
50
50
|
]
|
51
51
|
|
52
52
|
api_expects(:content_imports, :version)
|
53
|
-
.with_params('
|
53
|
+
.with_params('organization_id' => organization_id, 'path' => path, 'metadata' => metadata)
|
54
54
|
.returns(response)
|
55
55
|
|
56
56
|
expect_foreman_task(task_id)
|
@@ -74,7 +74,7 @@ describe 'content-import version' do
|
|
74
74
|
it 'fails on missing metadata.json' do
|
75
75
|
bad_path = "/nosuchdir"
|
76
76
|
params = [
|
77
|
-
"--
|
77
|
+
"--organization-id=#{organization_id}",
|
78
78
|
"--path=#{bad_path}"
|
79
79
|
]
|
80
80
|
result = run_cmd(@cmd + params)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require 'hammer_cli_katello/organization'
|
3
|
+
require 'hammer_cli_katello/associating_commands'
|
4
|
+
|
5
|
+
describe HammerCLIKatello::Organization::InfoCommand do
|
6
|
+
before do
|
7
|
+
@cmd = %w(organization info)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "includes simple content access attributes" do
|
11
|
+
org_id = 2
|
12
|
+
params = ["--id=#{org_id}"]
|
13
|
+
api_expects(:organizations, :index).returns(index_response([{'id' => org_id}]))
|
14
|
+
|
15
|
+
api_expects(:organizations, :show)
|
16
|
+
.with_params('id' => org_id.to_s)
|
17
|
+
.returns("simple_content_access" => true, "id" => org_id)
|
18
|
+
result = run_cmd(@cmd + params)
|
19
|
+
expected = success_result(FieldMatcher.new('Simple Content Access', 'Enabled'))
|
20
|
+
assert_cmd(expected, result)
|
21
|
+
end
|
22
|
+
end
|
@@ -1,20 +1,59 @@
|
|
1
1
|
require_relative 'test_helper'
|
2
2
|
|
3
3
|
describe 'ping' do
|
4
|
+
let(:standard_response_services) do
|
5
|
+
{
|
6
|
+
'katello_agent' =>
|
7
|
+
{'status' => 'ok', 'message' => '0 Processed, 0 Failed', 'duration_ms' => '34'},
|
8
|
+
'foreman_tasks' =>
|
9
|
+
{'status' => 'ok', 'duration_ms' => '34'},
|
10
|
+
'candlepin' => {'status' => 'ok', 'duration_ms' => '34'},
|
11
|
+
'candlepin_events' =>
|
12
|
+
{'status' => 'ok', 'message' => '0 Processed, 0 Failed', 'duration_ms' => '34'},
|
13
|
+
'candlepin_auth' =>
|
14
|
+
{'status' => 'ok', 'duration_ms' => '34'},
|
15
|
+
'katello_events' =>
|
16
|
+
{'status' => 'ok', 'message' => '0 Processed, 0 Failed', 'duration_ms' => '34'},
|
17
|
+
'pulp3' =>
|
18
|
+
{'status' => 'ok', 'duration_ms' => '34'}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
let(:standard_response) do
|
22
|
+
{
|
23
|
+
'status' => 'ok',
|
24
|
+
'services' => standard_response_services
|
25
|
+
}
|
26
|
+
end
|
27
|
+
let(:standard_response_keys) do
|
28
|
+
%w(katello_agent foreman_tasks candlepin candlepin_events
|
29
|
+
candlepin_auth katello_events pulp3).sort
|
30
|
+
end
|
31
|
+
let(:hammer_ping) { %w(ping katello) }
|
32
|
+
|
4
33
|
it 'does not require authentication' do
|
5
|
-
api_expects(:ping, :index).returns(
|
34
|
+
api_expects(:ping, :index).returns(standard_response)
|
35
|
+
|
36
|
+
run_cmd(hammer_ping)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "includes all keys" do
|
40
|
+
api_expects(:ping, :index).returns(standard_response)
|
41
|
+
|
42
|
+
result = JSON.parse(run_cmd(%w(--output=json ping katello))&.out)&.first&.keys&.sort
|
43
|
+
expected = standard_response_keys
|
44
|
+
|
45
|
+
assert_equal result, expected
|
46
|
+
end
|
47
|
+
|
48
|
+
it "skips katello_agent if not included in API response" do
|
49
|
+
response_without_katello_agent = {
|
6
50
|
'status' => 'ok',
|
7
|
-
'services' => {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
'pulp3' => {'status' => 'ok', 'duration_ms' => '34'}
|
15
|
-
}
|
16
|
-
)
|
17
|
-
|
18
|
-
run_cmd(%w(ping katello))
|
51
|
+
'services' => standard_response_services.select { |k, _v| k != 'katello_agent' }
|
52
|
+
}
|
53
|
+
api_expects(:ping, :index).returns(response_without_katello_agent)
|
54
|
+
result = JSON.parse(run_cmd(%w(--output=json ping katello))&.out)&.first&.keys&.sort
|
55
|
+
expected = standard_response_keys.select { |k| k != 'katello_agent' }
|
56
|
+
|
57
|
+
assert_equal result, expected
|
19
58
|
end
|
20
59
|
end
|
data/test/test_helper.rb
CHANGED
@@ -17,7 +17,7 @@ require 'minitest/spec'
|
|
17
17
|
require 'mocha/minitest'
|
18
18
|
require 'hammer_cli'
|
19
19
|
|
20
|
-
KATELLO_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '4.
|
20
|
+
KATELLO_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '4.1')
|
21
21
|
|
22
22
|
if HammerCLI.context[:api_connection]
|
23
23
|
HammerCLI.context[:api_connection].create('foreman') do
|
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: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Price
|
@@ -35,7 +35,7 @@ authors:
|
|
35
35
|
autorequire:
|
36
36
|
bindir: bin
|
37
37
|
cert_chain: []
|
38
|
-
date: 2021-
|
38
|
+
date: 2021-04-28 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: hammer_cli_foreman
|
@@ -65,34 +65,6 @@ dependencies:
|
|
65
65
|
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
name: hammer_cli_foreman_bootdisk
|
70
|
-
requirement: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '0'
|
75
|
-
type: :runtime
|
76
|
-
prerelease: false
|
77
|
-
version_requirements: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '0'
|
82
|
-
- !ruby/object:Gem::Dependency
|
83
|
-
name: hammer_cli_foreman_docker
|
84
|
-
requirement: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '0'
|
89
|
-
type: :runtime
|
90
|
-
prerelease: false
|
91
|
-
version_requirements: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - ">="
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '0'
|
96
68
|
- !ruby/object:Gem::Dependency
|
97
69
|
name: rake
|
98
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -251,8 +223,10 @@ files:
|
|
251
223
|
- lib/hammer_cli_katello/content_view_name_resolvable.rb
|
252
224
|
- lib/hammer_cli_katello/content_view_purge.rb
|
253
225
|
- lib/hammer_cli_katello/content_view_version.rb
|
254
|
-
- lib/hammer_cli_katello/cv_import_export_helper.rb
|
255
226
|
- lib/hammer_cli_katello/deb_package.rb
|
227
|
+
- lib/hammer_cli_katello/docker.rb
|
228
|
+
- lib/hammer_cli_katello/docker_manifest.rb
|
229
|
+
- lib/hammer_cli_katello/docker_tag.rb
|
256
230
|
- lib/hammer_cli_katello/erratum.rb
|
257
231
|
- lib/hammer_cli_katello/erratum_info_command.rb
|
258
232
|
- lib/hammer_cli_katello/exception_handler.rb
|
@@ -342,6 +316,7 @@ files:
|
|
342
316
|
- test/data/3.8/foreman_api.json
|
343
317
|
- test/data/3.9/foreman_api.json
|
344
318
|
- test/data/4.0/foreman_api.json
|
319
|
+
- test/data/4.1/foreman_api.json
|
345
320
|
- test/data/Readme.md
|
346
321
|
- test/functional/activation_key/add_host_collection_test.rb
|
347
322
|
- test/functional/activation_key/content_override_test.rb
|
@@ -379,6 +354,7 @@ files:
|
|
379
354
|
- test/functional/content_export/incremental/version_test.rb
|
380
355
|
- test/functional/content_export/list_test.rb
|
381
356
|
- test/functional/content_import/library_test.rb
|
357
|
+
- test/functional/content_import/list_test.rb
|
382
358
|
- test/functional/content_import/metadata.json
|
383
359
|
- test/functional/content_import/version_test.rb
|
384
360
|
- test/functional/content_view/add_content_view_version_test.rb
|
@@ -402,10 +378,6 @@ files:
|
|
402
378
|
- test/functional/content_view/remove_content_view_version_test.rb
|
403
379
|
- test/functional/content_view/remove_test.rb
|
404
380
|
- test/functional/content_view/update_test.rb
|
405
|
-
- test/functional/content_view/version/cv_import_export_helper_test.rb
|
406
|
-
- test/functional/content_view/version/default_export_test.rb
|
407
|
-
- test/functional/content_view/version/export_test.rb
|
408
|
-
- test/functional/content_view/version/import_test.rb
|
409
381
|
- test/functional/content_view/version/incremental_update_test.rb
|
410
382
|
- test/functional/content_view/version/list_test.rb
|
411
383
|
- test/functional/content_view/version/promote_test.rb
|
@@ -468,6 +440,7 @@ files:
|
|
468
440
|
- test/functional/module_stream/info_test.rb
|
469
441
|
- test/functional/module_stream/list_test.rb
|
470
442
|
- test/functional/organization/delete_test.rb
|
443
|
+
- test/functional/organization/info_test.rb
|
471
444
|
- test/functional/organization/organization_helpers.rb
|
472
445
|
- test/functional/package/list_test.rb
|
473
446
|
- test/functional/package_group/list_test.rb
|
@@ -559,6 +532,7 @@ test_files:
|
|
559
532
|
- test/data/3.8/foreman_api.json
|
560
533
|
- test/data/3.9/foreman_api.json
|
561
534
|
- test/data/4.0/foreman_api.json
|
535
|
+
- test/data/4.1/foreman_api.json
|
562
536
|
- test/data/Readme.md
|
563
537
|
- test/functional/activation_key/add_host_collection_test.rb
|
564
538
|
- test/functional/activation_key/content_override_test.rb
|
@@ -596,6 +570,7 @@ test_files:
|
|
596
570
|
- test/functional/content_export/incremental/version_test.rb
|
597
571
|
- test/functional/content_export/list_test.rb
|
598
572
|
- test/functional/content_import/library_test.rb
|
573
|
+
- test/functional/content_import/list_test.rb
|
599
574
|
- test/functional/content_import/metadata.json
|
600
575
|
- test/functional/content_import/version_test.rb
|
601
576
|
- test/functional/content_view/add_content_view_version_test.rb
|
@@ -619,10 +594,6 @@ test_files:
|
|
619
594
|
- test/functional/content_view/remove_content_view_version_test.rb
|
620
595
|
- test/functional/content_view/remove_test.rb
|
621
596
|
- test/functional/content_view/update_test.rb
|
622
|
-
- test/functional/content_view/version/cv_import_export_helper_test.rb
|
623
|
-
- test/functional/content_view/version/default_export_test.rb
|
624
|
-
- test/functional/content_view/version/export_test.rb
|
625
|
-
- test/functional/content_view/version/import_test.rb
|
626
597
|
- test/functional/content_view/version/incremental_update_test.rb
|
627
598
|
- test/functional/content_view/version/list_test.rb
|
628
599
|
- test/functional/content_view/version/promote_test.rb
|
@@ -685,6 +656,7 @@ test_files:
|
|
685
656
|
- test/functional/module_stream/info_test.rb
|
686
657
|
- test/functional/module_stream/list_test.rb
|
687
658
|
- test/functional/organization/delete_test.rb
|
659
|
+
- test/functional/organization/info_test.rb
|
688
660
|
- test/functional/organization/organization_helpers.rb
|
689
661
|
- test/functional/package/list_test.rb
|
690
662
|
- test/functional/package_group/list_test.rb
|
@@ -1,187 +0,0 @@
|
|
1
|
-
# rubocop:disable Metrics/ModuleLength
|
2
|
-
module HammerCLIKatello
|
3
|
-
module CVImportExportHelper
|
4
|
-
PUBLISHED_REPOS_DIR = "/var/lib/pulp/published/yum/https/repos/".freeze
|
5
|
-
|
6
|
-
def fetch_exportable_cvv_repositories(cvv)
|
7
|
-
immediate = []
|
8
|
-
non_immediate_names = []
|
9
|
-
|
10
|
-
cvv['repositories'].each do |repo|
|
11
|
-
next unless repo['content_type'] == 'yum'
|
12
|
-
|
13
|
-
api_repo = show(:repositories, 'id' => repo['id'], :full_result => true)
|
14
|
-
|
15
|
-
download_policy = if api_repo['library_instance_id']
|
16
|
-
library = show(:repositories, 'id' => api_repo['library_instance_id'])
|
17
|
-
library['download_policy']
|
18
|
-
else
|
19
|
-
api_repo['download_policy']
|
20
|
-
end
|
21
|
-
|
22
|
-
if download_policy == 'immediate'
|
23
|
-
immediate << api_repo
|
24
|
-
else
|
25
|
-
non_immediate_names << api_repo['name']
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
warn_repo_download_policy(non_immediate_names)
|
30
|
-
|
31
|
-
return immediate
|
32
|
-
end
|
33
|
-
|
34
|
-
def find_local_component_id(component_from_export)
|
35
|
-
*name, version = component_from_export.split(' ')
|
36
|
-
name = name.join(' ')
|
37
|
-
existing_component_cv = content_view(name, options['option_organization_id'])
|
38
|
-
found_composite_version = existing_component_cv['versions'].select do |v|
|
39
|
-
v['version'] == version
|
40
|
-
end
|
41
|
-
if found_composite_version.empty?
|
42
|
-
raise _("Unable to find CV version %{cvv} on system. Please ensure it " \
|
43
|
-
"is already imported." % {'cvv' => component_from_export})
|
44
|
-
end
|
45
|
-
found_composite_version.first['id']
|
46
|
-
end
|
47
|
-
|
48
|
-
def warn_repo_download_policy(repository_names)
|
49
|
-
return if repository_names.empty?
|
50
|
-
|
51
|
-
msg = <<~MSG
|
52
|
-
The following repositories could not be exported due to the download policy
|
53
|
-
not being set to 'immediate':
|
54
|
-
#{repository_names.join(', ')}
|
55
|
-
MSG
|
56
|
-
print_message msg
|
57
|
-
end
|
58
|
-
|
59
|
-
def collect_packages(repositories)
|
60
|
-
repositories.each do |repo|
|
61
|
-
per_page = 50
|
62
|
-
repo['packages'] = []
|
63
|
-
repo['errata'] = []
|
64
|
-
repo_packages = repo['content_counts']['rpm']
|
65
|
-
errata_count = repo['content_counts']['erratum']
|
66
|
-
pkg_pages = (repo_packages / per_page.to_f).ceil
|
67
|
-
errata_pages = (errata_count / per_page.to_f).ceil
|
68
|
-
(1..pkg_pages).each do |page|
|
69
|
-
repo['packages'] += index(:packages, 'repository_id' => repo['id'],
|
70
|
-
:page => page, :per_page => 50)
|
71
|
-
end
|
72
|
-
(1..errata_pages).each do |page|
|
73
|
-
repo['errata'] += index(:errata, 'repository_id' => repo['id'],
|
74
|
-
:page => page, :per_page => 50)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def import_checks(cv, import_cv, major, minor)
|
80
|
-
version = "#{major}.#{minor}".to_f
|
81
|
-
|
82
|
-
if import_cv.nil?
|
83
|
-
raise _("The Content View #{cv['name']} is not present on this server,"\
|
84
|
-
" please create the Content View and try the import again.")
|
85
|
-
end
|
86
|
-
|
87
|
-
unless import_cv['default']
|
88
|
-
if import_cv['latest_version'].to_f >= version
|
89
|
-
raise _("The latest version (#{import_cv['latest_version']}) of"\
|
90
|
-
" the Content View '#{cv['name']}'"\
|
91
|
-
" is greater or equal to the version you are trying to import (#{version})")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
unless import_cv['repository_ids'].nil?
|
96
|
-
repositories = import_cv['repository_ids'].collect do |repo_id|
|
97
|
-
show(:repositories, 'id' => repo_id)
|
98
|
-
end
|
99
|
-
repositories.each do |repo|
|
100
|
-
if repo['mirror_on_sync'] == true
|
101
|
-
raise _("The Repository '#{repo['name']}' is set with Mirror-on-Sync to YES."\
|
102
|
-
" Please change Mirror-on-Sync to NO and try the import again.")
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def untar_export(options)
|
109
|
-
export_tar_file = options[:filename]
|
110
|
-
export_tar_dir = options[:dirname]
|
111
|
-
export_tar_prefix = options[:prefix]
|
112
|
-
|
113
|
-
Dir.chdir(export_tar_dir) do
|
114
|
-
`tar -xf #{export_tar_file}`
|
115
|
-
end
|
116
|
-
|
117
|
-
Dir.chdir("#{export_tar_dir}/#{export_tar_prefix}") do
|
118
|
-
if File.exist?(export_tar_file.gsub('.tar', '-repos.tar'))
|
119
|
-
`tar -xf #{export_tar_file.gsub('.tar', '-repos.tar')}`
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def obtain_export_params(option_export_tar)
|
125
|
-
export_tar_file = File.basename(option_export_tar)
|
126
|
-
{:filename => export_tar_file,
|
127
|
-
:dirname => File.dirname(option_export_tar),
|
128
|
-
:prefix => export_tar_file.gsub('.tar', '')}
|
129
|
-
end
|
130
|
-
|
131
|
-
def read_json(options)
|
132
|
-
export_tar_file = options[:filename]
|
133
|
-
export_tar_dir = options[:dirname]
|
134
|
-
export_tar_prefix = options[:prefix]
|
135
|
-
|
136
|
-
json_file = export_tar_file.gsub('tar', 'json')
|
137
|
-
json_file = "#{export_tar_dir}/#{export_tar_prefix}/#{json_file}"
|
138
|
-
json_file = File.read(json_file)
|
139
|
-
JSON.parse(json_file)
|
140
|
-
end
|
141
|
-
|
142
|
-
def export_json(export_json_options)
|
143
|
-
content_view_version = export_json_options[:cvv]
|
144
|
-
repositories = export_json_options[:repositories]
|
145
|
-
json = {
|
146
|
-
"name" => content_view_version['content_view']['name'],
|
147
|
-
"major" => content_view_version['major'],
|
148
|
-
"minor" => content_view_version['minor']
|
149
|
-
}
|
150
|
-
json["composite_components"] = export_json_options[:component_cvvs]
|
151
|
-
json["repositories"] = repositories.collect do |repo|
|
152
|
-
{
|
153
|
-
"id" => repo['id'],
|
154
|
-
"label" => repo['label'],
|
155
|
-
"content_type" => repo['content_type'],
|
156
|
-
"backend_identifier" => repo['backend_identifier'],
|
157
|
-
"relative_path" => repo['relative_path'],
|
158
|
-
"on_disk_path" => "#{PUBLISHED_REPOS_DIR}/#{repo['relative_path']}",
|
159
|
-
"rpm_filenames" => repo['packages'].collect { |package| package['filename'] },
|
160
|
-
"errata_ids" => repo['errata'].collect { |errata| errata['errata_id'] }
|
161
|
-
}
|
162
|
-
end
|
163
|
-
json
|
164
|
-
end
|
165
|
-
|
166
|
-
def fail_msg_import
|
167
|
-
_("This command is not supported with Pulp 3. Use `hammer content-import` instead.")
|
168
|
-
end
|
169
|
-
|
170
|
-
def fail_msg_export
|
171
|
-
_("This command is not supported with Pulp 3. Use `hammer content-export` instead.")
|
172
|
-
end
|
173
|
-
|
174
|
-
def validate_pulp3_not_enabled(failure_message)
|
175
|
-
pulp3_enabled = HammerCLIForeman
|
176
|
-
.foreman_api_connection
|
177
|
-
.resource(:content_exports)
|
178
|
-
.call(:api_status)['api_usable']
|
179
|
-
if pulp3_enabled
|
180
|
-
raise failure_message
|
181
|
-
end
|
182
|
-
rescue NoMethodError
|
183
|
-
# if the api endpoint isn't there, the validation passes
|
184
|
-
true
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require_relative '../../test_helper'
|
2
|
-
describe 'CVImportExportHelper' do
|
3
|
-
describe 'validate_pulp3_not_enabled' do
|
4
|
-
include HammerCLIKatello::CVImportExportHelper
|
5
|
-
it 'returns true when the api endpoint does not return a value' do
|
6
|
-
api_expects(:content_exports, :api_status)
|
7
|
-
assert_equal true, validate_pulp3_not_enabled('fail_msg')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'raises error when the api reports Pulp 3 is enabled' do
|
11
|
-
api_expects(:content_exports, :api_status).returns('api_usable' => true)
|
12
|
-
assert_raises(RuntimeError, 'fail msg') { validate_pulp3_not_enabled('fail msg') }
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns nil when the api reports Pulp 3 is not enabled' do
|
16
|
-
api_expects(:content_exports, :api_status).returns('api_usable' => false)
|
17
|
-
assert_equal nil, validate_pulp3_not_enabled('fail_msg')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../../test_helper')
|
2
|
-
|
3
|
-
describe 'content-view version export' do
|
4
|
-
include ForemanTaskHelpers
|
5
|
-
|
6
|
-
before do
|
7
|
-
@cmd = %w(content-view version export-default)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "performs export with bad SELinux" do
|
11
|
-
params = [
|
12
|
-
'--export-dir=/tmp/default'
|
13
|
-
]
|
14
|
-
|
15
|
-
File.expects(:exist?).with('/usr/share/foreman').returns(true)
|
16
|
-
File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
|
17
|
-
|
18
|
-
Dir.expects(:mkdir).with('/tmp/default').returns(0)
|
19
|
-
Kernel.expects(:system).with("rsync -aL /var/lib/pulp/published/yum/https/repos/ /tmp/default")
|
20
|
-
|
21
|
-
result = run_cmd(@cmd + params)
|
22
|
-
assert_equal(HammerCLI::EX_CANTCREAT, result.exit_code)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "performs export" do
|
26
|
-
params = [
|
27
|
-
'--export-dir=/tmp/default'
|
28
|
-
]
|
29
|
-
|
30
|
-
File.expects(:exist?).with('/usr/share/foreman').returns(true)
|
31
|
-
File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
|
32
|
-
|
33
|
-
Dir.expects(:exist?).with('/tmp/default').returns(0)
|
34
|
-
Kernel.expects(:system).with("rsync -aL /var/lib/pulp/published/yum/https/repos/ /tmp/default")
|
35
|
-
.returns(true)
|
36
|
-
|
37
|
-
result = run_cmd(@cmd + params)
|
38
|
-
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
39
|
-
end
|
40
|
-
end
|