From 9bc0b159b8d09b2f29c36c7a53cfb73968788d07 Mon Sep 17 00:00:00 2001 From: mehabhalodiya Date: Wed, 27 Nov 2024 00:32:20 +0530 Subject: [PATCH] Add task for list_all_resources.sh Signed-off-by: mehabhalodiya --- reliability-v2/config/reliability.yaml | 3 ++ reliability-v2/tasks/Tasks.py | 2 +- .../tasks/script/list_all_resources.sh | 30 +++++++++---------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/reliability-v2/config/reliability.yaml b/reliability-v2/config/reliability.yaml index 99871c8d7a3..35b3e73759f 100644 --- a/reliability-v2/config/reliability.yaml +++ b/reliability-v2/config/reliability.yaml @@ -36,6 +36,7 @@ reliability: - func apply_nonamespace -p "/network-policy/02_anp_allow-traffic-egress-cidr-cluster-network-p20.yaml" - func apply_nonamespace -p "/network-policy/04_anp_allow-traffic-dev-test-p30.yaml" - func apply_nonamespace -p "/network-policy/03_anp_allow-traffic-dev-prod-p31.yaml" + - /list_all_resources.sh tasks: - func check_operators - oc get project -l purpose=reliability @@ -43,6 +44,8 @@ reliability: - kubectl get pods -A -o wide | egrep -v "Completed|Running" # Run test case as scripts. KUBECONFIG of the current user is set as env variable by reliability-v2. #- . /create-delete-pod-ensure-service.sh + post_tasks: + - /list_all_resources.sh - name: dev-test user_name: testuser- # if user_start and user_end exist, this will be username prefix diff --git a/reliability-v2/tasks/Tasks.py b/reliability-v2/tasks/Tasks.py index 350df2e7030..c8f3c0d0427 100644 --- a/reliability-v2/tasks/Tasks.py +++ b/reliability-v2/tasks/Tasks.py @@ -445,4 +445,4 @@ def check_netobserv_pods(self, user): else: self.logger.error(f"Pods status fetch error: result {result}, rc - {rc}") - return (result, rc_return) \ No newline at end of file + return (result, rc_return) diff --git a/reliability-v2/tasks/script/list_all_resources.sh b/reliability-v2/tasks/script/list_all_resources.sh index 3a0d199f057..4933a0135d1 100755 --- a/reliability-v2/tasks/script/list_all_resources.sh +++ b/reliability-v2/tasks/script/list_all_resources.sh @@ -76,7 +76,7 @@ get_all_items() { fi elapsed_time=$(($(date +%s) - start_time)) if [[ "$VERBOSE" == true ]]; then - echo "$this_type: ${elapsed_time}s" + echo "$this_type: ${elapsed_time}s" >> resource_list.log fi if [[ -n "$result" ]]; then for this_result in $result; do @@ -88,7 +88,7 @@ get_all_items() { done fi done - echo -e "${type_items[@]}" + echo -e "${type_items[@]}" >> resource_list.log } # Function to print items based on the output format @@ -97,32 +97,32 @@ print_items() { local output=${OUTPUT:-"list"} for this_type in "${all_items[@]}"; do if [[ "$output" == "list" ]]; then - echo -e "\n\n===============" - echo "TYPE: $this_type" - echo -e "${all_items[$this_type]}" - echo -e "\n\n===============" + echo -e "\n\n===============" >> resource_list.log + echo "TYPE: $this_type" >> resource_list.log + echo -e "${all_items[$this_type]}" >> resource_list.log + echo -e "\n\n===============" >> resource_list.log elif [[ "$output" == "ns-count" ]]; then declare -A ns_count for item in ${all_items[$this_type]}; do ns="${item%%:*}" ((ns_count["$ns"]++)) done - echo -e "\n\n===============" - echo "TYPE: $this_type" + echo -e "\n\n===============" >> resource_list.log + echo "TYPE: $this_type" >> resource_list.log for ns in "${!ns_count[@]}"; do - echo -e "\t$ns: ${ns_count[$ns]}" - echo -e "\n\n===============" + echo -e "\t$ns: ${ns_count[$ns]}" >> resource_list.log + echo -e "\n\n===============" >> resource_list.log done else count=0 - echo -e "\n\n===============" - echo "TYPE: $this_type" + echo -e "\n\n===============" >> resource_list.log + echo "TYPE: $this_type" >> resource_list.log for item in ${all_items[$this_type]}; do - echo "$item" + echo "$item" >> resource_list.log ((count++)) done - echo "$this_type Count: $count" - echo -e "\n\n===============" + echo "$this_type Count: $count" >> resource_list.log + echo -e "\n\n===============" >> resource_list.log fi