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 "Downloading latest snapshot properties file"
29 if ! wget -O $WORKSPACE/opnfv.properties http://$GS_URL/snapshot.properties; then
30 echo "ERROR: Unable to find snapshot.properties at ${GS_URL}...exiting"
34 # find latest check sum
35 latest_snap_checksum=$(cat opnfv.properties | grep OPNFV_SNAP_SHA512SUM | awk -F "=" '{print $2}')
36 if [ -z "$latest_snap_checksum" ]; then
37 echo "ERROR: checksum of latest snapshot from snapshot.properties is null!"
41 local_snap_checksum=""
43 # check snap cache directory exists
44 # if snapshot cache exists, find the checksum
45 if [ -d "$SNAP_CACHE" ]; then
46 latest_snap=$(ls ${SNAP_CACHE} | grep tar.gz | tail -n 1)
47 if [ -n "$latest_snap" ]; then
48 local_snap_checksum=$(sha512sum ${SNAP_CACHE}/${latest_snap} | cut -d' ' -f1)
51 mkdir -p ${SNAP_CACHE}
54 # compare check sum and download latest snap if not up to date
55 if [ "$local_snap_checksum" != "$latest_snap_checksum" ]; then
56 snap_url=$(cat opnfv.properties | grep OPNFV_SNAP_URL | awk -F "=" '{print $2}')
57 if [ -z "$snap_url" ]; then
58 echo "ERROR: Snap URL from snapshot.properties is null!"
61 echo "INFO: SHA mismatch, will download latest snapshot"
63 rm -rf ${SNAP_CACHE}/*
64 wget --directory-prefix=${SNAP_CACHE}/ ${snap_url}
65 snap_tar=$(basename ${snap_url})
67 snap_tar=${latest_snap}
70 echo "INFO: Snapshot to be used is ${snap_tar}"
72 # move to snap cache dir and unpack
73 pushd ${SNAP_CACHE} > /dev/null
77 virsh_networks=$(ls *.xml | grep -v baremetal)
79 if [ -z "$virsh_networks" ]; then
80 echo "ERROR: no virsh networks found in snapshot unpack"
84 echo "Checking overcloudrc"
85 if ! stat overcloudrc; then
86 echo "ERROR: overcloudrc does not exist in snap unpack"
90 for network_def in ${virsh_networks}; do
91 sudo virsh net-create ${network_def}
92 network=$(echo ${network_def} | awk -F '.' '{print $1}')
93 if ! sudo virsh net-list | grep ${network}; then
94 sudo virsh net-start ${network}
96 echo "Checking if OVS bridge is missing for network: ${network}"
97 if ! sudo ovs-vsctl show | grep "br-${network}"; then
98 sudo ovs-vsctl add-br br-${network}
99 echo "OVS Bridge created: br-${network}"
100 if [ "br-${network}" == 'br-admin' ]; then
101 echo "Configuring IP 192.0.2.99 on br-admin"
102 sudo ip addr add 192.0.2.99/24 dev br-admin
103 sudo ip link set up dev br-admin
104 elif [ "br-${network}" == 'br-external' ]; then
105 echo "Configuring IP 192.168.37.1 on br-external"
106 sudo ip addr add 192.168.37.1/24 dev br-external
107 sudo ip link set up dev br-external
108 # Routes for admin network
109 # The overcloud controller is multi-homed and will fail to respond
110 # to traffic from the functest container due to reverse-path-filtering
111 # This route allows reverse traffic, by forcing admin network destined
112 # traffic through the external network for controller IPs only.
113 # Compute nodes have no ip on external interfaces.
114 controller_ips=$(cat overcloudrc | grep -Eo "192.0.2.[0-9]+")
115 for ip in $controller_ips; do
116 sudo ip route add ${ip}/32 dev br-external
122 echo "Virsh networks up: $(sudo virsh net-list)"
123 echo "Bringing up Overcloud VMs..."
124 virsh_vm_defs=$(ls baremetal*.xml)
126 if [ -z "$virsh_vm_defs" ]; then
127 echo "ERROR: no virsh VMs found in snapshot unpack"
131 for node_def in ${virsh_vm_defs}; do
132 sed -ri "s/machine='[^\s]+'/machine='pc'/" ${node_def}
133 sudo virsh define ${node_def}
134 node=$(echo ${node_def} | awk -F '.' '{print $1}')
135 sudo cp -f ${node}.qcow2 /var/lib/libvirt/images/
136 sudo virsh start ${node}
137 echo "Node: ${node} started"
140 # copy overcloudrc for functest
141 mkdir -p $HOME/cloner-info
142 cp -f overcloudrc $HOME/cloner-info/
144 admin_controller_ip=$(cat overcloudrc | grep -Eo -m 1 "192.0.2.[0-9]+")
145 netvirt_url="http://${admin_controller_ip}:8081/restconf/operational/network-topology:network-topology/topology/netvirt:1"
149 while [ "$counter" -le 10 ]; do
150 if curl --fail --silent ${admin_controller_ip}:80 > /dev/null; then
151 echo "Overcloud Horizon is up...Checking if OpenDaylight NetVirt is up..."
152 if curl --fail --silent -u admin:admin ${netvirt_url} > /dev/null; then
153 echo "OpenDaylight is up. Overcloud deployment complete"
156 echo "OpenDaylight not yet up, try ${counter}"
159 echo "Horizon/Apache not yet up, try ${counter}"
161 counter=$((counter+1))
165 echo "ERROR: Deployment not up after 10 minutes...exiting."