Skip to content

Commit

Permalink
updated changes after testing02
Browse files Browse the repository at this point in the history
  • Loading branch information
Pankhuri-Rajesh committed Nov 20, 2024
1 parent 71cd606 commit d401691
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 15 deletions.
3 changes: 2 additions & 1 deletion constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
kubernetes==26.1.0
requests-oauthlib==0.8.0
4 changes: 2 additions & 2 deletions goss-testing/tests/ncn/goss-iuf-activity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }}
Expand All @@ -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 }}"
Expand Down
21 changes: 16 additions & 5 deletions goss-testing/tests/ncn/goss-iuf-workflowtemplates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
{{ $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:
{{ $testlabel := "iuf_worklfowtemplates" }}
{{$testlabel}}:
title: iuf worklfow-templates
meta:
desc: Executes few IUF workflowtemplates
desc: Executes two IUF workflowtemplates
sev: 0
exec: |-
"{{$logrun}}" -l "{{$testlabel}}" bash -c '
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/csm_testing/tests/iuf_apis/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down
26 changes: 26 additions & 0 deletions src/csm_testing/tests/iuf_cleanup/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/csm_testing/tests/iuf_stages/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 = (
Expand Down
1 change: 1 addition & 0 deletions src/csm_testing/tests/iuf_stages_cleanup/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .__main__ import get_nexus_credentials, get_ca_certificates
2 changes: 1 addition & 1 deletion src/csm_testing/tests/iuf_stages_cleanup/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d401691

Please sign in to comment.