Allow configuration file to be specified via --config-file

Additionally - Allows Moniker to run when no configuration file is found, using the defaults.

Fixes bug #1083331

Change-Id: Ie7659db7c873ae1ba47a29d160a0fb73739dbeb0
This commit is contained in:
Kiall Mac Innes 2013-01-08 10:06:04 +00:00
parent 19a3ae7acb
commit 523811014a
4 changed files with 24 additions and 13 deletions

View File

@ -17,6 +17,7 @@ from paste import deploy
from moniker.openstack.common import log as logging
from moniker.openstack.common import wsgi
from moniker.openstack.common import cfg
from moniker import exceptions
from moniker import utils
@ -26,9 +27,15 @@ LOG = logging.getLogger(__name__)
class Service(wsgi.Service):
def __init__(self, backlog=128, threads=1000):
config_path = utils.find_config(cfg.CONF.api_paste_config)
config_paths = utils.find_config(cfg.CONF.api_paste_config)
application = deploy.loadapp("config:%s" % config_path,
if len(config_paths) == 0:
msg = 'Unable to determine appropriate api-paste-config file'
raise exceptions.ConfigurationError(msg)
LOG.info('Using api-paste-config found at: %s' % config_paths[0])
application = deploy.loadapp("config:%s" % config_paths[0],
name='osapi_dns')
super(Service, self).__init__(application=application,

View File

@ -23,10 +23,6 @@ class ConfigurationError(Base):
pass
class ConfigNotFound(ConfigurationError):
pass
class NoServersConfigured(ConfigurationError):
pass

View File

@ -30,7 +30,15 @@ cfg.CONF.register_opts([
def init_policy():
LOG.info('Initializing Policy')
with open(utils.find_config(cfg.CONF.policy_file)) as fh:
policy_files = utils.find_config(cfg.CONF.policy_file)
if len(policy_files) == 0:
msg = 'Unable to determine appropriate policy json file'
raise exceptions.ConfigurationError(msg)
LOG.info('Using policy_file found at: %s' % policy_files[0])
with open(policy_files[0]) as fh:
policy_json = fh.read()
rules = policy.Rules.load_json(policy_json, cfg.CONF.policy_default_rule)

View File

@ -39,8 +39,7 @@ def find_config(config_path):
Code nabbed from cinder.
:param config_path: Full or relative path to the config.
:returns: Full path of the config, if it exists.
:raises: `moniker.exceptions.ConfigNotFound`
:returns: List of config paths
"""
possible_locations = [
config_path,
@ -50,18 +49,19 @@ def find_config(config_path):
"/etc/moniker/%s" % config_path,
]
found_locations = []
for path in possible_locations:
LOG.debug('Searching for configuration at path: %s' % path)
if os.path.exists(path):
LOG.debug('Found configuration at path: %s' % path)
return os.path.abspath(path)
found_locations.append(os.path.abspath(path))
msg = 'No configuration file found for %s' % config_path
raise exceptions.ConfigNotFound(msg)
return found_locations
def read_config(prog, argv):
config_files = [find_config('%s.conf' % prog)]
config_files = find_config('%s.conf' % prog)
cfg.CONF(argv[1:], project='moniker', prog=prog,
default_config_files=config_files)