Address issue with oslo config rejecting cli options for logging
This commit is contained in:
parent
478c7e62f7
commit
b404d85b63
2
.coveragerc
Normal file
2
.coveragerc
Normal file
@ -0,0 +1,2 @@
|
||||
[report]
|
||||
omit = etc/*,setup.py,*egg*,.tox/*,barbican/tests/*,barbican/openstack/*
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -26,6 +26,7 @@ pip-log.txt
|
||||
.coverage
|
||||
.tox
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
|
@ -24,22 +24,27 @@ from barbican.api.resources import TenantsResource, TenantResource
|
||||
from barbican.api.resources import CSRsResource, CSRResource
|
||||
from barbican.api.resources import CertificatesResource, CertificateResource
|
||||
from barbican.api.resources import SecretsResource, SecretResource
|
||||
|
||||
# Resources
|
||||
VERSIONS = VersionResource()
|
||||
TENANTS = TenantsResource()
|
||||
TENANT = TenantResource()
|
||||
SECRETS = SecretsResource()
|
||||
SECRET = SecretResource()
|
||||
CSRS = CSRsResource()
|
||||
CSR = CSRResource()
|
||||
CERTS = CertificatesResource()
|
||||
CERT = CertificateResource()
|
||||
from barbican.openstack.common import log
|
||||
from barbican.common import config
|
||||
|
||||
|
||||
def create_main_app(global_config, **local_conf):
|
||||
"""uWSGI factory method for the Barbican-API application"""
|
||||
|
||||
config.parse_args()
|
||||
log.setup('barbican')
|
||||
|
||||
# Resources
|
||||
VERSIONS = VersionResource()
|
||||
TENANTS = TenantsResource()
|
||||
TENANT = TenantResource()
|
||||
SECRETS = SecretsResource()
|
||||
SECRET = SecretResource()
|
||||
CSRS = CSRsResource()
|
||||
CSR = CSRResource()
|
||||
CERTS = CertificatesResource()
|
||||
CERT = CertificateResource()
|
||||
|
||||
wsgi_app = api = falcon.API()
|
||||
api.add_route('/', VERSIONS)
|
||||
api.add_route('/tenants', TENANTS)
|
||||
@ -51,5 +56,4 @@ def create_main_app(global_config, **local_conf):
|
||||
api.add_route('/{tenant_id}/certificates', CERTS)
|
||||
api.add_route('/{tenant_id}/certificates/{cert_id}', CERT)
|
||||
|
||||
return wsgi_app
|
||||
|
||||
return wsgi_app
|
@ -20,16 +20,12 @@ A filter middleware that just outputs to logs, for instructive/sample purposes o
|
||||
"""
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from barbican.api.middleware import Middleware
|
||||
from barbican.common import utils
|
||||
|
||||
import barbican.openstack.common.log as logging
|
||||
|
||||
|
||||
LOG = utils.getLogger(__name__)
|
||||
CONF = cfg.CONF
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SimpleFilter(Middleware):
|
||||
|
||||
|
@ -27,12 +27,11 @@ from barbican.model.repositories import TenantRepo, SecretRepo
|
||||
from barbican.model.repositories import CSRRepo, CertificateRepo
|
||||
from barbican.queue.resources import QueueResource, StartCSRMessage
|
||||
from barbican.crypto.fields import encrypt, decrypt
|
||||
from barbican.common import config
|
||||
from barbican.openstack.common.gettextutils import _
|
||||
import barbican.openstack.common.log as logging
|
||||
from barbican.openstack.common import jsonutils as json
|
||||
from barbican.common import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOG = utils.getLogger(__name__)
|
||||
|
||||
|
||||
def _tenant_not_found():
|
||||
|
@ -17,18 +17,76 @@
|
||||
Configuration setup for Barbican.
|
||||
"""
|
||||
|
||||
|
||||
import logging
|
||||
import logging.config
|
||||
import logging.handlers
|
||||
import os
|
||||
import sys
|
||||
|
||||
from barbican.version import __version__
|
||||
from oslo.config import cfg
|
||||
|
||||
# Ensure the local python config path is on the list to pull config info from
|
||||
CONF_FILES = cfg.find_config_files(prog='barbican-api')
|
||||
|
||||
#CONF_FILES = cfg.find_config_files(project='barbican', prog='barbican-api')
|
||||
CONF_FILES.append('./etc/barbican/barbican-api.conf')
|
||||
CONF_FILES.append('../etc/barbican/barbican-api.conf')
|
||||
CONF_FILES = [cfile for cfile in CONF_FILES if os.path.isfile(cfile)]
|
||||
|
||||
# Set configuration files
|
||||
CONF = cfg.CONF
|
||||
CONF(prog='barbican-api', default_config_files=CONF_FILES)
|
||||
CONF.import_opt('verbose', 'barbican.openstack.common.log')
|
||||
CONF.import_opt('debug', 'barbican.openstack.common.log')
|
||||
CONF.import_opt('log_dir', 'barbican.openstack.common.log')
|
||||
CONF.import_opt('log_file', 'barbican.openstack.common.log')
|
||||
CONF.import_opt('log_config', 'barbican.openstack.common.log')
|
||||
CONF.import_opt('log_format', 'barbican.openstack.common.log')
|
||||
CONF.import_opt('log_date_format', 'barbican.openstack.common.log')
|
||||
CONF.import_opt('use_syslog', 'barbican.openstack.common.log')
|
||||
CONF.import_opt('syslog_log_facility', 'barbican.openstack.common.log')
|
||||
|
||||
|
||||
def parse_args(args=None, usage=None, default_config_files=None):
|
||||
CONF(args=args,
|
||||
project='barbican',
|
||||
prog='barbican-api',
|
||||
version=__version__,
|
||||
usage=usage,
|
||||
default_config_files=default_config_files)
|
||||
|
||||
|
||||
def setup_logging():
|
||||
"""
|
||||
Sets up the logging options
|
||||
"""
|
||||
|
||||
if CONF.log_config:
|
||||
# Use a logging configuration file for all settings...
|
||||
if os.path.exists(CONF.log_config):
|
||||
logging.config.fileConfig(CONF.log_config)
|
||||
return
|
||||
else:
|
||||
raise RuntimeError("Unable to locate specified logging "
|
||||
"config file: %s" % CONF.log_config)
|
||||
|
||||
root_logger = logging.root
|
||||
if CONF.debug:
|
||||
root_logger.setLevel(logging.DEBUG)
|
||||
elif CONF.verbose:
|
||||
root_logger.setLevel(logging.INFO)
|
||||
else:
|
||||
root_logger.setLevel(logging.WARNING)
|
||||
|
||||
formatter = logging.Formatter(CONF.log_format, CONF.log_date_format)
|
||||
|
||||
if CONF.use_syslog:
|
||||
try:
|
||||
facility = getattr(logging.handlers.SysLogHandler,
|
||||
CONF.syslog_log_facility)
|
||||
except AttributeError:
|
||||
raise ValueError(_("Invalid syslog facility"))
|
||||
|
||||
handler = logging.handlers.SysLogHandler(address='/dev/log',
|
||||
facility=facility)
|
||||
elif CONF.log_file:
|
||||
logfile = CONF.log_file
|
||||
if CONF.log_dir:
|
||||
logfile = os.path.join(CONF.log_dir, logfile)
|
||||
handler = logging.handlers.WatchedFileHandler(logfile)
|
||||
else:
|
||||
handler = logging.StreamHandler(sys.stdout)
|
||||
|
||||
handler.setFormatter(formatter)
|
||||
root_logger.addHandler(handler)
|
||||
|
29
barbican/common/utils.py
Normal file
29
barbican/common/utils.py
Normal file
@ -0,0 +1,29 @@
|
||||
# Copyright (c) 2013 Rackspace, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""
|
||||
Common utilities for Barbican.
|
||||
"""
|
||||
|
||||
import barbican.openstack.common.log as logging
|
||||
|
||||
|
||||
# Return a logger instance.
|
||||
# Note: Centralize access to the logger to avoid the dreaded
|
||||
# 'ArgsAlreadyParsedError: arguments already parsed: cannot register CLI option'
|
||||
# error.
|
||||
def getLogger(name):
|
||||
return logging.getLogger(name)
|
||||
|
@ -17,7 +17,6 @@
|
||||
Defines database models for Barbican
|
||||
"""
|
||||
|
||||
|
||||
from sqlalchemy import Column, Integer, String, BigInteger
|
||||
from sqlalchemy.ext.compiler import compiles
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
@ -28,9 +27,9 @@ from sqlalchemy import Index, UniqueConstraint
|
||||
from barbican.openstack.common import timeutils
|
||||
from barbican.openstack.common import uuidutils
|
||||
from barbican.openstack.common import jsonutils as json
|
||||
import barbican.openstack.common.log as logging
|
||||
from barbican.common import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOG = utils.getLogger(__name__)
|
||||
BASE = declarative_base()
|
||||
|
||||
|
||||
|
@ -30,14 +30,14 @@ import sqlalchemy.orm as sa_orm
|
||||
import sqlalchemy.sql as sa_sql
|
||||
|
||||
from barbican.common import exception
|
||||
from barbican.common import config
|
||||
# TBD: from barbican.db.sqlalchemy import migration
|
||||
from barbican.model import models
|
||||
from barbican.openstack.common import timeutils
|
||||
from barbican.openstack.common.gettextutils import _
|
||||
import barbican.openstack.common.log as os_logging
|
||||
from barbican.common import utils
|
||||
|
||||
LOG = utils.getLogger(__name__)
|
||||
|
||||
LOG = os_logging.getLogger(__name__)
|
||||
|
||||
_ENGINE = None
|
||||
_MAKER = None
|
||||
|
@ -13,16 +13,22 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from datetime import datetime
|
||||
from barbican.api.resources import *
|
||||
from barbican.model.models import *
|
||||
from barbican.crypto.fields import *
|
||||
from barbican.common import config
|
||||
|
||||
from mock import MagicMock
|
||||
|
||||
import falcon
|
||||
import json
|
||||
import unittest
|
||||
|
||||
from datetime import datetime
|
||||
from barbican.api.resources import VersionResource
|
||||
from barbican.api.resources import TenantsResource, TenantResource
|
||||
from barbican.api.resources import CSRsResource, CSRResource
|
||||
from barbican.api.resources import CertificatesResource, CertificateResource
|
||||
from barbican.api.resources import SecretsResource, SecretResource
|
||||
from barbican.model.models import Certificate, CSR, Secret, Tenant
|
||||
from barbican.model.repositories import CSRRepo, CertificateRepo
|
||||
from barbican.model.repositories import TenantRepo, SecretRepo
|
||||
from barbican.crypto.fields import decrypt_value, encrypt_value
|
||||
from barbican.common import config
|
||||
from barbican.common import exception
|
||||
|
||||
|
||||
|
@ -1,61 +0,0 @@
|
||||
# Copyright (c) 2013 Rackspace, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from oslo.config import cfg
|
||||
from barbican.common import config
|
||||
import logging
|
||||
|
||||
# Configuration test configuration options
|
||||
test_group = cfg.OptGroup(name='test', title='Configuration Test')
|
||||
|
||||
CFG_TEST_OPTIONS = [
|
||||
cfg.BoolOpt('should_pass',
|
||||
default=False,
|
||||
help="""Example option to make sure configuration
|
||||
loading passes test.
|
||||
"""
|
||||
)
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def suite():
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(WhenConfiguring())
|
||||
|
||||
return suite
|
||||
|
||||
|
||||
class WhenConfiguring(unittest.TestCase):
|
||||
|
||||
def test_loading(self):
|
||||
|
||||
LOG.debug("In test 'test_loading'")
|
||||
|
||||
CONF.register_group(test_group)
|
||||
CONF.register_opts(CFG_TEST_OPTIONS, group=test_group)
|
||||
|
||||
self.assertTrue(CONF.test.should_pass)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -17,9 +17,9 @@
|
||||
Simple Worker API implementation.
|
||||
"""
|
||||
from barbican.queue.resources import StartCSRMessage
|
||||
import barbican.openstack.common.log as logging
|
||||
from barbican.common import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOG = utils.getLogger(__name__)
|
||||
|
||||
|
||||
class StartCSRProcessor(object):
|
||||
|
@ -5,7 +5,7 @@
|
||||
PKG=barbican
|
||||
|
||||
# For local development, set VENV_PYTHON equal to the path to your virtual environment's site-packages location
|
||||
VENV=.venv_barbican
|
||||
VENV=.venv
|
||||
VENV_PYTHON=./$VENV/lib/python2.7/site-packages
|
||||
|
||||
PATH=/opt/uwsgi:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/etc/$PKG:$PATH
|
||||
|
@ -13,7 +13,7 @@ bind_port = 9292
|
||||
|
||||
# Log to this file. Make sure you do not set the same log
|
||||
# file for both the API and registry servers!
|
||||
log_file = /var/log/barbican/api.log
|
||||
#log_file = /var/log/barbican/api.log
|
||||
|
||||
# Backlog requests when creating socket
|
||||
backlog = 4096
|
||||
@ -87,4 +87,5 @@ scrub_time = 43200
|
||||
scrubber_datadir = /var/lib/barbican/scrubber
|
||||
|
||||
[test]
|
||||
should_pass = true
|
||||
should_pass = True
|
||||
yada = foo
|
||||
|
@ -27,12 +27,12 @@ tag_svn_revision = 0
|
||||
where=barbican
|
||||
nocapture=1
|
||||
cover-erase=1
|
||||
with-xunit=1
|
||||
all-modules=1
|
||||
traverse-namespace=1
|
||||
#-with-xunit=1
|
||||
#-all-modules=1
|
||||
#-traverse-namespace=1
|
||||
#with-coverage=1
|
||||
cover-package=barbican
|
||||
cover-inclusive=1
|
||||
#-cover-inclusive=1
|
||||
|
||||
# TBD: OpenStack stuff...
|
||||
# NOTE(jkoelker) To run the test suite under nose install the following
|
||||
|
Loading…
x
Reference in New Issue
Block a user