From 0e07b7b99858af772cdb559b626ad9e70c893bf0 Mon Sep 17 00:00:00 2001 From: Jeffrey Zhang Date: Fri, 16 Dec 2016 00:28:36 +0800 Subject: [PATCH] Collect logs at the end of gate Collecting more logs will be helpful for use to debug the gate. Closes-Bug: #1650552 Change-Id: I5e243c4e5075215cbed57b65655c99f2ddcadaaf --- tools/gate_run.sh | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tools/gate_run.sh b/tools/gate_run.sh index 89db9de520..e68ff6431a 100755 --- a/tools/gate_run.sh +++ b/tools/gate_run.sh @@ -1,4 +1,81 @@ #!/bin/bash +set -o errexit +set -o xtrace + +function collect_logs { + set +o errexit + mkdir -p logs + + # copy system log + + sudo cp -r /var/log logs/system_log + + if which journalctl ; then + # the journal gives us syslog() and kernel output, so is like + # a concatenation of the above. + sudo journalctl --no-pager | sudo tee logs/syslog.txt > /dev/null + sudo journalctl --no-pager -u docker.service | sudo tee logs/docker.log > /dev/null + else + # assume rsyslog + sudo cp /var/log/syslog logs/syslog.txt + sudo cp /var/log/kern.log logs/kern_log.txt + sudo cp /var/log/upstart/docker.log logs/docker.log + fi + + if [[ -d /var/lib/docker/volumes/kolla_logs/_data ]]; then + sudo cp -r /var/lib/docker/volumes/kolla_logs/_data logs/kolla_logs + fi + + # sudo config + sudo cp -r /etc/sudoers.d logs/ + sudo cp /etc/sudoers logs/sudoers.txt + + df -h > logs/df.txt + free > logs/free.txt + sudo parted -l | sudo tee logs/parted-l.txt > /dev/null + mount > logs/mount.txt + env > logs/env.txt + + if [ `command -v dpkg` ]; then + dpkg -l | sudo tee logs/dpkg-l.txt > /dev/null + fi + if [ `command -v rpm` ]; then + rpm -qa | sudo tee logs/rpm-qa.txt > /dev/null + fi + + # final memory usage and process list + ps -eo user,pid,ppid,lwp,%cpu,%mem,size,rss,cmd > logs/ps.txt + + # docker related information + (docker info && docker images && docker ps -a) > logs/docker-info.txt + + sudo cp -r /etc/kolla logs/kolla_configs + + # fix the permissions for logs folder + sudo chmod -R 777 logs + + # rename files to .txt; this is so that when displayed via + # logs.openstack.org clicking results in the browser shows the + # files, rather than trying to send it to another app or make you + # download it, etc. + + # firstly, rename all .log files to .txt files + for f in $(find logs -name "*.log"); do + sudo mv $f ${f/.log/.txt} + done + + # append .txt to all kolla config file + find logs/kolla_configs -type -f -exec mv '{}' '{}'.txt \; + + # Compress all text logs + find logs -iname '*.txt' -execdir gzip -9 {} \+ + find logs -iname '*.json' -execdir gzip -9 {} \+ + + set -o errexit +} + +trap collect_logs EXIT + tools/setup_gate.sh tox -e $ACTION-$BASE_DISTRO-$INSTALL_TYPE