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)
17 if [ -z "$SNAP_TYPE" ]; then
18 echo "ERROR: SNAP_TYPE not provided...exiting"
22 echo "Creating Apex snapshot..."
23 echo "-------------------------"
26 # create tmp directory
30 # TODO(trozet) remove this after fix goes in for tripleo_inspector to copy these
31 pushd ${tmp_dir} > /dev/null
32 echo "Copying overcloudrc and ssh key from Undercloud..."
34 UNDERCLOUD=$(sudo virsh domifaddr undercloud | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
35 sudo scp ${SSH_OPTIONS[@]} stack@${UNDERCLOUD}:overcloudrc ./
36 # Copy out ssh key of stack from undercloud
37 sudo scp ${SSH_OPTIONS[@]} stack@${UNDERCLOUD}:.ssh/id_rsa ./
40 echo "Gathering introspection information"
41 git clone https://gerrit.opnfv.org/gerrit/sdnvpn.git
42 pushd sdnvpn/odl-pipeline/lib > /dev/null
43 sudo ./tripleo_introspector.sh --out-file ${tmp_dir}/node.yaml
47 echo "Shutting down nodes"
49 nodes=$(sudo virsh list | grep -Eo "baremetal[0-9]")
50 for node in $nodes; do
51 sudo virsh shutdown ${node} --mode acpi
54 for node in $nodes; do
56 while [ "$count" -lt 10 ]; do
58 if sudo virsh list | grep ${node}; then
59 echo "Waiting for $node to shutdown, try $count"
66 if [ "$count" -ge 10 ]; then
67 echo "Node $node failed to shutdown"
72 pushd ${tmp_dir} > /dev/null
73 echo "Gathering virsh definitions"
74 # copy qcow2s, virsh definitions
75 for node in $nodes; do
76 sudo cp -f /var/lib/libvirt/images/${node}.qcow2 ./
77 sudo virsh dumpxml ${node} > ${node}.xml
80 # copy virsh net definitions
81 sudo virsh net-dumpxml admin > admin.xml
83 sudo chown jenkins-ci:jenkins-ci *
87 tar czf ../apex-${SNAP_TYPE}-snap-${DATE}.tar.gz .
89 sudo rm -rf ${tmp_dir}
90 echo "Snapshot saved as apex-${SNAP_TYPE}-snap-${DATE}.tar.gz"
92 # update opnfv properties file
93 if [ "$SNAP_TYPE" == 'csit' ]; then
94 snap_sha=$(sha512sum apex-csit-snap-${DATE}.tar.gz | cut -d' ' -f1)
95 if curl --fail -O -L http://$GS_URL/snapshot.properties; then
96 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
97 sed -i '/^OPNFV_SNAP_SHA512SUM=/{h;s/=.*/='${snap_sha}'/};${x;/^$/{s//OPNFV_SNAP_SHA512SUM='${snap_sha}'/;H};x}' snapshot.properties
99 cat << EOF > snapshot.properties
100 OPNFV_SNAP_URL=${GS_URL}/apex-csit-snap-${DATE}.tar.gz
101 OPNFV_SNAP_SHA512SUM=${snap_sha}
104 echo "OPNFV_SNAP_URL=$GS_URL/apex-csit-snap-${DATE}.tar.gz"
105 echo "OPNFV_SNAP_SHA512SUM=$(sha512sum apex-csit-snap-${DATE}.tar.gz | cut -d' ' -f1)"
106 echo "Updated properties file: "
107 cat snapshot.properties