Add oslo config glue

Sem-Ver: feature
This commit is contained in:
Mehdi Abaakouk 2016-09-21 09:54:04 +02:00
parent 40a80c12c9
commit 2d5bef79de
5 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,44 @@
# 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 copy
import logging
from oslo_config import cfg
LOG = logging.getLogger(__name__)
service_opts = [
cfg.BoolOpt('log_options',
default=True,
help='Enables or disables logging values of all '
'registered options when starting a service (at DEBUG '
'level).'),
cfg.IntOpt('graceful_shutdown_timeout',
default=60,
help='Specify a timeout after which a gracefully shutdown '
'server will exit. Zero value means endless wait.'),
]
def load_options(service, conf):
"""Load some service configuration from oslo config object."""
conf.register_opts(service_opts)
service.graceful_shutdown_timeout = conf.graceful_shutdown_timeout
if conf.log_options:
LOG.debug('Full set of CONF:')
conf.log_opt_values(LOG, logging.DEBUG)
def list_opts(self):
"""Entry point for oslo-config-generator."""
return [(None, copy.deepcopy(service_opts))]

View File

@ -15,7 +15,10 @@ import sys
import threading
import time
from oslo_config import cfg
import cotyledon
from cotyledon import oslo_config_glue
LOG = logging.getLogger(__name__)
@ -54,6 +57,17 @@ class BuggyService(cotyledon.Service):
LOG.error("time.sleep done")
class OsloService(cotyledon.Service):
name = "oslo"
def __init__(self, worker_id):
conf = cfg.ConfigOpts()
conf([], project='gnocchi', validate_default_values=True,
version="0.1")
oslo_config_glue.load_options(self, conf)
oslo_config_glue.list_opts()
def example_app():
logging.basicConfig(level=logging.DEBUG)
p = cotyledon.ServiceManager()
@ -67,3 +81,10 @@ def buggy_app():
p = cotyledon.ServiceManager()
p.add(BuggyService)
p.run()
def oslo_app():
logging.basicConfig(level=logging.DEBUG)
p = cotyledon.ServiceManager()
p.add(OsloService)
p.run()

View File

@ -219,3 +219,14 @@ class TestBuggyCotyledon(Base):
b'exiting buggy(0) [XXXX] now.',
b'DEBUG:cotyledon:Shutdown finish'
], lines[-2:])
class TestOsloCotyledon(Base):
name = "cotyledon-oslo"
def test_options(self):
lines = self.get_lines(1)
self.assertEqual(
b'DEBUG:cotyledon.oslo_config_glue:Full set of CONF:',
lines[0])
self.subp.terminate()

View File

@ -26,6 +26,10 @@ packages =
console_scripts =
cotyledon-example = cotyledon.tests.examples:example_app
cotyledon-buggy = cotyledon.tests.examples:buggy_app
cotyledon-oslo = cotyledon.tests.examples:oslo_app
oslo.config.opts =
cotyledon.service = cotyledon.oslo_config_glue:list_opts
[build_sphinx]
source-dir = doc/source

View File

@ -9,6 +9,7 @@ python-subunit>=0.0.18
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
oslosphinx>=2.5.0 # Apache-2.0
oslotest>=1.10.0 # Apache-2.0
oslo.config>=3.14.0 # Apache-2.0
testrepository>=0.0.18
testscenarios>=0.4
testtools>=1.4.0