From d401691f934cf83119dc9704787de5a33930dbf6 Mon Sep 17 00:00:00 2001 From: Pankhuri-Rajesh Date: Wed, 20 Nov 2024 15:24:23 +0530 Subject: [PATCH] updated changes after testing02 --- constraints.txt | 3 ++- .../workflows/iuf_base_workflow.yaml | 0 .../workflows/update_cpc_workflow.yaml | 0 .../workflowtemplates/iuf_base_template.yaml | 0 .../update_product_catalog_template.yaml | 0 goss-testing/tests/ncn/goss-iuf-activity.yaml | 4 +-- .../tests/ncn/goss-iuf-workflowtemplates.yaml | 21 +++++++++++---- requirements.txt | 1 + src/csm_testing/tests/iuf_apis/__main__.py | 6 ++--- src/csm_testing/tests/iuf_cleanup/__main__.py | 26 +++++++++++++++++++ src/csm_testing/tests/iuf_stages/__main__.py | 6 ++--- .../tests/iuf_stages_cleanup/__init__.py | 1 + .../tests/iuf_stages_cleanup/__main__.py | 2 +- 13 files changed, 55 insertions(+), 15 deletions(-) rename goss-testing/{tests/ncn => scripts}/workflows/iuf_base_workflow.yaml (100%) rename goss-testing/{tests/ncn => scripts}/workflows/update_cpc_workflow.yaml (100%) rename goss-testing/{tests/ncn => scripts}/workflowtemplates/iuf_base_template.yaml (100%) rename goss-testing/{tests/ncn => scripts}/workflowtemplates/update_product_catalog_template.yaml (100%) diff --git a/constraints.txt b/constraints.txt index b4e1513e..be21f148 100644 --- a/constraints.txt +++ b/constraints.txt @@ -5,4 +5,5 @@ PyYAML>=6.0.1,<6.1 # to avoid version conflicts requests==2.25.1 requests-retry-session>=0.1,<0.2 -kubernetes==26.1.0 \ No newline at end of file +kubernetes==26.1.0 +requests-oauthlib==0.8.0 \ No newline at end of file diff --git a/goss-testing/tests/ncn/workflows/iuf_base_workflow.yaml b/goss-testing/scripts/workflows/iuf_base_workflow.yaml similarity index 100% rename from goss-testing/tests/ncn/workflows/iuf_base_workflow.yaml rename to goss-testing/scripts/workflows/iuf_base_workflow.yaml diff --git a/goss-testing/tests/ncn/workflows/update_cpc_workflow.yaml b/goss-testing/scripts/workflows/update_cpc_workflow.yaml similarity index 100% rename from goss-testing/tests/ncn/workflows/update_cpc_workflow.yaml rename to goss-testing/scripts/workflows/update_cpc_workflow.yaml diff --git a/goss-testing/tests/ncn/workflowtemplates/iuf_base_template.yaml b/goss-testing/scripts/workflowtemplates/iuf_base_template.yaml similarity index 100% rename from goss-testing/tests/ncn/workflowtemplates/iuf_base_template.yaml rename to goss-testing/scripts/workflowtemplates/iuf_base_template.yaml diff --git a/goss-testing/tests/ncn/workflowtemplates/update_product_catalog_template.yaml b/goss-testing/scripts/workflowtemplates/update_product_catalog_template.yaml similarity index 100% rename from goss-testing/tests/ncn/workflowtemplates/update_product_catalog_template.yaml rename to goss-testing/scripts/workflowtemplates/update_product_catalog_template.yaml diff --git a/goss-testing/tests/ncn/goss-iuf-activity.yaml b/goss-testing/tests/ncn/goss-iuf-activity.yaml index 139d0465..3159421d 100644 --- a/goss-testing/tests/ncn/goss-iuf-activity.yaml +++ b/goss-testing/tests/ncn/goss-iuf-activity.yaml @@ -29,7 +29,7 @@ {{ $logrun := .Env.GOSS_BASE | printf "%s/scripts/log_run.sh" }} {{ $iuf_pre_checks := $scripts | printf "%s/python/iuf_pre_checks" }} {{ $iuf_run := $scripts | printf "%s/python/iuf_run" }} -{{ $iuf_post_checks := $scripts | printf "%s/python/iuf_post_checks.py" }} +{{ $iuf_post_checks := $scripts | printf "%s/python/iuf_post_checks" }} {{ $iuf_cleanup := $scripts | printf "%s/python/iuf_cleanup" }} command: {{ $testlabel := "iuf_activity" }} @@ -53,7 +53,7 @@ command: run_exit_code=$? # Run post-checks for IUF - "{{$iuf_post_checks}}" "{{ index $activity 0 }}"" + "{{$iuf_post_checks}}" "{{ index $activity 0 }}" # Run cleanup step independently "{{$iuf_cleanup}}" "{{ index $activity 0 }}" diff --git a/goss-testing/tests/ncn/goss-iuf-workflowtemplates.yaml b/goss-testing/tests/ncn/goss-iuf-workflowtemplates.yaml index a8c9827c..e38c1322 100644 --- a/goss-testing/tests/ncn/goss-iuf-workflowtemplates.yaml +++ b/goss-testing/tests/ncn/goss-iuf-workflowtemplates.yaml @@ -27,8 +27,8 @@ {{ $scripts := .Env.GOSS_BASE | printf "%s/scripts" }} {{ $logrun := .Env.GOSS_BASE | printf "%s/scripts/log_run.sh" }} {{ $iuf_pre_checks := $scripts | printf "%s/python/iuf_pre_checks" }} -{{ $workflows_dir := "/opt/cray/tests/install/iuf/workflows" }} -{{ $workflowtemplates_dir := "/opt/cray/tests/install/iuf/workflowtemplates" }} +{{ $workflows_dir := .Env.GOSS_BASE | printf "%s/scripts/workflows" }} +{{ $workflowtemplates_dir := .Env.GOSS_BASE | printf "%s/scripts/workflowtemplates" }} {{ $check_workflows := $scripts | printf "%s/python/check_workflow_template" }} command: @@ -36,7 +36,7 @@ command: {{$testlabel}}: title: iuf worklfow-templates meta: - desc: Executes few IUF workflowtemplates + desc: Executes two IUF workflowtemplates sev: 0 exec: |- "{{$logrun}}" -l "{{$testlabel}}" bash -c ' @@ -50,14 +50,25 @@ command: sed "s/namespace: services/namespace: auto/" | kubectl apply -n auto -f - && \ # TEST CASE: Run IUF CPC template - "{{$check_workflows}}" "{{$workflowtemplates_dir}}/update_product_catalog_template.yaml" "{{$workflows_dir}}/update_cpc_workflow.yaml {{ index $template_images 0 }}" && \ + "{{$check_workflows}}" "{{$workflowtemplates_dir}}/update_product_catalog_template.yaml" "{{$workflows_dir}}/update_cpc_workflow.yaml" "{{ index $template_images 0 }}" && \ + + # Capture the exit code of the previous step + run_exit_code_1=$? # TEST CASE: Run iuf base template - "{{$check_workflows}}" "{{$workflowtemplates_dir}}/iuf_base_template.yaml" "{{$workflows_dir}}/iuf_base_workflow.yaml {{ index $template_images 1 }}" + "{{$check_workflows}}" "{{$workflowtemplates_dir}}/iuf_base_template.yaml" "{{$workflows_dir}}/iuf_base_workflow.yaml" "{{ index $template_images 1 }}" + + # Capture the exit code of the previous step + run_exit_code_2=$? # Cleanup: Delete the configmap and namespace kubectl delete configmap cray-product-catalog-test -n auto && \ kubectl delete namespace auto + + # Exit with code 1 if test case failed with exit code 1 + if [ $run_exit_code_1 -eq 1 ] || [ $run_exit_code_2 -eq 1 ]; then + exit 1 + fi ' exit-status: 0 timeout: 1800000 diff --git a/requirements.txt b/requirements.txt index bf59b442..2ade4903 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,7 @@ cray-product-catalog PyYAML requests-retry-session python-keycloak +requests-oauthlib # There are some additional Python packages that test scripts can rely on that are # not listed above. This is because they are listed as requirements in the csm-testing diff --git a/src/csm_testing/tests/iuf_apis/__main__.py b/src/csm_testing/tests/iuf_apis/__main__.py index d892b84a..bcb28001 100644 --- a/src/csm_testing/tests/iuf_apis/__main__.py +++ b/src/csm_testing/tests/iuf_apis/__main__.py @@ -41,6 +41,9 @@ MEDIA_DIR = "/etc/cray/upgrade/csm/automation-tests" tar_dir = "/opt/cray/tests/install/ncn/scripts/iuf_run_setup" +count = 0 +total_count = 15 + class AuthException(Exception): """A wrapper for raising an AuthException exception.""" pass @@ -772,9 +775,6 @@ def main(): print(f"ERROR: Failed copying files: {e}") sys.exit(1) - - count = 0 - total_count = 15 activity = sys.argv[1] print("INFO: This is the activity: {}".format(activity)) diff --git a/src/csm_testing/tests/iuf_cleanup/__main__.py b/src/csm_testing/tests/iuf_cleanup/__main__.py index 44594ac7..3efb248d 100644 --- a/src/csm_testing/tests/iuf_cleanup/__main__.py +++ b/src/csm_testing/tests/iuf_cleanup/__main__.py @@ -44,6 +44,17 @@ def get_workflows(activity_name): return e.returncode return workflows +def get_configmaps(activity_name): + command = f"kubectl get configmap -n argo -o custom-columns=NAME:.metadata.name|grep {activity_name}" + configmaps=[] + try: + result = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + if not result.returncode: + configmaps=result.stdout.splitlines() + except subprocess.CalledProcessError as e: + return e.returncode + return configmaps + def cleanup(activity_name = "test-activity"): command_delete_logs = f"rm -r {LOG_DIR}/{activity_name}" command_delete_media_dir = f"rm -r {MEDIA_DIR}" @@ -73,6 +84,21 @@ def cleanup(activity_name = "test-activity"): print("INFO: Command output:", result.stdout) except Exception as e : print(f"ERROR: Unable to delete workflow {workflow} , {e}") + else: + print(f"WARNING: Workflows not found for {activity_name}") + sys.exit(1) + + # Deleting configmaps for the activity + configmaps = get_configmaps(activity_name) + if isinstance(configmaps, list) and all(isinstance(cm, str) for cm in configmaps) : + print(f"INFO: configmaps found for {activity_name} :{configmaps}") + for configmap in configmaps: + command_delete_configmap = f"kubectl delete workflow {configmap} -n argo" + try : + result = subprocess.run(command_delete_configmap, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + print("INFO: Command output:", result.stdout) + except Exception as e : + print(f"ERROR: Unable to delete configmap {configmap} , {e}") else: print(f"WARNING: Workflows not found for {activity_name}") sys.exit(1) diff --git a/src/csm_testing/tests/iuf_stages/__main__.py b/src/csm_testing/tests/iuf_stages/__main__.py index 4a6d9a56..1d3fb1c7 100644 --- a/src/csm_testing/tests/iuf_stages/__main__.py +++ b/src/csm_testing/tests/iuf_stages/__main__.py @@ -32,14 +32,14 @@ import requests from requests.auth import HTTPBasicAuth import json -from iuf_stages_cleanup import get_nexus_credentials, get_ca_certificates +from csm_testing.tests.iuf_stages_cleanup import get_nexus_credentials, get_ca_certificates MEDIA_DIR = "/etc/cray/upgrade/csm/automation-tests" PRODUCT_CATALOG_CONFIG_MAP_NAMESPACE='services' from cray_product_catalog.query import * -IMAGE = "registry.local/artifactory.algol60.net/csm-docker/stable/product-deletion-utility:1.0.0" +IMAGE = "registry.local/artifactory.algol60.net/csm-docker/stable/product-deletion-utility:1.0.1" NAMESPACE = "services" CONFIGMAP_NAME = "cray-product-catalog" PRODUCT_NAME = "dummy" @@ -333,7 +333,7 @@ def update_cfs_config(ACTIVITY_NAME): def prepare_images(ACTIVITY_NAME): global test_cases try: - command = f"iuf -a {ACTIVITY_NAME} -m {MEDIA_DIR} run -rv {MEDIA_DIR}/product_vars.yaml -bm {MEDIA_DIR}/management-bootprep.yaml -r prepare_images" + command = f"iuf -a {ACTIVITY_NAME} -m {MEDIA_DIR} run -rv {MEDIA_DIR}/product_vars.yaml -bm {MEDIA_DIR}/management-bootprep.yaml -r prepare-images" run_command(command) kubectl_command = ( diff --git a/src/csm_testing/tests/iuf_stages_cleanup/__init__.py b/src/csm_testing/tests/iuf_stages_cleanup/__init__.py index e69de29b..34d32379 100644 --- a/src/csm_testing/tests/iuf_stages_cleanup/__init__.py +++ b/src/csm_testing/tests/iuf_stages_cleanup/__init__.py @@ -0,0 +1 @@ +from .__main__ import get_nexus_credentials, get_ca_certificates \ No newline at end of file diff --git a/src/csm_testing/tests/iuf_stages_cleanup/__main__.py b/src/csm_testing/tests/iuf_stages_cleanup/__main__.py index 34f54bc9..88737dac 100644 --- a/src/csm_testing/tests/iuf_stages_cleanup/__main__.py +++ b/src/csm_testing/tests/iuf_stages_cleanup/__main__.py @@ -33,7 +33,7 @@ from kubernetes import client, config import sys -IMAGE = "registry.local/artifactory.algol60.net/csm-docker/stable/product-deletion-utility:1.0.0" +IMAGE = "registry.local/artifactory.algol60.net/csm-docker/stable/product-deletion-utility:1.0.1" NAMESPACE = "services" CONFIGMAP_NAME = "cray-product-catalog" PRODUCT_NAME = "dummy"