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 echo "Creating Apex snapshot..."
18 echo "-------------------------"
21 # create tmp directory
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..."
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 ./
35 echo "Gathering introspection information"
36 git clone https://gerrit.opnfv.org/gerrit/sdnvpn.git
37 pushd sdnvpn/odl-pipeline/lib > /dev/null
38 sudo ./tripleo_introspector.sh --out-file ${tmp_dir}/node.yaml
42 echo "Shutting down nodes"
44 nodes=$(sudo virsh list | grep -Eo "baremetal[0-9]")
45 for node in $nodes; do
46 sudo virsh shutdown ${node} --mode acpi
49 for node in $nodes; do
51 while [ "$count" -lt 10 ]; do
53 if sudo virsh list | grep ${node}; then
54 echo "Waiting for $node to shutdown, try $count"
61 if [ "$count" -ge 10 ]; then
62 echo "Node $node failed to shutdown"
67 pushd ${tmp_dir} > /dev/null
68 echo "Gathering virsh definitions"
69 # copy qcow2s, virsh definitions
70 for node in $nodes; do
71 sudo cp -f /var/lib/libvirt/images/${node}.qcow2 ./
72 sudo virsh dumpxml ${node} > ${node}.xml
75 # copy virsh net definitions
76 for net in admin api external storage tenant; do
77 sudo virsh net-dumpxml ${net} > ${net}.xml
80 sudo chown jenkins-ci:jenkins-ci *
84 tar czf ../apex-csit-snap-${DATE}.tar.gz .
86 sudo rm -rf ${tmp_dir}
87 echo "Snapshot saved as apex-csit-snap-${DATE}.tar.gz"
89 # update opnfv properties file
90 curl -O -L http://$GS_URL/snapshot.properties
91 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
92 snap_sha=$(sha512sum apex-csit-snap-${DATE}.tar.gz | cut -d' ' -f1)
93 sed -i '/^OPNFV_SNAP_SHA512SUM=/{h;s/=.*/='${snap_sha}'/};${x;/^$/{s//OPNFV_SNAP_SHA512SUM='${snap_sha}'/;H};x}' snapshot.properties
94 echo "OPNFV_SNAP_URL=$GS_URL/apex-csit-snap-${DATE}.tar.gz"
95 echo "OPNFV_SNAP_SHA512SUM=$(sha512sum apex-csit-snap-${DATE}.tar.gz | cut -d' ' -f1)"
96 echo "Updated properties file: "
97 cat snapshot.properties