Skip to content

Commit

Permalink
Make gateway fixture session scope
Browse files Browse the repository at this point in the history
  • Loading branch information
pehala committed Mar 15, 2024
1 parent 9422da2 commit 218f810
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 28 deletions.
2 changes: 1 addition & 1 deletion testsuite/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def backend(request, openshift, blame, label):

@pytest.fixture(scope="session")
def gateway(request, kuadrant, openshift, blame, label, testconfig, wildcard_domain) -> Gateway:
"""Deploys Envoy that wire up the Backend behind the reverse-proxy and Authorino instance"""
"""Deploys Gateway that wires up the Backend behind the reverse-proxy and Authorino instance"""
if kuadrant:
gw = KuadrantGateway.create_instance(openshift, blame("gw"), wildcard_domain, {"app": label})
else:
Expand Down
32 changes: 8 additions & 24 deletions testsuite/tests/kuadrant/authorino/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,39 @@
from testsuite.openshift.authorino import AuthorinoCR, Authorino, PreexistingAuthorino


@pytest.fixture(scope="module")
def authorino_parameters():
"""Optional parameters for Authorino creation, passed to the __init__"""
return {}


@pytest.fixture(scope="module")
def authorino(authorino, openshift, blame, request, testconfig, module_label, authorino_parameters) -> Authorino:
@pytest.fixture(scope="session")
def authorino(authorino, openshift, blame, request, testconfig, label) -> Authorino:
"""Authorino instance"""
if authorino:
return authorino

authorino_config = testconfig["service_protection"]["authorino"]
if not authorino_config["deploy"]:
if len(authorino_parameters) > 0:
return pytest.skip("Can't change parameters of already deployed Authorino")
return PreexistingAuthorino(
authorino_config["auth_url"],
authorino_config["oidc_url"],
authorino_config["metrics_service_name"],
)

labels = authorino_parameters.setdefault("label_selectors", [])
labels.append(f"testRun={module_label}")

authorino_parameters.setdefault("name", blame("authorino"))

authorino = AuthorinoCR.create_instance(
openshift,
image=authorino_config.get("image"),
log_level=authorino_config.get("log_level"),
**authorino_parameters,
name=blame("authorino"),
label_selectors=[f"testRun={label}"],
)
request.addfinalizer(lambda: authorino.delete(ignore_not_found=True))
request.addfinalizer(authorino.delete)
authorino.commit()
authorino.wait_for_ready()
return authorino


# pylint: disable=unused-argument
@pytest.fixture(scope="module")
def authorization(
authorization, oidc_provider, authorino, route, authorization_name, openshift, module_label
) -> AuthConfig:
"""In case of Authorino, AuthConfig used for authorization"""
def authorization(authorization, oidc_provider, route, authorization_name, openshift, label) -> AuthConfig:
"""In case of Authorino, AuthC onfig used for authorization"""
if authorization is None:
authorization = AuthConfig.create_instance(
openshift, authorization_name, route, labels={"testRun": module_label}
)
authorization = AuthConfig.create_instance(openshift, authorization_name, route, labels={"testRun": label})
authorization.identity.add_oidc("rhsso", oidc_provider.well_known["issuer"])
return authorization

Expand Down
52 changes: 52 additions & 0 deletions testsuite/tests/kuadrant/authorino/operator/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Conftest for all tests requiring direct access to Authorino Operator"""

import pytest

from testsuite.gateway.envoy import Envoy
from testsuite.openshift.authorino import AuthorinoCR, Authorino


@pytest.fixture(scope="module")
def gateway(request, authorino, openshift, blame, label, testconfig) -> Envoy:
"""Deploys Envoy that wires up the Backend behind the reverse-proxy and Authorino instance"""
gw = Envoy(
openshift,
blame("gw"),
authorino,
testconfig["service_protection"]["envoy"]["image"],
labels={"app": label},
)
request.addfinalizer(gw.delete)
gw.commit()
gw.wait_for_ready(timeout=10 * 60)
return gw


@pytest.fixture(scope="module")
def authorino_parameters():
"""Optional parameters for Authorino creation, passed to the __init__"""
return {}


@pytest.fixture(scope="module")
def authorino(openshift, blame, request, testconfig, label, authorino_parameters) -> Authorino:
"""Module scoped Authorino instance, with specific parameters"""
authorino_config = testconfig["service_protection"]["authorino"]
if not authorino_config["deploy"]:
return pytest.skip("Can't change parameters of already deployed Authorino")

labels = authorino_parameters.setdefault("label_selectors", [])
labels.append(f"testRun={label}")

authorino_parameters.setdefault("name", blame("authorino"))

authorino = AuthorinoCR.create_instance(
openshift,
image=authorino_config.get("image"),
log_level=authorino_config.get("log_level"),
**authorino_parameters,
)
request.addfinalizer(authorino.delete)
authorino.commit()
authorino.wait_for_ready()
return authorino
6 changes: 3 additions & 3 deletions testsuite/tests/kuadrant/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


# pylint: disable=unused-argument
@pytest.fixture(scope="module")
@pytest.fixture(scope="session")
def authorino(kuadrant):
"""Authorino instance when configured through Kuadrant"""
if kuadrant:
Expand All @@ -24,10 +24,10 @@ def authorization_name(blame):


@pytest.fixture(scope="module")
def authorization(authorino, kuadrant, oidc_provider, route, authorization_name, openshift, module_label):
def authorization(kuadrant, oidc_provider, route, authorization_name, openshift, label):
"""Authorization object (In case of Kuadrant AuthPolicy)"""
if kuadrant:
return AuthPolicy.create_instance(openshift, authorization_name, route, labels={"testRun": module_label})
return AuthPolicy.create_instance(openshift, authorization_name, route, labels={"testRun": label})
return None


Expand Down

0 comments on commit 218f810

Please sign in to comment.