Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions tests/interop/test_subscription_status_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,10 @@ def test_subscription_status_edge(openshift_dyn_client):
"openshift-gitops-operator": ["openshift-operators"],
}

(
operator_versions,
missing_subs,
unhealthy_subs,
missing_installplans,
upgrades_pending,
) = subscription.subscription_status(openshift_dyn_client, expected_subs)

for line in operator_versions:
logger.info(line)

cluster_version = subscription.openshift_version(openshift_dyn_client)
logger.info(f"Openshift version:\n{cluster_version.instance.status.history}")

if missing_subs or unhealthy_subs or missing_installplans or upgrades_pending:
err_msg = "Subscription status check failed"
err_msg = subscription.subscription_status(
openshift_dyn_client, expected_subs, diff=False
)
if err_msg:
logger.error(f"FAIL: {err_msg}")
assert False, err_msg
else:
Expand Down
101 changes: 4 additions & 97 deletions tests/interop/test_subscription_status_hub.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import difflib
import logging
import os
import re
import subprocess

import pytest
from validatedpatterns_tests.interop import subscription
Expand All @@ -21,100 +17,11 @@ def test_subscription_status_hub(openshift_dyn_client):
"multicluster-engine": ["multicluster-engine"],
}

(
operator_versions,
missing_subs,
unhealthy_subs,
missing_installplans,
upgrades_pending,
) = subscription.subscription_status(openshift_dyn_client, expected_subs)

if missing_subs:
logger.error(f"FAIL: The following subscriptions are missing: {missing_subs}")
if unhealthy_subs:
logger.error(
f"FAIL: The following subscriptions are unhealthy: {unhealthy_subs}"
)
if missing_installplans:
logger.error(
f"FAIL: The install plan for the following subscriptions is missing: {missing_installplans}"
)
if upgrades_pending:
logger.error(
f"FAIL: The following subscriptions are in UpgradePending state: {upgrades_pending}"
)

cluster_version = subscription.openshift_version(openshift_dyn_client)
logger.info(f"Openshift version:\n{cluster_version.instance.status.history}")

if os.getenv("EXTERNAL_TEST") != "true":
shortversion = re.sub("(.[0-9]+$)", "", os.getenv("OPENSHIFT_VER"))
currentfile = os.getcwd() + "/operators_hub_current"
sourceFile = open(currentfile, "w")
for line in operator_versions:
logger.info(line)
print(line, file=sourceFile)
sourceFile.close()

logger.info("Clone operator-versions repo")
try:
operator_versions_repo = (
"git@gitlab.cee.redhat.com:mpqe/mps/vp/operator-versions.git"
)
clone = subprocess.run(
["git", "clone", operator_versions_repo], capture_output=True, text=True
)
logger.info(clone.stdout)
logger.info(clone.stderr)
except Exception:
pass

previouspath = os.getcwd() + f"/operator-versions/mcgitops_hub_{shortversion}"
previousfile = f"mcgitops_hub_{shortversion}"

logger.info("Ensure previous file exists")
checkpath = os.path.exists(previouspath)
logger.info(checkpath)

if checkpath is True:
logger.info("Diff current operator list with previous file")
diff = opdiff(open(previouspath).readlines(), open(currentfile).readlines())
diffstring = "".join(diff)
logger.info(diffstring)

logger.info("Write diff to file")
sourceFile = open("operator_diffs_hub.log", "w")
print(diffstring, file=sourceFile)
sourceFile.close()
else:
logger.info("Skipping operator diff - previous file not found")

if missing_subs or unhealthy_subs or missing_installplans or upgrades_pending:
err_msg = "Subscription status check failed"
err_msg = subscription.subscription_status(
openshift_dyn_client, expected_subs, diff=True
)
if err_msg:
logger.error(f"FAIL: {err_msg}")
assert False, err_msg
else:
# Only push the new operarator list if the test passed
# and we are not testing a pre-release operator nor
# running externally
if os.getenv("EXTERNAL_TEST") != "true":
if checkpath is True and not os.environ["INDEX_IMAGE"]:
os.remove(previouspath)
os.rename(currentfile, previouspath)

cwd = os.getcwd() + "/operator-versions"
logger.info(f"CWD: {cwd}")

logger.info("Push new operator list")
subprocess.run(["git", "add", previousfile], cwd=cwd)
subprocess.run(
["git", "commit", "-m", "Update operator versions list"],
cwd=cwd,
)
subprocess.run(["git", "push"], cwd=cwd)

logger.info("PASS: Subscription status check passed")


def opdiff(*args):
return filter(lambda x: not x.startswith(" "), difflib.ndiff(*args))
143 changes: 14 additions & 129 deletions tests/interop/test_validate_edge_site_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,14 @@
import os

import pytest
from ocp_resources.route import Route
from validatedpatterns_tests.interop import components
from validatedpatterns_tests.interop.crd import ArgoCD
from validatedpatterns_tests.interop.edge_util import (
get_long_live_bearer_token,
get_site_response,
)
from validatedpatterns_tests.interop import application, components

from . import __loggername__

logger = logging.getLogger(__loggername__)

oc = os.environ["HOME"] + "/oc_client/oc"

"""
Validate following multicloud-gitops components pods and endpoints on edge site (line server):

1) argocd
2) ACM agents
3) applications health (Applications deployed through argocd)
"""


