Merge "Switch Freezer-api to oslo.config and oslo.log"
This commit is contained in:
commit
04a3c8983a
29
README.rst
29
README.rst
|
@ -81,9 +81,34 @@ To get information about optional additional parameters:
|
|||
--------------------------------
|
||||
::
|
||||
|
||||
# uwsgi --http :9090 --need-app --master --module freezer_api.cmd.api:application
|
||||
# uwsgi --http :9090 --need-app --master --module freezer_api.cmd.wsgi:application
|
||||
|
||||
# uwsgi --https :9090,foobar.crt,foobar.key --need-app --master --module freezer_api.cmd.api:application
|
||||
# uwsgi --https :9090,foobar.crt,foobar.key --need-app --master --module freezer_api.cmd.wsgi:application
|
||||
|
||||
|
||||
1.7 example running freezer-api with apache2
|
||||
--------------------------------
|
||||
::
|
||||
# sudo vi /etc/apache2/sites-enabled/freezer-api.conf
|
||||
<VirtualHost ...>
|
||||
WSGIDaemonProcess freezer-api processes=2 threads=2 user=freezer
|
||||
WSGIProcessGroup freezer-api
|
||||
WSGIApplicationGroup freezer-api
|
||||
WSGIScriptAlias / /opt/stack/freezer_api/cmd/wsgi.py
|
||||
|
||||
ErrorLog /var/log/freezer-api/freezer-api.log
|
||||
CustomLog /var/log/freezer-api/freezer-api_access.log combined
|
||||
LogLevel info
|
||||
|
||||
<Directory /opt/stack/freezer_api>
|
||||
Options Indexes FollowSymLinks MultiViews
|
||||
Require all granted
|
||||
AllowOverride None
|
||||
Order allow,deny
|
||||
allow from all
|
||||
LimitRequestBody 102400
|
||||
</Directory>
|
||||
</VirtualHost>
|
||||
|
||||
|
||||
2. Devstack Plugin
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
[DEFAULT]
|
||||
output_file = etc/freezer-api.conf.sample
|
||||
wrap_width = 79
|
||||
namespace = "freezer-api"
|
||||
namespace = oslo.log
|
|
@ -4,7 +4,7 @@ Listen %SERVICE_HOST%:%FREEZER_API_PORT%
|
|||
WSGIDaemonProcess freezer-api processes=2 threads=2 user=%USER%
|
||||
WSGIProcessGroup freezer-api
|
||||
WSGIApplicationGroup freezer-api
|
||||
WSGIScriptAlias / %FREEZER_API_DIR%/freezer_api/cmd/api.py
|
||||
WSGIScriptAlias / %FREEZER_API_DIR%/freezer_api/cmd/wsgi.py
|
||||
|
||||
ErrorLog /var/log/%APACHE_NAME%/freezer-api.log
|
||||
CustomLog /var/log/%APACHE_NAME%/freezer-api_access.log combined
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
[DEFAULT]
|
||||
|
||||
#
|
||||
# From freezer-api
|
||||
#
|
||||
|
||||
# IP address to listen on. Default is 0.0.0.0 (IP address value)
|
||||
#bind_host = 0.0.0.0
|
||||
|
||||
# Port number to listen on. Default is 9090 (integer value)
|
||||
# Minimum value: 1
|
||||
# Maximum value: 65535
|
||||
#bind_port = 9090
|
||||
|
||||
#
|
||||
# From oslo.log
|
||||
#
|
||||
|
||||
# If set to true, the logging level will be set to DEBUG instead of the default
|
||||
# INFO level. (boolean value)
|
||||
#debug = false
|
||||
|
||||
# If set to false, the logging level will be set to WARNING instead of the
|
||||
# default INFO level. (boolean value)
|
||||
# This option is deprecated for removal.
|
||||
# Its value may be silently ignored in the future.
|
||||
#verbose = true
|
||||
|
||||
# The name of a logging configuration file. This file is appended to any
|
||||
# existing logging configuration files. For details about logging configuration
|
||||
# files, see the Python logging module documentation. Note that when logging
|
||||
# configuration files are used then all logging configuration is set in the
|
||||
# configuration file and other logging configuration options are ignored (for
|
||||
# example, logging_context_format_string). (string value)
|
||||
# Deprecated group/name - [DEFAULT]/log_config
|
||||
#log_config_append = <None>
|
||||
|
||||
# Defines the format string for %%(asctime)s in log records. Default:
|
||||
# %(default)s . This option is ignored if log_config_append is set. (string
|
||||
# value)
|
||||
#log_date_format = %Y-%m-%d %H:%M:%S
|
||||
|
||||
# (Optional) Name of log file to send logging output to. If no default is set,
|
||||
# logging will go to stderr as defined by use_stderr. This option is ignored if
|
||||
# log_config_append is set. (string value)
|
||||
# Deprecated group/name - [DEFAULT]/logfile
|
||||
#log_file = <None>
|
||||
|
||||
# (Optional) The base directory used for relative log_file paths. This option
|
||||
# is ignored if log_config_append is set. (string value)
|
||||
# Deprecated group/name - [DEFAULT]/logdir
|
||||
#log_dir = <None>
|
||||
|
||||
# Uses logging handler designed to watch file system. When log file is moved or
|
||||
# removed this handler will open a new log file with specified path
|
||||
# instantaneously. It makes sense only if log_file option is specified and
|
||||
# Linux platform is used. This option is ignored if log_config_append is set.
|
||||
# (boolean value)
|
||||
#watch_log_file = false
|
||||
|
||||
# Use syslog for logging. Existing syslog format is DEPRECATED and will be
|
||||
# changed later to honor RFC5424. This option is ignored if log_config_append
|
||||
# is set. (boolean value)
|
||||
#use_syslog = false
|
||||
|
||||
# Syslog facility to receive log lines. This option is ignored if
|
||||
# log_config_append is set. (string value)
|
||||
#syslog_log_facility = LOG_USER
|
||||
|
||||
# Log output to standard error. This option is ignored if log_config_append is
|
||||
# set. (boolean value)
|
||||
#use_stderr = true
|
||||
|
||||
# Format string to use for log messages with context. (string value)
|
||||
#logging_context_format_string = %(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [%(request_id)s %(user_identity)s] %(instance)s%(message)s
|
||||
|
||||
# Format string to use for log messages when context is undefined. (string
|
||||
# value)
|
||||
#logging_default_format_string = %(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [-] %(instance)s%(message)s
|
||||
|
||||
# Additional data to append to log message when logging level for the message
|
||||
# is DEBUG. (string value)
|
||||
#logging_debug_format_suffix = %(funcName)s %(pathname)s:%(lineno)d
|
||||
|
||||
# Prefix each line of exception output with this format. (string value)
|
||||
#logging_exception_prefix = %(asctime)s.%(msecs)03d %(process)d ERROR %(name)s %(instance)s
|
||||
|
||||
# Defines the format string for %(user_identity)s that is used in
|
||||
# logging_context_format_string. (string value)
|
||||
#logging_user_identity_format = %(user)s %(tenant)s %(domain)s %(user_domain)s %(project_domain)s
|
||||
|
||||
# List of package logging levels in logger=LEVEL pairs. This option is ignored
|
||||
# if log_config_append is set. (list value)
|
||||
#default_log_levels = amqp=WARN,amqplib=WARN,boto=WARN,qpid=WARN,sqlalchemy=WARN,suds=INFO,oslo.messaging=INFO,iso8601=WARN,requests.packages.urllib3.connectionpool=WARN,urllib3.connectionpool=WARN,websocket=WARN,requests.packages.urllib3.util.retry=WARN,urllib3.util.retry=WARN,keystonemiddleware=WARN,routes.middleware=WARN,stevedore=WARN,taskflow=WARN,keystoneauth=WARN,oslo.cache=INFO,dogpile.core.dogpile=INFO
|
||||
|
||||
# Enables or disables publication of error events. (boolean value)
|
||||
#publish_errors = false
|
||||
|
||||
# The format for an instance that is passed with the log message. (string
|
||||
# value)
|
||||
#instance_format = "[instance: %(uuid)s] "
|
||||
|
||||
# The format for an instance UUID that is passed with the log message. (string
|
||||
# value)
|
||||
#instance_uuid_format = "[instance: %(uuid)s] "
|
||||
|
||||
# Enables or disables fatal status of deprecations. (boolean value)
|
||||
#fatal_deprecations = false
|
|
@ -0,0 +1,20 @@
|
|||
# (c) Copyright 2016 Hewlett-Packard Enterprise Development Company, L.P.
|
||||
#
|
||||
# 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.
|
||||
|
||||
# Freezer-api Version
|
||||
|
||||
import pbr.version
|
||||
|
||||
|
||||
__version__ = pbr.version.VersionInfo('freezer-api').version_string()
|
|
@ -17,12 +17,11 @@ limitations under the License.
|
|||
|
||||
from __future__ import print_function
|
||||
import falcon
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from keystonemiddleware import auth_token
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from wsgiref import simple_server
|
||||
|
||||
from freezer_api.api.common import middleware
|
||||
|
@ -32,11 +31,15 @@ from freezer_api.api import versions
|
|||
from freezer_api.common import _i18n
|
||||
from freezer_api.common import config
|
||||
from freezer_api.common import exceptions as freezer_api_exc
|
||||
from freezer_api.common import log
|
||||
from freezer_api.storage import driver
|
||||
|
||||
CONF = cfg.CONF
|
||||
_LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
def get_application(db):
|
||||
config.parse_args()
|
||||
config.setup_logging()
|
||||
app = falcon.API()
|
||||
|
||||
for exception_class in freezer_api_exc.exception_handlers_catalog:
|
||||
|
@ -56,41 +59,30 @@ def get_application(db):
|
|||
if 'keystone_authtoken' in config.CONF:
|
||||
app = auth_token.AuthProtocol(app, {})
|
||||
else:
|
||||
logging.warning(_i18n._LW("keystone authentication disabled"))
|
||||
_LOG.warning(_i18n._LW("keystone authentication disabled"))
|
||||
|
||||
app = middleware.HealthApp(app=app, path='/v1/health')
|
||||
|
||||
return app
|
||||
|
||||
config_file = '/etc/freezer-api.conf'
|
||||
config_files_list = [config_file] if os.path.isfile(config_file) else []
|
||||
config.parse_args(args=[], default_config_files=config_files_list)
|
||||
log.setup()
|
||||
logging.info(_i18n._LI("Freezer API starting"))
|
||||
logging.info(_i18n._LI("Freezer config file(s) used: %s")
|
||||
% ', '.join(cfg.CONF.config_file))
|
||||
try:
|
||||
db = driver.get_db()
|
||||
application = get_application(db)
|
||||
except Exception as err:
|
||||
message = _i18n._('Unable to start server: %s ') % err
|
||||
print(message)
|
||||
logging.fatal(message)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
db = driver.get_db()
|
||||
application = get_application(db)
|
||||
except Exception as err:
|
||||
message = _i18n._('Unable to start server: %s ') % err
|
||||
print(message)
|
||||
_LOG.error(message)
|
||||
sys.exit(1)
|
||||
# quick simple server for testing purposes or simple scenarios
|
||||
ip, port = '127.0.0.1', 9090
|
||||
if len(sys.argv) > 1:
|
||||
ip = sys.argv[1]
|
||||
if ':' in ip:
|
||||
ip, port = ip.split(':')
|
||||
ip = CONF.get('bind_host', '0.0.0.0')
|
||||
port = CONF.get('bind_port', 9090)
|
||||
httpd = simple_server.make_server(ip, int(port), application)
|
||||
message = _i18n._('Server listening on %(ip)s:%(port)s'
|
||||
% {'ip': ip, 'port': port})
|
||||
print(message)
|
||||
logging.info(message)
|
||||
_LOG.info(message)
|
||||
try:
|
||||
httpd.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"""Freezer swift.py related tests
|
||||
|
||||
(c) Copyright 2014,2015 Hewlett-Packard Development Company, L.P.
|
||||
"""
|
||||
(c) Copyright 2015-2016 Hewlett-Packard Enterprise Development Company, L.P.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -15,16 +14,20 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
|
||||
"""
|
||||
from freezer_api.cmd.api import get_application
|
||||
from freezer_api.storage import driver
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
import unittest
|
||||
from mock import Mock, patch
|
||||
|
||||
from freezer_api.cmd import api
|
||||
from freezer_api.api import common
|
||||
|
||||
class TestAPI(unittest.TestCase):
|
||||
CONF = cfg.CONF
|
||||
_LOG = log.getLogger(__name__)
|
||||
|
||||
@patch('freezer_api.storage.elastic.logging')
|
||||
def test_auth_install(self, mock_logging):
|
||||
app = api.get_application(None)
|
||||
assert isinstance(app, common.middleware.HealthApp)
|
||||
try:
|
||||
db = driver.get_db()
|
||||
except Exception as err:
|
||||
message = 'Unable to start server: {0} '.format(err)
|
||||
_LOG.error(message)
|
||||
|
||||
application = get_application(db)
|
|
@ -14,25 +14,62 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
|
||||
common_cli_opts = [
|
||||
cfg.BoolOpt('verbose',
|
||||
short='v',
|
||||
default=False,
|
||||
help='Print more verbose output.'),
|
||||
cfg.BoolOpt('debug',
|
||||
short='d',
|
||||
default=False,
|
||||
help='Print debugging output.'),
|
||||
]
|
||||
from freezer_api import __version__ as FREEZER_API_VERSION
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_cli_opts(common_cli_opts)
|
||||
|
||||
|
||||
def parse_args(args=[], usage=None, default_config_files=[]):
|
||||
CONF(args=args,
|
||||
def api_common_opts():
|
||||
|
||||
_COMMON = [
|
||||
cfg.IPOpt('bind-host',
|
||||
default='0.0.0.0',
|
||||
dest='bind_host',
|
||||
help='IP address to listen on. Default is 0.0.0.0'),
|
||||
cfg.PortOpt('bind-port',
|
||||
default=9090,
|
||||
dest='bind_port',
|
||||
help='Port number to listen on. Default is 9090'
|
||||
)
|
||||
]
|
||||
|
||||
return _COMMON
|
||||
|
||||
|
||||
def parse_args():
|
||||
CONF.register_cli_opts(api_common_opts())
|
||||
log.register_options(CONF)
|
||||
default_config_files = cfg.find_config_files('freezer', 'freezer-api')
|
||||
CONF(args=sys.argv[1:],
|
||||
project='freezer-api',
|
||||
default_config_files=default_config_files)
|
||||
default_config_files=default_config_files,
|
||||
version=FREEZER_API_VERSION
|
||||
)
|
||||
|
||||
|
||||
def setup_logging():
|
||||
_DEFAULT_LOG_LEVELS = ['amqp=WARN', 'amqplib=WARN', 'boto=WARN',
|
||||
'qpid=WARN', 'stevedore=WARN','oslo_log=INFO',
|
||||
'iso8601=WARN',
|
||||
'requests.packages.urllib3.connectionpool=WARN',
|
||||
'urllib3.connectionpool=WARN', 'websocket=WARN',
|
||||
'keystonemiddleware=WARN', 'routes.middleware=WARN']
|
||||
_DEFAULT_LOGGING_CONTEXT_FORMAT = ('%(asctime)s.%(msecs)03d %(process)d '
|
||||
'%(levelname)s %(name)s [%(request_id)s '
|
||||
'%(user_identity)s] %(instance)s '
|
||||
'%(message)s')
|
||||
log.set_defaults(_DEFAULT_LOGGING_CONTEXT_FORMAT, _DEFAULT_LOG_LEVELS)
|
||||
log.setup(CONF, 'freezer-api', version=FREEZER_API_VERSION)
|
||||
|
||||
|
||||
def list_opts():
|
||||
_OPTS = {
|
||||
None: api_common_opts()
|
||||
}
|
||||
return _OPTS.items()
|
||||
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
"""
|
||||
(c) Copyright 2014,2015 Hewlett-Packard Development Company, L.P.
|
||||
|
||||
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 logging
|
||||
from oslo_config import cfg
|
||||
|
||||
|
||||
logging_cli_opts = [
|
||||
cfg.StrOpt('log-file',
|
||||
metavar='PATH',
|
||||
help='(Optional) Name of log file to output to. '
|
||||
'If no default is set, logging will go to stdout.'),
|
||||
cfg.BoolOpt('use-syslog',
|
||||
help='Use syslog for logging.'),
|
||||
cfg.StrOpt('syslog-log-facility',
|
||||
help='syslog facility to receive log lines')
|
||||
]
|
||||
|
||||
logging_opts = [
|
||||
cfg.StrOpt('logging_file',
|
||||
metavar='PATH',
|
||||
default='freezer-api.log',
|
||||
help='(Optional) Name of log file to output to. '
|
||||
'If no default is set, logging will go to stdout.'),
|
||||
cfg.BoolOpt('logging_use_syslog',
|
||||
default=False,
|
||||
help='Use syslog for logging.'),
|
||||
cfg.StrOpt('logging_syslog_log_facility',
|
||||
default='LOG_USER',
|
||||
help='syslog facility to receive log lines')
|
||||
]
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(logging_opts)
|
||||
CONF.register_cli_opts(logging_cli_opts)
|
||||
|
||||
|
||||
def setup():
|
||||
try:
|
||||
log_file = CONF['log_file'] # cli provided
|
||||
except Exception:
|
||||
log_file = CONF['logging_file'] # .conf file
|
||||
logging.basicConfig(
|
||||
filename=log_file,
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s %(name)s %(levelname)s %(message)s')
|
|
@ -4,4 +4,5 @@ jsonschema>=2.0.0,<3.0.0,!=2.5.0 # MIT
|
|||
keystonemiddleware>=4.0.0 # Apache-2.0
|
||||
oslo.config>=3.2.0 # Apache-2.0
|
||||
oslo.i18n>=1.5.0 # Apache-2.0
|
||||
oslo.log>=1.14.0 # Apache-2.0
|
||||
six>=1.9.0 # MIT
|
||||
|
|
|
@ -42,6 +42,8 @@ build-dir = doc/build
|
|||
all_files = 1
|
||||
|
||||
[entry_points]
|
||||
oslo.config.opts =
|
||||
freezer-api = freezer_api.common.config:list_opts
|
||||
console_scripts =
|
||||
freezer-api = freezer_api.cmd.api:main
|
||||
freezer-db-init = freezer_api.cmd.db_init:main
|
||||
|
|
7
setup.py
7
setup.py
|
@ -15,6 +15,13 @@
|
|||
# limitations under the License.
|
||||
|
||||
from setuptools import setup
|
||||
# In python < 2.7.4, a lazy loading of package `pbr` will break
|
||||
# setuptools if some other modules registered functions in `atexit`.
|
||||
# solution from: http://bugs.python.org/issue15881#msg170215
|
||||
try:
|
||||
import multiprocessing # noqa
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
setup(
|
||||
setup_requires=['pbr'],
|
||||
|
|
Loading…
Reference in New Issue