states: Break on error, retry states up to 5 times
[fuel.git] / mcp / scripts / log.sh
1 #!/bin/bash -e
2 ##############################################################################
3 # Copyright (c) 2017 Mirantis Inc., Enea AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 #
10 # Collect /var/log from all cluster nodes via Salt Master
11 #
12
13 # shellcheck disable=SC1090
14 [ -n "${SSH_OPTS}" ] || source "$(dirname "${BASH_SOURCE[0]}")/globals.sh"
15
16 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
17 DEPLOY_LOG=$1
18 OPNFV_TMP_LOG="opnfv_fuel_logs"
19
20 [ -n "${DEPLOY_LOG}" ] || exit 0
21
22 # ssh to cfg01
23 # shellcheck disable=SC2086,2087
24 ssh ${SSH_OPTS} "${SSH_SALT}" bash -s << LOG_COLLECT_END
25   sudo -i
26
27   echo salt -C '*' cp.push_dir /var/log upload_path='${OPNFV_TMP_LOG}'
28   salt -C '*' cp.push_dir /var/log upload_path='${OPNFV_TMP_LOG}'
29
30   cd /var/cache/salt/master/minions && \
31     find */files/${OPNFV_TMP_LOG}/ | \
32       xargs tar czf \$(eval echo \~\${SUDO_USER}/${OPNFV_TMP_LOG}.tar.gz) \
33         --transform 's|/files/${OPNFV_TMP_LOG}||'
34 LOG_COLLECT_END
35
36 # shellcheck disable=SC2086
37 scp ${SSH_OPTS} "${SSH_SALT}:${OPNFV_TMP_LOG}.tar.gz" "${DEPLOY_LOG}"
38 # shellcheck disable=SC2086,2029
39 ssh ${SSH_OPTS} "${SSH_SALT}" rm -f "${OPNFV_TMP_LOG}.tar.gz"