summaryrefslogtreecommitdiffstats
path: root/jjb/apex/apex-snapshot-create.sh
blob: 342896c7d0ca459fd95e50de7f37670c5a3a138d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Na
#!/usr/bin/env bash
##############################################################################
# Copyright (c) 2016 Tim Rozet (Red Hat) and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

set -o errexit
set -o nounset
set -o pipefail

SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)

if [ -z "$SNAP_TYPE" ]; then
  echo "ERROR: SNAP_TYPE not provided...exiting"
  exit 1
fi

echo "Creating Apex snapshot..."
echo "-------------------------"
echo

# create tmp directory
tmp_dir=$(pwd)/.tmp
mkdir -p ${tmp_dir}

# TODO(trozet) remove this after fix goes in for tripleo_inspector to copy these
pushd ${tmp_dir} > /dev/null
echo "Copying overcloudrc and ssh key from Undercloud..."
# Store overcloudrc
UNDERCLOUD=$(sudo virsh domifaddr undercloud | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
sudo scp ${SSH_OPTIONS[@]} stack@${UNDERCLOUD}:overcloudrc ./
# Copy out ssh key of stack from undercloud
sudo scp ${SSH_OPTIONS[@]} stack@${UNDERCLOUD}:.ssh/id_rsa ./
popd > /dev/null

echo "Gathering introspection information"
git clone https://gerrit.opnfv.org/gerrit/sdnvpn.git
pushd sdnvpn/odl-pipeline/lib > /dev/null
sudo ./tripleo_introspector.sh --out-file ${tmp_dir}/node.yaml
popd > /dev/null
sudo rm -rf sdnvpn

echo "Shutting down nodes"
# Shut down nodes
nodes=$(sudo virsh list | grep -Eo "baremetal[0-9]")
for node in $nodes; do
  sudo virsh shutdown ${node} --mode acpi
done

for node in $nodes; do
  count=0
  while [ "$count" -lt 10 ]; do
    sleep 10
    if sudo virsh list | grep ${node}; then
       echo "Waiting for $node to shutdown, try $count"
    else
       break
    fi
    count=$((count+1))
  done

  if [ "$count" -ge 10 ]; then
    echo "Node $node failed to shutdown"
    exit 1
  fi
done

pushd ${tmp_dir} > /dev/null
echo "Gathering virsh definitions"
# copy qcow2s, virsh definitions
for node in $nodes; do
  sudo cp -f /var/lib/libvirt/images/${node}.qcow2 ./
  sudo virsh dumpxml ${node} > ${node}.xml
done

# copy virsh net definitions
for net in admin api external storage tenant; do
  sudo virsh net-dumpxml ${net} > ${net}.xml
done

sudo chown jenkins-ci:jenkins-ci *

# tar up artifacts
DATE=`date +%Y-%m-%d`
tar czf ../apex-${SNAP_TYPE}-snap-${DATE}.tar.gz .
popd > /dev/null
sudo rm -rf ${tmp_dir}
echo "Snapshot saved as apex-${SNAP_TYPE}-snap-${DATE}.tar.gz"

# update opnfv properties file
if [ "$SNAP_TYPE" == 'csit' ]; then
  curl -O -L http://$GS_URL/snapshot.properties
  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
  snap_sha=$(sha512sum apex-csit-snap-${DATE}.tar.gz | cut -d' ' -f1)
  sed -i '/^OPNFV_SNAP_SHA512SUM=/{h;s/=.*/='${snap_sha}'/};${x;/^$/{s//OPNFV_SNAP_SHA512SUM='${snap_sha}'/;H};x}' snapshot.properties
  echo "OPNFV_SNAP_URL=$GS_URL/apex-csit-snap-${DATE}.tar.gz"
  echo "OPNFV_SNAP_SHA512SUM=$(sha512sum apex-csit-snap-${DATE}.tar.gz | cut -d' ' -f1)"
  echo "Updated properties file: "
  cat snapshot.properties
fi