Merge "Add docker build for escalator"
[releng.git] / jjb / apex / apex-snapshot-create.sh
1 #!/usr/bin/env bash
2 ##############################################################################
3 # Copyright (c) 2016 Tim Rozet (Red Hat) and others.
4 #
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 ##############################################################################
10
11 set -o errexit
12 set -o nounset
13 set -o pipefail
14
15 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)
16
17 echo "Creating Apex snapshot..."
18 echo "-------------------------"
19 echo
20
21 # create tmp directory
22 tmp_dir=$(pwd)/.tmp
23 mkdir -p ${tmp_dir}
24
25 # TODO(trozet) remove this after fix goes in for tripleo_inspector to copy these
26 pushd ${tmp_dir} > /dev/null
27 echo "Copying overcloudrc and ssh key from Undercloud..."
28 # Store overcloudrc
29 UNDERCLOUD=$(sudo virsh domifaddr undercloud | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
30 sudo scp ${SSH_OPTIONS[@]} stack@${UNDERCLOUD}:overcloudrc ./
31 # Copy out ssh key of stack from undercloud
32 sudo scp ${SSH_OPTIONS[@]} stack@${UNDERCLOUD}:.ssh/id_rsa ./
33 popd > /dev/null
34
35 echo "Gathering introspection information"
36 git clone https://gerrit.opnfv.org/gerrit/sdnvpn.git
37 pushd sdnvpn/odl-pipeline/lib > /dev/null
38 ./tripleo_introspector.sh --out-file ${tmp_dir}/node.yaml
39 popd > /dev/null
40
41 echo "Shutting down nodes"
42 # Shut down nodes
43 nodes=$(sudo virsh list | grep -Eo "baremetal[0-9]")
44 for node in $nodes; do
45   sudo virsh shutdown ${node} --mode acpi
46 done
47
48 for node in $nodes; do
49   count=0
50   while [ "$count" -lt 10 ]; do
51     sleep 10
52     if sudo virsh list | grep ${node}; then
53        echo "Waiting for $node to shutdown, try $count"
54     else
55        break
56     fi
57     count=$((count+1))
58   done
59
60   if [ "$count" -ge 10 ]; then
61     echo "Node $node failed to shutdown"
62     exit 1
63   fi
64 done
65
66 echo "Gathering virsh definitions"
67 # copy qcow2s, virsh definitions
68 for node in $nodes; do
69   cp -f /var/lib/libvirt/images/${node}.qcow2 ./
70   sudo virsh dumpxml ${node} > ${node}.xml
71 done
72
73 # copy virsh net definitions
74 for net in admin api external storage tenant; do
75   sudo virsh net-dumpxml ${net} > ${net}.xml
76 done
77
78 # tar up artifacts
79 DATE=`date +%Y-%m-%d`
80 tar czf ../apex-csit-snap-${DATE}.tar.gz .
81 popd > /dev/null
82 rm -rf ./.tmp
83 echo "Snapshot saved as apex-csit-snap-${DATE}.tar.gz"
84
85 # update opnfv properties file
86 curl -O -L http://$GS_URL/snapshot.properties
87 sed -i '/^OPNFV_SNAP_URL=/{h;s#=.*#='${GS_URL}'/apex-csit-snap-'${DATE}'.tar.gz#};${x;/^$/{s##OPNFV_SNAP_URL='${GS_URL}'/apex-csit-snap-'${DATE}'.tar.gz#;H};x}' snapshot.properties
88 snap_sha=$(sha512sum apex-csit-snap-${DATE}.tar.gz | cut -d' ' -f1)
89 sed -i '/^OPNFV_SNAP_SHA512SUM=/{h;s/=.*/='${snap_sha}'/};${x;/^$/{s//OPNFV_SNAP_SHA512SUM='${snap_sha}'/;H};x}' snapshot.properties
90 echo "OPNFV_SNAP_URL=$GS_URL/apex-csit-snap-${DATE}.tar.gz"
91 echo "OPNFV_SNAP_SHA512SUM=$(sha512sum apex-csit-snap-${DATE}.tar.gz | cut -d' ' -f1)"
92 echo "Updated properties file: "
93 cat snapshot.properties