@pytest.mark.test_validate_edge_site_components
def test_validate_edge_site_components():
Expand All @@ -35,150 +21,49 @@ def test_validate_edge_site_components():
@pytest.mark.validate_edge_site_reachable
def test_validate_edge_site_reachable(kube_config, openshift_dyn_client):
logger.info("Check if edge site API end point is reachable")
edge_api_url = kube_config.host
if not edge_api_url:
err_msg = "Edge site url is missing in kubeconfig file"
err_msg = components.validate_site_reachable(kube_config, openshift_dyn_client)
if err_msg:
logger.error(f"FAIL: {err_msg}")
assert False, err_msg
else:
logger.info(f"EDGE api url : {edge_api_url}")

bearer_token = get_long_live_bearer_token(
dyn_client=openshift_dyn_client,
namespace="openshift-gitops",
sub_string="argocd-dex-server-token",
)

if not bearer_token:
assert False, "Bearer token is missing for argocd-dex-server"
logger.info("PASS: Edge site is reachable")

edge_api_response = get_site_response(
site_url=edge_api_url, bearer_token=bearer_token
)

if edge_api_response.status_code != 200:
err_msg = "Edge site is not reachable. Please check the deployment."
@pytest.mark.validate_argocd_reachable_edge_site
def test_validate_argocd_reachable_edge_site(openshift_dyn_client):
logger.info("Check if argocd route/url on edge site is reachable")
err_msg = components.validate_argocd_reachable(openshift_dyn_client)
if err_msg:
logger.error(f"FAIL: {err_msg}")
assert False, err_msg
else:
logger.info("PASS: Edge site is reachable")
logger.info("PASS: Argocd is reachable")


@pytest.mark.check_pod_status_edge
def test_check_pod_status(openshift_dyn_client):
logger.info("Checking pod status")

err_msg = []
projects = [
"openshift-operators",
"open-cluster-management-agent",
"open-cluster-management-agent-addon",
"openshift-gitops",
]

missing_projects = components.check_project_absense(openshift_dyn_client, projects)
missing_pods = []
failed_pods = []

for project in projects:
missing_pods += components.check_pod_absence(openshift_dyn_client, project)
failed_pods += components.check_pod_status(openshift_dyn_client, project)

if missing_projects:
err_msg.append(f"The following namespaces are missing: {missing_projects}")

if missing_pods:
err_msg.append(
f"The following namespaces have no pods deployed: {missing_pods}"
)

if failed_pods:
err_msg.append(f"The following pods are failed: {failed_pods}")

err_msg = components.check_pod_status(openshift_dyn_client, projects)
if err_msg:
logger.error(f"FAIL: {err_msg}")
assert False, err_msg
else:
logger.info("PASS: Pod status check succeeded.")


@pytest.mark.validate_argocd_reachable_edge_site
def test_validate_argocd_reachable_edge_site(openshift_dyn_client):
namespace = "openshift-gitops"

try:
for route in Route.get(
dyn_client=openshift_dyn_client,
namespace=namespace,
name="openshift-gitops-server",
):
argocd_route_url = route.instance.spec.host
except StopIteration:
err_msg = f"Argocd url/route is missing in {namespace} namespace"
logger.error(f"FAIL: {err_msg}")
assert False, err_msg

logger.info("Check if argocd route/url on hub site is reachable")
if not argocd_route_url:
err_msg = f"Argocd url/route is missing in {namespace} namespace"
logger.error(f"FAIL: {err_msg}")
assert False, err_msg
else:
final_argocd_url = f"{'https://'}{argocd_route_url}"
logger.info(f"Argocd route/url : {final_argocd_url}")

bearer_token = get_long_live_bearer_token(
dyn_client=openshift_dyn_client,
namespace=namespace,
sub_string="argocd-dex-server-token",
)
if not bearer_token:
err_msg = "Bearer token is missing for argocd-dex-server"
logger.error(f"FAIL: {err_msg}")
assert False, err_msg
else:
logger.debug(f"Argocd bearer token : {bearer_token}")

argocd_route_response = get_site_response(
site_url=final_argocd_url, bearer_token=bearer_token
)

logger.info(f"Argocd route response : {argocd_route_response}")

if argocd_route_response.status_code != 200:
err_msg = "Argocd is not reachable. Please check the deployment."
logger.error(f"FAIL: {err_msg}")
assert False, err_msg
else:
logger.info("PASS: Argocd is reachable")


@pytest.mark.validate_argocd_applications_health_edge_site
def test_validate_argocd_applications_health_edge_site(openshift_dyn_client):
unhealthy_apps = []
logger.info("Get all applications deployed by argocd on edge site")
projects = ["openshift-gitops"]
for project in projects:
logger.info(f"PROJECT: {project}")
for app in ArgoCD.get(dyn_client=openshift_dyn_client, namespace=project):
app_name = app.instance.metadata.name
app_health = app.instance.status.health.status
app_sync = app.instance.status.sync.status

logger.info(f"Status for {app_name} : {app_health} : {app_sync}")

if "Healthy" != app_health or "Synced" != app_sync:
logger.info(f"Dumping failed resources for app: {app_name}")
unhealthy_apps.append(app_name)
try:
for res in app.instance.status.resources:
if (
res.health and res.health.status != "Healthy"
) or res.status != "Synced":
logger.info(f"\n{res}")
except TypeError:
logger.info(f"No resources found for app: {app_name}")

unhealthy_apps = application.get_argocd_application_status(
openshift_dyn_client, projects
)
if unhealthy_apps:
err_msg = "Some or all applications deployed on edge site are unhealthy"
logger.error(f"FAIL: {err_msg}:\n{unhealthy_apps}")
Expand Down
Loading