Skip to content

Commit d88ce04

Browse files
[ISV-6605] Fix static-tests error message on incorrect replaces version
1 parent 2c9a1df commit d88ce04

9 files changed

Lines changed: 427 additions & 205 deletions

File tree

ansible/inventory/group_vars/operator-pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
##### General settings
33
ansible_connection: local
4-
ansible_python_interpreter: /usr/bin/python3
4+
ansible_python_interpreter: "{{ ansible_playbook_python }}"
55
env: unset
66
oc_namespace: "operator-pipeline-{{ env }}"
77
oc_signing_namespace: "signing-pipeline-{{ env }}"

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from github.Repository import Repository
2424
from github.PullRequest import PullRequest
2525

26-
2726
logger = logging.getLogger(__name__)
2827

2928

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from operatorcert.integration.runner import run_integration_tests
1111

12-
1312
LOGGER = logging.getLogger("operator-cert")
1413

1514

operator-pipeline-images/operatorcert/static_tests/community/bundle.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ def check_replaces_availability(bundle: Bundle) -> Iterator[CheckResult]:
343343
x.csv_operator_version: x.operator_version
344344
for x in bundle.operator.all_bundles()
345345
}
346+
347+
if replaces_version not in ver_to_dir:
348+
yield Fail(
349+
f"{bundle} attempts to replace version '{replaces_version}' which"
350+
f" does not exist. Available versions: {sorted(ver_to_dir.keys())}"
351+
)
352+
return
353+
346354
replaces_bundle = bundle.operator.bundle(ver_to_dir[replaces_version])
347355

348356
ocp_versions_str = bundle.annotations.get("com.redhat.openshift.versions")

operator-pipeline-images/tests/integration/conftest.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
@pytest.fixture
77
def operator_pipelines_path(tmp_path: Path) -> Path:
88
ansible_cfg = tmp_path / "ansible.cfg"
9-
ansible_cfg.write_text(
10-
"""
9+
ansible_cfg.write_text("""
1110
[defaults]
1211
roles_path=./ansible/roles
1312
inventory=./ansible/inventory/local
14-
"""
15-
)
13+
""")
1614
roles_dir = tmp_path / "ansible" / "roles"
1715
inventory_dir = tmp_path / "ansible" / "inventory"
1816
playbooks_dir = tmp_path / "ansible" / "playbooks"
@@ -22,13 +20,11 @@ def operator_pipelines_path(tmp_path: Path) -> Path:
2220
inventory = inventory_dir / "local"
2321
inventory.write_text("localhost ansible_connection=local\n")
2422
site_playbook = playbooks_dir / "site.yml"
25-
site_playbook.write_text(
26-
"""
23+
site_playbook.write_text("""
2724
---
2825
- hosts: localhost
2926
tasks: []
30-
"""
31-
)
27+
""")
3228
return tmp_path
3329

3430

operator-pipeline-images/tests/static_tests/community/test_bundle.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,34 @@ def test_check_replaces_availability(
606606
assert set(errors) == expected
607607

608608

609+
def test_check_replaces_availability_nonexistent_version(
610+
tmp_path: Path,
611+
) -> None:
612+
"""Test that attempting to replace a non-existent version produces a clear error message"""
613+
create_files(
614+
tmp_path,
615+
bundle_files("hello", "0.0.1"),
616+
bundle_files(
617+
"hello",
618+
"0.0.2",
619+
csv={"spec": {"replaces": "hello.v0.0.5"}}, # 0.0.5 doesn't exist
620+
),
621+
)
622+
623+
repo = Repo(tmp_path)
624+
operator = repo.operator("hello")
625+
bundle = operator.bundle("0.0.2")
626+
errors = list(check_replaces_availability(bundle))
627+
628+
assert len(errors) == 1
629+
assert isinstance(errors[0], Fail)
630+
assert (
631+
"Bundle(hello/0.0.2) attempts to replace version '0.0.5' which does not exist"
632+
in errors[0].reason
633+
)
634+
assert "Available versions:" in errors[0].reason
635+
636+
609637
@pytest.mark.parametrize(
610638
"files, bundle_to_check, expected",
611639
[

operator-pipeline-images/tests/test_tekton.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def test_pipelinerun() -> None:
4040
assert str(pr.start_time) == "2021-11-10 18:38:09+00:00"
4141
assert pr.finally_taskruns == pr.taskruns[:2]
4242

43-
md = textwrap.dedent(
44-
"""
43+
md = textwrap.dedent("""
4544
# Pipeline Summary
4645
4746
Pipeline: *operator-hosted-pipeline*
@@ -60,7 +59,6 @@ def test_pipelinerun() -> None:
6059
| :heavy_check_mark: | bundle-path-validation | 2021-11-10 18:39:29+00:00 | 14 seconds |
6160
| :heavy_check_mark: | content-hash | 2021-11-10 18:39:46+00:00 | 17 seconds |
6261
| :x: | certification-project-check | 2021-11-10 18:39:46+00:00 | 17 seconds |
63-
"""
64-
)
62+
""")
6563

6664
assert pr.markdown_summary() == md

pdm.lock

Lines changed: 383 additions & 189 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ build-backend = "pdm.pep517.api"
9595
[project.optional-dependencies]
9696
operatorcert-dev = [
9797
"black>=23.3.0",
98-
"pytest>=7.3.2",
98+
"pytest>=9.0.3",
9999
"pytest-cov>=4.1.0",
100100
"yamllint>=1.32.0",
101101
"requests-mock>=1.11.0",

0 commit comments

Comments
 (0)