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,297 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../../../test_helper')
|
2
|
+
require 'hammer_cli_katello/content_export_complete'
|
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 complete version' do
|
8
|
+
include ForemanTaskHelpers
|
9
|
+
include ContentExportHelpers
|
10
|
+
include ContentViewHelpers
|
11
|
+
include LifecycleEnvironmentHelpers
|
12
|
+
|
13
|
+
before do
|
14
|
+
@cmd = %w(content-export complete 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) do
|
29
|
+
{
|
30
|
+
"id" => 1000,
|
31
|
+
"path" => "/tmp",
|
32
|
+
"metadata" => {}
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:content_view_id) { '77' }
|
37
|
+
let(:content_view_version_id) { '1001' }
|
38
|
+
|
39
|
+
let(:version) { '10.0' }
|
40
|
+
let(:destination_server) { "dream.example.com" }
|
41
|
+
|
42
|
+
it "performs export with required options and async" do
|
43
|
+
params = [
|
44
|
+
"--id=#{content_view_version_id}",
|
45
|
+
'--destination-server=foo',
|
46
|
+
'--async'
|
47
|
+
]
|
48
|
+
expects_repositories_in_version(content_view_version_id)
|
49
|
+
ex = api_expects(:content_exports, :version)
|
50
|
+
ex.returns(response)
|
51
|
+
|
52
|
+
result = run_cmd(@cmd + params)
|
53
|
+
|
54
|
+
assert_equal("Content view version is being exported in task #{task_id}.\n"\
|
55
|
+
+ "Once the task completes the export metadata must be generated with the "\
|
56
|
+
+ "command:\n hammer content-export generate-metadata --task-id #{task_id}\n", result.out)
|
57
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "performs export with required options and async for syncable format" do
|
61
|
+
params = [
|
62
|
+
"--id=#{content_view_version_id}",
|
63
|
+
'--format=syncable',
|
64
|
+
'--async'
|
65
|
+
]
|
66
|
+
expects_repositories_in_version(content_view_version_id)
|
67
|
+
ex = api_expects(:content_exports, :version)
|
68
|
+
ex.returns(response)
|
69
|
+
|
70
|
+
result = run_cmd(@cmd + params)
|
71
|
+
|
72
|
+
assert_equal("Content view version is being exported in task #{task_id}.\n"\
|
73
|
+
+ "Once the task completes the listing files may be generated with the command:"\
|
74
|
+
+ "\n hammer content-export generate-listing --task-id #{task_id}\n", result.out)
|
75
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "performs export with required options" do
|
79
|
+
params = [
|
80
|
+
"--id=#{content_view_version_id}",
|
81
|
+
'--destination-server=foo'
|
82
|
+
]
|
83
|
+
expects_repositories_in_version(content_view_version_id)
|
84
|
+
ex = api_expects(:content_exports, :version)
|
85
|
+
ex.returns(response)
|
86
|
+
|
87
|
+
expect_foreman_task(task_id).at_least_once
|
88
|
+
|
89
|
+
HammerCLIKatello::ContentExportComplete::VersionCommand.
|
90
|
+
any_instance.
|
91
|
+
expects(:fetch_export_history).
|
92
|
+
returns(export_history)
|
93
|
+
|
94
|
+
result = run_cmd(@cmd + params)
|
95
|
+
assert_match(/Generated .*metadata.*json/, result.out)
|
96
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "performs export with format" do
|
100
|
+
params = [
|
101
|
+
"--id=#{content_view_version_id}",
|
102
|
+
'--format=syncable'
|
103
|
+
]
|
104
|
+
expects_repositories_in_version(content_view_version_id)
|
105
|
+
ex = api_expects(:content_exports, :version)
|
106
|
+
ex.returns(response)
|
107
|
+
|
108
|
+
expect_foreman_task(task_id).at_least_once
|
109
|
+
path = "/foo/bar"
|
110
|
+
syncable_export_history = {
|
111
|
+
"id" => 1000,
|
112
|
+
"path" => path,
|
113
|
+
"metadata" => {"format" => "syncable"}
|
114
|
+
}
|
115
|
+
HammerCLIKatello::ContentExportComplete::VersionCommand.
|
116
|
+
any_instance.
|
117
|
+
expects(:fetch_export_history).
|
118
|
+
returns(syncable_export_history)
|
119
|
+
|
120
|
+
result = run_cmd(@cmd + params)
|
121
|
+
assert_match(/Generated/, result.out)
|
122
|
+
assert_match(path, result.out)
|
123
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'fails on missing required params' do
|
127
|
+
params = [
|
128
|
+
'--boo-id=2'
|
129
|
+
]
|
130
|
+
|
131
|
+
result = run_cmd(@cmd + params)
|
132
|
+
expected_error = "Could not export the content view version:\n"
|
133
|
+
|
134
|
+
assert_equal(result.exit_code, HammerCLI::EX_USAGE)
|
135
|
+
assert_equal(result.err[/#{expected_error}/], expected_error)
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'fails on missing content-view name/id' do
|
139
|
+
params = []
|
140
|
+
|
141
|
+
result = run_cmd(@cmd + params)
|
142
|
+
expected_error = "At least one of options --id, --content-view, --content-view-id is required"
|
143
|
+
|
144
|
+
assert_equal(result.exit_code, HammerCLI::EX_USAGE)
|
145
|
+
assert_match(/#{expected_error}/, result.err)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'fails on missing content-view version' do
|
149
|
+
params = ["--content-view-id=2"]
|
150
|
+
result = run_cmd(@cmd + params)
|
151
|
+
expected_error = "--version, --lifecycle-environment-id, --lifecycle-environment is required."
|
152
|
+
|
153
|
+
assert_equal(result.exit_code, HammerCLI::EX_USAGE)
|
154
|
+
assert_match(/#{expected_error}/, result.err)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'fails on missing content-view missing org' do
|
158
|
+
params = ["--content-view=lol", "--version=4.0"]
|
159
|
+
result = run_cmd(@cmd + params)
|
160
|
+
expected_error = "At least one of options --organization-id, "\
|
161
|
+
"--organization, --organization-label is required."
|
162
|
+
|
163
|
+
assert_equal(result.exit_code, HammerCLI::EX_USAGE)
|
164
|
+
assert_match(/#{expected_error}/, result.err)
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'correctly resolves content-view-id and content view version number' do
|
168
|
+
params = ["--content-view-id=#{content_view_id}",
|
169
|
+
"--version=#{version}",
|
170
|
+
"--destination-server=#{destination_server}",
|
171
|
+
"--async"]
|
172
|
+
|
173
|
+
cvv_expect = api_expects(:content_view_versions, :index) do |p|
|
174
|
+
assert_equal p['content_view_id'].to_s, content_view_id.to_s
|
175
|
+
assert_equal p["version"], version
|
176
|
+
end
|
177
|
+
|
178
|
+
cvv_expect.at_least_once.
|
179
|
+
returns(index_response([{'id' => content_view_version_id}]))
|
180
|
+
|
181
|
+
ex = api_expects(:content_exports, :version) do |p|
|
182
|
+
assert_equal p['id'], content_view_version_id
|
183
|
+
assert_equal p["destination_server"], destination_server
|
184
|
+
end
|
185
|
+
ex.returns(response)
|
186
|
+
|
187
|
+
expects_repositories_in_version(content_view_version_id)
|
188
|
+
run_cmd(@cmd + params)
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'correctly resolves chunk-size-gb' do
|
192
|
+
chunk_size = 1000
|
193
|
+
params = ["--id=#{content_view_version_id}",
|
194
|
+
"--chunk-size-gb=#{chunk_size}",
|
195
|
+
"--organization-id=99"]
|
196
|
+
|
197
|
+
expects_repositories_in_version(content_view_version_id)
|
198
|
+
|
199
|
+
ex = api_expects(:content_exports, :version) do |p|
|
200
|
+
assert_equal p["chunk_size_gb"], chunk_size
|
201
|
+
end
|
202
|
+
ex.returns(response)
|
203
|
+
|
204
|
+
expect_foreman_task(task_id).at_least_once
|
205
|
+
|
206
|
+
HammerCLIKatello::ContentExportComplete::VersionCommand.
|
207
|
+
any_instance.
|
208
|
+
expects(:fetch_export_history).
|
209
|
+
returns(export_history)
|
210
|
+
|
211
|
+
result = run_cmd(@cmd + params)
|
212
|
+
assert_match(/Generated .*metadata.*json/, result.out)
|
213
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'fails on invalid chunk-size-gb value' do
|
217
|
+
params = ["--id=#{content_view_version_id}",
|
218
|
+
"--chunk-size-gb=0.5",
|
219
|
+
"--organization-id=99"]
|
220
|
+
|
221
|
+
result = run_cmd(@cmd + params)
|
222
|
+
assert_match(/Error: Option '--chunk-size-gb': Numeric value is required/, result.err)
|
223
|
+
assert_equal(HammerCLI::EX_USAGE, result.exit_code)
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'warns of lazy repositories' do
|
227
|
+
params = ["--id=#{content_view_version_id}"]
|
228
|
+
expects_repositories_in_version(content_view_version_id, [{id: 200}])
|
229
|
+
|
230
|
+
ex = api_expects(:content_exports, :version)
|
231
|
+
ex.returns(response)
|
232
|
+
|
233
|
+
expect_foreman_task(task_id).at_least_once
|
234
|
+
|
235
|
+
HammerCLIKatello::ContentExportComplete::VersionCommand.
|
236
|
+
any_instance.
|
237
|
+
expects(:fetch_export_history).
|
238
|
+
returns(export_history)
|
239
|
+
|
240
|
+
result = run_cmd(@cmd + params)
|
241
|
+
assert_match(/Unable to fully export this version because/, result.out)
|
242
|
+
assert_match(/200/, result.out)
|
243
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'Errors out on lazy repositories if --fail-on-missing-content' do
|
247
|
+
params = ["--id=#{content_view_version_id}",
|
248
|
+
"--fail-on-missing-content"]
|
249
|
+
expects_repositories_in_version(content_view_version_id, [{id: 200}])
|
250
|
+
|
251
|
+
ex = api_expects(:content_exports, :version)
|
252
|
+
ex.returns(response)
|
253
|
+
|
254
|
+
expect_foreman_task(task_id).at_least_once
|
255
|
+
|
256
|
+
HammerCLIKatello::ContentExportComplete::VersionCommand.
|
257
|
+
any_instance.
|
258
|
+
expects(:fetch_export_history).
|
259
|
+
returns(export_history)
|
260
|
+
|
261
|
+
HammerCLIKatello::ContentExportComplete::VersionCommand.
|
262
|
+
any_instance.
|
263
|
+
expects(:exit).with(HammerCLI::EX_SOFTWARE)
|
264
|
+
|
265
|
+
result = run_cmd(@cmd + params)
|
266
|
+
assert_match(/Unable to fully export this version because/, result.out)
|
267
|
+
assert_match(/200/, result.out)
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'should accept content view and lifecycle environment and get the right version' do
|
271
|
+
env = "foo"
|
272
|
+
org_id = '100'
|
273
|
+
env_id = '223'
|
274
|
+
params = ["--content-view-id=#{content_view_id}",
|
275
|
+
"--lifecycle-environment=#{env}",
|
276
|
+
"--organization-id=#{org_id}"]
|
277
|
+
expect_lifecycle_environment_search(org_id, env, env_id)
|
278
|
+
expect_content_view_version_search({'environment_id' => env_id,
|
279
|
+
'content_view_id' => content_view_id},
|
280
|
+
'id' => content_view_version_id).at_least_once
|
281
|
+
|
282
|
+
expects_repositories_in_version(content_view_version_id)
|
283
|
+
ex = api_expects(:content_exports, :version)
|
284
|
+
ex.returns(response)
|
285
|
+
|
286
|
+
expect_foreman_task(task_id).at_least_once
|
287
|
+
|
288
|
+
HammerCLIKatello::ContentExportComplete::VersionCommand.
|
289
|
+
any_instance.
|
290
|
+
expects(:fetch_export_history).
|
291
|
+
returns(export_history)
|
292
|
+
|
293
|
+
result = run_cmd(@cmd + params)
|
294
|
+
assert_match(/Generated .*metadata.*json/, result.out)
|
295
|
+
assert_equal(HammerCLI::EX_OK, result.exit_code)
|
296
|
+
end
|
297
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative '../search_helpers'
|
2
|
+
|
3
|
+
module ContentExportHelpers
|
4
|
+
include SearchHelpers
|
5
|
+
def expects_repository(repository_id, returns = {})
|
6
|
+
ex = api_expects(:repositories, :show, "Find Repo #{repository_id}") do |p|
|
7
|
+
assert_equal p[:id].to_s, repository_id.to_s
|
8
|
+
end
|
9
|
+
ex.returns(returns)
|
10
|
+
end
|
11
|
+
|
12
|
+
def expects_repositories_in_library(organization_id, returns = [])
|
13
|
+
expect_lenient_search(:repositories,
|
14
|
+
params: {
|
15
|
+
organization_id: organization_id,
|
16
|
+
library: true,
|
17
|
+
search: "download_policy != immediate",
|
18
|
+
content_type: 'yum'
|
19
|
+
},
|
20
|
+
returns: returns)
|
21
|
+
end
|
22
|
+
|
23
|
+
def expects_repositories_in_version(version_id, returns = [])
|
24
|
+
expect_lenient_search(:repositories,
|
25
|
+
params: {
|
26
|
+
content_view_version_id: version_id,
|
27
|
+
library: true,
|
28
|
+
search: "download_policy != immediate",
|
29
|
+
content_type: 'yum'
|
30
|
+
},
|
31
|
+
returns: returns)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../../test_helper')
|
2
|
+
require 'hammer_cli_katello/content_export'
|
3
|
+
|
4
|
+
describe('content-export generate-listing') do
|
5
|
+
include ForemanTaskHelpers
|
6
|
+
|
7
|
+
before do
|
8
|
+
@cmd = %w(content-export generate-listing)
|
9
|
+
@params = []
|
10
|
+
@export_history_id = 100
|
11
|
+
@path = '/tmp'
|
12
|
+
@export_history = {
|
13
|
+
'id' => @export_history_id,
|
14
|
+
'path' => @path,
|
15
|
+
'metadata' => {'format' => 'syncable'}
|
16
|
+
}
|
17
|
+
@task_id = SecureRandom.uuid
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:cmd) { @cmd + @params }
|
21
|
+
let(:result) { run_cmd(cmd) }
|
22
|
+
|
23
|
+
describe('given an export history id') do
|
24
|
+
it('loads export history by id') do
|
25
|
+
@params = ["--id=#{@export_history_id}"]
|
26
|
+
|
27
|
+
HammerCLIKatello::ContentExport::GenerateListingCommand.
|
28
|
+
any_instance.
|
29
|
+
expects(:fetch_export_history).
|
30
|
+
returns(@export_history)
|
31
|
+
assert_match(/Generated/, result.out)
|
32
|
+
assert_match(@path, result.out)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe('given a task id') do
|
37
|
+
it('loads export history based on the task') do
|
38
|
+
@params = ["--task-id=#{@task_id}"]
|
39
|
+
|
40
|
+
HammerCLIKatello::ContentExport::GenerateListingCommand.
|
41
|
+
any_instance.
|
42
|
+
expects(:reload_task).
|
43
|
+
returns('id' => 'taskid')
|
44
|
+
|
45
|
+
HammerCLIKatello::ContentExport::GenerateListingCommand.
|
46
|
+
any_instance.
|
47
|
+
expects(:fetch_export_history).
|
48
|
+
returns(@export_history)
|
49
|
+
|
50
|
+
assert_match(/Generated/, result.out)
|
51
|
+
assert_match(@path, result.out)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe('given no arguments') do
|
56
|
+
it('tells the user to verify the arguments') do
|
57
|
+
expected = "Error: No export history was found. Verify the value given for "\
|
58
|
+
+ "--task-id or --id\n"
|
59
|
+
assert_equal(expected, result.err)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
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
|