Exemplo n.º 1
0
 def remove_container(self, contname, kill=True):
     """destroy container on exit
     :param kill: inhibits removal for testing purposes
     """
     found = self.get_container_by_name(contname)
     if found:
         LOG.info(_LI('Removing old container [%s]' % contname))
         if kill:
             self.dc.remove_container(found, force=True)
         else:
             self.dc.stop(found)
Exemplo n.º 2
0
 def remove_container(self, contname, kill=True):
     """destroy container on exit
     :param kill: inhibits removal for testing purposes
     """
     found = self.get_container_by_name(contname)
     if found:
         LOG.info(_LI('Removing old container [%s]' % contname))
         if kill:
             self.dc.remove_container(found, force=True)
         else:
             self.dc.stop(found)
Exemplo n.º 3
0
 def get_container_by_name(self, contname):
     """
     :param contname: name or alias of the container to find
     :return: container found
     """
     found = None
     for c in self.dc.containers(all=True):
         for n in c['Names']:
             if contname in n:
                 found = c
                 break
     if not found:
         LOG.info(_LI('Container not found for removal [%s]' % contname))
     return found
Exemplo n.º 4
0
 def get_container_by_name(self, contname):
     """
     :param contname: name or alias of the container to find
     :return: container found
     """
     found = None
     for c in self.dc.containers(all=True):
         for n in c['Names']:
             if contname in n:
                 found = c
                 break
     if not found:
         LOG.info(_LI('Container not found for removal [%s]' % contname))
     return found
Exemplo n.º 5
0
def _setup_logging_from_conf(project, version):
    log_root = getLogger(None).logger
    for handler in log_root.handlers:
        log_root.removeHandler(handler)

    logpath = _get_log_file_path()
    if logpath:
        filelog = logging.handlers.WatchedFileHandler(logpath)
        log_root.addHandler(filelog)

    if CONF.use_stderr:
        streamlog = ColorHandler()
        log_root.addHandler(streamlog)

    elif not logpath:
        # pass sys.stdout as a positional argument
        # python2.6 calls the argument strm, in 2.7 it's stream
        streamlog = logging.StreamHandler(sys.stdout)
        log_root.addHandler(streamlog)

    if CONF.publish_errors:
        handler = importutils.import_object(
            "oslo.messaging.notify.log_handler.PublishErrorsHandler",
            logging.ERROR)
        log_root.addHandler(handler)

    datefmt = CONF.log_date_format
    for handler in log_root.handlers:
        # NOTE(alaski): CONF.log_format overrides everything currently.  This
        # should be deprecated in favor of context aware formatting.
        if CONF.log_format:
            handler.setFormatter(logging.Formatter(fmt=CONF.log_format,
                                                   datefmt=datefmt))
            log_root.info(_LI(
                'Deprecated: log_format is now deprecated and will '
                'be removed in the next release'))
        else:
            handler.setFormatter(ContextFormatter(project=project,
                                                  version=version,
                                                  datefmt=datefmt))

    if CONF.debug:
        log_root.setLevel(logging.DEBUG)
    elif CONF.verbose:
        log_root.setLevel(logging.INFO)
    else:
        log_root.setLevel(logging.WARNING)

    for pair in CONF.default_log_levels:
        mod, _sep, level_name = pair.partition('=')
        logger = logging.getLogger(mod)
        # NOTE(AAzza) in python2.6 Logger.setLevel doesn't convert string name
        # to integer code.
        if sys.version_info < (2, 7):
            level = logging.getLevelName(level_name)
            logger.setLevel(level)
        else:
            logger.setLevel(level_name)

    if CONF.use_syslog:
        try:
            facility = _find_facility_from_conf()
            # TODO(bogdando) use the format provided by RFCSysLogHandler
            #   after existing syslog format deprecation in J
            if CONF.use_syslog_rfc_format:
                syslog = RFCSysLogHandler(address='/dev/log',
                                          facility=facility)
            else:
                syslog = logging.handlers.SysLogHandler(address='/dev/log',
                                                        facility=facility)
            log_root.addHandler(syslog)
        except socket.error:
            log_root.error('Unable to add syslog handler. Verify that syslog '
                           'is running.')