From fbf8e05938b7ce58bf090a37d004760836548d88 Mon Sep 17 00:00:00 2001 From: Lianhao Lu Date: Tue, 20 Nov 2018 13:59:49 +0800 Subject: Added additional supporting scripts for s3p test clean_policy.sh: remove policies correspdoing to s3p csar files. list_failed_policy.sh: try to get failed policies from pdp in s3p test. Issue-ID: POLICY-837 Change-Id: I742437f740eee191875b25eccd03f00574bc0dcc Signed-off-by: Lianhao Lu --- s3p/clean_policy.sh | 41 +++++++++++++++++++++++++++++++++++++++ s3p/list_failed_policy.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100755 s3p/clean_policy.sh create mode 100755 s3p/list_failed_policy.sh (limited to 's3p') diff --git a/s3p/clean_policy.sh b/s3p/clean_policy.sh new file mode 100755 index 00000000..7b45ea8b --- /dev/null +++ b/s3p/clean_policy.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +function print_usage_and_exit { + [ -z "$1" ] || echo "Error: $1" + echo "Usage: $0 [ | ]" + echo " - directory where the s3p csar files stores, policies related to them will be cleaned from PDP/PAP" + echo " - rulename to be cleaned" + exit 1 +} + +[ "$#" -ne 1 ] && print_usage_and_exit + +rules=() +if [ -d $1 ]; then + files=(`find "$1" -maxdepth 1 -name "*.csar" -printf "%f\n"`) + for i in ${files[@]}; do + fn=`echo $i | cut -d '.' -f 1` + rules+=("oofCasablanca.Config_OOF_Optimization_${fn}.1.xml") + done +else + rules+=($1) +fi + +for NAME in ${rules[@]}; do + BODY="{\"policyComponent\":\"PDP\",\"policyType\":\"Optimization\",\"pdpGroup\":\"default\",\"policyName\":\"${NAME}\"}" + rescode=`curl --silent --output /dev/null --write-out %{http_code} -k -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'ClientAuth: cHl0aG9uOnRlc3Q=' -H 'Authorization: Basic dGVzdHBkcDphbHBoYTEyMw==' -H 'Environment: TEST' -X DELETE -d $BODY https://pdp:8081/pdp/api/deletePolicy` + if [ "$rescode" == "200" ]; then + echo "delete $NAME in PDP success" + else + echo "delete $NAME in PDP FAIL with rescode $rescode" + fi + + BODY="{\"policyName\":\"${NAME}\",\"policyComponent\":\"PAP\",\"policyType\":\"Optimization\",\"deleteCondition\":\"ALL\"}" + rescode=`curl --silent --output /dev/null --write-out %{http_code} -k -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'ClientAuth: cHl0aG9uOnRlc3Q=' -H 'Authorization: Basic dGVzdHBkcDphbHBoYTEyMw==' -H 'Environment: TEST' -X DELETE -d $BODY https://pdp:8081/pdp/api/deletePolicy` + if [ "$rescode" == "200" ]; then + echo "delete $NAME in PAP success" + else + echo "delete $NAME in PAP FAIL with rescode $rescode" + fi +done + diff --git a/s3p/list_failed_policy.sh b/s3p/list_failed_policy.sh new file mode 100755 index 00000000..042dcf34 --- /dev/null +++ b/s3p/list_failed_policy.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +function print_usage_and_exit { + echo "Usage: $0 " + echo " - : s for stability log , p for perf log , or other for simple policy name" + echo " - " + exit 1 +} + +[ "$#" -ne 2 ] && print_usage_and_exit +case $1 in +[sS]) + type='s' + ;; +[pP]) + type='p' + ;; +*) + type='simple' + ;; +esac + +rules=() +if [ -f $2 ] && [ $type == 's' ]; then + resids=(`grep -o "get policy failed for resource [0-9]\+" $2 | cut -d ' ' -f 6`) + for i in ${resids[@]}; do + rules+=("oofCasablanca.Config_OOF_Optimization_s3p_$i.*") + done +elif [ -f $2 ] && [ $type == 'p' ]; then + idx=`grep -o "Fail at idx [0-9]\+" $2 | cut -d ' ' -f 4` + total=`cat perf_data.csv | wc -l` + while [ "s$idx" > "s" ] && [ $idx -lt $total ]; do + rules+=("oofCasablanca.Config_OOF_Optimization_s3p_$idx.*") + idx=$((idx+1)) + done +else + rules+=($2) +fi + +for NAME in ${rules[@]}; do + BODY="{\"policyName\":\"${NAME}\"}" + rescode=`curl --silent --write-out %{http_code} -k -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'ClientAuth: cHl0aG9uOnRlc3Q=' -H 'Authorization: Basic dGVzdHBkcDphbHBoYTEyMw==' -H 'Environment: TEST' -X POST -d $BODY --output /dev/null https://pdp:8081/pdp/api/listConfig` + if [ "$rescode" == '200' ]; then + echo "list policy $NAME in PDP success" + else + echo "list policy $NAME in PDP FAIL with rescode $rescode" + fi +done + -- cgit 1.2.3-korg