Skip to content

Commit 55fd2da

Browse files
authored
Merge pull request #301 from MichalHaluza/ubipop_config_from_cdn_definitons
Load content config repos from cdn-definitions [RHELDST-34516]
2 parents 117e9d4 + 93d5f7c commit 55fd2da

13 files changed

Lines changed: 328 additions & 235 deletions

File tree

conf/app.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ pulp_password = x
55
pulp_cert = x
66
pulp_key = x
77
content_config = {"repo_group_prefix": "url-to-config-repo"}
8+
cdn_definitions_url = https://gitlab.cee.redhat.com/cdn/cdn-definitions-private/-/raw/master/data.yaml
9+
cdn_definitions_env = prod

poetry.lock

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ more-executors = "*"
2828
ubi-config = "*"
2929
requests = "*"
3030
types-requests = "*"
31+
cdn-definitions = ">=3.4.0"
3132

3233
[tool.poetry.group.test]
3334
optional = true

tests/data/conf/test.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ pulp_password = yyy
55
pulp_cert = path/to/pulp_cert
66
pulp_key = path/to/pulp_key
77
content_config = {"ubi": "https://gitlab.foo.bar.com/ubi-config", "client-tools": "https://gitlab.foo.bar.com/ct-config"}
8+
cdn_definitions_url = https://gitlab.foo.bar.com/cdn-definitions.yaml
9+
cdn_definitions_env = test
810
publish_limit = 2
9-
ubi_manifest_data_expiration = 4444
11+
ubi_manifest_data_expiration = 4444

tests/test_app.py

Lines changed: 60 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ class MockAsyncResult:
2727
),
2828
],
2929
)
30+
@mock.patch("ubi_manifest.app.api.get_gitlab_healthcheck_url")
3031
@mock.patch("ubi_manifest.app.api.redis.from_url")
3132
@mock.patch("ubi_manifest.app.api.app.control.inspect")
3233
def test_status_beat_no_gitlab(
3334
inspect,
3435
mock_redis,
36+
get_gitlab_healthcheck_url,
3537
delta_seconds,
3638
beat_status,
3739
client,
@@ -46,7 +48,8 @@ def test_status_beat_no_gitlab(
4648
)
4749
beat = (datetime.now() - timedelta(seconds=delta_seconds)).isoformat().encode()
4850
mock_redis.return_value = MockedRedis(data={"celery-beat-heartbeat": beat})
49-
requests_mock.get("https://some_url/pulp/api/v2/status", reason="OK")
51+
get_gitlab_healthcheck_url.return_value = None
52+
requests_mock.get("https://pulp_url/pulp/api/v2/status", reason="OK")
5053

5154
response = client.get("/api/v1/status")
5255

@@ -67,13 +70,13 @@ def test_status_beat_no_gitlab(
6770
}
6871

6972

70-
@mock.patch("ubi_manifest.app.api.get_gitlab_base_url")
73+
@mock.patch("ubi_manifest.app.api.get_gitlab_healthcheck_url")
7174
@mock.patch("ubi_manifest.app.api.redis.from_url")
7275
@mock.patch("ubi_manifest.app.api.app.control.inspect")
7376
def test_status_no_beat_gitlab(
7477
inspect,
7578
mock_redis,
76-
get_gitlab_url,
79+
get_gitlab_healthcheck_url,
7780
client,
7881
requests_mock,
7982
):
@@ -85,10 +88,10 @@ def test_status_no_beat_gitlab(
8588
scheduled=mock.Mock(return_value={"worker01": []}),
8689
)
8790
mock_redis.return_value = MockedRedis(data={})
88-
get_gitlab_url.return_value = "https://gitlab.com"
91+
get_gitlab_healthcheck_url.return_value = "https://gitlab.com/-/health"
8992

9093
requests_mock.get("https://gitlab.com/-/health", reason="OK")
91-
requests_mock.get("https://some_url/pulp/api/v2/status", reason="OK")
94+
requests_mock.get("https://pulp_url/pulp/api/v2/status", reason="OK")
9295

9396
response = client.get("/api/v1/status")
9497

@@ -112,13 +115,13 @@ def test_status_no_beat_gitlab(
112115
}
113116

114117

115-
@mock.patch("ubi_manifest.app.api.get_gitlab_base_url")
118+
@mock.patch("ubi_manifest.app.api.get_gitlab_healthcheck_url")
116119
@mock.patch("ubi_manifest.app.api.redis.from_url")
117120
@mock.patch("ubi_manifest.app.api.app.control.inspect")
118121
def test_status_errors(
119122
inspect,
120123
mock_redis,
121-
get_gitlab_url,
124+
get_gitlab_healthcheck_url,
122125
client,
123126
requests_mock,
124127
):
@@ -130,13 +133,13 @@ def test_status_errors(
130133
scheduled=mock.Mock(return_value={"worker01": []}),
131134
)
132135
mock_redis.return_value = MockedRedis(data={}, ping_fail=True)
133-
get_gitlab_url.return_value = "https://gitlab.com"
136+
get_gitlab_healthcheck_url.return_value = "https://gitlab.com/-/health"
134137

135138
requests_mock.get(
136139
"https://gitlab.com/-/health", status_code=503, reason="Service Unavailable"
137140
)
138141
requests_mock.get(
139-
"https://some_url/pulp/api/v2/status",
142+
"https://pulp_url/pulp/api/v2/status",
140143
status_code=503,
141144
reason="Service Unavailable",
142145
)
@@ -164,7 +167,7 @@ def test_status_errors(
164167
},
165168
"connection_to_pulp": {
166169
"status": "Failed",
167-
"msg": "503 Server Error: Service Unavailable for url: https://some_url/pulp/api/v2/status",
170+
"msg": "503 Server Error: Service Unavailable for url: https://pulp_url/pulp/api/v2/status",
168171
},
169172
}
170173

