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 # info should have already been collected in apex-fetch-snap-info so copy it
31 cp -r /tmp/csit/* ${tmp_dir}/
33 echo "Shutting down nodes"
35 nodes=$(sudo virsh list | grep -Eo "baremetal[0-9]")
36 for node in $nodes; do
37 sudo virsh shutdown ${node} --mode acpi
40 for node in $nodes; do
42 while [ "$count" -lt 10 ]; do
44 if sudo virsh list | grep ${node}; then
45 echo "Waiting for $node to shutdown, try $count"
52 if [ "$count" -ge 10 ]; then
53 echo "Node $node failed to shutdown"
58 pushd ${tmp_dir} > /dev/null
59 echo "Gathering virsh definitions"
60 # copy qcow2s, virsh definitions
61 for node in $nodes; do
62 sudo cp -f /var/lib/libvirt/images/${node}.qcow2 ./
63 sudo virsh dumpxml ${node} > ${node}.xml
66 # copy virsh net definitions
67 sudo virsh net-dumpxml admin > admin.xml
69 sudo chown jenkins-ci:jenkins-ci *
73 tar czf ../apex-${SNAP_TYPE}-snap-${DATE}.tar.gz .
75 sudo rm -rf ${tmp_dir}
76 echo "Snapshot saved as apex-${SNAP_TYPE}-snap-${DATE}.tar.gz"
78 # update opnfv properties file
79 if [ "$SNAP_TYPE" == 'csit' ]; then
80 snap_sha=$(sha512sum apex-csit-snap-${DATE}.tar.gz | cut -d' ' -f1)
81 if curl --fail -O -L http://$GS_URL/snapshot.properties; then
82 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
83 sed -i '/^OPNFV_SNAP_SHA512SUM=/{h;s/=.*/='${snap_sha}'/};${x;/^$/{s//OPNFV_SNAP_SHA512SUM='${snap_sha}'/;H};x}' snapshot.properties
85 cat << EOF > snapshot.properties
86 OPNFV_SNAP_URL=${GS_URL}/apex-csit-snap-${DATE}.tar.gz
87 OPNFV_SNAP_SHA512SUM=${snap_sha}
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