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 full_snap_url="gs://${GS_URL}/${OS_VERSION}/${TOPOLOGY}"
30 echo "Downloading latest snapshot properties file"
31 if ! gsutil cp ${full_snap_url}/snapshot.properties $WORKSPACE/opnfv.properties; then
32 echo "ERROR: Unable to find snapshot.properties at ${full_snap_url}...exiting"
36 echo "Properties contents:"
37 cat ${WORKSPACE}/opnfv.properties
39 # find latest check sum
40 latest_snap_checksum=$(cat ${WORKSPACE}/opnfv.properties | grep OPNFV_SNAP_SHA512SUM | awk -F "=" '{print $2}')
41 if [ -z "$latest_snap_checksum" ]; then
42 echo "ERROR: checksum of latest snapshot from snapshot.properties is null!"
46 local_snap_checksum=""
47 SNAP_CACHE=${SNAP_CACHE}/${OS_VERSION}/${TOPOLOGY}
49 # check snap cache directory exists
50 # if snapshot cache exists, find the checksum
51 if [ -d "$SNAP_CACHE" ]; then
52 latest_snap=$(ls ${SNAP_CACHE} | grep tar.gz | tail -n 1)
53 if [ -n "$latest_snap" ]; then
54 local_snap_checksum=$(sha512sum ${SNAP_CACHE}/${latest_snap} | cut -d' ' -f1)
55 echo "Local snap checksum is: ${local_snap_checksum}"
58 mkdir -p ${SNAP_CACHE}
61 # compare check sum and download latest snap if not up to date
62 if [ "$local_snap_checksum" != "$latest_snap_checksum" ]; then
63 snap_url=$(cat opnfv.properties | grep OPNFV_SNAP_URL | awk -F "=" '{print $2}')
64 if [ -z "$snap_url" ]; then
65 echo "ERROR: Snap URL from snapshot.properties is null!"
68 echo "INFO: SHA mismatch, will download latest snapshot"
70 rm -rf ${SNAP_CACHE}/*
71 gsutil cp "gs://${snap_url}" ${SNAP_CACHE}/
72 snap_tar=$(basename ${snap_url})
74 snap_tar=${latest_snap}
77 echo "INFO: Snapshot to be used is ${snap_tar}"
79 # move to snap cache dir and unpack
80 pushd ${SNAP_CACHE} > /dev/null
84 virsh_networks=$(ls *.xml | grep -v baremetal)
86 if [ -z "$virsh_networks" ]; then
87 echo "ERROR: no virsh networks found in snapshot unpack"
91 echo "Checking overcloudrc"
92 if ! stat overcloudrc; then
93 echo "ERROR: overcloudrc does not exist in snap unpack"
97 for network_def in ${virsh_networks}; do
98 sudo virsh net-create ${network_def}
99 network=$(echo ${network_def} | awk -F '.' '{print $1}')
100 if ! sudo virsh net-list | grep ${network}; then
101 sudo virsh net-start ${network}
103 echo "Checking if OVS bridge is missing for network: ${network}"
104 if ! sudo ovs-vsctl show | grep "br-${network}"; then
105 sudo ovs-vsctl add-br br-${network}
106 echo "OVS Bridge created: br-${network}"
107 if [ "br-${network}" == 'br-admin' ]; then
108 echo "Configuring IP 192.0.2.99 on br-admin"
109 sudo ip addr add 192.0.2.99/24 dev br-admin
110 sudo ip link set up dev br-admin
111 elif [ "br-${network}" == 'br-external' ]; then
112 echo "Configuring IP 192.168.37.1 on br-external"
113 sudo ip addr add 192.168.37.1/24 dev br-external
114 sudo ip link set up dev br-external
115 # Routes for admin network
116 # The overcloud controller is multi-homed and will fail to respond
117 # to traffic from the functest container due to reverse-path-filtering
118 # This route allows reverse traffic, by forcing admin network destined
119 # traffic through the external network for controller IPs only.
120 # Compute nodes have no ip on external interfaces.
121 controller_ips=$(cat overcloudrc | grep -Eo "192.0.2.[0-9]+")
122 for ip in $controller_ips; do
123 sudo ip route add ${ip}/32 dev br-external
129 echo "Virsh networks up: $(sudo virsh net-list)"
130 echo "Bringing up Overcloud VMs..."
131 virsh_vm_defs=$(ls baremetal*.xml)
133 if [ -z "$virsh_vm_defs" ]; then
134 echo "ERROR: no virsh VMs found in snapshot unpack"
138 for node_def in ${virsh_vm_defs}; do
139 sed -ri "s/machine='[^\s]+'/machine='pc'/" ${node_def}
140 sudo virsh define ${node_def}
141 node=$(echo ${node_def} | awk -F '.' '{print $1}')
142 sudo cp -f ${node}.qcow2 /var/lib/libvirt/images/
143 sudo virsh start ${node}
144 echo "Node: ${node} started"
147 # copy overcloudrc for functest
148 mkdir -p $HOME/cloner-info
149 cp -f overcloudrc $HOME/cloner-info/
151 admin_controller_ip=$(cat overcloudrc | grep -Eo -m 1 "192.0.2.[0-9]+" | head -1)
152 netvirt_url="http://${admin_controller_ip}:8081/restconf/operational/network-topology:network-topology/topology/netvirt:1"
156 while [ "$counter" -le 10 ]; do
157 echo "Checking if OpenStack is up"
158 if nc -z ${admin_controller_ip} 9696 > /dev/null; then
159 echo "Overcloud Neutron is up...Checking if OpenDaylight NetVirt is up..."
160 if curl --fail --silent -u admin:${SDN_CONTROLLER_PASSWORD} ${netvirt_url} > /dev/null; then
161 echo "OpenDaylight is up. Overcloud deployment complete"
164 echo "OpenDaylight not yet up, try ${counter}"
167 echo "Neutron not yet up, try ${counter}"
169 counter=$((counter+1))
173 echo "ERROR: Deployment not up after 10 minutes...exiting."