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.
@@ -1,148 +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)
8
- end
9
-
10
- it "performs export" do
11
- HammerCLIKatello::ContentViewVersion::ExportCommand
12
- .any_instance
13
- .expects(:validate_pulp3_not_enabled)
14
- .returns(true)
15
- params = [
16
- '--id=5',
17
- '--export-dir=/tmp/exports'
18
- ]
19
-
20
- ex = api_expects(:content_view_versions, :show)
21
- ex.returns(
22
- 'id' => '5',
23
- 'repositories' => [{'id' => '2', 'content_type' => 'yum'}],
24
- 'major' => 1,
25
- 'minor' => 0,
26
- 'content_view' => {'name' => 'cv'},
27
- 'content_view_id' => 4321
28
- )
29
-
30
- ex = api_expects(:content_views, :show)
31
- ex.returns(
32
- 'id' => '4321',
33
- 'composite' => false,
34
- 'label' => 'cv'
35
- )
36
-
37
- ex = api_expects(:repositories, :show).with_params('id' => '2')
38
- ex.returns(
39
- 'id' => '2',
40
- 'label' => 'Test_Repo',
41
- 'content_type' => 'yum',
42
- 'download_policy' => 'immediate',
43
- 'backend_identifier' => 'Default_Organization-Library-Test_Repo',
44
- 'relative_path' => 'Default_Organization/Library/Test_Repo',
45
- 'library_instance_id' => '1',
46
- 'content_counts' => {
47
- 'rpm' => 1,
48
- 'erratum' => 1
49
- }
50
- )
51
-
52
- api_expects(:repositories, :show).with_params('id' => '1').returns(
53
- 'id' => '1',
54
- 'download_policy' => 'immediate'
55
- )
56
- api_expects(:packages, :index).returns('results' => [])
57
- api_expects(:errata, :index).returns('results' => [])
58
-
59
- File.expects(:exist?).with('/usr/share/foreman').returns(true)
60
- File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
61
-
62
- Dir.expects(:chdir).with("/var/lib/pulp/published/yum/https/repos/").returns(true)
63
- Dir.expects(:mkdir).with('/tmp/exports/export-cv-1.0').returns(0)
64
- Dir.expects(:chdir).with('/tmp/exports').returns(0)
65
- Dir.expects(:chdir).with('/tmp/exports/export-cv-1.0').returns(0)
66
-
67
- result = run_cmd(@cmd + params)
68
- assert_equal(HammerCLI::EX_OK, result.exit_code)
69
- end
70
-
71
- it "performs composite export" do
72
- HammerCLIKatello::ContentViewVersion::ExportCommand
73
- .any_instance
74
- .expects(:validate_pulp3_not_enabled)
75
- .returns(true)
76
- params = [
77
- '--id=999',
78
- '--export-dir=/tmp/exports'
79
- ]
80
-
81
- ex = api_expects(:content_view_versions, :show)
82
- ex.returns(
83
- 'id' => '999',
84
- 'repositories' => [{'id' => '2'}],
85
- 'major' => 1,
86
- 'minor' => 0,
87
- 'content_view' => {'name' => 'cv'},
88
- 'content_view_id' => 4321
89
- )
90
-
91
- ex = api_expects(:content_views, :show)
92
- ex.returns(
93
- 'id' => '4321',
94
- 'composite' => true,
95
- 'components' => [{ 'name' => "injera 95.5" }, {'name' => 'carrot wot 87.0'}],
96
- 'label' => 'cv'
97
- )
98
-
99
- File.expects(:exist?).with('/usr/share/foreman').returns(true)
100
- File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
101
-
102
- Dir.expects(:chdir).with("/var/lib/pulp/published/yum/https/repos/").never
103
- Dir.expects(:mkdir).with('/tmp/exports/export-cv-1.0').returns(0)
104
- Dir.expects(:chdir).with('/tmp/exports').returns(0)
105
- Dir.expects(:chdir).with('/tmp/exports/export-cv-1.0').returns(0)
106
-
107
- result = run_cmd(@cmd + params)
108
- assert_equal(HammerCLI::EX_OK, result.exit_code)
109
- end
110
-
111
- it "fails export if content view version has no repository" do
112
- HammerCLIKatello::ContentViewVersion::ExportCommand
113
- .any_instance
114
- .expects(:validate_pulp3_not_enabled)
115
- .returns(true)
116
- params = [
117
- '--id=5',
118
- '--export-dir=/tmp/exports'
119
- ]
120
-
121
- ex = api_expects(:content_view_versions, :show)
122
- ex.returns(
123
- 'id' => '5',
124
- 'name' => 'Test_version',
125
- 'repositories' => [],
126
- 'major' => 1,
127
- 'minor' => 0,
128
- 'content_view' => {'name' => 'cv'},
129
- 'content_view_id' => 4321,
130
- 'puppet_modules' => []
131
- )
132
-
133
- ex = api_expects(:content_views, :show)
134
- ex.returns(
135
- 'id' => '4321',
136
- 'composite' => false
137
- )
138
-
139
- File.expects(:exist?).with('/usr/share/foreman').returns(true)
140
- File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
141
-
142
- result = run_cmd(@cmd + params)
143
- assert_equal(result.err, "Could not export the content view:\n"\
144
- " Error: Ensure the content view version 'Test_version'"\
145
- " has at least one repository.\n")
146
- assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
147
- end
148
- end
@@ -1,346 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '../../test_helper')
2
-
3
- describe 'content-view version import' do
4
- include ForemanTaskHelpers
5
-
6
- before do
7
- @cmd = %w(content-view version import)
8
- end
9
-
10
- it "performs import" do
11
- HammerCLIKatello::ContentViewVersion::ImportCommand
12
- .any_instance
13
- .expects(:validate_pulp3_not_enabled)
14
- .returns(true)
15
- params = [
16
- '--export-tar=/tmp/exports/export-2.tar',
17
- '--organization-id=1'
18
- ]
19
-
20
- File.expects(:exist?).with('/usr/share/foreman').returns(true)
21
- File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
22
-
23
- File.expects(:exist?).with("/tmp/exports/export-2.tar").returns(true)
24
- Dir.expects(:chdir).with('/tmp/exports').returns(0)
25
- Dir.expects(:chdir).with('/tmp/exports/export-2').returns(0)
26
- File.expects(:read).with("/tmp/exports/export-2/export-2.json").returns(
27
- JSON.dump(
28
- 'name' => 'Foo View',
29
- 'major' => '5',
30
- 'minor' => '0',
31
- 'repositories' => [{
32
- 'label' => 'foo',
33
- 'rpm_filenames' => ['foo-1.0-1.el7']
34
- }]
35
- )
36
- )
37
-
38
- ex = api_expects(:content_views, :index)
39
- ex = ex.with_params('name' => 'Foo View', 'organization_id' => '1')
40
- ex.returns(
41
- 'results' => [{
42
- 'id' => '5',
43
- 'repositories' => [{'id' => '2', 'label' => 'foo'}],
44
- 'content_view' => {'name' => 'cv'}
45
- }]
46
- )
47
-
48
- ex = api_expects(:repositories, :index)
49
- ex = ex.with_params('organization_id' => '1', 'library' => true)
50
- ex.returns(
51
- 'results' => [{
52
- 'id' => '2',
53
- 'label' => 'foo'
54
- }]
55
- )
56
-
57
- ex = api_expects(:repositories, :sync)
58
- ex = ex.with_params('id' => '2', 'source_url' => "file:///tmp/exports/export-2/")
59
- ex.returns('id' => '2', 'state' => 'planned')
60
-
61
- expect_foreman_task('3')
62
-
63
- ex = api_expects(:content_views, :publish)
64
- ex = ex.with_params(
65
- 'id' => '5',
66
- 'major' => '5',
67
- 'minor' => '0',
68
- 'repos_units' => [{
69
- 'label' => 'foo',
70
- 'rpm_filenames' => ['foo-1.0-1.el7']
71
- }]
72
- )
73
- ex.returns('id' => '2', 'state' => 'planned')
74
-
75
- expect_foreman_task('3')
76
-
77
- result = run_cmd(@cmd + params)
78
- assert_equal(HammerCLI::EX_OK, result.exit_code)
79
- end
80
-
81
- it "performs composite import" do
82
- HammerCLIKatello::ContentViewVersion::ImportCommand
83
- .any_instance
84
- .expects(:validate_pulp3_not_enabled)
85
- .returns(true)
86
- params = [
87
- '--export-tar=/tmp/exports/export-999.tar',
88
- '--organization-id=1'
89
- ]
90
-
91
- File.expects(:exist?).with('/usr/share/foreman').returns(true)
92
- File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
93
-
94
- File.expects(:exist?).with("/tmp/exports/export-999.tar").returns(true)
95
- Dir.expects(:chdir).with('/tmp/exports').returns(0)
96
- Dir.expects(:chdir).with('/tmp/exports/export-999').returns(0)
97
- File.expects(:read).with("/tmp/exports/export-999/export-999.json").returns(
98
- JSON.dump(
99
- 'name' => 'Foo Composite View',
100
- 'major' => '10',
101
- 'minor' => '0',
102
- 'composite_components' => ["berbere 55.32"]
103
- )
104
- )
105
-
106
- ex = api_expects(:content_views, :index)
107
- ex = ex.with_params('name' => 'berbere', 'organization_id' => '1')
108
- ex.returns(
109
- 'results' => [{'versions' => [{'version' => '10.0', 'id' => '654'},
110
- {'version' => '55.32', 'id' => '876'}]
111
- }]
112
- )
113
-
114
- ex = api_expects(:content_views, :index)
115
- ex = ex.with_params('name' => 'Foo Composite View', 'organization_id' => '1')
116
- ex.returns(
117
- 'results' => [{
118
- 'id' => '5',
119
- 'repositories' => [{'id' => '2', 'label' => 'foo'}],
120
- 'content_view' => {'name' => 'cv'}
121
- }]
122
- )
123
-
124
- ex = api_expects(:content_views, :update)
125
- ex = ex.with_params(
126
- 'id' => '5',
127
- 'component_ids' => ['876']
128
- )
129
- ex.returns('id' => '5', 'state' => 'planned')
130
-
131
- ex = api_expects(:content_views, :publish)
132
- ex = ex.with_params(
133
- 'id' => '5',
134
- 'major' => '10',
135
- 'minor' => '0'
136
- )
137
- ex.returns('id' => '2', 'state' => 'planned')
138
-
139
- expect_foreman_task('3')
140
-
141
- result = run_cmd(@cmd + params)
142
- assert_equal(HammerCLI::EX_OK, result.exit_code)
143
- end
144
-
145
- it "performs composite import, component not found" do
146
- HammerCLIKatello::ContentViewVersion::ImportCommand
147
- .any_instance
148
- .expects(:validate_pulp3_not_enabled)
149
- .returns(true)
150
- params = [
151
- '--export-tar=/tmp/exports/export-999.tar',
152
- '--organization-id=1'
153
- ]
154
-
155
- File.expects(:exist?).with('/usr/share/foreman').returns(true)
156
- File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
157
-
158
- File.expects(:exist?).with("/tmp/exports/export-999.tar").returns(true)
159
- Dir.expects(:chdir).with('/tmp/exports').returns(0)
160
- Dir.expects(:chdir).with('/tmp/exports/export-999').returns(0)
161
- File.expects(:read).with("/tmp/exports/export-999/export-999.json").returns(
162
- JSON.dump(
163
- 'name' => 'Foo Composite View',
164
- 'major' => '10',
165
- 'minor' => '0',
166
- 'composite_components' => ["berbere 55.32", "unicorn 99.99"]
167
- )
168
- )
169
-
170
- ex = api_expects(:content_views, :index)
171
- ex = ex.with_params('name' => 'berbere', 'organization_id' => '1')
172
- ex.returns(
173
- 'results' => [{'versions' => [{'version' => '10.0', 'id' => '654'},
174
- {'version' => '55.32', 'id' => '876'}]
175
- }]
176
- )
177
-
178
- ex = api_expects(:content_views, :index)
179
- ex = ex.with_params('name' => 'unicorn', 'organization_id' => '1')
180
- ex.returns(
181
- 'results' => []
182
- )
183
-
184
- ex = api_expects(:content_views, :index)
185
- ex = ex.with_params('name' => 'Foo Composite View', 'organization_id' => '1')
186
- ex.returns(
187
- 'results' => [{
188
- 'id' => '5',
189
- 'repositories' => [{'id' => '2', 'label' => 'foo'}],
190
- 'content_view' => {'name' => 'cv'}
191
- }]
192
- )
193
-
194
- result = run_cmd(@cmd + params)
195
- assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
196
- end
197
-
198
- it "fails import if cv has not been created" do
199
- HammerCLIKatello::ContentViewVersion::ImportCommand
200
- .any_instance
201
- .expects(:validate_pulp3_not_enabled)
202
- .returns(true)
203
- params = [
204
- '--export-tar=/tmp/exports/export-2.tar',
205
- '--organization-id=1'
206
- ]
207
-
208
- File.expects(:exist?).with('/usr/share/foreman').returns(true)
209
- File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
210
-
211
- File.expects(:exist?).with("/tmp/exports/export-2.tar").returns(true)
212
- Dir.expects(:chdir).with('/tmp/exports').returns(0)
213
- Dir.expects(:chdir).with('/tmp/exports/export-2').returns(0)
214
- File.expects(:read).with("/tmp/exports/export-2/export-2.json").returns(
215
- JSON.dump(
216
- 'name' => 'Foo View'
217
- )
218
- )
219
-
220
- ex = api_expects(:content_views, :index)
221
- ex = ex.with_params('name' => 'Foo View', 'organization_id' => '1')
222
- ex.returns([])
223
-
224
- result = run_cmd(@cmd + params)
225
- assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
226
- end
227
-
228
- it "fails import if repo is set to mirror-on-sync" do
229
- HammerCLIKatello::ContentViewVersion::ImportCommand
230
- .any_instance
231
- .expects(:validate_pulp3_not_enabled)
232
- .returns(true)
233
- params = [
234
- '--export-tar=/tmp/exports/export-2.tar',
235
- '--organization-id=1'
236
- ]
237
-
238
- File.expects(:exist?).with('/usr/share/foreman').returns(true)
239
- File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
240
-
241
- File.expects(:exist?).with("/tmp/exports/export-2.tar").returns(true)
242
- Dir.expects(:chdir).with('/tmp/exports').returns(0)
243
- Dir.expects(:chdir).with('/tmp/exports/export-2').returns(0)
244
- File.expects(:read).with("/tmp/exports/export-2/export-2.json").returns(
245
- JSON.dump(
246
- 'name' => 'Foo View',
247
- 'major' => '2',
248
- 'minor' => '1'
249
- )
250
- )
251
-
252
- ex = api_expects(:content_views, :index)
253
- ex = ex.with_params('name' => 'Foo View', 'organization_id' => '1')
254
- ex.returns(
255
- 'results' => [{
256
- 'id' => '5',
257
- 'repositories' => [{'id' => '2', 'label' => 'foo', 'mirror_on_sync' => 'true'}],
258
- 'content_view' => {'name' => 'cv'}
259
- }]
260
- )
261
-
262
- result = run_cmd(@cmd + params)
263
- assert_equal(result.exit_code, 70)
264
- end
265
-
266
- it "fails import if cv version already exists" do
267
- HammerCLIKatello::ContentViewVersion::ImportCommand
268
- .any_instance
269
- .expects(:validate_pulp3_not_enabled)
270
- .returns(true)
271
- params = [
272
- '--export-tar=/tmp/exports/export-2.tar',
273
- '--organization-id=1'
274
- ]
275
-
276
- File.expects(:exist?).with('/usr/share/foreman').returns(true)
277
- File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
278
-
279
- File.expects(:exist?).with("/tmp/exports/export-2.tar").returns(true)
280
- Dir.expects(:chdir).with('/tmp/exports').returns(0)
281
- Dir.expects(:chdir).with('/tmp/exports/export-2').returns(0)
282
- File.expects(:read).with("/tmp/exports/export-2/export-2.json").returns(
283
- JSON.dump(
284
- 'name' => 'Foo View',
285
- 'major' => '2',
286
- 'minor' => '1'
287
- )
288
- )
289
-
290
- ex = api_expects(:content_views, :index)
291
- ex = ex.with_params('name' => 'Foo View', 'organization_id' => '1')
292
- ex.returns(
293
- 'results' => [{
294
- 'id' => '5',
295
- 'content_view' => {'name' => 'cv'},
296
- 'versions' => [{'version' => '2.1', 'id' => '654'}]
297
- }]
298
- )
299
-
300
- result = run_cmd(@cmd + params)
301
- assert_equal(result.exit_code, 70)
302
- end
303
-
304
- it "fails import if any repository does not exist" do
305
- HammerCLIKatello::ContentViewVersion::ImportCommand
306
- .any_instance
307
- .expects(:validate_pulp3_not_enabled)
308
- .returns(true)
309
- params = [
310
- '--export-tar=/tmp/exports/export-2.tar',
311
- '--organization-id=1'
312
- ]
313
-
314
- File.expects(:exist?).with('/usr/share/foreman').returns(true)
315
- File.stubs(:exist?).with('/var/log/hammer/hammer.log._copy_').returns(false)
316
-
317
- File.expects(:exist?).with("/tmp/exports/export-2.tar").returns(true)
318
- Dir.expects(:chdir).with('/tmp/exports').returns(0)
319
- Dir.expects(:chdir).with('/tmp/exports/export-2').returns(0)
320
- File.expects(:read).with("/tmp/exports/export-2/export-2.json").returns(
321
- JSON.dump(
322
- 'name' => 'Foo View',
323
- 'repositories' => ['label' => 'foo'],
324
- 'major' => '2',
325
- 'minor' => '1'
326
- )
327
- )
328
-
329
- ex = api_expects(:content_views, :index)
330
- ex = ex.with_params('name' => 'Foo View', 'organization_id' => '1')
331
- ex.returns(
332
- 'results' => [{
333
- 'id' => '5',
334
- 'repositories' => [{'id' => '2', 'label' => 'foo'}],
335
- 'content_view' => {'name' => 'cv'}
336
- }]
337
- )
338
-
339
- ex = api_expects(:repositories, :index)
340
- ex = ex.with_params('organization_id' => '1', 'library' => true)
341
- ex.returns([])
342
-
343
- result = run_cmd(@cmd + params)
344
- assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code)
345
- end
346
- end