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