-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunchTest.sh
More file actions
executable file
·142 lines (126 loc) · 3.86 KB
/
launchTest.sh
File metadata and controls
executable file
·142 lines (126 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
###Get CampaignName and Cerberus Host
while getopts a:h:c:k:t:u:d:C:E:R:T: flag
do
case "${flag}" in
a) AUTHOR=${OPTARG};;
h) HOST=${OPTARG};;
c) CAMPAIGN=${OPTARG};;
k) APIKEY=${OPTARG};;
t) TIMEOUT=${OPTARG};;
u) ITDUR=${OPTARG};;
d) DEBUG=" -v";;
C) set -f
IFS=,
COUNTRY=($OPTARG);;
E) set -f
IFS=,
ENVIRONMENT=($OPTARG);;
R) set -f
IFS=,
ROBOT=($OPTARG);;
T) TAG=${OPTARG};;
esac
done
EXTRA_ARGS=()
echo "Author: $AUTHOR";
echo "Cerberus Host: $HOST";
echo "Campaign Name: $CAMPAIGN";
#echo "Debug: $DEBUG";
###If Iteration Duration not provided, default to 3
if [[ "$ITDUR" == "" ]];
then
ITDUR=3;
fi
###If Timeout Iteration nb not provided, default to 300
if [[ "$TIMEOUT" != "" ]];
then
echo "Timeout: $TIMEOUT iterations of $ITDUR sec";
else
TIMEOUT=500;
echo "Timeout (default): $TIMEOUT iterations of $ITDUR sec";
fi
###Control host value
if [[ "$HOST" == "" ]];
then
echo "HOST not defined!!";
exit 1;
fi
if [[ "$COUNTRY" != "" ]]; then
echo "Override Country: ${COUNTRY[@]}";
for i in "${COUNTRY[@]}"; do
EXTRA_ARGS+=(-d "country=${i}")
done
fi
if [[ "$ENVIRONMENT" != "" ]]; then
echo "Override Environment: ${ENVIRONMENT[@]}";
for i in "${ENVIRONMENT[@]}"; do
EXTRA_ARGS+=(-d "environment=${i}")
done
fi
if [[ "$ROBOT" != "" ]]; then
echo "Override Robot: ${ROBOT[@]}";
for i in "${ROBOT[@]}"; do
EXTRA_ARGS+=(-d "robot=${i}")
done
fi
###If tag not provided, generate using Campaign Name, Commiter and UnixTimestamp
if [[ "$TAG" != "" ]];
then
echo "Override Tag: $TAG";
tag=$TAG
else
tag=$CAMPAIGN.$AUTHOR.$(date +%y%m%d-%H%M%S)
fi
EXTRA_ARGS+=(-d "tag=$tag")
###Run Campaign
echo "Trigger Campaign '$CAMPAIGN' to '$HOST/AddToExecutionQueueV003' with tag '$TAG'"
callTrigger=$(curl -s $DEBUG --request POST --url "$HOST/AddToExecutionQueueV003" -d campaign=$CAMPAIGN -d outputformat=json "${EXTRA_ARGS[@]}" -H "apikey:$APIKEY")
callTriggerRC=$(echo $callTrigger | jq -r '.messageType')
callTriggerMess=$(echo $callTrigger | jq -r '.message')
if [[ "$callTriggerRC" != "OK" ]]; then
echo "Could not trigger the campaign!!"
echo $callTriggerMess
exit 1
else
echo $callTriggerMess
fi
#echo $callTrigger
###Loop on resultCI Until end of campaign
num=1
while [ $num -le $TIMEOUT ]
do
sleep $ITDUR
## Get the tag result.
resultFull=$(curl -s $DEBUG --request POST --url "$HOST/ResultCIV004" -d tag=$tag -H "apikey:$APIKEY")
## Parsing call result
result=$(echo $resultFull | jq -r '.result')
resultMess=$(echo $resultFull | jq -r '.message')
resultTot=$(echo $resultFull | jq -r '.TOTAL_nbOfExecution')
resultQU=$(echo $resultFull | jq -r '.status_QU_nbOfExecution')
resultPE=$(echo $resultFull | jq -r '.status_PE_nbOfExecution')
resultOK=$(echo $resultFull | jq -r '.status_OK_nbOfExecution')
resultKO=$(echo $resultFull | jq -r '.status_KO_nbOfExecution')
resultFA=$(echo $resultFull | jq -r '.status_FA_nbOfExecution')
resultCIR=$(echo $resultFull | jq -r '.CI_finalResult')
resultCIT=$(echo $resultFull | jq -r '.CI_finalResultThreshold')
echo $(date +%y-%m-%d" "%H:%M:%S)" Check Campaign result ($num/$TIMEOUT) | QU:"$resultQU" PE:"$resultPE" | OK:"$resultOK" KO:"$resultKO" FA:"$resultFA
## Exit if result is no longuer pending
if [[ "$result" != "PE" ]]; then
break
fi
((num=num+1))
# echo "Campaign still running... Let's try again."
done
## Timeout reached!!!
if [[ $num -ge $TIMEOUT ]]; then
echo "Maximum iteration checks reached!!!"
exit 1
fi
## Result fail!!!
if [[ "$result" != "OK" ]]; then
echo "Campaign Failed. CIScore $resultCIR is above threshold $resultCIT!!!"
exit 1
fi
## Result OK
echo "Campaign Successful. Congratulation !!!"