Skip to content

Commit

Permalink
Merge pull request #324 from mbaldessari/qe-fix
Browse files Browse the repository at this point in the history
Qe fix
  • Loading branch information
mlabonte-rh authored Dec 10, 2024
2 parents f963055 + 11ddfc3 commit 8545f15
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tests/interop/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +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

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
91 changes: 76 additions & 15 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,10 +20,40 @@
oc = os.environ["HOME"] + "/oc_client/oc"


# FIXME(bandini): For now we skip this test, we need to rewrite it so that the change pushed in git
# is done in the in-cluster gitea and not on the upstream repo. Otherwise the change will never be
# propagated
@pytest.mark.skip(reason="Need to push the changes to the in-cluster gitea")
# 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 @@ -76,21 +110,48 @@ def test_toggle_machine_sensor(openshift_dyn_client):
orig_content=orig_content,
new_content=new_content,
)
(gitea_user, gitea_pass, gitea_route) = get_gitea_info()
gitea_url = (
f"https://{gitea_user}:{gitea_pass}@{gitea_route}/{gitea_user}/industrial-edge"
)
logger.info(
f"Using the gitea user {gitea_user} on https://{gitea_route}/{gitea_user}/industrial-edge"
)
if gitea_pass == "" or gitea_user == "" or gitea_route == "":
err_msg = "gitea_pass or gitea_user or gitea_route were empty"
logger.error(f"FAIL: {err_msg}")
assert False, err_msg

logger.info("Merge the change")
if os.getenv("EXTERNAL_TEST") != "true":
subprocess.run(["git", "add", machine_sensor_file], cwd=patterns_repo)
subprocess.run(
["git", "commit", "-m", "Toggling SENSOR_TEMPERATURE_ENABLED"],
cwd=patterns_repo,
)
push = subprocess.run(
["git", "push"], cwd=patterns_repo, capture_output=True, text=True
)
cur_dir = patterns_repo
else:
subprocess.run(["git", "add", machine_sensor_file])
subprocess.run(["git", "commit", "-m", "Toggling SENSOR_TEMPERATURE_ENABLED"])
push = subprocess.run(["git", "push"], capture_output=True, text=True)
cur_dir = os.getcwd()

subprocess.run(
[
"git",
"-c",
"http.sslVerify=false",
"remote",
"add",
"gitea-qe",
"-f",
gitea_url,
],
cwd=cur_dir,
)
subprocess.run(["git", "add", machine_sensor_file], cwd=cur_dir)
subprocess.run(
["git", "commit", "-m", "Toggling SENSOR_TEMPERATURE_ENABLED"],
cwd=cur_dir,
)
push = subprocess.run(
["git", "-c", "http.sslVerify=false", "push", "gitea-qe"],
cwd=cur_dir,
capture_output=True,
text=True,
)
logger.info(push.stdout)
logger.info(push.stderr)

Expand Down

0 comments on commit 8545f15

Please sign in to comment.