Skip to content

Commit

Permalink
Fetch gitea info from inside the test
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaldessari committed Dec 9, 2024
1 parent 11622de commit 11ddfc3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
6 changes: 1 addition & 5 deletions tests/interop/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ pytest -lv --disable-warnings test_check_logging_hub.py --kubeconfig $KUBECONFIG

KUBECONFIG=$KUBECONFIG_EDGE pytest -lv --disable-warnings test_check_logging_edge.py --kubeconfig $KUBECONFIG_EDGE --junit-xml $WORKSPACE/test_check_logging_edge.xml

# We need a few things from the hub cluster before working on the edge cluster
export GITEA_PASS=$(oc --kubeconfig $KUBECONFIG extract -n vp-gitea secret/gitea-admin-secret --to=- --keys=password 2>/dev/null)
export GITEA_USER=$(oc --kubeconfig $KUBECONFIG extract -n vp-gitea secret/gitea-admin-secret --to=- --keys=username 2>/dev/null)
export GITEA_ROUTE=$(oc --kubeconfig $KUBECONFIG get routes -n vp-gitea gitea-route -o jsonpath='{.spec.host}')
KUBECONFIG=$KUBECONFIG_EDGE pytest -lv --disable-warnings test_toggle_machine_sensor.py --kubeconfig $KUBECONFIG_EDGE --junit-xml $WORKSPACE/test_toggle_machine_sensor.xml
KUBECONFIG_HUB=$KUBECONFIG KUBECONFIG=$KUBECONFIG_EDGE pytest -lv --disable-warnings test_toggle_machine_sensor.py --kubeconfig $KUBECONFIG_EDGE --junit-xml $WORKSPACE/test_toggle_machine_sensor.xml

pytest -lv --disable-warnings test_pipeline_build_check.py --kubeconfig $KUBECONFIG --junit-xml $WORKSPACE/test_pipeline_build_check.xml

Expand Down
42 changes: 39 additions & 3 deletions tests/interop/test_toggle_machine_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import subprocess
import time

import kubernetes
import pytest
from ocp_resources.config_map import ConfigMap
from ocp_resources.route import Route
from ocp_resources.secret import Secret
from openshift.dynamic import DynamicClient
from openshift.dynamic.exceptions import NotFoundError
from validatedpatterns_tests.interop.edge_util import modify_file_content

Expand All @@ -16,6 +20,40 @@
oc = os.environ["HOME"] + "/oc_client/oc"


# returns (user, pass, route) tuple
def get_gitea_info():
kubefile = os.getenv("KUBECONFIG_HUB")
kexp = os.path.expandvars(kubefile)
ocp_hub = DynamicClient(
client=kubernetes.config.new_client_from_config(config_file=kexp)
)
logger.info("Getting HUB gitea info")
try:
gitea_secret_obj = Secret.get(
dyn_client=ocp_hub, namespace="vp-gitea", name="gitea-admin-secret"
)
gitea_secret = next(gitea_secret_obj)
except NotFoundError:
err_msg = "The gitea-admin-secret was not found in ns vp-gitea"
logger.error(f"FAIL: {err_msg}")
assert False, err_msg
username = gitea_secret.instance.data.username
password = gitea_secret.instance.data.password

try:
gitea_route_obj = Route.get(
dyn_client=ocp_hub, namespace="vp-gitea", name="gitea-route"
)
gitea_route = next(gitea_route_obj)
except NotFoundError:
err_msg = "The gitea-route was not found in ns vp-gitea"
logger.error(f"FAIL: {err_msg}")
assert False, err_msg
route = gitea_route.instance.spec.host

return (username, password, route)


@pytest.mark.toggle_machine_sensor
def test_toggle_machine_sensor(openshift_dyn_client):
logger.info("Testing machine-sensor config change")
Expand Down Expand Up @@ -72,9 +110,7 @@ def test_toggle_machine_sensor(openshift_dyn_client):
orig_content=orig_content,
new_content=new_content,
)
gitea_pass = os.getenv("GITEA_PASS")
gitea_user = os.getenv("GITEA_USER")
gitea_route = os.getenv("GITEA_ROUTE")
(gitea_user, gitea_pass, gitea_route) = get_gitea_info()
gitea_url = (
f"https://{gitea_user}:{gitea_pass}@{gitea_route}/{gitea_user}/industrial-edge"
)
Expand Down

0 comments on commit 11ddfc3

Please sign in to comment.