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
This commit is contained in:
Major Hayden 2017-08-25 11:46:44 -05:00
parent 56a6dabdca
commit 690ce10bbd
No known key found for this signature in database
GPG Key ID: 737051E0C1011FB1

View File

@ -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"