2 ##############################################################################
3 # Copyright (c) 2016 Tim Rozet (Red Hat) and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
15 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)
16 SNAP_CACHE=$HOME/snap_cache
19 echo "Deploying Apex snapshot..."
20 echo "--------------------------"
23 echo "Cleaning server"
28 echo "Detecting requested OpenStack branch and topology type in gerrit comment"
29 parsed_comment=$(echo $GERRIT_EVENT_COMMENT_TEXT | sed -n 's/^opnfv-check\s*//p')
30 parsed_comment=$(echo $parsed_comment | sed -n 's/\s*$//p')
31 if [ ! -z "$parsed_comment" ]; then
32 if echo $parsed_comment | grep -E '^[a-z]+-(no)?ha'; then
33 IFS='-' read -r -a array <<< "$parsed_comment"
34 os_version=${array[0]}
36 echo "OS version detected in gerrit comment: ${os_version}"
37 echo "Topology type detected in gerrit comment: ${topo}"
39 echo "Invalid format given for scenario in gerrit comment: ${parsed_comment}...aborting"
43 echo "No scenario given in gerrit comment, will use default (master OpenStack, noha)"
48 full_snap_url=http://$GS_URL/${os_version}/${topo}
50 echo "Downloading latest snapshot properties file"
51 if ! wget -O $WORKSPACE/opnfv.properties ${full_snap_url}/snapshot.properties; then
52 echo "ERROR: Unable to find snapshot.properties at ${full_snap_url}...exiting"
56 # find latest check sum
57 latest_snap_checksum=$(cat opnfv.properties | grep OPNFV_SNAP_SHA512SUM | awk -F "=" '{print $2}')
58 if [ -z "$latest_snap_checksum" ]; then
59 echo "ERROR: checksum of latest snapshot from snapshot.properties is null!"
63 local_snap_checksum=""
64 SNAP_CACHE=${SNAP_CACHE}/${os_version}/${topo}
66 # check snap cache directory exists
67 # if snapshot cache exists, find the checksum
68 if [ -d "$SNAP_CACHE" ]; then
69 latest_snap=$(ls ${SNAP_CACHE} | grep tar.gz | tail -n 1)
70 if [ -n "$latest_snap" ]; then
71 local_snap_checksum=$(sha512sum ${SNAP_CACHE}/${latest_snap} | cut -d' ' -f1)
74 mkdir -p ${SNAP_CACHE}
77 # compare check sum and download latest snap if not up to date
78 if [ "$local_snap_checksum" != "$latest_snap_checksum" ]; then
79 snap_url=$(cat opnfv.properties | grep OPNFV_SNAP_URL | awk -F "=" '{print $2}')
80 if [ -z "$snap_url" ]; then
81 echo "ERROR: Snap URL from snapshot.properties is null!"
84 echo "INFO: SHA mismatch, will download latest snapshot"
86 rm -rf ${SNAP_CACHE}/*
87 wget --directory-prefix=${SNAP_CACHE}/ ${snap_url}
88 snap_tar=$(basename ${snap_url})
90 snap_tar=${latest_snap}
93 echo "INFO: Snapshot to be used is ${snap_tar}"
95 # move to snap cache dir and unpack
96 pushd ${SNAP_CACHE} > /dev/null
100 virsh_networks=$(ls *.xml | grep -v baremetal)
102 if [ -z "$virsh_networks" ]; then
103 echo "ERROR: no virsh networks found in snapshot unpack"
107 echo "Checking overcloudrc"
108 if ! stat overcloudrc; then
109 echo "ERROR: overcloudrc does not exist in snap unpack"
113 for network_def in ${virsh_networks}; do
114 sudo virsh net-create ${network_def}
115 network=$(echo ${network_def} | awk -F '.' '{print $1}')
116 if ! sudo virsh net-list | grep ${network}; then
117 sudo virsh net-start ${network}
119 echo "Checking if OVS bridge is missing for network: ${network}"
120 if ! sudo ovs-vsctl show | grep "br-${network}"; then
121 sudo ovs-vsctl add-br br-${network}
122 echo "OVS Bridge created: br-${network}"
123 if [ "br-${network}" == 'br-admin' ]; then
124 echo "Configuring IP 192.0.2.99 on br-admin"
125 sudo ip addr add 192.0.2.99/24 dev br-admin
126 sudo ip link set up dev br-admin
127 elif [ "br-${network}" == 'br-external' ]; then
128 echo "Configuring IP 192.168.37.1 on br-external"
129 sudo ip addr add 192.168.37.1/24 dev br-external
130 sudo ip link set up dev br-external
131 # Routes for admin network
132 # The overcloud controller is multi-homed and will fail to respond
133 # to traffic from the functest container due to reverse-path-filtering
134 # This route allows reverse traffic, by forcing admin network destined
135 # traffic through the external network for controller IPs only.
136 # Compute nodes have no ip on external interfaces.
137 controller_ips=$(cat overcloudrc | grep -Eo "192.0.2.[0-9]+")
138 for ip in $controller_ips; do
139 sudo ip route add ${ip}/32 dev br-external
145 echo "Virsh networks up: $(sudo virsh net-list)"
146 echo "Bringing up Overcloud VMs..."
147 virsh_vm_defs=$(ls baremetal*.xml)
149 if [ -z "$virsh_vm_defs" ]; then
150 echo "ERROR: no virsh VMs found in snapshot unpack"
154 for node_def in ${virsh_vm_defs}; do
155 sed -ri "s/machine='[^\s]+'/machine='pc'/" ${node_def}
156 sudo virsh define ${node_def}
157 node=$(echo ${node_def} | awk -F '.' '{print $1}')
158 sudo cp -f ${node}.qcow2 /var/lib/libvirt/images/
159 # FIXME (trozet) install java on each disk image as required to upgrade ODL
160 # should be added to Apex as part of the deployment. Remove this after that
162 sudo LIBGUESTFS_BACKEND=direct virt-customize --install java-1.8.0-openjdk -a /var/lib/libvirt/images/${node}.qcow2
163 sudo virsh start ${node}
164 echo "Node: ${node} started"
167 # copy overcloudrc for functest
168 mkdir -p $HOME/cloner-info
169 cp -f overcloudrc $HOME/cloner-info/
171 admin_controller_ip=$(cat overcloudrc | grep -Eo -m 1 "192.0.2.[0-9]+" | head -1)
172 netvirt_url="http://${admin_controller_ip}:8081/restconf/operational/network-topology:network-topology/topology/netvirt:1"
176 while [ "$counter" -le 10 ]; do
177 echo "Checking if OpenStack is up"
178 if nc -z ${admin_controller_ip} 9696 > /dev/null; then
179 echo "Overcloud Neutron is up...Checking if OpenDaylight NetVirt is up..."
180 if curl --fail --silent -u admin:admin ${netvirt_url} > /dev/null; then
181 echo "OpenDaylight is up. Overcloud deployment complete"
184 echo "OpenDaylight not yet up, try ${counter}"
187 echo "Neutron not yet up, try ${counter}"
189 counter=$((counter+1))
193 echo "ERROR: Deployment not up after 10 minutes...exiting."