Skip to content

Commit

Permalink
Merge pull request #78 from pehala/tools2
Browse files Browse the repository at this point in the history
Add tools
  • Loading branch information
pehala authored Sep 7, 2022
2 parents 45923f2 + 5ba3eb6 commit c2e67f6
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 3 deletions.
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ This repository contains end-to-end tests for Kuadrant project. Currently, it on

## Requirements

To run the testsuite you currently need an OpenShift 4 cluster with Authorino Operator deployed and namespace where the tests will be executed.
To run the testsuite you currently need an OpenShift 4.x cluster with Authorino Operator deployed and namespace where the tests will be executed.

## Configuration

Kuadrant testsuite uses [Dynaconf](https://www.dynaconf.com/) for configuration, which means you can specify the configuration through either settings files in `config` directory or through environmental variables.
All the required and possible configuration options can be found in `config/settings.local.yaml.tpl`

### OpenShift auto-fetching

Some configuration options can be fetched from OpenShift if there are correctly deployed [tools](https://github.com/3scale-qe/tools).
Tools can be deployed by using `overlays/kuadrant` overlay and deploying RHSSO with the provided script like this:
```bash
oc apply -k overlays/kuadrant/ --namespace tools
NAMESPACE=tools ./base/rhsso/deploy-rhsso.sh
```

### Settings files

Settings files are located at `config` directory and are in `yaml` format. To use them for local development, you can create `settings.local.yaml` and put all settings there.
Expand Down Expand Up @@ -41,14 +50,29 @@ To run all tests you can then use ```make test```
### Running from container

For just running tests, the container image is the easiest option, you can log in to OpenShift and then run it like this

NOTE: For binding kubeconfig file, the "others" need to have permission to read, otherwise it will not work.
The results and reports will be saved in `/test-run-results` in the container.

#### With tools setup

```bash
podman run \
-v $HOME/.kube/config:/run/kubeconfig:z \
-e KUADRANT_OPENSHIFT__project=authorino \
-e KUADRANT_OPENSHIFT2__project=authorino2 \
quay.io/kuadrant/testsuite:latest
```

#### Without tools

```bash
podman run \
-v $HOME/.kube/config:/run/kubeconfig:z \
-e KUADRANT_OPENSHIFT__project=authorino \
-e KUADRANT_OPENSHIFT2__project=authorino2 \
-e KUADRANT_RHSSO__url="https://my-sso.net" \
-e KUADRANT_RHSSO__password="ADMIN_PASSWORD" \
-e KUADRANT_RHSSO__username="ADMIN_USERNAME" \
quay.io/kuadrant/testsuite:latest
```
NOTE: For binding kubeconfig file, the "others" need to have permission to read, otherwise it will not work.
The results and reports will be saved in `/test-run-results` in the container.
2 changes: 2 additions & 0 deletions config/settings.local.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# 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
# tools:
# project: "tools" # Optional: OpenShift project, where external tools are located
# rhsso:
# url: "SSO_URL"
# username: "SSO_ADMIN_USERNAME"
Expand Down
2 changes: 2 additions & 0 deletions config/settings.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
default:
skip_cleanup: false
dynaconf_merge: true
tools:
project: "tools"
cfssl: "cfssl"
rhsso:
username: "admin"
Expand Down
22 changes: 22 additions & 0 deletions testsuite/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
"""Module which initializes Dynaconf"""

from dynaconf import Dynaconf, Validator

from testsuite.config.tools import fetch_route, fetch_secret


# pylint: disable=too-few-public-methods
class DefaultValueValidator(Validator):
"""Validator which will run default function only when the original value is missing"""

def __init__(self, name, default, **kwargs) -> None:
super().__init__(name, ne=None,
messages={
"operations": ("{name} must {operation} {op_value} but it is {value} in env {env}. "
"You might be missing tools on the cluster.")
},
default=default,
when=Validator(name, must_exist=False),
**kwargs)


settings = Dynaconf(
environments=True,
lowercase_read=True,
Expand All @@ -10,6 +29,9 @@
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")),
],
loaders=["testsuite.config.openshift_loader", "dynaconf.loaders.env_loader"]
)
5 changes: 5 additions & 0 deletions testsuite/config/openshift_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ def load(obj, env=None, silent=True, key=None, filename=None):
section["token"] % None)
obj["openshift"] = client

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

openshift2 = None
if "openshift2" in obj and "project" in obj["openshift2"]:
openshift2 = client.change_project(obj["openshift2"]["project"])
Expand Down
33 changes: 33 additions & 0 deletions testsuite/config/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Dynaconf loader for fetching data from tools namespace"""
import logging

logger = logging.getLogger(__name__)


def fetch_route(name):
"""Fetches the URL of a route with specific name"""
def _fetcher(settings, _):
try:
openshift = settings["tools"]
route = openshift.routes[name]
if "tls" in route.model.spec:
return "https://" + route.model.spec.host
return "http://" + route.model.spec.host
# pylint: disable=broad-except
except Exception:
logger.warning("Unable to fetch route %s from tools", name)
return None
return _fetcher


def fetch_secret(name, key):
"""Fetches the key out of a secret with specific name"""
def _fetcher(settings, _):
try:
openshift = settings["tools"]
return openshift.secrets[name][key]
# pylint: disable=broad-except
except Exception:
logger.warning("Unable to fetch secret %s[%s] from tools", name, key)
return None
return _fetcher

0 comments on commit c2e67f6

Please sign in to comment.