This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
buildtestvms.sh
executable file
·123 lines (108 loc) · 3.56 KB
/
buildtestvms.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
#!/bin/bash
# Instruct Foreman to rebuild the test VMs
#
# e.g ${WORKSPACE}/scripts/buildtestvms.sh 'test'
#
# this will tell Foreman to rebuild all machines in hostgroup TESTVM_HOSTGROUP
# Load common parameter variables
. $(dirname "${0}")/common.sh
if [[ -z ${PUSH_USER} ]] || [[ -z ${SATELLITE} ]] || [[ -z ${RSA_ID} ]] \
|| [[ -z ${ORG} ]] || [[ -z ${TESTVM_HOSTCOLLECTION} ]]
then
err "Environment variable PUSH_USER, SATELLITE, RSA_ID, ORG " \
"or TESTVM_HOSTCOLLECTION not set or not found."
exit ${WORKSPACE_ERR}
fi
get_test_vm_list # populate TEST_VM_LIST
# TODO: Error out if no test VM's are available.
if [ $(echo ${#TEST_VM_LIST[@]}) -eq 0 ]; then
err "No test VMs configured in Satellite"
fi
# rebuild test VMs
for I in "${TEST_VM_LIST[@]}"
do
inform "Rebuilding VM ID $I"
ssh -q -l ${PUSH_USER} -i ${RSA_ID} ${SATELLITE} \
"hammer host update --id $I --build yes"
_PROBED_STATUS=$(ssh -q -l ${PUSH_USER} -i ${RSA_ID} ${SATELLITE} "hammer host status --id $I" | grep Power | cut -f2 -d: | tr -d ' ')
# different hypervisors report power status with different words. parse and get a single word per status
# KVM uses running / shutoff
# VMware uses poweredOn / poweredOff
# libvirt uses running / off
# add other hypervisors as you come across them and please submit to https://github.com/RedHatEMEA/soe-ci
case "${_PROBED_STATUS}" in
running)
_STATUS=On
;;
poweredOn)
_STATUS=On
;;
up)
_STATUS=On
;;
shutoff)
_STATUS=Off
;;
poweredOff)
_STATUS=Off
;;
down)
_STATUS=Off
;;
off)
_STATUS=Off
;;
*)
echo "can not parse power status, please review $0"
esac
if [[ ${_STATUS} == 'On' ]]
then
# forcefully poweroff the SUT
ssh -q -l ${PUSH_USER} -i ${RSA_ID} ${SATELLITE} \
"hammer host stop --force --id $I"
ssh -q -l ${PUSH_USER} -i ${RSA_ID} ${SATELLITE} \
"hammer host start --id $I"
elif [[ ${_STATUS} == 'Off' ]]
then
ssh -q -l ${PUSH_USER} -i ${RSA_ID} ${SATELLITE} \
"hammer host start --id $I"
else
err "Host $I is neither running nor shutoff. No action possible!"
exit 1
fi
done
# we need to wait until all the test machines have been rebuilt by foreman
# this check was previously only in pushtests, but when using pipelines
# it's more sensible to wait here while the machines are in build mode
# the ping and ssh checks must remain in pushtests.sh
# as a pupet only build will not call this script
declare -A vmcopy # declare an associative array to copy our VM array into
for I in "${TEST_VM_LIST[@]}"; do vmcopy[$I]=$I; done
WAIT=0
while [[ ${#vmcopy[@]} -gt 0 ]]
do
inform "Waiting 1 minute"
sleep 60
((WAIT+=60))
for I in "${vmcopy[@]}"
do
inform "Checking if host $I is in build mode."
status=$(ssh -q -l ${PUSH_USER} -i ${RSA_ID} ${SATELLITE} \
"hammer host info --name $I | \
grep -e \"Managed.*yes\" -e \"Enabled.*yes\" -e \"Build.*no\" \
| wc -l")
# Check if status is OK, then the SUT will have left build mode
if [[ ${status} == 3 ]]
then
tell "host $I no longer in build mode."
unset vmcopy[$I]
else
tell "host $I is still in build mode."
fi
done
if [[ ${WAIT} -gt 6000 ]]
then
err "At least one host still in build mode after 6000 seconds. Exiting."
exit 1
fi
done