From 690ce10bbdea13f5ca5b7f02f42bd48e9ad06c04 Mon Sep 17 00:00:00 2001 From: Major Hayden Date: Fri, 25 Aug 2017 11:46:44 -0500 Subject: [PATCH] Check for lxc-ls/paths before collecting logs The ansible-hardening gate doesn't have an /openstack/logs directory nor does it have the lxc-ls executable. This patch checks for both of those before collecting logs. This patch is currently blocking the ansible-hardening gate. Change-Id: Ic4ea169908fec86623dbe91859ec524e48683ab7 --- test-log-collect.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test-log-collect.sh b/test-log-collect.sh index 92825e8b..8feb34a2 100755 --- a/test-log-collect.sh +++ b/test-log-collect.sh @@ -45,17 +45,21 @@ if [[ -d "/etc/nodepool" ]]; then # NOTE(mhayden): We use sudo here to ensure that all logs are copied. sudo ${RSYNC_CMD} /var/log/ "${WORKING_DIR}/logs/host" || true - sudo ${RSYNC_CMD} /openstack/log/ "${WORKING_DIR}/logs/openstack" || true + if [ -d "/openstack/log" ]; then + sudo ${RSYNC_CMD} /openstack/log/ "${WORKING_DIR}/logs/openstack" || true + fi # Archive host's /etc directory sudo ${RSYNC_ETC_CMD} /etc/ "${WORKING_DIR}/logs/etc/host/" || true # Loop over each container and archive its /etc directory - for CONTAINER_NAME in `sudo lxc-ls -1`; do - CONTAINER_PID=$(sudo lxc-info -p -n ${CONTAINER_NAME} | awk '{print $2}') - ETC_DIR="/proc/${CONTAINER_PID}/root/etc/" - sudo ${RSYNC_ETC_CMD} ${ETC_DIR} "${WORKING_DIR}/logs/etc/openstack/${CONTAINER_NAME}/" || true - done + if which lxc-ls &> /dev/null; then + for CONTAINER_NAME in `sudo lxc-ls -1`; do + CONTAINER_PID=$(sudo lxc-info -p -n ${CONTAINER_NAME} | awk '{print $2}') + ETC_DIR="/proc/${CONTAINER_PID}/root/etc/" + sudo ${RSYNC_ETC_CMD} ${ETC_DIR} "${WORKING_DIR}/logs/etc/openstack/${CONTAINER_NAME}/" || true + done + fi # NOTE(mhayden): All of the files must be world-readable so that the log # pickup jobs will work properly. Without this, you get a "File not found"