From 3b6dc2958226907acc42f928dd1f71562d6a909d Mon Sep 17 00:00:00 2001 From: Elena Ezhova Date: Thu, 28 May 2015 15:19:33 +0300 Subject: [PATCH] Move the option definitions into a private file bp graduate-oslo-service Change-Id: I563c48bfc79bee931b3022a210a6e77fe14c86a8 --- oslo_service/_options.py | 47 +++++++++++++++++++++++++++++++ oslo_service/eventlet_backdoor.py | 20 ++++--------- oslo_service/periodic_task.py | 12 ++------ oslo_service/sslutils.py | 17 ++--------- 4 files changed, 58 insertions(+), 38 deletions(-) create mode 100644 oslo_service/_options.py diff --git a/oslo_service/_options.py b/oslo_service/_options.py new file mode 100644 index 00000000..92970904 --- /dev/null +++ b/oslo_service/_options.py @@ -0,0 +1,47 @@ +# Copyright 2015 Mirantis 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. + +from oslo_config import cfg + + +help_for_backdoor_port = ( + "Acceptable values are 0, , and :, where 0 results " + "in listening on a random tcp port number; results in listening " + "on the specified port number (and not enabling backdoor if that port " + "is in use); and : results in listening on the smallest " + "unused port number within the specified range of port numbers. The " + "chosen port is displayed in the service's log file.") +eventlet_backdoor_opts = [ + cfg.StrOpt('backdoor_port', + help="Enable eventlet backdoor. %s" % help_for_backdoor_port) +] + +periodic_opts = [ + cfg.BoolOpt('run_external_periodic_tasks', + default=True, + help='Some periodic tasks can be run in a separate process. ' + 'Should we run them here?'), +] + +ssl_opts = [ + cfg.StrOpt('ca_file', + help="CA certificate file to use to verify " + "connecting clients."), + cfg.StrOpt('cert_file', + help="Certificate file to use when starting " + "the server securely."), + cfg.StrOpt('key_file', + help="Private key file to use when starting " + "the server securely."), +] diff --git a/oslo_service/eventlet_backdoor.py b/oslo_service/eventlet_backdoor.py index b9f0281e..46a73430 100644 --- a/oslo_service/eventlet_backdoor.py +++ b/oslo_service/eventlet_backdoor.py @@ -31,28 +31,18 @@ import greenlet from oslo_config import cfg from oslo_service._i18n import _LI +from oslo_service import _options -help_for_backdoor_port = ( - "Acceptable values are 0, , and :, where 0 results " - "in listening on a random tcp port number; results in listening " - "on the specified port number (and not enabling backdoor if that port " - "is in use); and : results in listening on the smallest " - "unused port number within the specified range of port numbers. The " - "chosen port is displayed in the service's log file.") -eventlet_backdoor_opts = [ - cfg.StrOpt('backdoor_port', - help="Enable eventlet backdoor. %s" % help_for_backdoor_port) -] CONF = cfg.CONF -CONF.register_opts(eventlet_backdoor_opts) +CONF.register_opts(_options.eventlet_backdoor_opts) LOG = logging.getLogger(__name__) def list_opts(): """Entry point for oslo-config-generator. """ - return [(None, copy.deepcopy(eventlet_backdoor_opts))] + return [(None, copy.deepcopy(_options.eventlet_backdoor_opts))] class EventletBackdoorConfigValueError(Exception): @@ -97,8 +87,8 @@ def _parse_port_range(port_range): raise ValueError return start, end except ValueError as ex: - raise EventletBackdoorConfigValueError(port_range, ex, - help_for_backdoor_port) + raise EventletBackdoorConfigValueError( + port_range, ex, _options.help_for_backdoor_port) def _listen(host, start_port, end_port, listen_func): diff --git a/oslo_service/periodic_task.py b/oslo_service/periodic_task.py index d58a8c74..c25e66aa 100644 --- a/oslo_service/periodic_task.py +++ b/oslo_service/periodic_task.py @@ -20,17 +20,11 @@ from oslo_config import cfg import six from oslo_service._i18n import _, _LE, _LI +from oslo_service import _options -periodic_opts = [ - cfg.BoolOpt('run_external_periodic_tasks', - default=True, - help='Some periodic tasks can be run in a separate process. ' - 'Should we run them here?'), -] - CONF = cfg.CONF -CONF.register_opts(periodic_opts) +CONF.register_opts(_options.periodic_opts) LOG = logging.getLogger(__name__) @@ -39,7 +33,7 @@ DEFAULT_INTERVAL = 60.0 def list_opts(): """Entry point for oslo-config-generator.""" - return [(None, copy.deepcopy(periodic_opts))] + return [(None, copy.deepcopy(_options.periodic_opts))] class InvalidPeriodicTaskArg(Exception): diff --git a/oslo_service/sslutils.py b/oslo_service/sslutils.py index 2f7a0abe..bde3db81 100644 --- a/oslo_service/sslutils.py +++ b/oslo_service/sslutils.py @@ -19,28 +19,17 @@ import ssl from oslo_config import cfg from oslo_service._i18n import _ +from oslo_service import _options -ssl_opts = [ - cfg.StrOpt('ca_file', - help="CA certificate file to use to verify " - "connecting clients."), - cfg.StrOpt('cert_file', - help="Certificate file to use when starting " - "the server securely."), - cfg.StrOpt('key_file', - help="Private key file to use when starting " - "the server securely."), -] - CONF = cfg.CONF config_section = 'ssl' -CONF.register_opts(ssl_opts, config_section) +CONF.register_opts(_options.ssl_opts, config_section) def list_opts(): """Entry point for oslo-config-generator.""" - return [(config_section, copy.deepcopy(ssl_opts))] + return [(config_section, copy.deepcopy(_options.ssl_opts))] def is_enabled():