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"
24 git clone https://gerrit.opnfv.org/gerrit/apex.git
25 pushd apex/ci > /dev/null
26 sudo CONFIG=../build/ LIB=../lib ./clean.sh
29 echo "Downloading latest snapshot properties file"
30 if ! wget -O $WORKSPACE/opnfv.properties http://$GS_URL/snapshot.properties; then
31 echo "ERROR: Unable to find snapshot.properties at ${GS_URL}...exiting"
35 # find latest check sum
36 latest_snap_checksum=$(cat opnfv.properties | grep OPNFV_SNAP_SHA512SUM | awk -F "=" '{print $2}')
37 if [ -z "$latest_snap_checksum" ]; then
38 echo "ERROR: checksum of latest snapshot from snapshot.properties is null!"
42 local_snap_checksum=""
44 # check snap cache directory exists
45 if [ -d "$SNAP_CACHE" ]; then
46 latest_snap=$(ls -Art | grep tar.gz | tail -n 1)
47 if [ -n "$latest_snap" ]; then
48 local_snap_checksum=$(sha512sum ${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" -ne "$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"
62 wget --directory-prefix=${SNAP_CACHE}/ ${snap_url}
63 snap_tar=$(basename ${snap_url})
65 snap_tar=${latest_snap}
68 echo "INFO: Snapshot to be used is ${snap_tar}"
70 # create tmp directory and unpack snap
72 pushd ./tmp > /dev/null
76 virsh_networks=$(ls *.xml | grep -v baremetal)
78 if [ -z "$virsh_networks" ]; then
79 echo "ERROR: no virsh networks found in snapshot unpack"
83 for network_def in ${virsh_networks}; do
84 sudo virsh net-create ${network_def}
85 network=$(echo ${network_def} | awk -F '.' '{print $1}')
86 if ! sudo virsh net-list | grep ${network}; then
87 sudo virsh net-start ${network}
89 echo "Checking if OVS bridge is missing for network: ${network}"
90 if ! ovs-vsctl show | grep "br-${network}"; then
91 ovs-vsctl add-br br-${network}
92 echo "OVS Bridge created: br-${network}"
93 if [ "br-${network}" == 'br-admin' ]; then
94 echo "Configuring IP 192.0.2.99 on br-admin"
95 sudo ip addr add 192.0.2.99/24 dev br-admin
96 sudo ip link set up dev br-admin
97 elif [ "br-${network}" == 'br-external' ]; then
98 echo "Configuring IP 192.168.37.99 on br-external"
99 sudo ip addr add 192.168.37.99/24 dev br-external
100 sudo ip link set up dev br-external
105 echo "Virsh networks up: $(virsh net-list)"
106 echo "Bringing up Overcloud VMs..."
107 virsh_vm_defs=$(ls baremetal*.xml)
109 if [ -z "$virsh_vm_defs" ]; then
110 echo "ERROR: no virsh VMs found in snapshot unpack"
114 for node_def in ${virsh_vm_defs}; do
115 sudo virsh define ${node_def}
116 node=$(echo ${node_def} | awk -F '.' '{print $1}')
117 sudo cp -f ${node}.qcow2 /var/lib/libvirt/images/
118 sudo virsh start ${node}
119 echo "Node: ${node} started"
122 echo "Checking overcloudrc"
123 if ! stat overcloudrc; then
124 echo "ERROR: overcloudrc does not exist in snap unpack"
128 # copy overcloudrc for functest
129 mkdir -p $HOME/cloner-info
130 cp -f overcloudrc $HOME/cloner-info/
132 admin_controller_ip=$(cat overcloudrc | grep -Eo "192.0.2.[0-9]+")
133 netvirt_url="http://${admin_controller_ip}:8081/restconf/operational/network-topology:network-topology/topology/netvirt:1"
137 while [ "$counter" -le 10 ]; do
138 if curl --fail ${admin_controller_ip}:80; then
139 echo "Overcloud Horizon is up...Checking if OpenDaylight NetVirt is up..."
140 if curl --fail ${netvirt_url} > /dev/null; then
141 echo "OpenDaylight is up. Overcloud deployment complete"
144 echo "OpenDaylight not yet up, try ${counter}"
147 echo "Horizon/Apache not yet up, try ${counter}"
149 counter=$((counter+1))
153 echo "ERROR: Deployment not up after 10 minutes...exiting."