From 70c3a3ddc8c43aa4caeebb950b7aced4b3445c83 Mon Sep 17 00:00:00 2001 From: Mark LaBonte Date: Fri, 6 Nov 2026 14:10:28 -0500 Subject: [PATCH 1/3] Add ci test for AAP login --- tests/ci/helpers.py | 88 ++++++++++++++++++++++++++++++++++++++++++++ tests/ci/test_hub.py | 88 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 tests/ci/helpers.py diff --git a/tests/ci/helpers.py b/tests/ci/helpers.py new file mode 100644 index 00000000..930cb78a --- /dev/null +++ b/tests/ci/helpers.py @@ -0,0 +1,88 @@ +import os + +import pytest +import requests +from ocp_resources.gateway_gateway_networking_k8s_io import Gateway +from ocp_resources.route import Route + + +def route_url(openshift_dyn_client, namespace, name): + """Return http(s) URL for a named OpenShift Route.""" + routes = [ + route + for route in Route.get( + dyn_client=openshift_dyn_client, namespace=namespace, name=name + ) + ] + + assert ( + len(routes) == 1 + ), f"Expected to find the route '{name}' in the namespace '{namespace}'" + + spec = routes[0].instance.spec + scheme = "https" if getattr(spec, "tls", None) else "http" + return f"{scheme}://{spec.host}" + + +def gateway_url(openshift_dyn_client, namespace, name): + """Return http(s) URL for a named Gateway API Gateway address.""" + gateways = [ + gateway + for gateway in Gateway.get( + dyn_client=openshift_dyn_client, namespace=namespace, name=name + ) + ] + + assert ( + len(gateways) == 1 + ), f"Expected to find the gateway '{name}' in the namespace '{namespace}'" + + instance = gateways[0].instance + addresses = getattr(instance.status, "addresses", None) or [] + assert addresses, ( + f"Expected gateway '{namespace}/{name}' to have at least one status address" + ) + + listeners = getattr(instance.spec, "listeners", None) or [] + scheme = "https" + if listeners and str(listeners[0].protocol).upper() == "HTTP": + scheme = "http" + + return f"{scheme}://{addresses[0].value}" + + +def assert_url_reachable(url, timeout=60): + response = requests.get(url, verify=False, timeout=timeout) + assert ( + response.status_code == 200 + ), f"Expected a 200 from '{url}' but got {response.status_code}" + + +def kubeadmin_password(): + """Return kubeadmin password from env or the file next to VP_HUBCONFIG.""" + password = os.getenv("KUBEADMIN_PASSWORD") or os.getenv("VP_KUBEADMIN") + if password: + return password.strip() + + kubeconfig = os.getenv("VP_HUBCONFIG") + if not kubeconfig: + pytest.fail( + "Set KUBEADMIN_PASSWORD or VP_HUBCONFIG (with a sibling admin-password file)" + ) + + candidates = [] + if kubeconfig.endswith("-kubeconfig"): + candidates.append(f"{kubeconfig[: -len('-kubeconfig')]}-admin-password") + candidates.append(os.path.join(os.path.dirname(kubeconfig), "kubeadmin-password")) + + for path in candidates: + if os.path.isfile(path): + with open(path, encoding="utf-8") as handle: + value = handle.read().strip() + if value: + return value + + pytest.fail( + "kubeadmin password not found; set KUBEADMIN_PASSWORD or place " + "-admin-password next to VP_HUBCONFIG" + ) diff --git a/tests/ci/test_hub.py b/tests/ci/test_hub.py index 47f8a5a2..eb460fb1 100644 --- a/tests/ci/test_hub.py +++ b/tests/ci/test_hub.py @@ -1,9 +1,33 @@ +import os +import re import pytest +import subprocess +from pathlib import Path from ocp_resources.virtual_machine import VirtualMachine from openshift.dynamic.exceptions import NotFoundError +from playwright.sync_api import Page, expect, sync_playwright from validatedpatterns_tests.interop import application, components, subscription +from .helpers import ( + kubeadmin_password, + route_url, +) + + +def _results_dir(): + path = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".results") + os.makedirs(path, exist_ok=True) + return path + + +def _openshift_login(page, url, password): + page.goto(url) + page.get_by_label("Username *").fill("kubeadmin") + page.get_by_label("Password *").fill(password) + page.get_by_role("button", name="Log in").click() + + @pytest.mark.parametrize( "openshift_dyn_client", ["VP_HUBCONFIG"], @@ -107,3 +131,67 @@ def test_vm_status_hub(openshift_dyn_client): errors.append(f"Unhealthy vms: {', '.join(unhealthy_vms)}") assert not errors, "VM status check failed:\n" + "\n".join(errors) + + +@pytest.mark.parametrize( + "openshift_dyn_client", + ["VP_HUBCONFIG"], + indirect=True, +) +def test_aap_login(openshift_dyn_client): + console_url = route_url(openshift_dyn_client, "openshift-console", "console") + secrets_url = console_url + "/k8s/ns/ansible-automation-platform/core~v1~Secret" + aap_url = route_url(openshift_dyn_client, "ansible-automation-platform", "aap") + password = kubeadmin_password() + results_dir = _results_dir() + + with sync_playwright() as playwright: + browser = playwright.chromium.launch(headless=True) + context = browser.new_context(ignore_https_errors=True) + context.grant_permissions(["clipboard-read", "clipboard-write"]) + context.set_default_timeout(120_000) + page = context.new_page() + try: + page.goto(secrets_url) + _openshift_login(page, secrets_url, password) + + page.wait_for_timeout(5000) + + # Dismiss welcome screen if visible + welcome = page.get_by_role("button", name="Close") + if welcome.is_visible(timeout=60): + welcome.click() + + page.locator('[data-test-id="aap-admin-password"]').click() + page.locator('[data-test="reveal-values"]').click() + page.get_by_role("button", name="Copy to clipboard").click() + + clip = page.evaluate("() => navigator.clipboard.readText()") + + page.goto(aap_url) + page.get_by_role("textbox", name="Username").fill("admin") + page.get_by_role("textbox", name="Password").click(button="right") + page.keyboard.press("ControlOrMeta+V") + page.get_by_role("button", name="Log in").click() + + page.get_by_test_id("platform-overview").click() + page.get_by_role("button", name="Settings").click() + page.get_by_test_id("platform-subscription-details").click() + + finally: + context.close() + browser.close() + + os.environ["KUBECONFIG"] = os.getenv("VP_HUBCONFIG", "") + + # Verify that the script returns the same password + result = subprocess.run( + ["bash", "../../pattern.sh", "../../scripts/ansible_get_credentials.sh"], + capture_output=True, + text=True, + check=False, + ) + + assert result.returncode == 0 + assert clip in result.stdout + assert result.stderr == "" From 59c702b7b71efb72eddf993e4e6ba1c7e6d78acd Mon Sep 17 00:00:00 2001 From: Mark LaBonte Date: Fri, 6 Nov 2026 14:37:39 -0500 Subject: [PATCH 2/3] Linting --- tests/ci/helpers.py | 6 +++--- tests/ci/test_hub.py | 9 ++------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/ci/helpers.py b/tests/ci/helpers.py index 930cb78a..328cce32 100644 --- a/tests/ci/helpers.py +++ b/tests/ci/helpers.py @@ -39,9 +39,9 @@ def gateway_url(openshift_dyn_client, namespace, name): instance = gateways[0].instance addresses = getattr(instance.status, "addresses", None) or [] - assert addresses, ( - f"Expected gateway '{namespace}/{name}' to have at least one status address" - ) + assert ( + addresses + ), f"Expected gateway '{namespace}/{name}' to have at least one status address" listeners = getattr(instance.spec, "listeners", None) or [] scheme = "https" diff --git a/tests/ci/test_hub.py b/tests/ci/test_hub.py index eb460fb1..2454f2fc 100644 --- a/tests/ci/test_hub.py +++ b/tests/ci/test_hub.py @@ -1,14 +1,10 @@ import os -import re -import pytest import subprocess -from pathlib import Path +import pytest from ocp_resources.virtual_machine import VirtualMachine from openshift.dynamic.exceptions import NotFoundError -from playwright.sync_api import Page, expect, sync_playwright +from playwright.sync_api import sync_playwright from validatedpatterns_tests.interop import application, components, subscription - - from .helpers import ( kubeadmin_password, route_url, @@ -143,7 +139,6 @@ def test_aap_login(openshift_dyn_client): secrets_url = console_url + "/k8s/ns/ansible-automation-platform/core~v1~Secret" aap_url = route_url(openshift_dyn_client, "ansible-automation-platform", "aap") password = kubeadmin_password() - results_dir = _results_dir() with sync_playwright() as playwright: browser = playwright.chromium.launch(headless=True) From d166463c804367e10a2cba3658fe2a1add0d487b Mon Sep 17 00:00:00 2001 From: Mark LaBonte Date: Fri, 6 Nov 2026 14:40:13 -0500 Subject: [PATCH 3/3] Linting --- tests/ci/test_hub.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/ci/test_hub.py b/tests/ci/test_hub.py index 2454f2fc..af8a1354 100644 --- a/tests/ci/test_hub.py +++ b/tests/ci/test_hub.py @@ -1,10 +1,12 @@ import os import subprocess + import pytest from ocp_resources.virtual_machine import VirtualMachine from openshift.dynamic.exceptions import NotFoundError from playwright.sync_api import sync_playwright from validatedpatterns_tests.interop import application, components, subscription + from .helpers import ( kubeadmin_password, route_url,