Merge pull request #151 from harlowja/master

Fix missing logger + traceback verbosity
This commit is contained in:
Joshua Harlow 2012-03-30 10:41:09 -07:00
commit 8fd6b8a77b
5 changed files with 42 additions and 35 deletions

View File

@ -111,6 +111,14 @@ class ComponentBase(object):
def __str__(self): def __str__(self):
return "%s: %s" % (self.__class__.__name__, self.component_name) return "%s: %s" % (self.__class__.__name__, self.component_name)
def _get_params(self):
return {
'COMPONENT_DIR': self.component_dir,
'APP_DIR': self.app_dir,
'CONFIG_DIR': self.cfg_dir,
'TRACE_DIR': self.trace_dir,
}
def known_subsystems(self): def known_subsystems(self):
return set() return set()
@ -204,13 +212,9 @@ class PkgInstallComponent(ComponentBase, PackageBasedComponentMixin):
return down.GitDownloader(self.distro, uri, target_dir, branch).download() return down.GitDownloader(self.distro, uri, target_dir, branch).download()
def _get_param_map(self, config_fn): def _get_param_map(self, config_fn):
return { mp = ComponentBase._get_params(self)
'COMPONENT_DIR': self.component_dir, mp['CONFIG_FN'] = config_fn or ''
'APP_DIR': self.app_dir, return mp
'CONFIG_DIR': self.cfg_dir,
'TRACE_DIR': self.trace_dir,
'CONFIG_FN': config_fn,
}
def _get_packages(self): def _get_packages(self):
pkg_list = list(self.packages) pkg_list = list(self.packages)
@ -444,7 +448,8 @@ class PkgUninstallComponent(ComponentBase, PackageBasedComponentMixin):
pkgs = self.tracereader.packages_installed() pkgs = self.tracereader.packages_installed()
if pkgs: if pkgs:
pkg_names = set([p['name'] for p in pkgs]) pkg_names = set([p['name'] for p in pkgs])
utils.log_iterable(pkg_names, header="Potentially removing %s packages" % (len(pkg_names))) utils.log_iterable(pkg_names, logger=LOG,
header="Potentially removing %s packages" % (len(pkg_names)))
which_removed = set() which_removed = set()
with utils.progress_bar(UNINSTALL_TITLE, len(pkgs), reverse=True) as p_bar: with utils.progress_bar(UNINSTALL_TITLE, len(pkgs), reverse=True) as p_bar:
for (i, p) in enumerate(pkgs): for (i, p) in enumerate(pkgs):
@ -529,12 +534,9 @@ class ProgramRuntime(ComponentBase):
return list() return list()
def _get_param_map(self, app_name): def _get_param_map(self, app_name):
return { mp = ComponentBase._get_params(self)
'COMPONENT_DIR': self.component_dir, mp['APP_NAME'] = app_name or ''
'APP_DIR': self.app_dir, return mp
'CONFIG_DIR': self.cfg_dir,
'TRACE_DIR': self.trace_dir,
}
def pre_start(self): def pre_start(self):
pass pass

View File

@ -86,15 +86,16 @@ class DBInstaller(comp.PkgInstallComponent):
def _get_param_map(self, config_fn): def _get_param_map(self, config_fn):
# This dictionary will be used for parameter replacement # This dictionary will be used for parameter replacement
# In pre-install and post-install sections # In pre-install and post-install sections
host_ip = self.cfg.get('host', 'ip') mp = comp.PkgInstallComponent._get_param_map(self, config_fn)
out = { adds = {
'PASSWORD': self.pw_gen.get_password("sql", PASSWORD_PROMPT), 'PASSWORD': self.pw_gen.get_password("sql", PASSWORD_PROMPT),
'BOOT_START': ("%s" % (True)).lower(), 'BOOT_START': ("%s" % (True)).lower(),
'USER': self.cfg.getdefaulted("db", "sql_user", 'root'), 'USER': self.cfg.getdefaulted("db", "sql_user", 'root'),
'SERVICE_HOST': host_ip, 'SERVICE_HOST': self.cfg.get('host', 'ip'),
'HOST_IP': host_ip 'HOST_IP': self.cfg.get('host', 'ip'),
} }
return out mp.update(adds)
return mp
def warm_configs(self): def warm_configs(self):
for key, prompt in WARMUP_PWS: for key, prompt in WARMUP_PWS:

View File

@ -74,13 +74,17 @@ COWS['unhappy'] = r'''
''' '''
def configure_logging(verbosity_level=1, dry_run=False): def construct_log_level(verbosity_level, dry_run=False):
log_level = logging.INFO
if verbosity_level >= 3:
log_level = logging.DEBUG
elif verbosity_level == 2 or dry_run:
log_level = logging.AUDIT
return log_level
# Debug by default
def configure_logging(log_level):
root_logger = logging.getLogger().logger root_logger = logging.getLogger().logger
root_logger.setLevel(logging.DEBUG)
# Set our pretty logger
console_logger = logging.StreamHandler(sys.stdout) console_logger = logging.StreamHandler(sys.stdout)
console_format = '%(levelname)s: @%(name)s : %(message)s' console_format = '%(levelname)s: @%(name)s : %(message)s'
if sh.in_terminal(): if sh.in_terminal():
@ -88,13 +92,6 @@ def configure_logging(verbosity_level=1, dry_run=False):
else: else:
console_logger.setFormatter(logging.Formatter(console_format)) console_logger.setFormatter(logging.Formatter(console_format))
root_logger.addHandler(console_logger) root_logger.addHandler(console_logger)
# Adjust logging verbose level based on the command line switch.
log_level = logging.INFO
if verbosity_level >= 3:
log_level = logging.DEBUG
elif verbosity_level == 2 or dry_run:
log_level = logging.AUDIT
root_logger.setLevel(log_level) root_logger.setLevel(log_level)

13
stack
View File

@ -18,7 +18,7 @@
import sys import sys
import time import time
import traceback import traceback as tb
from devstack import cfg from devstack import cfg
from devstack import cfg_helpers from devstack import cfg_helpers
@ -179,9 +179,11 @@ def main():
prog_name = sys.argv[0] prog_name = sys.argv[0]
# Configure logging # Configure logging
utils.configure_logging(args['verbosity'], args['dryrun']) log_level = utils.construct_log_level(args['verbosity'], args['dryrun'])
utils.configure_logging(log_level)
LOG.debug("Command line options %s" % (args)) LOG.debug("Command line options %s" % (args))
LOG.debug("Log level is: %s" % (log_level))
# Will need root to setup openstack # Will need root to setup openstack
if not sh.got_root(): if not sh.got_root():
@ -206,7 +208,12 @@ def main():
return 0 return 0
except Exception: except Exception:
utils.goodbye(False) utils.goodbye(False)
traceback.print_exc(file=sys.stdout) traceback = None
if log_level <= logging.DEBUG:
# See: http://docs.python.org/library/traceback.html
traceback = sys.exc_traceback
tb.print_exception(sys.exc_type, sys.exc_value,
traceback, file=sys.stdout)
return 1 return 1

View File

@ -31,7 +31,7 @@ if __name__ == "__main__":
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
uris = options.uris or list() uris = options.uris or list()
uri_sep = ",".join(uris) uri_sep = ",".join(uris)
utils.configure_logging(3) utils.configure_logging(logging.DEBUG)
config = cfg.StackConfigParser() config = cfg.StackConfigParser()
config.add_section('img') config.add_section('img')
config.set('img', 'image_urls', uri_sep) config.set('img', 'image_urls', uri_sep)