forked from sclorg/ci-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_nightly_tests.sh
executable file
·144 lines (130 loc) · 4.57 KB
/
run_nightly_tests.sh
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
143
144
#!/bin/bash
set -x
LOGS_DIR="/home/fedora/logs"
[[ -z "$1" ]] && { echo "You have to specify target to build SCL images. c9s, c8s, rhel8, centos7, rhel7 or fedora" && exit 1 ; }
TARGET="$1"
shift
[[ -z "$1" ]] && { echo "You have to specify type of the test to run. test, test-openshift, test-openshift-4" && exit 1 ; }
TESTS="$1"
TMT_REPO="https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans"
TMT_BRANCH="master"
API_KEY="API_KEY_PRIVATE"
TFT_PLAN="nightly-container-$TARGET"
if [[ "$TARGET" == "rhel8" ]]; then
COMPOSE="RHEL-8-Updated"
elif [[ "$TARGET" == "rhel7" ]]; then
COMPOSE="RHEL-7-LatestUpdated"
elif [[ "$TARGET" == "rhel9" ]]; then
COMPOSE="RHEL-9.1.0-Nightly"
elif [[ "$TARGET" == "centos7" ]]; then
COMPOSE="CentOS-7-latest"
TMT_REPO="https://github.com/sclorg/sclorg-testing-farm"
TMT_BRANCH="main"
TFT_PLAN="nightly-container-centos-7"
elif [[ "$TARGET" == "fedora" ]]; then
COMPOSE="Fedora-36-Updated"
TMT_REPO="https://github.com/sclorg/sclorg-testing-farm"
TMT_BRANCH="main"
TFT_PLAN="nightly-container-f"
elif [[ "$TARGET" == "c9s" ]]; then
COMPOSE="CentOS-Stream-8"
TMT_REPO="https://github.com/sclorg/sclorg-testing-farm"
TMT_BRANCH="main"
TFT_PLAN="nightly-container-centos-stream-8"
elif [[ "$TARGET" == "c8s" ]]; then
COMPOSE="CentOS-Stream-8"
TMT_REPO="https://github.com/sclorg/sclorg-testing-farm"
TMT_BRANCH="main"
TFT_PLAN="nightly-container-centos-stream-8"
else
echo "This target is not supported"
exit 1
fi
if [[ "$TESTS" != "test" ]] && [[ "$TESTS" != "test-openshift" ]] && [[ "$TESTS" != "test-openshift-4" ]]; then
echo "This test scenario is not enabled."
exit 1
fi
JOB_JSON="job-${TARGET}-${TESTS}.json"
REQUEST_JSON="request-${TARGET}-${TESTS}.json"
RESPONSE_JSON="response-${TARGET}-${TESTS}.json"
cd /home/fedora || { echo "Could not switch to /home/fedora"; exit 1; }
if [[ ! -d "${LOGS_DIR}" ]]; then
mkdir -p "${LOGS_DIR}"
fi
LOG="${LOGS_DIR}/$TARGET-$TESTS.log"
date > "${LOG}"
curl -L https://url.corp.redhat.com/fmf-data > /tmp/fmf_data
source /tmp/fmf_data
echo "TARGET is: ${TARGET} and test is: ${TESTS}" | tee -a "${LOG}"
function final_report() {
echo "FINAL REPORT for ${REQ_ID}" | tee -a "${LOG}"
curl "$TF_ENDPOINT/requests/$REQ_ID" > "${JOB_JSON}"
cat "${JOB_JSON}" | tee -a "${LOG}"
state=$(jq -r .state "${JOB_JSON}")
result=$(jq -r .result.overall "${JOB_JSON}")
echo "STATE: $state" | tee -a "${LOG}"
echo "RESULT: $result" | tee -a "${LOG}"
new_state="success"
infra_error=" "
echo "State is $state and result is: $result"
if [ "$state" == "complete" ]; then
if [ "$result" != "passed" ]; then
new_state="failure"
fi
else
# Mark job in case of infrastructure issues. Report to Testing Farm team
infra_error=" - Infra problems"
new_state="failure"
fi
if [[ x"$new_state" == x"failure" ]]; then
curl "$TF_LOG/$REQ_ID/pipeline.log" > "${RESULT_DIR}/${TARGET}.log"
fi
echo "New State: $new_state" | tee -a "${LOG}"
echo "Infra state: $infra_error" | tee -a "${LOG}"
}
function schedule_testing_farm_request() {
echo "Schedule job for: $TARGET" | tee -a "${LOG}"
cat << EOF > "${REQUEST_JSON}"
{
"api_key": "${!API_KEY}",
"test": {"fmf": {
"url": "${TMT_REPO}",
"ref": "${TMT_BRANCH}",
"name": "${TFT_PLAN}"
}},
"environments": [{
"arch": "x86_64",
"os": {"compose": "$COMPOSE"},
"variables": {
"TEST": "$TESTS",
"OS": "$TARGET"
}}]
}
EOF
cat "${REQUEST_JSON}" | tee -a "${LOG}"
curl "$TF_ENDPOINT/requests" --data @${REQUEST_JSON} --header "Content-Type: application/json" --output "${RESPONSE_JSON}"
cat "${RESPONSE_JSON}" | tee -a "${LOG}"
REQ_ID=$(jq -r .id "${RESPONSE_JSON}")
echo "$REQ_ID" | tee -a "${LOG}"
}
function check_testing_farm_status() {
echo "Check state for $REQ_ID" | tee -a "${LOG}"
CMD="$TF_ENDPOINT/requests/$REQ_ID"
echo "Command for checking state is: ${CMD}" | tee -a "${LOG}"
curl $CMD > "${JOB_JSON}"
state=$(jq -r .state "${JOB_JSON}")
# Wait till job is not finished. As soon as state is complete or failure then go to the finish action
while [ "$state" == "running" ] || [ "$state" == "new" ] || [ "$state" == "pending" ] || [ "$state" == "queued" ]; do
# Wait 300s. We do not need to query Testing Farm each second
sleep 300
date | tee -a "${LOG}"
echo "${CMD}" | tee -a "${LOG}"
curl "$CMD" > "${JOB_JSON}"
cat "${JOB_JSON}" | tee -a "${LOG}"
state=$(jq -r .state "${JOB_JSON}")
echo "$state" | tee -a "${LOG}"
done
}
schedule_testing_farm_request
check_testing_farm_status
final_report