Skip to content

Commit

Permalink
Merge pull request Kuadrant#340 from pehala/fix_kuadrant_check
Browse files Browse the repository at this point in the history
Always run Kuadrant check
  • Loading branch information
pehala authored Mar 6, 2024
2 parents 96d6bc7 + e1c957b commit 3eb83fe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ testsuite/%: FORCE poetry-no-dev

test: ## Run all non mgc tests
test pytest tests: poetry-no-dev
$(PYTEST) -n4 -m 'not mgc' --dist loadfile $(flags) testsuite
$(PYTEST) -n4 -m 'not mgc' --dist loadfile --enforce $(flags) testsuite

authorino: ## Run only authorino related tests
authorino: poetry-no-dev
Expand Down
21 changes: 14 additions & 7 deletions testsuite/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@
@functools.cache
def has_kuadrant():
"""Returns True, if Kuadrant deployment is present and should be used"""
spokes = weakget(settings)["control_plane"]["spokes"] % {}

for name, openshift in spokes.items():
# Try if Kuadrant is deployed
if not openshift.connected:
return False, f"Spoke {name} is not connected"
if spokes := weakget(settings)["control_plane"]["spokes"] % {}:
for name, openshift in spokes.items():
# Try if Kuadrant is deployed
if not openshift.connected:
return False, f"Spoke {name} is not connected"
project = settings["service_protection"]["system_project"]
kuadrant_openshift = openshift.change_project(project)
kuadrants = kuadrant_openshift.do_action("get", "kuadrant", "-o", "json", parse_output=True)
if len(kuadrants.model["items"]) == 0:
return False, f"Spoke {name} does not have Kuadrant resource in project {project}"

else:
openshift = settings["service_protection"]["project"]
project = settings["service_protection"]["system_project"]
kuadrant_openshift = openshift.change_project(project)
kuadrants = kuadrant_openshift.do_action("get", "kuadrant", "-o", "json", parse_output=True)
if len(kuadrants.model["items"]) == 0:
return False, f"Spoke {name} does not have Kuadrant resource in project {project}"
return False, f"Kuadrant resource is not installed in project {project}"

return True, None

Expand Down
1 change: 0 additions & 1 deletion testsuite/config/openshift_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def load(obj, env=None, silent=True, key=None, filename=None):
obj["tools"] = tools

service_protection = obj.setdefault("service_protection", {})
inject_client(service_protection, client, "system_project")
inject_client(service_protection, client, "project")
inject_client(service_protection, client, "project2")

Expand Down
15 changes: 4 additions & 11 deletions testsuite/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ def pytest_runtest_setup(item):
skip_or_fail(
"Unable to run Standalone only test: Standalone mode is disabled, please use --standalone flag"
)
if "kuadrant_only" in marks:
kuadrant, error = has_kuadrant()
if not kuadrant:
skip_or_fail(f"Unable to locate Kuadrant installation: {error}")
if "mgc" in marks:
mgc, error = has_mgc()
if not mgc:
skip_or_fail(f"Unable to locate MGC installation: {error}")
kuadrant, error = has_kuadrant()
if not kuadrant:
skip_or_fail(f"Unable to locate Kuadrant installation: {error}")


@pytest.hookimpl(hookwrapper=True)
Expand Down Expand Up @@ -251,17 +250,11 @@ def module_label(label):


@pytest.fixture(scope="module")
def kuadrant(request, testconfig, openshift):
def kuadrant(request):
"""Returns Kuadrant instance if exists, or None"""
if request.config.getoption("--standalone"):
return None

# Try if Kuadrant is deployed
kuadrant_openshift = testconfig["service_protection"]["system_project"]
kuadrants = kuadrant_openshift.do_action("get", "kuadrant", "-o", "json", parse_output=True)
if len(kuadrants.model["items"]) == 0:
pytest.fail("Running Kuadrant tests, but Kuadrant resource was not found")

# TODO: Return actual Kuadrant object
return True

Expand Down

0 comments on commit 3eb83fe

Please sign in to comment.