-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathci-setup-anvil-bm-vm
executable file
·219 lines (188 loc) · 5.93 KB
/
ci-setup-anvil-bm-vm
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
#!/bin/bash
set -e
. $HOME/ci-tools/ci-setup-anvil-vm-env
echo "Destroying VMs (if any)"
for i in $ALLNODES $CACHENODES; do
destroy_vm $i
done
$HOME/ci-tools/ci-setup-anvil-bm-vm-cache $BUILD none none
echo "Creating nodes disks"
cd "$DEPLOYDIR/snapshots"
rm -rf *.qcow2
for i in $ALLNODES; do
qemu-img create -b "$DEPLOYDIR/cache/${BUILD}-latest.qcow2" -F qcow2 -f qcow2 "$i-vol.qcow2" 200G
qemu-img create -f qcow2 "$i-vol2.qcow2" 200G
done
cd "$DEPLOYDIR/configs"
# ifn ip network is defined in ci-tools/ci-setup-anvil-bm
# and ci-tools/anvil-config-templates/ network templates
echo "Generating VM network configs and updating /etc/hosts"
if [ ! -f /etc/hosts.anvil ]; then
cp /etc/hosts /etc/hosts.anvil
else
cp /etc/hosts.anvil /etc/hosts
fi
ipbase=2
for i in $ALLNODES; do
IFNIP=192.168.122.$ipbase
cat "$TEMPLATESDIR/anvil_striker_net_config.cfg" | \
sed \
-e "s#@IFNIP@#$IFNIP#g" \
> "$DEPLOYDIR/configs/${i}_net_config.cfg"
echo "$IFNIP ${i}.alteeve.com ${i}" >> /etc/hosts
ipbase=$((ipbase + 1))
done
echo "Generating cloud-init configs"
for i in $ALLNODES; do
case $i in
*striker*)
ANVILPKG="striker"
;;
*a01n*)
ANVILPKG="node"
;;
*dr*)
ANVILPKG="dr"
;;
esac
cat "$TEMPLATESDIR/anvil_cloud_init_${BUILD}.cfg" | \
sed \
-e "s#@HOSTNAME@#${i}#g" \
-e "s#@BUILD@#${BUILD}#g" \
-e "s#@SSHKEY@#${SSHKEY}#g" \
-e "s#@KEY@#${KEY}#g" \
-e "s#@ORG@#${ORG}#g" \
-e "s#@AKEY@#${AKEY}#g" \
-e "s#@PRNUM@#${PRNUM}#g" \
-e "s#@PRREPO@#${PRREPO}#g" \
-e "s#@ANVIL@#${ANVIL}#g" \
-e "s#@ANVILDEPS@#${ANVILDEPS}#g" \
-e "s#@ALTEEVE@#${ALTEEVE}#g" \
-e "s#@ALTEEVESTAGING@#${ALTEEVESTAGING}#g" \
-e "s#@ANVILPKG@# - anvil-${ANVILPKG}#g" \
> "$DEPLOYDIR/configs/${i}_cloud_init.cfg"
done
echo "Generating cloud-init metadata and seed images"
for i in $ALLNODES; do
rm -f "$DEPLOYDIR/snapshots/${i}-seed.img"
echo "instance-id: $(uuidgen)" > "$DEPLOYDIR/configs/${i}-metadata"
cloud-localds -v --network-config="$DEPLOYDIR/configs/${i}_net_config.cfg" "$DEPLOYDIR/snapshots/${i}-seed.img" "$DEPLOYDIR/configs/${i}_cloud_init.cfg" "$DEPLOYDIR/configs/${i}-metadata"
done
echo "Creating VMs"
# those have to match the ports down for Simengine bmc/storage
vmportbase=20100
monportbase=20200
storageportbase=20300
for i in $ALLNODES; do
netconf="--network network:ifn1_bridge1,model=e1000 --network network:ifn1_bridge1,model=e1000 --network network:bcn1_bridge1,model=e1000 --network network:bcn1_bridge1,model=e1000"
case $i in
*striker*)
qemu_command_list=()
;;
*)
netconf="$netconf --network network:sn1_bridge1,model=e1000 --network network:sn1_bridge1,model=e1000"
qemu_command_list=(
"-chardev socket,id=ipmi0,host=localhost,port=$vmportbase,reconnect=2"
"-device ipmi-bmc-extern,id=bmc0,chardev=ipmi0"
"-device isa-ipmi-bt,bmc=bmc0"
"-serial mon:tcp::$monportbase,server,telnet,nowait"
"-chardev socket,id=simengine-storage-tcp,host=localhost,port=$storageportbase,reconnect=2"
"-device virtio-serial"
"-device virtserialport,chardev=simengine-storage-tcp,name=systems.cdot.simengine.storage.net"
)
vmportbase=$((vmportbase + 1))
monportbase=$((monportbase + 1))
storageportbase=$((storageportbase + 1))
;;
esac
virt-install --name ${i} \
--virt-type kvm --memory 16384 --vcpus 6 \
--boot hd,menu=on \
--disk path="$DEPLOYDIR/snapshots/${i}-seed.img",device=cdrom \
--disk path="$DEPLOYDIR/snapshots/$i-vol.qcow2",device=disk \
--disk path="$DEPLOYDIR/snapshots/$i-vol2.qcow2",device=disk \
--graphics vnc \
--os-type Linux --os-variant $KVMVAR \
$netconf \
--qemu-commandline="${qemu_command_list[*]}" \
--noautoconsole
done
echo "Waiting for nodes and cloud-init to complete full init"
bootdone=no
expected=0
error=0
for i in $ALLNODES; do
expected=$((expected + 1))
done
while [ "$bootdone" = "no" ]; do
actual=0
for i in $ALLNODES; do
status=$(ssh $i cloud-init status 2>/dev/null | awk '{print $NF}')
echo "cloud-init status node $i: $status"
if [ "$status" = "error" ]; then
error=1
ALLNODES=$(echo $ALLNODES | sed -e 's#'$i'##g')
expected=$((expected - 1))
echo "ERROR cloud init log for node $i:"
ssh $i cat /var/log/cloud-init-output.log
echo "---------------------------"
fi
if [ "$status" = "done" ]; then
actual=$((actual + 1))
fi
done
echo "$(date) actual: $actual expected: $expected"
if [ "$actual" = "$expected" ]; then
bootdone=yes
else
sleep 10
fi
done
if [ "$error" = "1" ]; then
exit 1
fi
$HOME/ci-tools/ci-setup-anvil-simengine
echo "Generating anvil striker auto config"
cp "$TEMPLATESDIR/anvil_striker_auto.cfg" "$DEPLOYDIR/configs/anvil_striker_auto.cfg"
for i in $ALLNODES; do
ifaces=5
case $i in
*striker*)
ifaces=3
;;
esac
for x in $(seq 0 $ifaces); do
mac="$(ssh $i ifconfig eth$x | grep ether | awk '{print $2}')"
sed -i -e 's#@'$i'-eth'$x'@#'$mac'#g' "$DEPLOYDIR/configs/anvil_striker_auto.cfg"
done
done
rm -rf "$DEPLOYDIR/anvil-test-suite"
cd "$DEPLOYDIR"
git clone git@github.com:Alteeve/anvil-test-suite.git
cd anvil-test-suite
set +e
./run-tests -b $BREAKPOINT
ret=$?
cd /root/ci-tools
# collecting all build info
rm -rf $DEPLOYDIR/logs/$BUILD_NUMBER/
mkdir -p $DEPLOYDIR/logs/$BUILD_NUMBER/
cp $DEPLOYDIR/configs/anvil_striker_auto.cfg $DEPLOYDIR/logs/$BUILD_NUMBER/anvil_striker_auto.cfg
for i in $ALLNODES; do
scp ${i}:/var/log/anvil.log $DEPLOYDIR/logs/$BUILD_NUMBER/${i}_anvil.log
done
for i in $STRIKERS; do
pg_dumpall --host=${i} --username=postgres | gzip > $DEPLOYDIR/logs/$BUILD_NUMBER/${i}_anvil.db.gz || true
done
cd $DEPLOYDIR/logs/
tar zcvp -f $BUILD_NUMBER.tar.gz $BUILD_NUMBER/
scp $BUILD_NUMBER.tar.gz anvil-ci-proxy:/var/www/html/testing-logs/$BUILD_NUMBER.tar.gz
cd -
rm -rf $DEPLOYDIR/logs/$BUILD_NUMBER/
echo "Complete anvil logs available here for download: http://anvil-ci-repo.kronosnet.org/testing-logs/$BUILD_NUMBER.tar.gz"
if [ -n "$KEY" ]; then
for i in $ALLNODES; do
ssh $i subscription-manager unregister || true
done
fi
exit $ret