Skip to content

Commit

Permalink
introduce kcp into testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Čáp committed Sep 20, 2022
1 parent c26cb2f commit 2de934b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
5 changes: 4 additions & 1 deletion config/settings.local.yaml.tpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#default:
# skip_cleanup: false
# openshift:
# openshift: # Required for kuadrant tests: if no further configuration needed pass an empty dict
# project: "kuadrant" # Optional: namespace for tests to run, if None uses current project
# api_url: "https://api.openshift.com" # Optional: OpenShift API URL, if None it will OpenShift that you are logged in
# token: "KUADRANT_RULEZ" # Optional: OpenShift Token, if None it will OpenShift that you are logged in
# openshift2:
# project: "kuadrant2" # Required: Secondary OpenShift project, for running tests across projects
# kcp: # Required for glbc tests: if no further configuration needed pass en empty dict
# namespace: "glbc-test" # Optional: namespace for tests to run, if None uses current namespace
# kubeconfig_path: "~/.kube/config" # Optional: kubeconfig to use for kcp if None default is used
# tools:
# project: "tools" # Optional: OpenShift project, where external tools are located
# rhsso:
Expand Down
1 change: 1 addition & 0 deletions config/settings.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
default:
skip_cleanup: false
dynaconf_merge: true
openshift: {}
tools:
project: "tools"
cfssl: "cfssl"
Expand Down
10 changes: 6 additions & 4 deletions testsuite/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def __init__(self, name, default, **kwargs) -> None:
**kwargs)


_openshift_validator = Validator("openshift", eq=None)

settings = Dynaconf(
environments=True,
lowercase_read=True,
Expand All @@ -28,10 +30,10 @@ def __init__(self, name, default, **kwargs) -> None:
envvar_prefix="KUADRANT",
merge_enabled=True,
validators=[
Validator("authorino.deploy", eq=True) | Validator("authorino.url", must_exist=True),
DefaultValueValidator("rhsso.url", must_exist=True, default=fetch_route("no-ssl-sso")),
DefaultValueValidator("rhsso.password",
must_exist=True, default=fetch_secret("credential-sso", "ADMIN_PASSWORD")),
_openshift_validator | Validator("authorino.url", must_exist=True),
_openshift_validator | DefaultValueValidator("rhsso.url", must_exist=True, default=fetch_route("no-ssl-sso")),
_openshift_validator | DefaultValueValidator("rhsso.password", must_exist=True,
default=fetch_secret("credential-sso", "ADMIN_PASSWORD")),
],
loaders=["testsuite.config.openshift_loader", "dynaconf.loaders.env_loader"]
)
27 changes: 20 additions & 7 deletions testsuite/config/openshift_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,32 @@
def load(obj, env=None, silent=True, key=None, filename=None):
"""Creates all OpenShift clients"""
config = weakget(obj)
section = config["openshift"]
client = OpenShiftClient(
section["project"] % None,
section["api_url"] % None,
section["token"] % None)
if "openshift" in obj:
section = config["openshift"]
client = OpenShiftClient(
section["project"] % None,
section["api_url"] % None,
section["token"] % None)
else:
client = None
obj["openshift"] = client

tools = None
if "tools" in obj and "project" in obj["tools"]:
if "tools" in obj and "project" in obj["tools"] and client:
tools = client.change_project(obj["tools"]["project"])
obj["tools"] = tools

openshift2 = None
if "openshift2" in obj and "project" in obj["openshift2"]:
if "openshift2" in obj and "project" in obj["openshift2"] and client:
openshift2 = client.change_project(obj["openshift2"]["project"])
obj["openshift2"] = openshift2

kcp = None
if "kcp" in obj and "namespace" in obj["kcp"]:
kcp_section = config["kcp"]
kcp = OpenShiftClient(
project=kcp_section["namespace"] % None,
kubeconfig_path=kcp_section["kubeconfig_path"] % None
)
kcp.is_ready = lambda _: True
obj["kcp"] = kcp
8 changes: 6 additions & 2 deletions testsuite/openshift/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ class OpenShiftClient:

# pylint: disable=too-many-public-methods

def __init__(self, project: str, api_url: str = None, token: str = None):
def __init__(self, project: str, api_url: str = None, token: str = None, kubeconfig_path: str = None):
self._project = project
self._api_url = api_url
self.token = token
self._kubeconfig_path = kubeconfig_path

def change_project(self, project):
"""Return new OpenShiftClient with a different project"""
return OpenShiftClient(project, self._api_url, self.token)
return OpenShiftClient(project, self._api_url, self.token, self._kubeconfig_path)

@cached_property
def context(self):
"""Prepare context for command execution"""
context = Context()

context.project_name = self._project
context.api_url = self._api_url
context.token = self.token
context.kubeconfig_path = self._kubeconfig_path

return context

@property
Expand Down
16 changes: 16 additions & 0 deletions testsuite/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def testconfig():
def openshift(testconfig):
"""OpenShift client for the primary namespace"""
client = testconfig["openshift"]
if client is None:
pytest.skip("Openshift required but was not configured")
if not client.connected:
pytest.fail("You are not logged into Openshift or the namespace doesn't exist")
return client
Expand All @@ -52,6 +54,20 @@ def openshift2(testconfig):
return client


@pytest.fixture(scope="session")
def kcp(testconfig):
"""Modified OpenShift client acting as Kcp client"""
client = testconfig["kcp"]
if client is None:
pytest.skip("Kcp required but was not configured")

# does not work for kcp yet
# if not client.connected:
# pytest.fail("You are not logged into Openshift or the namespace for Kcp doesn't exist")

return client


@pytest.fixture(scope="session")
def rhsso(request, testconfig, blame):
"""RHSSO OIDC Provider fixture"""
Expand Down

0 comments on commit 2de934b

Please sign in to comment.