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 if [ -z "$SNAP_TYPE" ]; then
24 echo "ERROR: SNAP_TYPE not provided...exiting"
28 echo "Cleaning server"
33 full_snap_url="gs://${GS_URL}/${OS_VERSION}/${TOPOLOGY}"
35 echo "Downloading latest snapshot properties file"
36 if ! gsutil cp ${full_snap_url}/snapshot.properties $WORKSPACE/opnfv.properties; then
37 echo "ERROR: Unable to find snapshot.properties at ${full_snap_url}...exiting"
41 echo "Properties contents:"
42 cat ${WORKSPACE}/opnfv.properties
44 # find latest check sum
45 latest_snap_checksum=$(cat ${WORKSPACE}/opnfv.properties | grep ${SNAP_TYPE}_SNAP_SHA512SUM | awk -F "=" '{print $2}')
46 if [ -z "$latest_snap_checksum" ]; then
47 echo "ERROR: checksum of latest snapshot from snapshot.properties is null!"
51 local_snap_checksum=""
52 SNAP_CACHE=${SNAP_CACHE}/${OS_VERSION}/${TOPOLOGY}
54 # check snap cache directory exists
55 # if snapshot cache exists, find the checksum
56 if [ -d "$SNAP_CACHE" ]; then
57 latest_snap=$(ls ${SNAP_CACHE} | grep tar.gz | grep $SNAP_TYPE | tail -n 1)
58 if [ -n "$latest_snap" ]; then
59 local_snap_checksum=$(sha512sum ${SNAP_CACHE}/${latest_snap} | cut -d' ' -f1)
60 echo "Local snap checksum is: ${local_snap_checksum}"
63 mkdir -p ${SNAP_CACHE}
66 # compare check sum and download latest snap if not up to date
67 if [ "$local_snap_checksum" != "$latest_snap_checksum" ]; then
68 snap_url=$(cat opnfv.properties | grep ${SNAP_TYPE}_SNAP_URL | awk -F "=" '{print $2}')
69 # TODO(trozet): Remove this once OPNFV url is deprecated
70 if [[ -z "$snap_url" && "$SNAP_TYPE" == 'csit' ]]; then
71 echo "WARN: Unable to find snap url for ${SNAP_TYPE}, attempting to use OPNFV"
72 snap_url=$(cat opnfv.properties | grep OPNFV_SNAP_URL | awk -F "=" '{print $2}')
74 if [ -z "$snap_url" ]; then
75 echo "ERROR: Snap URL from snapshot.properties is null!"
78 echo "INFO: SHA mismatch, will download latest snapshot"
80 rm -rf ${SNAP_CACHE}/*
81 gsutil cp "gs://${snap_url}" ${SNAP_CACHE}/
82 snap_tar=$(basename ${snap_url})
84 snap_tar=${latest_snap}
87 echo "INFO: Snapshot to be used is ${snap_tar}"
89 # move to snap cache dir and unpack
90 pushd ${SNAP_CACHE} > /dev/null
94 virsh_networks=$(ls *.xml | grep -v baremetal)
96 if [ -z "$virsh_networks" ]; then
97 echo "ERROR: no virsh networks found in snapshot unpack"
101 echo "Checking overcloudrc"
102 if ! stat overcloudrc; then
103 echo "ERROR: overcloudrc does not exist in snap unpack"
107 for network_def in ${virsh_networks}; do
108 sudo virsh net-create ${network_def}
109 network=$(echo ${network_def} | awk -F '.' '{print $1}')
110 if ! sudo virsh net-list | grep ${network}; then
111 sudo virsh net-start ${network}
113 echo "Checking if OVS bridge is missing for network: ${network}"
114 if ! sudo ovs-vsctl show | grep "br-${network}"; then
115 sudo ovs-vsctl add-br br-${network}
116 echo "OVS Bridge created: br-${network}"
117 if [ "br-${network}" == 'br-admin' ]; then
118 echo "Configuring IP 192.0.2.99 on br-admin"
119 sudo ip addr add 192.0.2.99/24 dev br-admin
120 sudo ip link set up dev br-admin
121 elif [ "br-${network}" == 'br-external' ]; then
122 echo "Configuring IP 192.168.37.1 on br-external"
123 sudo ip addr add 192.168.37.1/24 dev br-external
124 sudo ip link set up dev br-external
125 # Routes for admin network
126 # The overcloud controller is multi-homed and will fail to respond
127 # to traffic from the functest container due to reverse-path-filtering
128 # This route allows reverse traffic, by forcing admin network destined
129 # traffic through the external network for controller IPs only.
130 # Compute nodes have no ip on external interfaces.
131 controller_ips=$(cat overcloudrc | grep -Eo "192.0.2.[0-9]+")
132 for ip in $controller_ips; do
133 sudo ip route add ${ip}/32 dev br-external
139 echo "Virsh networks up: $(sudo virsh net-list)"
140 echo "Bringing up Overcloud VMs..."
141 virsh_vm_defs=$(ls baremetal*.xml)
143 if [ -z "$virsh_vm_defs" ]; then
144 echo "ERROR: no virsh VMs found in snapshot unpack"
148 for node_def in ${virsh_vm_defs}; do
149 sed -ri "s/machine='[^\s]+'/machine='pc'/" ${node_def}
150 sudo virsh define ${node_def}
151 node=$(echo ${node_def} | awk -F '.' '{print $1}')
152 sudo cp -f ${node}.qcow2 /var/lib/libvirt/images/
153 sudo virsh start ${node}
154 echo "Node: ${node} started"
157 # copy overcloudrc for functest
158 mkdir -p $HOME/cloner-info
159 cp -f overcloudrc $HOME/cloner-info/
161 admin_controller_ip=$(cat overcloudrc | grep -Eo -m 1 "192.0.2.[0-9]+" | head -1)
162 netvirt_url="http://${admin_controller_ip}:8081/restconf/operational/network-topology:network-topology/topology/netvirt:1"
166 while [ "$counter" -le 10 ]; do
167 echo "Checking if OpenStack is up"
168 if nc -z ${admin_controller_ip} 9696 > /dev/null; then
169 echo "Overcloud Neutron is up...Checking if OpenDaylight NetVirt is up..."
170 if curl --fail --silent -u admin:${SDN_CONTROLLER_PASSWORD} ${netvirt_url} > /dev/null; then
171 echo "OpenDaylight is up. Overcloud deployment complete"
174 echo "OpenDaylight not yet up, try ${counter}"
177 echo "Neutron not yet up, try ${counter}"
179 counter=$((counter+1))
183 echo "ERROR: Deployment not up after 10 minutes...exiting."