forked from SatelliteQE/robottelo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_container_management.py
More file actions
416 lines (349 loc) · 16.2 KB
/
Copy pathtest_container_management.py
File metadata and controls
416 lines (349 loc) · 16.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
"""Tests for the Container Management Content
:Requirement: ContainerImageManagement
:CaseAutomation: Automated
:Team: Artemis
:CaseComponent: ContainerImageManagement
"""
import re
from fauxfactory import gen_string
import pytest
from wait_for import wait_for
from robottelo.config import settings
from robottelo.constants import (
REPO_TYPE,
)
from robottelo.logging import logger
def _repo(sat, product_id, name=None, upstream_name=None, url=None):
"""Creates a Docker-based repository.
:param product_id: ID of the ``Product``.
:param str name: Name for the repository. If ``None`` then a random
value will be generated.
:param str upstream_name: A valid name of an existing upstream repository.
If ``None`` then defaults to settings.container.upstream_name constant.
:param str url: URL of repository. If ``None`` then defaults to
settings.container.registry_hub constant.
:return: A ``Repository`` object.
"""
return sat.cli_factory.make_repository(
{
'content-type': REPO_TYPE['docker'],
'docker-upstream-name': upstream_name or settings.container.upstream_name,
'name': name or gen_string('alpha', 5),
'product-id': product_id,
'url': url or settings.container.registry_hub,
}
)
class TestDockerClient:
"""Tests specific to using ``Docker`` as a client to pull Docker images
from a Satellite 6 instance.
:CaseImportance: Medium
"""
def test_positive_pull_image(
self, request, module_org, module_container_contenthost, target_sat
):
"""A Docker-enabled client can use ``docker pull`` to pull a
Docker image off a Satellite 6 instance.
:id: 023f0538-2aad-4f87-b8a8-6ccced648366
:steps:
1. Publish and promote content view with Docker content
2. Register Docker-enabled client against Satellite 6.
:expectedresults: Client can pull Docker images from server and run it.
:parametrized: yes
"""
product = target_sat.cli_factory.make_product_wait({'organization-id': module_org.id})
repo = _repo(target_sat, product['id'])
target_sat.cli.Repository.synchronize({'id': repo['id']})
repo = target_sat.cli.Repository.info({'id': repo['id']})
try:
result = module_container_contenthost.execute(
f'docker login -u {settings.server.admin_username}'
f' -p {settings.server.admin_password} {target_sat.hostname}'
)
assert result.status == 0
request.addfinalizer(
lambda: module_container_contenthost.execute(f'docker logout {target_sat.hostname}')
)
# publishing takes few seconds sometimes
result, _ = wait_for(
lambda: module_container_contenthost.execute(f'docker pull {repo["published-at"]}'),
num_sec=60,
delay=2,
fail_condition=lambda out: out.status != 0,
logger=logger,
)
assert result.status == 0
try:
result = module_container_contenthost.execute(
f'docker run -d {repo["published-at"]}'
)
assert result.status == 0
match = re.match(r'^[0-9a-f]+$', result.stdout)
if match:
container_id = match.group(0)
finally:
# Stop and remove the container
if container_id:
module_container_contenthost.execute(f'docker stop {container_id}')
module_container_contenthost.execute(f'docker rm {container_id}')
finally:
# Remove docker image
module_container_contenthost.execute(f'docker rmi {repo["published-at"]}')
@pytest.mark.skip_if_not_set('docker')
@pytest.mark.e2e
def test_positive_container_admin_end_to_end_search(
self, request, module_org, module_container_contenthost, target_sat
):
"""Verify that docker command line can be used against
Satellite server to search for container images stored
on Satellite instance.
:id: cefa74e1-e40d-4f47-853b-1268643cea2f
:steps:
1. Publish and promote content view with Docker content
2. Set 'Unauthenticated Pull' option to false
3. Try to search for docker images on Satellite
4. Use Docker client to login to Satellite docker hub
5. Search for docker images
6. Use Docker client to log out of Satellite docker hub
7. Try to search for docker images (ensure last search result
is caused by change of Satellite option and not login/logout)
8. Set 'Unauthenticated Pull' option to true
9. Search for docker images
:expectedresults: Client can search for docker images stored
on Satellite instance
:parametrized: yes
"""
pattern_prefix = gen_string('alpha', 5)
registry_name_pattern = (
f'{pattern_prefix}-<%= content_view.label %>/<%= repository.docker_upstream_name %>'
)
# Satellite setup: create product and add Docker repository;
# create content view and add Docker repository;
# create lifecycle environment and promote content view to it
lce = target_sat.cli_factory.make_lifecycle_environment({'organization-id': module_org.id})
product = target_sat.cli_factory.make_product_wait({'organization-id': module_org.id})
repo = _repo(target_sat, product['id'], upstream_name=settings.container.upstream_name)
target_sat.cli.Repository.synchronize({'id': repo['id']})
content_view = target_sat.cli_factory.make_content_view(
{'composite': False, 'organization-id': module_org.id}
)
target_sat.cli.ContentView.add_repository(
{'id': content_view['id'], 'repository-id': repo['id']}
)
target_sat.cli.ContentView.publish({'id': content_view['id']})
content_view = target_sat.cli.ContentView.info({'id': content_view['id']})
target_sat.cli.ContentView.version_promote(
{'id': content_view['versions'][0]['id'], 'to-lifecycle-environment-id': lce['id']}
)
target_sat.cli.LifecycleEnvironment.update(
{
'registry-name-pattern': registry_name_pattern,
'registry-unauthenticated-pull': 'false',
'id': lce['id'],
'organization-id': module_org.id,
}
)
docker_repo_uri = (
f'{target_sat.hostname}/{pattern_prefix}-{content_view["label"]}/'
f'{settings.container.upstream_name}'
).lower()
# 3. Try to search for docker images on Satellite
remote_search_command = (
f'docker search {target_sat.hostname}/{settings.container.upstream_name}'
)
result = module_container_contenthost.execute(remote_search_command)
assert result.status == 0
assert docker_repo_uri not in result.stdout
# 4. Use Docker client to login to Satellite docker hub
result = module_container_contenthost.execute(
f'docker login -u {settings.server.admin_username}'
f' -p {settings.server.admin_password} {target_sat.hostname}'
)
assert result.status == 0
request.addfinalizer(
lambda: module_container_contenthost.execute(f'docker logout {target_sat.hostname}')
)
# 5. Search for docker images
result = module_container_contenthost.execute(remote_search_command)
assert result.status == 0
assert docker_repo_uri in result.stdout
# 6. Use Docker client to log out of Satellite docker hub
result = module_container_contenthost.execute(f'docker logout {target_sat.hostname}')
assert result.status == 0
# 7. Try to search for docker images
result = module_container_contenthost.execute(remote_search_command)
assert result.status == 0
assert docker_repo_uri not in result.stdout
# 8. Set 'Unauthenticated Pull' option to true
target_sat.cli.LifecycleEnvironment.update(
{
'registry-unauthenticated-pull': 'true',
'id': lce['id'],
'organization-id': module_org.id,
}
)
# 9. Search for docker images
result = module_container_contenthost.execute(remote_search_command)
assert result.status == 0
assert docker_repo_uri in result.stdout
@pytest.mark.skip_if_not_set('docker')
@pytest.mark.e2e
def test_positive_container_admin_end_to_end_pull(
self, request, module_org, module_container_contenthost, target_sat
):
"""Verify that docker command line can be used against
Satellite server to pull in container images stored
on Satellite instance.
:id: 2a331f88-406b-4a5c-ae70-302a9994077f
:steps:
1. Publish and promote content view with Docker content
2. Set 'Unauthenticated Pull' option to false
3. Try to pull in docker image from Satellite
4. Use Docker client to login to Satellite container registry
5. Pull in docker image
6. Use Docker client to log out of Satellite container registry
7. Try to pull in docker image (ensure next pull result
is caused by change of Satellite option and not login/logout)
8. Set 'Unauthenticated Pull' option to true
9. Pull in docker image
:expectedresults: Client can pull in docker images stored
on Satellite instance
:parametrized: yes
"""
pattern_prefix = gen_string('alpha', 5)
docker_upstream_name = settings.container.upstream_name
registry_name_pattern = (
f'{pattern_prefix}-<%= content_view.label %>/<%= repository.docker_upstream_name %>'
)
# Satellite setup: create product and add Docker repository;
# create content view and add Docker repository;
# create lifecycle environment and promote content view to it
lce = target_sat.cli_factory.make_lifecycle_environment({'organization-id': module_org.id})
product = target_sat.cli_factory.make_product_wait({'organization-id': module_org.id})
repo = _repo(target_sat, product['id'], upstream_name=docker_upstream_name)
target_sat.cli.Repository.synchronize({'id': repo['id']})
content_view = target_sat.cli_factory.make_content_view(
{'composite': False, 'organization-id': module_org.id}
)
target_sat.cli.ContentView.add_repository(
{'id': content_view['id'], 'repository-id': repo['id']}
)
target_sat.cli.ContentView.publish({'id': content_view['id']})
content_view = target_sat.cli.ContentView.info({'id': content_view['id']})
target_sat.cli.ContentView.version_promote(
{'id': content_view['versions'][0]['id'], 'to-lifecycle-environment-id': lce['id']}
)
target_sat.cli.LifecycleEnvironment.update(
{
'registry-name-pattern': registry_name_pattern,
'registry-unauthenticated-pull': 'false',
'id': lce['id'],
'organization-id': module_org.id,
}
)
docker_repo_uri = (
f'{target_sat.hostname}/{pattern_prefix}-{content_view["label"]}/{docker_upstream_name}'
).lower()
# 3. Try to pull in docker image from Satellite
docker_pull_command = f'docker pull {docker_repo_uri}'
result = module_container_contenthost.execute(docker_pull_command)
assert result.status != 0
# 4. Use Docker client to login to Satellite docker hub
result = module_container_contenthost.execute(
f'docker login -u {settings.server.admin_username}'
f' -p {settings.server.admin_password} {target_sat.hostname}'
)
assert result.status == 0
request.addfinalizer(
lambda: module_container_contenthost.execute(f'docker logout {target_sat.hostname}')
)
# 5. Pull in docker image
# publishing takes few seconds sometimes
result, _ = wait_for(
lambda: module_container_contenthost.execute(docker_pull_command),
num_sec=60,
delay=2,
fail_condition=lambda out: out.status != 0,
logger=logger,
)
assert result.status == 0
# 6. Use Docker client to log out of Satellite docker hub
result = module_container_contenthost.execute(f'docker logout {target_sat.hostname}')
assert result.status == 0
# 7. Try to pull in docker image
result = module_container_contenthost.execute(docker_pull_command)
assert result.status != 0
# 8. Set 'Unauthenticated Pull' option to true
target_sat.cli.LifecycleEnvironment.update(
{
'registry-unauthenticated-pull': 'true',
'id': lce['id'],
'organization-id': module_org.id,
}
)
# 9. Pull in docker image
result = module_container_contenthost.execute(docker_pull_command)
assert result.status == 0
def test_positive_pull_content_with_longer_name(
self, request, target_sat, module_container_contenthost, module_org
):
"""Verify that long name CV publishes when CV & docker repo both have a larger name.
:id: e0ac0be4-f5ff-4a88-bb29-33aa2d874f46
:steps:
1. Create Product, docker repo, CV and LCE with a long name
2. Sync the repos
3. Add repository to CV, Publish, and then Promote CV to LCE
4. Pull in docker image
:expectedresults:
1. Long Product, repository, CV and LCE should create successfully
2. Sync repository successfully
3. Publish & Promote should success
4. Can pull in docker images
:BZ: 2127470
:customerscenario: true
"""
pattern_postfix = gen_string('alpha', 10).lower()
product_name = f'containers-{pattern_postfix}'
repo_name = f'repo-{pattern_postfix}'
lce_name = f'lce-{pattern_postfix}'
cv_name = f'cv-{pattern_postfix}'
# 1. Create Product, docker repo, CV and LCE with a long name
product = target_sat.cli_factory.make_product_wait(
{'name': product_name, 'organization-id': module_org.id}
)
repo = _repo(
target_sat,
product['id'],
name=repo_name,
upstream_name=settings.container.upstream_name,
)
# 2. Sync the repos
target_sat.cli.Repository.synchronize({'id': repo['id']})
lce = target_sat.cli_factory.make_lifecycle_environment(
{'name': lce_name, 'organization-id': module_org.id}
)
cv = target_sat.cli_factory.make_content_view(
{'name': cv_name, 'composite': False, 'organization-id': module_org.id}
)
# 3. Add repository to CV, Publish, and then Promote CV to LCE
target_sat.cli.ContentView.add_repository({'id': cv['id'], 'repository-id': repo['id']})
target_sat.cli.ContentView.publish({'id': cv['id']})
cv = target_sat.cli.ContentView.info({'id': cv['id']})
target_sat.cli.ContentView.version_promote(
{'id': cv['versions'][0]['id'], 'to-lifecycle-environment-id': lce['id']}
)
podman_pull_command = (
f"podman pull --tls-verify=false {target_sat.hostname}/{module_org.label}"
f"/{lce['label']}/{cv['label']}/{product['label']}/{repo_name}".lower()
)
# 4. Pull in docker image
assert (
module_container_contenthost.execute(
f'podman login -u {settings.server.admin_username}'
f' -p {settings.server.admin_password} {target_sat.hostname}'
).status
== 0
)
request.addfinalizer(
lambda: module_container_contenthost.execute(f'podman logout {target_sat.hostname}')
)
assert module_container_contenthost.execute(podman_pull_command).status == 0