generated from validatedpatterns/multicloud-gitops
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
140 additions
and
1,033 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,2 @@ | ||
import os | ||
|
||
import pytest | ||
from kubernetes import config | ||
from kubernetes.client import Configuration | ||
from openshift.dynamic import DynamicClient | ||
|
||
from . import __loggername__ | ||
from .css_logger import CSS_Logger | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--kubeconfig", | ||
action="store", | ||
default=None, | ||
help="The full path to the kubeconfig file to be used", | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def get_kubeconfig(request): | ||
if request.config.getoption("--kubeconfig"): | ||
k8config = request.config.getoption("--kubeconfig") | ||
elif "KUBECONFIG" in os.environ.keys() and os.environ["KUBECONFIG"]: | ||
k8config = os.environ["KUBECONFIG"] | ||
else: | ||
raise ValueError( | ||
"A kubeconfig file was not provided. Please provide one either " | ||
"via the --kubeconfig command option or by setting a KUBECONFIG " | ||
"environment variable" | ||
) | ||
return k8config | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def kube_config(get_kubeconfig): | ||
kc = Configuration | ||
config.load_kube_config(config_file=get_kubeconfig, client_configuration=kc) | ||
return kc | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def openshift_dyn_client(get_kubeconfig): | ||
return DynamicClient(client=config.new_client_from_config(get_kubeconfig)) | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def setup_logger(): | ||
logger = CSS_Logger(__loggername__) | ||
return logger | ||
from validatedpatterns_tests.interop.conftest_logger import * # noqa: F401, F403 | ||
from validatedpatterns_tests.interop.conftest_openshift import * # noqa: F401, F403 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import json | ||
import os | ||
import subprocess | ||
from datetime import datetime | ||
|
||
from junitparser import JUnitXml | ||
|
||
oc = os.environ["HOME"] + "/oc_client/oc" | ||
|
||
ci_badge = { | ||
"schemaVersion": 1, | ||
"label": "Community test", | ||
"message": "", | ||
"color": "red", | ||
"openshiftVersion": "", | ||
"infraProvider": os.environ.get("INFRA_PROVIDER"), | ||
"patternName": os.environ.get("PATTERN_NAME"), | ||
"patternRepo": "", | ||
"patternBranch": "", | ||
"date": datetime.today().strftime("%Y-%m-%d"), | ||
"testSource": "Community", | ||
"debugInfo": None, | ||
} | ||
|
||
|
||
def get_openshift_version(): | ||
try: | ||
version_ret = subprocess.run([oc, "version", "-o", "json"], capture_output=True) | ||
version_out = version_ret.stdout.decode("utf-8") | ||
openshift_version = json.loads(version_out)["openshiftVersion"] | ||
major_minor = ".".join(openshift_version.split(".")[:-1]) | ||
return openshift_version, major_minor | ||
except KeyError as e: | ||
print("KeyError:" + str(e)) | ||
return None | ||
|
||
|
||
if __name__ == "__main__": | ||
versions = get_openshift_version() | ||
ci_badge["openshiftVersion"] = versions[0] | ||
|
||
pattern_repo = subprocess.run( | ||
["git", "config", "--get", "remote.origin.url"], capture_output=True, text=True | ||
) | ||
pattern_branch = subprocess.run( | ||
["git", "branch", "--show-current"], capture_output=True, text=True | ||
) | ||
|
||
ci_badge["patternRepo"] = pattern_repo.stdout.strip() | ||
ci_badge["patternBranch"] = pattern_branch.stdout.strip() | ||
|
||
# Check each xml file for failures | ||
results_dir = os.environ.get("WORKSPACE") | ||
failures = 0 | ||
|
||
for file in os.listdir(results_dir): | ||
if file.startswith("test_") and file.endswith(".xml"): | ||
with open(os.path.join(results_dir, file), "r") as result_file: # type: ignore | ||
xml = JUnitXml.fromfile(result_file) # type: ignore | ||
for suite in xml: | ||
for case in suite: | ||
if case.result: | ||
failures += 1 | ||
|
||
# Determine badge color from results | ||
if failures == 0: | ||
ci_badge["color"] = "green" | ||
|
||
# For now we assume `message` is the same as patternBranch | ||
ci_badge["message"] = ci_badge["patternBranch"] | ||
|
||
ci_badge_json_basename = ( | ||
os.environ.get("PATTERN_SHORTNAME") # type: ignore | ||
+ "-" | ||
+ os.environ.get("INFRA_PROVIDER") | ||
+ "-" | ||
+ versions[1] | ||
+ "-stable-badge.json" | ||
) | ||
ci_badge_json_filename = os.path.join(results_dir, ci_badge_json_basename) # type: ignore | ||
print(f"Creating CI badge file at: {ci_badge_json_filename}") | ||
|
||
with open(ci_badge_json_filename, "w") as ci_badge_file: | ||
json.dump(ci_badge, ci_badge_file) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.