Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace standalone config option for --standalone flag #337

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ authorino: poetry-no-dev

authorino-standalone: ## Run only test capable of running with standalone Authorino
authorino-standalone: poetry-no-dev
$(PYTEST) -n4 -m 'authorino and not kuadrant_only' --dist loadfile --enforce $(flags) testsuite/tests/kuadrant/authorino
$(PYTEST) -n4 -m 'authorino and not kuadrant_only' --dist loadfile --enforce --standalone $(flags) testsuite/tests/kuadrant/authorino
averevki marked this conversation as resolved.
Show resolved Hide resolved

limitador: ## Run only Limitador related tests
limitador: poetry-no-dev
Expand Down
1 change: 0 additions & 1 deletion config/settings.local.yaml.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#default:
# skip_cleanup: false
# tester: "someuser" # Optional: name of the user, who is running the tests, defaults to whoami/uid
# standalone: false # True, if Testsuite should test only individual components (e.g. Authorino/limitador operators)
averevki marked this conversation as resolved.
Show resolved Hide resolved
# cluster: # Workload cluster where tests should run, will get overriden if run on Multicluster
# project: "kuadrant" # Optional: Default namespace for this cluster
# api_url: "https://api.openshift.com" # Optional: OpenShift API URL, if None it will OpenShift that you are logged in
Expand Down
1 change: 0 additions & 1 deletion config/settings.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
default:
skip_cleanup: false
dynaconf_merge: true
standalone: false
cluster: {}
tools:
project: "tools"
Expand Down
14 changes: 0 additions & 14 deletions testsuite/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ def has_kuadrant():
"""Returns True, if Kuadrant deployment is present and should be used"""
spokes = weakget(settings)["control_plane"]["spokes"] % {}

if settings.get("standalone", False):
return False, "Standalone mode is enabled"

for name, openshift in spokes.items():
# Try if Kuadrant is deployed
if not openshift.connected:
Expand All @@ -28,22 +25,11 @@ def has_kuadrant():
return True, None


@functools.cache
def is_standalone():
"""Return True, if the testsuite is configured to run with envoy in standalone mode, without Gateway API"""
if not settings.get("standalone", False):
return False, "Standalone mode is disabled"
return True, None


@functools.cache
def has_mgc():
"""Returns True, if MGC is configured and deployed"""
spokes = weakget(settings)["control_plane"]["spokes"] % {}

if settings.get("standalone", False):
return False, "Standalone mode is enabled"

if len(spokes) == 0:
return False, "Spokes are not configured"

Expand Down
2 changes: 0 additions & 2 deletions testsuite/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ def __init__(self, name, default, **kwargs) -> None:
DefaultValueValidator("rhsso.url", default=fetch_route("no-ssl-sso")),
DefaultValueValidator("rhsso.password", default=fetch_secret("credential-sso", "ADMIN_PASSWORD")),
DefaultValueValidator("mockserver.url", default=fetch_route("mockserver", force_http=True)),
Validator("standalone", must_exist=False, eq=True)
| Validator("service_protection.gateway.name", must_exist=True),
],
validate_only=["authorino", "kuadrant"],
loaders=["dynaconf.loaders.env_loader", "testsuite.config.openshift_loader"],
Expand Down
42 changes: 26 additions & 16 deletions testsuite/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dynaconf import ValidationError
from keycloak import KeycloakAuthenticationError

from testsuite.capabilities import has_kuadrant, has_mgc, is_standalone
from testsuite.capabilities import has_kuadrant, has_mgc
from testsuite.certificates import CFSSLClient
from testsuite.config import settings
from testsuite.mockserver import Mockserver
Expand All @@ -29,7 +29,10 @@ def pytest_addoption(parser):
parser.addoption(
"--performance", action="store_true", default=False, help="Run also performance tests (default: False)"
)
parser.addoption("--enforce", action="store_true", default=False, help="Fails tests instead of skip")
parser.addoption(
"--enforce", action="store_true", default=False, help="Fails tests instead of skip, if capabilities are missing"
)
parser.addoption("--standalone", action="store_true", default=False, help="Runs testsuite in standalone mode")


def pytest_runtest_setup(item):
Expand All @@ -43,18 +46,25 @@ def pytest_runtest_setup(item):
if "performance" in marks and not item.config.getoption("--performance"):
pytest.skip("Excluding performance tests")
skip_or_fail = pytest.fail if item.config.getoption("--enforce") else pytest.skip
if "kuadrant_only" in marks:
kuadrant, error = has_kuadrant()
if not kuadrant:
skip_or_fail(f"Unable to locate Kuadrant installation: {error}")
if "standalone_only" in marks:
status, error = is_standalone()
if not status:
skip_or_fail(f"Unable to run Standalone tests: {error}")
if "mgc" in marks:
mgc, error = has_mgc()
if not mgc:
skip_or_fail(f"Unable to locate MGC installation: {error}")
standalone = item.config.getoption("--standalone")
if standalone:
if "mgc" in marks:
skip_or_fail("Unable to run MGC test: Standalone mode is enabled")
if "kuadrant_only" in marks:
skip_or_fail("Unable to run Kuadrant Only tests: Standalone mode is enabled")
else:
if "standalone_only" in marks:
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}")


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


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

# Try if Kuadrant is deployed
Expand Down
Loading