From 075eb3f5a80bc2ec881a80ff56e3190843886d03 Mon Sep 17 00:00:00 2001 From: Ivan Chavero Date: Fri, 15 Nov 2013 21:51:31 -0700 Subject: [PATCH] Move packstack logs to /var/log/packstack Move packstack and puppet logs to a more proper location. Change-Id: I83ce52865302738706425b0ca661ec46a9a445bc Fixes: rhbz#999923 --- packstack/installer/basedefs.py | 72 ++++++++++++++++++++++---------- packstack/installer/run_setup.py | 2 +- packstack/plugins/puppet_950.py | 2 +- 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/packstack/installer/basedefs.py b/packstack/installer/basedefs.py index d4d38d89a..1f3f665d3 100644 --- a/packstack/installer/basedefs.py +++ b/packstack/installer/basedefs.py @@ -9,38 +9,66 @@ import pwd import sys import datetime import tempfile +import random +import string +import errno +import logging from .utils import get_current_user +# Iinitializes the directory by creating it or +# changing ownsership it already exists. +# in case there's a problem it falls back to the +# default directory +# returns the name of the created directory +def init_directory(dirname, force_ownership=True): + try: + os.makedirs(dirname, 0700) + except OSError as e: + if e.errno == errno.EEXIST and os.path.isdir(dirname): + # directory is already created, check ownership + stat = os.stat(dirname) + if (force_ownership and stat.st_uid == 0 and + os.getuid() != stat.st_uid): + print ('%s is already created and owned by root. Please change ' + 'ownership and try again.' % dirname) + sys.exit(1) + elif e.errno == errno.EACCES: + logging.info("Can't create directory %s." % dirname) + return None + else: + raise + finally: + uid, gid = get_current_user() + if uid != 0 and os.getuid() == 0: + try: + os.chown(dirname, uid, gid) + except Exception, ex: + if force_ownership: + print ('Unable to change owner of %s. Please fix ownership' + ' manually and try again.' % dirname) + sys.exit(1) + return dirname APP_NAME = "Installer" FILE_YUM_VERSION_LOCK = "/etc/yum/pluginconf.d/versionlock.list" -PACKSTACK_VAR_DIR = "/var/tmp/packstack" -try: - os.mkdir(PACKSTACK_VAR_DIR, 0700) -except OSError: - # directory is already created, check ownership - stat = os.stat(PACKSTACK_VAR_DIR) - if stat.st_uid == 0 and os.getuid() != stat.st_uid: - print ('%s is already created and owned by root. Please change ' - 'ownership and try again.' % PACKSTACK_VAR_DIR) - sys.exit(1) -finally: - uid, gid = get_current_user() - - if uid != 0 and os.getuid() == 0: - try: - os.chown(PACKSTACK_VAR_DIR, uid, gid) - except Exception, ex: - print ('Unable to change owner of %s. Please fix ownership ' - 'manually and try again.' % PACKSTACK_VAR_DIR) - sys.exit(1) +PACKSTACK_VAR_DIR = init_directory("/var/tmp/packstack") +PACKSTACK_LOG_DIR = init_directory("/var/log/packstack", force_ownership=False) +if not PACKSTACK_LOG_DIR: + PACKSTACK_LOG_DIR = PACKSTACK_VAR_DIR _tmpdirprefix = datetime.datetime.now().strftime('%Y%m%d-%H%M%S-') -VAR_DIR = tempfile.mkdtemp(prefix=_tmpdirprefix, dir=PACKSTACK_VAR_DIR) -DIR_LOG = VAR_DIR +LOG_DIR = "" +VAR_DIR = tempfile.mkdtemp(prefix=_tmpdirprefix, dir=PACKSTACK_VAR_DIR,) +if PACKSTACK_VAR_DIR != PACKSTACK_LOG_DIR: + LOG_DIR = VAR_DIR.replace("tmp", "log") + init_directory(LOG_DIR) +else: + LOG_DIR = VAR_DIR + + PUPPET_MANIFEST_RELATIVE = "manifests" PUPPET_MANIFEST_DIR = os.path.join(VAR_DIR, PUPPET_MANIFEST_RELATIVE) diff --git a/packstack/installer/run_setup.py b/packstack/installer/run_setup.py index d111452f1..85c7283c9 100644 --- a/packstack/installer/run_setup.py +++ b/packstack/installer/run_setup.py @@ -36,7 +36,7 @@ def initLogging (debug): try: logFilename = "openstack-setup.log" - logFile = os.path.join(basedefs.DIR_LOG, logFilename) + logFile = os.path.join(basedefs.LOG_DIR, logFilename) # Create the log file with specific permissions, puppet has a habbit of putting # passwords in logs diff --git a/packstack/plugins/puppet_950.py b/packstack/plugins/puppet_950.py index 7ca618da5..5d01c733a 100644 --- a/packstack/plugins/puppet_950.py +++ b/packstack/plugins/puppet_950.py @@ -141,7 +141,7 @@ def waitforpuppet(currently_running): # Once a remote puppet run has finished, we retrieve the log # file and check it for errors local_server = utils.ScriptRunner() - log = os.path.join(basedefs.PUPPET_MANIFEST_DIR, + log = os.path.join(basedefs.LOG_DIR, os.path.basename(finished_logfile).replace(".finished", ".log")) local_server.append('scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@%s:%s %s' % (hostname, finished_logfile, log)) # To not pollute logs we turn of logging of command execution