@@ -279,7 +282,7 @@ def test_manifest_get_empty(client, auth_header):
279282

280283

281284
def test_manifest_get_not_found(client, auth_header):
282-
"""test getting depsolved content when the cotent is not available for given repo_id"""
285+
"""test getting depsolved content when the content is not available for given repo_id"""
283286
with mock.patch("ubi_manifest.app.api.redis.from_url") as mock_redis_from_url:
284287
mock_redis_from_url.return_value = MockedRedis(data={})
285288
response = client.get(
@@ -292,36 +295,48 @@ def test_manifest_get_not_found(client, auth_header):
292295
assert json_data["detail"] == "Content for ubi_repo_id not found"
293296

294297

298+
@mock.patch("ubi_manifest.app.utils.get_content_config_paths")
295299
@mock.patch("ubi_manifest.app.utils.ubiconfig.get_loader")
296300
@mock.patch("ubi_manifest.worker.utils.Client")
297301
@mock.patch("celery.app.task.Task.apply_async")
298302
def test_manifest_post_full_dep(
299-
mocked_apply_async, pulp_client, get_loader, client, pulp, auth_header
303+
mocked_apply_async,
304+
pulp_client,
305+
get_loader,
306+
get_content_config_paths,
307+
client,
308+
pulp,
309+
auth_header,
300310
):
301311
"""test request for depsolving for given repo ids where we use full depsolving"""
302312
mocked_apply_async.side_effect = [
303313
MockAsyncResult(task_id="foo-bar-id-1", state="PENDING"),
304314
MockAsyncResult(task_id="foo-bar-id-2", state="PENDING"),
305315
]
306-
configs = create_mock_configs(3)
307-
get_loader.return_value = mock.Mock(load_all=mock.Mock(return_value=configs))
316+
get_content_config_paths.return_value = ["url_or_dir_1", "url_or_dir_2"]
317+
ubi_configs = create_mock_configs(3, prefix="ubi")
318+
ct_configs = create_mock_configs(3, prefix="client-tools")
319+
get_loader.side_effect = [
320+
mock.Mock(load_all=mock.Mock(return_value=ubi_configs)),
321+
mock.Mock(load_all=mock.Mock(return_value=ct_configs)),
322+
]
308323
create_and_insert_repo(
309324
id="ubi_repo_1",
310-
content_set="content_set_0",
325+
content_set="ubi_content_set_0",
311326
ubi_population=True,
312327
arch="arch1",
313328
pulp=pulp,
314329
)
315330
create_and_insert_repo(
316331
id="ubi_repo_2",
317-
content_set="content_set_1",
332+
content_set="ubi_content_set_1",
318333
ubi_population=True,
319334
arch="arch1",
320335
pulp=pulp,
321336
)
322337
create_and_insert_repo(
323338
id="ubi_repo_3",
324-
content_set="content_set_2",
339+
content_set="ubi_content_set_2",
325340
ubi_population=True,
326341
arch="arch2",
327342
pulp=pulp,
@@ -359,31 +374,44 @@ def test_manifest_post_full_dep(
359374
assert json_data[1]["state"] == "PENDING"
360375

361376

377+
@mock.patch("ubi_manifest.app.utils.get_content_config_paths")
362378
@mock.patch("ubi_manifest.app.utils.ubiconfig.get_loader")
363379
@mock.patch("ubi_manifest.worker.utils.Client")
364380
@mock.patch("celery.app.task.Task.apply_async")
365381
def test_manifest_post_not_full_dep(
366-
mocked_apply_async, pulp_client, get_loader, client, pulp, auth_header
382+
mocked_apply_async,
383+
pulp_client,
384+
get_loader,
385+
get_content_config_paths,
386+
client,
387+
pulp,
388+
auth_header,
367389
):
368390
"""test request for depsolving for given repo ids where we do not use full depsolving"""
369391
mocked_apply_async.side_effect = [
370392
MockAsyncResult(task_id="foo-bar-id-1", state="PENDING"),
371393
MockAsyncResult(task_id="foo-bar-id-2", state="PENDING"),
372394
]
373-
configs = create_mock_configs(
374-
2, flags=[{"base_pkgs_only": True}, {"base_pkgs_only": True}]
395+
get_content_config_paths.return_value = ["url_or_dir_1", "url_or_dir_2"]
396+
ct_configs = create_mock_configs(
397+
2, flags={"base_pkgs_only": True}, prefix="client-tools"
375398
)
376-
get_loader.return_value = mock.Mock(load_all=mock.Mock(return_value=configs))
399+
get_loader.side_effect = [
400+
# Empty list also tests the case when a defined repo
401+
# doesn't contain any suitable content config
402+
mock.Mock(load_all=mock.Mock(return_value=[])),
403+
mock.Mock(load_all=mock.Mock(return_value=ct_configs)),
404+
]
377405
create_and_insert_repo(
378406
id="client-tools_repo_1",
379-
content_set="content_set_0",
407+
content_set="client-tools_content_set_0",
380408
ubi_population=True,
381409
arch="arch1",
382410
pulp=pulp,
383411
)
384412
create_and_insert_repo(
385413
id="client-tools_repo_2",
386-
content_set="content_set_1",
414+
content_set="client-tools_content_set_1",
387415
ubi_population=True,
388416
arch="arch1",
389417
pulp=pulp,
@@ -415,13 +443,21 @@ def test_manifest_post_not_full_dep(
415443
assert json_data[1]["state"] == "PENDING"
416444

417445

446+
@mock.patch("ubi_manifest.app.utils.get_content_config_paths")
418447
@mock.patch("ubi_manifest.app.utils.ubiconfig.get_loader")
419448
@mock.patch("ubi_manifest.worker.utils.Client")
420449
@mock.patch("celery.app.task.Task.apply_async")
421450
def test_manifest_post_no_depsolve_items(
422-
mocked_apply_async, pulp_client, get_loader, client, pulp, auth_header
451+
mocked_apply_async,
452+
pulp_client,
453+
get_loader,
454+
get_content_config_paths,
455+
client,
456+
pulp,
457+
auth_header,
423458
):
424459
"""test request for depsolving for given repo ids, but no depsolve items are identified"""
460+
get_content_config_paths.return_value = ["url_or_dir_1"]
425461
get_loader.return_value = mock.Mock(
426462
load_all=mock.Mock(return_value=create_mock_configs(3))
427463
)
@@ -453,62 +489,6 @@ def test_manifest_post_no_depsolve_items(
453489
)
454490

455491

456-
@mock.patch("ubi_manifest.app.utils.ubiconfig.get_loader")
457-
@mock.patch("ubi_manifest.worker.utils.Client")
458-
@mock.patch("celery.app.task.Task.apply_async")
459-
def test_manifest_post_more_repo_classes(
460-
mocked_apply_async, pulp_client, get_loader, client, auth_header
461-
):
462-
"""test request for depsolving for given repo ids, which are from different repo classes"""
463-
response = client.post(
464-
"/api/v1/manifest",
465-
json={"repo_ids": ["ubi_repo", "client-tools_repo"]},
466-
headers=auth_header(roles=["creator"]),
467-
)
468-
# The request has finished before any calls on pulp client or ubiconfig were made because
469-
# repos from two different classes were in the request.
470-
mocked_apply_async.assert_not_called()
471-
pulp_client.assert_not_called()
472-
get_loader.assert_not_called()
473-
# expected status code is 400
474-
assert response.status_code == 400
475-
# there is enough detail info in the response
476-
json_data = response.json()
477-
assert (
478-
json_data["detail"]
479-
== "Can't process repos from different classes ['ubi', 'client-tools'] in one request. "
480-
"Please make separate request for each class."
481-
)
482-
483-
484-
@mock.patch("ubi_manifest.app.utils.ubiconfig.get_loader")
485-
@mock.patch("ubi_manifest.worker.utils.Client")
486-
@mock.patch("celery.app.task.Task.apply_async")
487-
def test_manifest_post_wrong_repo_ids(
488-
mocked_apply_async, pulp_client, get_loader, client, auth_header
489-
):
490-
"""test request for depsolving for given repo ids, which are unexpected."""
491-
response = client.post(
492-
"/api/v1/manifest",
493-
json={"repo_ids": ["some_foreign_repo"]},
494-
headers=auth_header(roles=["creator"]),
495-
)
496-
# The request has finished before any calls on pulp client or ubiconfig were made because
497-
# repos from some unknown class were in the request.
498-
mocked_apply_async.assert_not_called()
499-
pulp_client.assert_not_called()
500-
get_loader.assert_not_called()
501-
# expected status code is 404
502-
assert response.status_code == 404
503-
# there is enough detail info in the response
504-
json_data = response.json()
505-
assert (
506-
json_data["detail"]
507-
== "Given repos ['some_foreign_repo'] have unexpected ids. It seems they are not "
508-
"from any of the accepted repo classes ['ubi', 'client-tools'] defined in content config."
509-
)
510-
511-
512492
@mock.patch("ubi_manifest.app.utils.ubiconfig.get_loader")
513493
@mock.patch("ubi_manifest.worker.utils.Client")
514494
@mock.patch("celery.app.task.Task.apply_async")

0 commit comments

Comments
 (0)