Skip to content

Commit e828cf3

Browse files
committed
Fix: Check permission handles removed operator
A removed operator is not available in the head repo and we need to get it from base repo instead. This commit splits operators into 2 categories. Added,updated and removed. Each of them is parsed from a different repository. JIRA: ISV-5167 Signed-off-by: Ales Raszka <[email protected]>
1 parent d616d6d commit e828cf3

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

operator-pipeline-images/operatorcert/entrypoints/check_permissions.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,20 @@ def check_permissions(
368368
with open(args.changes_file, "r", encoding="utf8") as f:
369369
changes = json.load(f)
370370

371-
affected_operators = changes.get("affected_operators", [])
372-
operators = {head_repo.operator(operator) for operator in affected_operators}
371+
# Get added and modified operators from head repo
372+
added_or_updated_operators = changes.get("added_operators", [])
373+
added_or_updated_operators.extend(changes.get("modified_operators", []))
374+
operators = {
375+
head_repo.operator(operator) for operator in added_or_updated_operators
376+
}
377+
378+
# Get deleted operators from base repo
379+
operators = operators.union(
380+
{
381+
base_repo.operator(operator)
382+
for operator in changes.get("deleted_operators", [])
383+
}
384+
)
373385

374386
# In this step we need to map the affected catalog operators to the actual
375387
# operators. This needs to be done because the permission and reviewers

operator-pipeline-images/tests/entrypoints/test_check_permissions.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,33 +326,39 @@ def test_check_permissions(
326326
head_repo = MagicMock()
327327

328328
mock_json_load.return_value = {
329-
"affected_operators": ["operator1", "operator2"],
330-
"added_catalog_operators": ["c1/operator3"],
331-
"modified_catalog_operators": ["c2/operator4"],
332-
"removed_catalog_operators": ["c3/operator5"],
329+
"added_operators": ["operator1"],
330+
"modified_operators": ["operator2"],
331+
"deleted_operators": ["operator3"],
332+
"added_catalog_operators": ["c1/operator4"],
333+
"modified_catalog_operators": ["c2/operator5"],
334+
"removed_catalog_operators": ["c3/operator6"],
333335
}
334336
head_repo.operator.side_effect = [
335337
MagicMock(name="operator1"),
336338
MagicMock(name="operator2"),
337339
]
338-
base_repo.operator.side_effect = [MagicMock(name="operator5")]
340+
base_repo.operator.side_effect = [
341+
MagicMock(name="operator3"),
342+
MagicMock(name="operator6"),
343+
]
339344
mock_review.return_value.check_permissions.side_effect = [
340345
False,
341346
check_permissions.MaintainersReviewNeeded("error"),
342347
True,
343348
True,
344349
True,
350+
True,
345351
]
346352
mock_catalog_operators.side_effect = [
347353
set(
348354
[
349-
MagicMock(name="operator3"),
350355
MagicMock(name="operator4"),
356+
MagicMock(name="operator5"),
351357
]
352358
),
353359
set(
354360
[
355-
MagicMock(name="operator5"),
361+
MagicMock(name="operator6"),
356362
]
357363
),
358364
]
@@ -361,10 +367,11 @@ def test_check_permissions(
361367
assert not result
362368

363369
head_repo.operator.assert_has_calls([call("operator1"), call("operator2")])
370+
base_repo.operator.assert_has_calls([call("operator3")])
364371
mock_catalog_operators.assert_has_calls(
365372
[
366-
call(head_repo, ["c1/operator3", "c2/operator4"]),
367-
call(base_repo, ["c3/operator5"]),
373+
call(head_repo, ["c1/operator4", "c2/operator5"]),
374+
call(base_repo, ["c3/operator6"]),
368375
]
369376
)
370377

0 commit comments

Comments
 (0)