hammer_cli_katello 1.5.0 → 1.6.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/acs.rb +82 -0
- data/lib/hammer_cli_katello/activation_key.rb +8 -2
- data/lib/hammer_cli_katello/content_export.rb +39 -0
- data/lib/hammer_cli_katello/content_export_helper.rb +64 -6
- data/lib/hammer_cli_katello/host_subscription.rb +32 -0
- data/lib/hammer_cli_katello/organization.rb +4 -0
- data/lib/hammer_cli_katello/repository.rb +1 -1
- data/lib/hammer_cli_katello/simple_content_access.rb +10 -0
- data/lib/hammer_cli_katello/version.rb +1 -1
- data/lib/hammer_cli_katello.rb +5 -0
- data/test/data/2.5/foreman_api.json +1 -0
- data/test/data/3.0/foreman_api.json +1 -0
- data/test/data/3.10/foreman_api.json +1 -0
- data/test/data/3.11/foreman_api.json +1 -0
- data/test/data/3.12/foreman_api.json +1 -0
- data/test/data/3.13/foreman_api.json +1 -0
- data/test/data/3.14/foreman_api.json +1 -0
- data/test/data/3.15/foreman_api.json +1 -0
- data/test/data/3.16/foreman_api.json +1 -0
- data/test/data/3.17/foreman_api.json +1 -0
- data/test/data/3.18/foreman_api.json +1 -0
- data/test/data/3.19/foreman_api.json +1 -0
- data/test/data/3.2/foreman_api.json +1 -0
- data/test/data/3.4/foreman_api.json +1 -0
- data/test/data/3.5/foreman_api.json +1 -0
- data/test/data/3.6/foreman_api.json +1 -0
- data/test/data/3.7/foreman_api.json +1 -0
- data/test/data/3.8/foreman_api.json +1 -0
- data/test/data/3.9/foreman_api.json +1 -0
- data/test/data/4.0/foreman_api.json +1 -0
- data/test/data/4.1/foreman_api.json +1 -0
- data/test/data/4.3/foreman_api.json +1 -0
- data/test/data/4.4/foreman_api.json +1 -0
- data/test/data/4.5/foreman_api.json +1 -0
- data/test/data/4.6/foreman_api.json +1 -0
- data/test/data/Readme.md +5 -0
- data/test/functional/acs/create_test.rb +27 -0
- data/test/functional/acs/delete_test.rb +13 -0
- data/test/functional/acs/info_test.rb +94 -0
- data/test/functional/acs/list_test.rb +62 -0
- data/test/functional/acs/update_test.rb +23 -0
- data/test/functional/activation_key/add_host_collection_test.rb +62 -0
- data/test/functional/activation_key/content_override_test.rb +92 -0
- data/test/functional/activation_key/create_test.rb +33 -0
- data/test/functional/activation_key/data/activation_key.json +17 -0
- data/test/functional/activation_key/info_test.rb +29 -0
- data/test/functional/activation_key/list_test.rb +68 -0
- data/test/functional/activation_key/product_content_test.rb +23 -0
- data/test/functional/activation_key/remove_host_collection_test.rb +62 -0
- data/test/functional/activation_key/subscriptions_test.rb +74 -0
- data/test/functional/activation_key/update_test.rb +26 -0
- data/test/functional/apipie_helper_test.rb +31 -0
- data/test/functional/capsule/capsule_helpers.rb +13 -0
- data/test/functional/capsule/content/add_lifecycle_environment_test.rb +40 -0
- data/test/functional/capsule/content/cancel_synchronization_test.rb +42 -0
- data/test/functional/capsule/content/capsule_content_helpers.rb +24 -0
- data/test/functional/capsule/content/data/library_env.json +47 -0
- data/test/functional/capsule/content/data/sync_status.json +6 -0
- data/test/functional/capsule/content/data/sync_tasks.json +62 -0
- data/test/functional/capsule/content/info_test.rb +61 -0
- data/test/functional/capsule/content/lifecycle_environments_test.rb +19 -0
- data/test/functional/capsule/content/remove_lifecycle_environment_test.rb +40 -0
- data/test/functional/capsule/content/synchronization_status_test.rb +107 -0
- data/test/functional/capsule/info_test.rb +25 -0
- data/test/functional/capsule/list_test.rb +24 -0
- data/test/functional/content_credentials/create_test.rb +32 -0
- data/test/functional/content_credentials/data/test_cert.json +43 -0
- data/test/functional/content_credentials/info_test.rb +50 -0
- data/test/functional/content_credentials/list_test.rb +66 -0
- data/test/functional/content_export/complete/library_test.rb +155 -0
- data/test/functional/content_export/complete/repository_test.rb +226 -0
- data/test/functional/content_export/complete/version_test.rb +297 -0
- data/test/functional/content_export/content_export_helpers.rb +33 -0
- data/test/functional/content_export/generate_listing_test.rb +62 -0
- data/test/functional/content_export/generate_metadata_test.rb +64 -0
- data/test/functional/content_export/incremental/library_test.rb +172 -0
- data/test/functional/content_export/incremental/repository_test.rb +212 -0
- data/test/functional/content_export/incremental/version_test.rb +268 -0
- data/test/functional/content_export/list_test.rb +64 -0
- data/test/functional/content_import/library_test.rb +85 -0
- data/test/functional/content_import/list_test.rb +65 -0
- data/test/functional/content_import/metadata.json +1 -0
- data/test/functional/content_import/version_test.rb +85 -0
- data/test/functional/content_units/info_test.rb +29 -0
- data/test/functional/content_units/list_test.rb +106 -0
- data/test/functional/content_view/add_content_view_version_test.rb +88 -0
- data/test/functional/content_view/add_repository_test.rb +21 -0
- data/test/functional/content_view/component/add_test.rb +177 -0
- data/test/functional/content_view/component/list_test.rb +55 -0
- data/test/functional/content_view/component/remove_test.rb +107 -0
- data/test/functional/content_view/component/update_test.rb +134 -0
- data/test/functional/content_view/content_view_helpers.rb +20 -0
- data/test/functional/content_view/copy_test.rb +53 -0
- data/test/functional/content_view/create_test.rb +34 -0
- data/test/functional/content_view/delete_test.rb +62 -0
- data/test/functional/content_view/filter/create_test.rb +57 -0
- data/test/functional/content_view/filter/delete_test.rb +90 -0
- data/test/functional/content_view/filter/info_test.rb +89 -0
- data/test/functional/content_view/filter/list_test.rb +98 -0
- data/test/functional/content_view/filter/update_test.rb +91 -0
- data/test/functional/content_view/list_test.rb +68 -0
- data/test/functional/content_view/publish_test.rb +24 -0
- data/test/functional/content_view/purge_test.rb +97 -0
- data/test/functional/content_view/remove_content_view_version_test.rb +88 -0
- data/test/functional/content_view/remove_test.rb +79 -0
- data/test/functional/content_view/update_test.rb +53 -0
- data/test/functional/content_view/version/incremental_update_test.rb +108 -0
- data/test/functional/content_view/version/list_test.rb +44 -0
- data/test/functional/content_view/version/promote_test.rb +75 -0
- data/test/functional/content_view/version/republish_repositories_test.rb +34 -0
- data/test/functional/content_view/version/update_test.rb +48 -0
- data/test/functional/erratum/erratum_helpers.rb +91 -0
- data/test/functional/erratum/info_test.rb +29 -0
- data/test/functional/erratum/list_test.rb +108 -0
- data/test/functional/file/file_helpers.rb +13 -0
- data/test/functional/file/info_test.rb +162 -0
- data/test/functional/file/list_test.rb +112 -0
- data/test/functional/filter_rule/create_test.rb +99 -0
- data/test/functional/filter_rule/delete_test.rb +104 -0
- data/test/functional/filter_rule/filter_rule_helpers.rb +12 -0
- data/test/functional/filter_rule/info_test.rb +104 -0
- data/test/functional/filter_rule/list_test.rb +91 -0
- data/test/functional/filter_rule/update_test.rb +104 -0
- data/test/functional/host/errata/apply_test.rb +45 -0
- data/test/functional/host/errata/info_test.rb +27 -0
- data/test/functional/host/errata/list_test.rb +49 -0
- data/test/functional/host/errata/recalculate_test.rb +26 -0
- data/test/functional/host/extensions/create_test.rb +95 -0
- data/test/functional/host/extensions/data/host.json +320 -0
- data/test/functional/host/extensions/data/host_list.json +117 -0
- data/test/functional/host/extensions/info_test.rb +35 -0
- data/test/functional/host/extensions/list_test.rb +21 -0
- data/test/functional/host/extensions/update_test.rb +70 -0
- data/test/functional/host/host_helpers.rb +8 -0
- data/test/functional/host/subscription/attach_test.rb +54 -0
- data/test/functional/host/subscription/auto_attach_test.rb +35 -0
- data/test/functional/host/subscription/content_override_test.rb +96 -0
- data/test/functional/host/subscription/enabled_repositories_test.rb +39 -0
- data/test/functional/host/subscription/product_content_test.rb +27 -0
- data/test/functional/host/subscription/register_test.rb +53 -0
- data/test/functional/host/subscription/remove_test.rb +52 -0
- data/test/functional/host/subscription/unregister_test.rb +37 -0
- data/test/functional/host/traces/list_test.rb +37 -0
- data/test/functional/host/traces/resolve_test.rb +31 -0
- data/test/functional/host_collection/add_host_test.rb +90 -0
- data/test/functional/host_collection/content_api_expectations.rb +35 -0
- data/test/functional/host_collection/content_install_test.rb +62 -0
- data/test/functional/host_collection/content_remove_test.rb +37 -0
- data/test/functional/host_collection/content_update_test.rb +37 -0
- data/test/functional/host_collection/copy_test.rb +64 -0
- data/test/functional/host_collection/create_test.rb +54 -0
- data/test/functional/host_collection/delete_test.rb +57 -0
- data/test/functional/host_collection/hosts_test.rb +39 -0
- data/test/functional/host_collection/info_test.rb +57 -0
- data/test/functional/host_collection/list_test.rb +63 -0
- data/test/functional/host_collection/remove_host_test.rb +90 -0
- data/test/functional/host_collection/update_test.rb +57 -0
- data/test/functional/hostgroup/create_test.rb +112 -0
- data/test/functional/hostgroup/data/hostgroup.json +50 -0
- data/test/functional/hostgroup/info_test.rb +33 -0
- data/test/functional/hostgroup/update_test.rb +120 -0
- data/test/functional/lifecycle_environment/create_test.rb +14 -0
- data/test/functional/lifecycle_environment/lifecycle_environment_helpers.rb +18 -0
- data/test/functional/lifecycle_environment/list_test.rb +38 -0
- data/test/functional/lifecycle_environment/update_test.rb +14 -0
- data/test/functional/local_helper_test.rb +30 -0
- data/test/functional/module_stream/info_test.rb +58 -0
- data/test/functional/module_stream/list_test.rb +53 -0
- data/test/functional/organization/cdn_configuration_test.rb +45 -0
- data/test/functional/organization/delete_test.rb +26 -0
- data/test/functional/organization/info_test.rb +45 -0
- data/test/functional/organization/organization_helpers.rb +10 -0
- data/test/functional/package/list_test.rb +160 -0
- data/test/functional/package_group/list_test.rb +38 -0
- data/test/functional/ping_test.rb +61 -0
- data/test/functional/product/create_test.rb +54 -0
- data/test/functional/product/delete_test.rb +41 -0
- data/test/functional/product/info_test.rb +33 -0
- data/test/functional/product/list_test.rb +58 -0
- data/test/functional/product/product_helpers.rb +24 -0
- data/test/functional/product/remove_sync_plan_test.rb +35 -0
- data/test/functional/product/set_sync_plan_test.rb +49 -0
- data/test/functional/product/update_proxy.rb +48 -0
- data/test/functional/product/update_test.rb +46 -0
- data/test/functional/repository/create_test.rb +21 -0
- data/test/functional/repository/delete_test.rb +95 -0
- data/test/functional/repository/info_test.rb +156 -0
- data/test/functional/repository/list_test.rb +68 -0
- data/test/functional/repository/reclaim_space_test.rb +105 -0
- data/test/functional/repository/remove_content_test.rb +108 -0
- data/test/functional/repository/repository_helpers.rb +18 -0
- data/test/functional/repository/republish_test.rb +37 -0
- data/test/functional/repository/synchronize_test.rb +57 -0
- data/test/functional/repository/update_test.rb +150 -0
- data/test/functional/repository/upload_test.rb +368 -0
- data/test/functional/repository_set/available_repositories_test.rb +18 -0
- data/test/functional/repository_set/disable_test.rb +48 -0
- data/test/functional/repository_set/enable_test.rb +42 -0
- data/test/functional/repository_set/info_test.rb +17 -0
- data/test/functional/repository_set/list_test.rb +18 -0
- data/test/functional/repository_set/repository_set_helpers.rb +20 -0
- data/test/functional/search_helpers.rb +17 -0
- data/test/functional/simple_content_access/disable_test.rb +48 -0
- data/test/functional/simple_content_access/enable_test.rb +46 -0
- data/test/functional/simple_content_access/status_test.rb +29 -0
- data/test/functional/srpm/list_test.rb +92 -0
- data/test/functional/subscription/list_test.rb +86 -0
- data/test/functional/sync_plan/create_test.rb +60 -0
- data/test/functional/sync_plan/delete_test.rb +46 -0
- data/test/functional/sync_plan/info_test.rb +37 -0
- data/test/functional/sync_plan/list_test.rb +31 -0
- data/test/functional/sync_plan/sync_plan_helpers.rb +8 -0
- data/test/functional/sync_plan/update_test.rb +44 -0
- data/test/functional/test_helper.rb +24 -0
- data/test/task_helper.rb +7 -0
- data/test/test_helper.rb +38 -0
- data/test/unit/id_name_options_validator_test.rb +96 -0
- data/test/unit/id_resolver_test.rb +58 -0
- data/test/unit/messages_test.rb +7 -0
- data/test/unit/search_options_creators_test.rb +145 -0
- metadata +425 -4
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper')
|
2
|
+
|
3
|
+
describe 'create content-credentials' do
|
4
|
+
before do
|
5
|
+
@cmd = %w(content-credentials create)
|
6
|
+
@base_params = ["--organization-id=#{org_id}", "--name=#{name}"]
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:org_id) { 1 }
|
10
|
+
let(:name) { 'sslcert' }
|
11
|
+
let(:cert) { File.join(File.dirname(__FILE__), 'data', 'test_cert.json') }
|
12
|
+
|
13
|
+
it 'Creates a SSL Content Credential' do
|
14
|
+
params = ["--path=#{cert}", '--content-type=cert']
|
15
|
+
|
16
|
+
api_expects(:content_credentials, :create, 'Create a Content Credential')
|
17
|
+
|
18
|
+
expected_result = success_result("Content Credential created.\n")
|
19
|
+
result = run_cmd(@cmd + @base_params + params)
|
20
|
+
assert_cmd(expected_result, result)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'Create a GPG Key Content Credential' do
|
24
|
+
params = ["--path=#{cert}", '--content-type=gpg_key']
|
25
|
+
|
26
|
+
api_expects(:content_credentials, :create, 'Create a Content Credential')
|
27
|
+
|
28
|
+
expected_result = success_result("Content Credential created.\n")
|
29
|
+
result = run_cmd(@cmd + @base_params + params)
|
30
|
+
assert_cmd(expected_result, result)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
{
|
2
|
+
"name":"test_cert",
|
3
|
+
"content_type":"cert",
|
4
|
+
"content":"hi",
|
5
|
+
"id":2,
|
6
|
+
"organization_id":1,
|
7
|
+
"organization":{
|
8
|
+
"name":"org2",
|
9
|
+
"label":"org2",
|
10
|
+
"id":1
|
11
|
+
},
|
12
|
+
"created_at":"2020-01-28 09:30:54 -0500",
|
13
|
+
"updated_at":"2020-01-28 09:30:54 -0500",
|
14
|
+
"gpg_key_products":[
|
15
|
+
|
16
|
+
],
|
17
|
+
"gpg_key_repos":[
|
18
|
+
|
19
|
+
],
|
20
|
+
"ssl_ca_products":[
|
21
|
+
|
22
|
+
],
|
23
|
+
"ssl_ca_root_repos":[
|
24
|
+
|
25
|
+
],
|
26
|
+
"ssl_client_products":[
|
27
|
+
|
28
|
+
],
|
29
|
+
"ssl_client_root_repos":[
|
30
|
+
|
31
|
+
],
|
32
|
+
"ssl_key_products":[
|
33
|
+
|
34
|
+
],
|
35
|
+
"ssl_key_root_repos":[
|
36
|
+
|
37
|
+
],
|
38
|
+
"permissions":{
|
39
|
+
"view_content_credenials":true,
|
40
|
+
"edit_content_credenials":true,
|
41
|
+
"destroy_content_credenials":true
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper')
|
2
|
+
require File.join(File.dirname(__FILE__), '../product/product_helpers')
|
3
|
+
|
4
|
+
def expect_credentials_search(org_id, name, id)
|
5
|
+
api_expects(:content_credentials, :index, 'List content credentials')
|
6
|
+
.with_params('name' => name, 'organization_id' => org_id)
|
7
|
+
.returns(index_response([{'id' => id}]))
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "get content-credentials info" do
|
11
|
+
include ProductHelpers
|
12
|
+
|
13
|
+
before do
|
14
|
+
@cmd = %w(content-credentials info)
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:org_id) { 1 }
|
18
|
+
let(:product_id) { 2 }
|
19
|
+
let(:key_id) { 3 }
|
20
|
+
|
21
|
+
it "Shows information about a content credental" do
|
22
|
+
params = ["--organization-id=#{org_id}", "--name=test_key"]
|
23
|
+
|
24
|
+
expect_credentials_search(org_id, 'test_key', key_id)
|
25
|
+
|
26
|
+
ex = api_expects(:content_credentials, :show, "Get info") do |par|
|
27
|
+
par["id"] == key_id
|
28
|
+
end
|
29
|
+
|
30
|
+
ex.returns({})
|
31
|
+
|
32
|
+
result = run_cmd(@cmd + params)
|
33
|
+
assert_equal(result.exit_code, 0)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "Shows information about a key with organization-id and key name" do
|
37
|
+
params = ["--name=test_key", "--organization-id=#{org_id}"]
|
38
|
+
|
39
|
+
expect_credentials_search(org_id, "test_key", key_id)
|
40
|
+
|
41
|
+
ex2 = api_expects(:content_credentials, :show, "Get info") do |par|
|
42
|
+
par["id"] == key_id
|
43
|
+
end
|
44
|
+
|
45
|
+
ex2.returns({})
|
46
|
+
|
47
|
+
result = run_cmd(@cmd + params)
|
48
|
+
assert_equal(result.exit_code, 0)
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper')
|
2
|
+
require File.join(File.dirname(__FILE__), '../lifecycle_environment/lifecycle_environment_helpers')
|
3
|
+
|
4
|
+
describe 'listing content credentials' do
|
5
|
+
include LifecycleEnvironmentHelpers
|
6
|
+
|
7
|
+
before do
|
8
|
+
@cmd = %w(content-credentials list)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:org_id) { 1 }
|
12
|
+
let(:lifecycle_env_id) { 1 }
|
13
|
+
let(:empty_response) do
|
14
|
+
{
|
15
|
+
"total" => 0,
|
16
|
+
"subtotal" => 0,
|
17
|
+
"page" => "1",
|
18
|
+
"per_page" => "1000",
|
19
|
+
"error" => nil,
|
20
|
+
"search" => nil,
|
21
|
+
"sort" => {
|
22
|
+
"by" => nil,
|
23
|
+
"order" => nil
|
24
|
+
},
|
25
|
+
"results" => []
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "lists an organizations keys" do
|
30
|
+
params = ["--organization-id=#{org_id}"]
|
31
|
+
|
32
|
+
ex = api_expects(:content_credentials, :index, 'Organization content credentials list') do |par|
|
33
|
+
par['organization_id'] == org_id && par['page'] == 1 &&
|
34
|
+
par['per_page'] == 1000
|
35
|
+
end
|
36
|
+
|
37
|
+
ex.returns(empty_response)
|
38
|
+
|
39
|
+
expected_result = success_result("---|------|-------------
|
40
|
+
ID | NAME | CONTENT TYPE
|
41
|
+
---|------|-------------
|
42
|
+
")
|
43
|
+
|
44
|
+
result = run_cmd(@cmd + params)
|
45
|
+
assert_cmd(expected_result, result)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "lists the keys by content-type" do
|
49
|
+
params = ['--content-type=gpg', "--organization-id=#{org_id}"]
|
50
|
+
|
51
|
+
ex = api_expects(:content_credentials, :index, 'content-type') do |par|
|
52
|
+
par['organization_id'] == org_id && par['page'] == 1 &&
|
53
|
+
par['per_page'] == 1000
|
54
|
+
end
|
55
|
+
|
56
|
+
ex.returns(empty_response)
|
57
|
+
|
58
|
+
expected_result = CommandExpectation.new("---|------|-------------
|
59
|
+
ID | NAME | CONTENT TYPE
|
60
|
+
---|------|-------------
|
61
|
+
")
|
62
|
+
|
63
|
+
result = run_cmd(@cmd + params)
|
64
|
+
assert_cmd(expected_result, result)
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,155 @@
|
|
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_complete'
|
5
|
+
|
6
|
+
describe 'content-export complete library' do
|
7
|
+
include ForemanTaskHelpers
|
8
|
+
include OrganizationHelpers
|
9
|
+
include ContentExportHelpers
|
10
|
+
|
11
|
+
before do
|
12
|
+
@cmd = %w(content-export complete 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) do
|
27
|
+
{
|
28
|
+
"id": 1000,
|
29
|
+
"path": "/tmp",
|
30
|
+
"metadata": {}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:organization_id) { '77' }
|
35
|
+
let(:organization_name) { 'Foo' }
|
36
|
+
let(:destination_server) { "dream.example.com" }
|
37
|
+
|
38
|
+
it "performs export with required options and async" do
|
39
|
+
params = [
|
40
|
+
"--organization-id=#{organization_id}",
|
41
|
+
'--destination-server=foo',
|
42
|
+
'--async'
|
43
|
+
]
|
44
|
+
expects_repositories_in_library(organization_id)
|
45
|
+
ex = api_expects(:content_exports, :library)
|
46
|
+
ex.returns(response)
|
47
|
+
|
48
|
+
result = run_cmd(@cmd + params)
|
49
|
+
|
50
|
+
assert_equal("Library environment is being exported in task #{task_id}.\n"\
|
51
|
+
+ "Once the task completes the export metadata must be generated with the "\
|
52
|
+
+ "command:\n hammer content-export generate-metadata --task-id #{task_id}\n", result.out)
|
53
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "performs export with required options" do
|
57
|
+
params = [
|
58
|
+
"--organization-id=#{organization_id}"
|
59
|
+
]
|
60
|
+
expects_repositories_in_library(organization_id)
|
61
|
+
ex = api_expects(:content_exports, :library)
|
62
|
+
ex.returns(response)
|
63
|
+
|
64
|
+
expect_foreman_task(task_id).at_least_once
|
65
|
+
|
66
|
+
HammerCLIKatello::ContentExportComplete::LibraryCommand.
|
67
|
+
any_instance.
|
68
|
+
expects(:fetch_export_history).
|
69
|
+
returns(export_history)
|
70
|
+
|
71
|
+
result = run_cmd(@cmd + params)
|
72
|
+
assert_match(/Generated .*metadata.*json/, result.out)
|
73
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'fails on missing required params' do
|
77
|
+
params = [
|
78
|
+
'--id=2'
|
79
|
+
]
|
80
|
+
|
81
|
+
result = run_cmd(@cmd + params)
|
82
|
+
expected_error = "Could not export the library:\n"
|
83
|
+
|
84
|
+
assert_equal(result.exit_code, HammerCLI::EX_USAGE)
|
85
|
+
assert_equal(result.err[/#{expected_error}/], expected_error)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'fails on empty params' do
|
89
|
+
params = []
|
90
|
+
result = run_cmd(@cmd + params)
|
91
|
+
expected_error = "Could not find organization, please set one of options"
|
92
|
+
|
93
|
+
assert_equal(result.exit_code, HammerCLI::EX_SOFTWARE)
|
94
|
+
assert_equal(result.err[/#{expected_error}/], expected_error)
|
95
|
+
assert_match(/#{expected_error}/, result.err)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'correctly resolves organization id from name' do
|
99
|
+
params = ["--organization=#{organization_name}",
|
100
|
+
"--async"]
|
101
|
+
expects_repositories_in_library(organization_id)
|
102
|
+
expect_organization_search(organization_name, organization_id)
|
103
|
+
|
104
|
+
ex = api_expects(:content_exports, :library) do |p|
|
105
|
+
assert_equal p['organization_id'].to_s, organization_id.to_s
|
106
|
+
end
|
107
|
+
ex.returns(response)
|
108
|
+
|
109
|
+
run_cmd(@cmd + params)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'warns of lazy repositories' do
|
113
|
+
params = ["--organization-id=#{organization_id}"]
|
114
|
+
expects_repositories_in_library(organization_id, [{id: 200}])
|
115
|
+
|
116
|
+
ex = api_expects(:content_exports, :library)
|
117
|
+
ex.returns(response)
|
118
|
+
|
119
|
+
expect_foreman_task(task_id).at_least_once
|
120
|
+
|
121
|
+
HammerCLIKatello::ContentExportComplete::LibraryCommand.
|
122
|
+
any_instance.
|
123
|
+
expects(:fetch_export_history).
|
124
|
+
returns(export_history)
|
125
|
+
|
126
|
+
result = run_cmd(@cmd + params)
|
127
|
+
assert_match(/Unable to fully export this organization's library/, result.out)
|
128
|
+
assert_match(/200/, result.out)
|
129
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'Errors out on lazy repositories if --fail-on-missing-content' do
|
133
|
+
params = ["--organization-id=#{organization_id}",
|
134
|
+
"--fail-on-missing-content"]
|
135
|
+
expects_repositories_in_library(organization_id, [{id: 200}])
|
136
|
+
|
137
|
+
ex = api_expects(:content_exports, :library)
|
138
|
+
ex.returns(response)
|
139
|
+
|
140
|
+
expect_foreman_task(task_id).at_least_once
|
141
|
+
|
142
|
+
HammerCLIKatello::ContentExportComplete::LibraryCommand.
|
143
|
+
any_instance.
|
144
|
+
expects(:fetch_export_history).
|
145
|
+
returns(export_history)
|
146
|
+
|
147
|
+
HammerCLIKatello::ContentExportComplete::LibraryCommand.
|
148
|
+
any_instance.
|
149
|
+
expects(:exit).with(HammerCLI::EX_SOFTWARE)
|
150
|
+
|
151
|
+
result = run_cmd(@cmd + params)
|
152
|
+
assert_match(/Unable to fully export this organization's library/, result.out)
|
153
|
+
assert_match(/200/, result.out)
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../../../test_helper')
|
2
|
+
require 'hammer_cli_katello/content_export_complete'
|
3
|
+
require_relative '../../product/product_helpers'
|
4
|
+
require_relative '../../repository/repository_helpers'
|
5
|
+
require_relative '../content_export_helpers'
|
6
|
+
|
7
|
+
describe 'content-export complete repository' do
|
8
|
+
include ForemanTaskHelpers
|
9
|
+
include ContentExportHelpers
|
10
|
+
include ProductHelpers
|
11
|
+
include RepositoryHelpers
|
12
|
+
|
13
|
+
before do
|
14
|
+
@cmd = %w(content-export complete 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) do
|
29
|
+
{
|
30
|
+
"id": 1000,
|
31
|
+
"path": "/tmp",
|
32
|
+
"metadata": {}
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:default_repository_options) do
|
37
|
+
{"download_policy" => "immediate", "id" => repository_id}
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:product_id) { '77' }
|
41
|
+
let(:repository_id) { '1001' }
|
42
|
+
|
43
|
+
let(:name) { 'repo' }
|
44
|
+
|
45
|
+
it "performs export with required options and async" do
|
46
|
+
params = [
|
47
|
+
"--id=#{repository_id}",
|
48
|
+
'--async'
|
49
|
+
]
|
50
|
+
expects_repository(repository_id, default_repository_options)
|
51
|
+
ex = api_expects(:content_exports, :repository)
|
52
|
+
ex.returns(response)
|
53
|
+
|
54
|
+
result = run_cmd(@cmd + params)
|
55
|
+
|
56
|
+
assert_equal("Repository is being exported in task #{task_id}.\n"\
|
57
|
+
+ "Once the task completes the export metadata must be generated with the "\
|
58
|
+
+ "command:\n hammer content-export generate-metadata --task-id #{task_id}\n", result.out)
|
59
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "performs export with required options" do
|
63
|
+
params = [
|
64
|
+
"--id=#{repository_id}"
|
65
|
+
]
|
66
|
+
expects_repository(repository_id, default_repository_options)
|
67
|
+
ex = api_expects(:content_exports, :repository)
|
68
|
+
ex.returns(response)
|
69
|
+
|
70
|
+
expect_foreman_task(task_id).at_least_once
|
71
|
+
|
72
|
+
HammerCLIKatello::ContentExportComplete::RepositoryCommand.
|
73
|
+
any_instance.
|
74
|
+
expects(:fetch_export_history).
|
75
|
+
returns(export_history)
|
76
|
+
|
77
|
+
result = run_cmd(@cmd + params)
|
78
|
+
assert_match(/Generated .*metadata.*json/, result.out)
|
79
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'fails on missing required params' do
|
83
|
+
params = [
|
84
|
+
'--boo-id=2'
|
85
|
+
]
|
86
|
+
|
87
|
+
result = run_cmd(@cmd + params)
|
88
|
+
expected_error = "Could not export the repository:\n"
|
89
|
+
|
90
|
+
assert_equal(result.exit_code, HammerCLI::EX_USAGE)
|
91
|
+
assert_equal(result.err[/#{expected_error}/], expected_error)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'fails on missing product name/id' do
|
95
|
+
params = ["--name=foo"]
|
96
|
+
|
97
|
+
result = run_cmd(@cmd + params)
|
98
|
+
expected_error = "At least one of options --product-id, --product is required"
|
99
|
+
|
100
|
+
assert_equal(result.exit_code, HammerCLI::EX_USAGE)
|
101
|
+
assert_match(/#{expected_error}/, result.err)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'fails on missing repository' do
|
105
|
+
params = ["--product-id=2"]
|
106
|
+
result = run_cmd(@cmd + params)
|
107
|
+
expected_error = "--name is required."
|
108
|
+
|
109
|
+
assert_equal(result.exit_code, HammerCLI::EX_USAGE)
|
110
|
+
assert_match(/#{expected_error}/, result.err)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'fails on missing product missing org' do
|
114
|
+
params = ["--product=lol", "--name=#{name}"]
|
115
|
+
result = run_cmd(@cmd + params)
|
116
|
+
expected_error = "At least one of options --organization-id,"\
|
117
|
+
" --organization, --organization-label is required"
|
118
|
+
|
119
|
+
assert_equal(result.exit_code, HammerCLI::EX_USAGE)
|
120
|
+
assert_match(/#{expected_error}/, result.err)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'correctly resolves product_id and repository name' do
|
124
|
+
params = ["--product-id=#{product_id}",
|
125
|
+
"--name=#{name}",
|
126
|
+
"--async"]
|
127
|
+
expects_repository(repository_id, default_repository_options)
|
128
|
+
|
129
|
+
cvv_expect = api_expects(:repositories, :index) do |p|
|
130
|
+
assert_equal p['product_id'].to_s, product_id.to_s
|
131
|
+
assert_equal p["name"], name
|
132
|
+
end
|
133
|
+
|
134
|
+
cvv_expect.at_least_once.
|
135
|
+
returns(index_response([{'id' => repository_id}]))
|
136
|
+
|
137
|
+
ex = api_expects(:content_exports, :repository) do |p|
|
138
|
+
assert_equal p['id'], repository_id
|
139
|
+
end
|
140
|
+
ex.returns(response)
|
141
|
+
run_cmd(@cmd + params)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'correctly resolves chunk-size-gb' do
|
145
|
+
chunk_size = 1000
|
146
|
+
params = ["--id=#{repository_id}",
|
147
|
+
"--chunk-size-gb=#{chunk_size}",
|
148
|
+
"--organization-id=99"]
|
149
|
+
|
150
|
+
expects_repository(repository_id, default_repository_options)
|
151
|
+
|
152
|
+
ex = api_expects(:content_exports, :repository) do |p|
|
153
|
+
assert_equal p["chunk_size_gb"], chunk_size
|
154
|
+
end
|
155
|
+
ex.returns(response)
|
156
|
+
|
157
|
+
expect_foreman_task(task_id).at_least_once
|
158
|
+
|
159
|
+
HammerCLIKatello::ContentExportComplete::RepositoryCommand.
|
160
|
+
any_instance.
|
161
|
+
expects(:fetch_export_history).
|
162
|
+
returns(export_history)
|
163
|
+
|
164
|
+
result = run_cmd(@cmd + params)
|
165
|
+
assert_match(/Generated .*metadata.*json/, result.out)
|
166
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'fails on invalid chunk-size-gb value' do
|
170
|
+
params = ["--id=#{repository_id}",
|
171
|
+
"--chunk-size-gb=0.5",
|
172
|
+
"--organization-id=99"]
|
173
|
+
|
174
|
+
result = run_cmd(@cmd + params)
|
175
|
+
assert_match(/Error: Option '--chunk-size-gb': Numeric value is required/, result.err)
|
176
|
+
assert_equal(HammerCLI::EX_USAGE, result.exit_code)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'Errors out on lazy repositories' do
|
180
|
+
params = ["--id=#{repository_id}"]
|
181
|
+
expects_repository(repository_id, "download_policy" => "on_demand", "id" => repository_id)
|
182
|
+
|
183
|
+
ex = api_expects(:content_exports, :repository)
|
184
|
+
ex.returns(response)
|
185
|
+
|
186
|
+
expect_foreman_task(task_id).at_least_once
|
187
|
+
|
188
|
+
HammerCLIKatello::ContentExportComplete::RepositoryCommand.
|
189
|
+
any_instance.
|
190
|
+
expects(:fetch_export_history).
|
191
|
+
returns(export_history)
|
192
|
+
|
193
|
+
HammerCLIKatello::ContentExportComplete::RepositoryCommand.
|
194
|
+
any_instance.
|
195
|
+
expects(:exit).with(HammerCLI::EX_SOFTWARE)
|
196
|
+
|
197
|
+
result = run_cmd(@cmd + params)
|
198
|
+
assert_match(/Unable to fully export this repository because/, result.out)
|
199
|
+
assert_match(/#{repository_id}/, result.out)
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should accept product and get the right repository' do
|
203
|
+
params = ["--product-id=#{product_id}",
|
204
|
+
"--name=#{name}"]
|
205
|
+
expect_repository_search(product_id.to_i, name, repository_id).at_least_once
|
206
|
+
repo_search = api_expects(:repositories, :index, 'Find a repository') do |p|
|
207
|
+
assert_equal p["product_id"].to_s, product_id.to_s
|
208
|
+
assert_equal p["name"], name
|
209
|
+
end
|
210
|
+
repo_search.returns(index_response([{'id' => repository_id}]))
|
211
|
+
|
212
|
+
expects_repository(repository_id, default_repository_options)
|
213
|
+
ex = api_expects(:content_exports, :repository)
|
214
|
+
ex.returns(response)
|
215
|
+
|
216
|
+
expect_foreman_task(task_id).at_least_once
|
217
|
+
|
218
|
+
HammerCLIKatello::ContentExportComplete::RepositoryCommand.
|
219
|
+
any_instance.
|
220
|
+
expects(:fetch_export_history).
|
221
|
+
returns(export_history)
|
222
|
+
result = run_cmd(@cmd + params)
|
223
|
+
assert_match(/Generated .*metadata.*json/, result.out)
|
224
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
225
|
+
end
|
226
|
+
end
|