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/snap/* ${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 snap_sha=$(sha512sum apex-${SNAP_TYPE}-snap-${DATE}.tar.gz | cut -d' ' -f1)
81 if curl --fail -O -L http://$GS_URL/snapshot.properties; then
82 # TODO(trozet): deprecate OPNFV_SNAP_URL for CSIT_SNAP_URL
83 if [ "$SNAP_TYPE" == 'csit' ]; then
84 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
85 sed -i '/^OPNFV_SNAP_SHA512SUM=/{h;s/=.*/='${snap_sha}'/};${x;/^$/{s//OPNFV_SNAP_SHA512SUM='${snap_sha}'/;H};x}' snapshot.properties
87 sed -i '/^'${SNAP_TYPE}'_SNAP_URL=/{h;s#=.*#='${GS_URL}'/apex-'${SNAP_TYPE}'-snap-'${DATE}'.tar.gz#};${x;/^$/{s##'${SNAP_TYPE}'_SNAP_URL='${GS_URL}'/apex-'${SNAP_TYPE}'-snap-'${DATE}'.tar.gz#;H};x}' snapshot.properties
88 sed -i '/^'${SNAP_TYPE}'_SNAP_SHA512SUM=/{h;s/=.*/='${snap_sha}'/};${x;/^$/{s//'${SNAP_TYPE}'_SNAP_SHA512SUM='${snap_sha}'/;H};x}' snapshot.properties
90 cat << EOF > snapshot.properties
91 ${SNAP_TYPE}_SNAP_URL=${GS_URL}/apex-${SNAP_TYPE}-snap-${DATE}.tar.gz
92 ${SNAP_TYPE}_SNAP_SHA512SUM=${snap_sha}
94 # TODO(trozet): deprecate OPNFV_SNAP_URL for CSIT_SNAP_URL
95 if [ "$SNAP_TYPE" == 'csit' ]; then
96 cat << EOF >> snapshot.properties
97 OPNFV_SNAP_URL=${GS_URL}/apex-csit-snap-${DATE}.tar.gz
98 OPNFV_SNAP_SHA512SUM=${snap_sha}
102 echo "${SNAP_TYPE}_SNAP_URL=$GS_URL/apex-${SNAP_TYPE}-snap-${DATE}.tar.gz"
103 echo "${SNAP_TYPE}_SNAP_SHA512SUM=$(sha512sum apex-${SNAP_TYPE}-snap-${DATE}.tar.gz | cut -d' ' -f1)"
104 echo "Updated properties file: "
105 cat snapshot.properties