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
/
Copy pathstarttestvms.sh
executable file
·79 lines (69 loc) · 2.16 KB
/
starttestvms.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
#!/bin/bash
# Instruct Foreman to start the test VMs (just in case they are off)
#
# e.g ${WORKSPACE}/scripts/starttestvms.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 "Making sure VM ID $I is on"
_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
# 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
inform "Host $I is already on."
elif [[ ${_STATUS} == 'Off' ]]
then
inform "Host $I is already off, switching it on."
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 0 while testingi for issue #50,
# allows for manual rebooting of the test VM(s)
exit 0
fi
done