-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestpackstack_rhel7_4systems.sh
executable file
·262 lines (225 loc) · 5.7 KB
/
testpackstack_rhel7_4systems.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/bash
# Set the following configuration options according to your environment
TEMPLATE_VM=rhel7-base
VM_FOLDER=/home/jpena/VMs
# Change this variable if you want to test any specific Packstack option
PACKSTACK_DEFAULT_OPTIONS="--debug"
usage()
{
echo "testpackstack_rhel7_4systems.sh <RHSM user> <RHSM passwd>"
}
clone_vm()
{
UUID=$(openssl rand -hex 6)
sudo virt-clone -o ${TEMPLATE_VM} -n rhel7-${UUID} -f ${VM_FOLDER}/rhel7-${UUID}.qcow2
if [ $? -ne 0 ]
then
echo "Error cloning $1 VM. Stopping"
exit 3
fi
return 0
}
start_vm()
{
sudo virsh start rhel7-$1
if [ $? -ne 0 ]
then
echo "Error starting $2 VM. Stopping"
exit 4
fi
}
get_vm_ip()
{
VMMAC=""
while [ "x$VMMAC" == "x" ]
do
VMMAC=$(sudo virsh dumpxml rhel7-$1 | grep "mac address" | awk -F\' '{print $2}')
if [ "x$VMMAC" == "x" ]
then
echo "MAC not found yet, sleeping..."
sleep 5
fi
done
VMIP=""
while [ "x$VMIP" == "x" ]
do
VMIP=$(arp -an | grep $VMMAC | awk '{print $2}' | tr -d \( | tr -d \))
if [ "x$VMIP" == "x" ]
then
echo "IP not found yet, sleeping..."
sleep 5
else
echo "VM booted with IP " $VMIP
fi
done
}
rhnreg_vm()
{
vmIP=$1
SSHOK=0
while [ ${SSHOK} -eq 0 ]
do
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@${vmIP} ls /root > /dev/null
if [ $? -eq 0 ]
then
SSHOK=1
else
echo "Cannot connect via SSH. Waiting"
sleep 10
fi
done
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@${vmIP} "/bin/bash " << EOF
echo ${2}.example.com > /etc/hostname
subscription-manager register --username=${RHSMUSER} --password=${RHSMPASS}
subscription-manager attach --auto
subscription-manager repos --disable \*
subscription-manager repos --enable rhel-7-server-rpms
subscription-manager repos --enable rhel-7-server-openstack-5.0-rpms
subscription-manager repos --enable rhel-7-server-rh-common-rpms
yum -y update ;
reboot
EOF
}
is_vm_alive()
{
count=0
found=0
while [ $count -lt 10 ]
do
ping -c 1 $1 > /dev/null
if [ $? -eq 0 ]
then
found=1
count=10
else
sleep 10
((count=$count+1))
echo $count
fi
done
if [ $found -eq 0 ]
then
return $found
fi
SSHOK=0
while [ ${SSHOK} -eq 0 ]
do
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@$1 ls /root > /dev/null
if [ $? -eq 0 ]
then
SSHOK=1
else
echo "Cannot connect via SSH. Waiting"
sleep 10
fi
done
return $SSHOK
}
generate_and_replicate_sshkeys()
{
controllerIP=$1
networkIP=$2
compute1IP=$3
compute2IP=$4
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@${controllerIP} << EOF
mkdir /root/.ssh
ssh-keygen -t dsa -f /root/.ssh/id_dsa -P ""
EOF
scp -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@${controllerIP}:/root/.ssh/id_dsa.pub /tmp/id_dsa.pub
pubkey=$(cat /tmp/id_dsa.pub)
for ip in $controllerIP $networkIP $compute1IP $compute2IP
do
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@${ip} "echo $pubkey >> /root/.ssh/authorized_keys"
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@${ip} "chmod 600 /root/.ssh/authorized_keys"
done
}
run_packstack()
{
controllerIP=$1
networkIP=$2
compute1IP=$3
compute2IP=$4
PACKSTACK_OPTIONS="${PACKSTACK_DEFAULT_OPTIONS} --os-controller-host=${controllerIP} --os-network-hosts=${networkIP} --os-compute-hosts=${compute1IP},${compute2IP}"
SSHOK=0
while [ ${SSHOK} -eq 0 ]
do
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@${controllerIP} ls /root > /dev/null
if [ $? -eq 0 ]
then
SSHOK=1
else
echo "Cannot connect via SSH. Waiting"
sleep 10
fi
done
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@${controllerIP} "/bin/bash" << EOF
yum -y install openstack-packstack
packstack --gen-answer-file=/root/aio-4node.txt
sed --in-place 's/CONFIG_HEAT_INSTALL=n/CONFIG_HEAT_INSTALL=y/g' /root/aio-4node.txt
sed --in-place "s/CONFIG_COMPUTE_HOSTS=${controllerIP}/CONFIG_COMPUTE_HOSTS=${compute1IP},${compute2IP}/" /root/aio-4node.txt
sed --in-place "s/CONFIG_NETWORK_HOSTS=${controllerIP}/CONFIG_NETWORK_HOSTS=${networkIP}/" /root/aio-4node.txt
sed --in-place "s/CONFIG_PROVISION_TEMPEST=n/CONFIG_PROVISION_TEMPEST=y/" /root/aio-4node.txt
packstack ${PACKSTACK_DEFAULT_OPTIONS} --answer-file=/root/aio-4node.txt
EOF
}
# Main
if [ $# -ne 2 ]
then
usage
exit 2
fi
RHSMUSER=$1
RHSMPASS=$2
clone_vm controller
UUID1=$UUID
clone_vm network
UUID2=$UUID
clone_vm hypervisor1
UUID3=$UUID
clone_vm hypervisor2
UUID4=$UUID
start_vm $UUID1 controller
start_vm $UUID2 network
start_vm $UUID3 hypervisor1
start_vm $UUID4 hypervisor2
get_vm_ip $UUID1
VMIP1=$VMIP
get_vm_ip $UUID2
VMIP2=$VMIP
get_vm_ip $UUID3
VMIP3=$VMIP
get_vm_ip $UUID4
VMIP4=$VMIP
sleep 30 # Give some time for VMs to boot
rhnreg_vm $VMIP1 controller
rhnreg_vm $VMIP2 network
rhnreg_vm $VMIP3 hypervisor1
rhnreg_vm $VMIP4 hypervisor2
is_vm_alive $VMIP1
if [ $? -ne 1 ]
then
echo "Controller VM did not reboot properly. Check, destroy and try again"
exit 1
fi
is_vm_alive $VMIP2
if [ $? -ne 1 ]
then
echo "Controller VM did not reboot properly. Check, destroy and try again"
exit 1
fi
is_vm_alive $VMIP3
if [ $? -ne 1 ]
then
echo "Hypervisor1 VM did not reboot properly. Check, destroy and try again"
exit 1
fi
is_vm_alive $VMIP4
if [ $? -ne 1 ]
then
echo "Hypervisor2 VM did not reboot properly. Check, destroy and try again"
exit 1
fi
generate_and_replicate_sshkeys $VMIP1 $VMIP2 $VMIP3 $VMIP4
run_packstack $VMIP1 $VMIP2 $VMIP3 $VMIP4
echo "Finished. You can now check logs and see how it went. Connect with"
echo "ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@${VMIP1}"