Fix bug #1075595 - Ensure a missing configuration file raises an error
Change-Id: Id87635a2434fd439070a271afe288ea3f581081b
This commit is contained in:
parent
64d7e8842e
commit
c305423b85
@ -14,24 +14,16 @@
|
||||
# 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 sys
|
||||
import eventlet
|
||||
from moniker.openstack.common import cfg
|
||||
from moniker.openstack.common import log as logging
|
||||
from moniker.openstack.common import service
|
||||
from moniker import utils
|
||||
from moniker.agent import bind9 as bind9_service
|
||||
|
||||
eventlet.monkey_patch()
|
||||
|
||||
config_files = cfg.find_config_files(project='moniker',
|
||||
prog='moniker-agent-bind9')
|
||||
|
||||
if os.path.exists('./etc/moniker-agent-bind9.conf'):
|
||||
config_files.append('./etc/moniker-agent-bind9.conf')
|
||||
|
||||
cfg.CONF(sys.argv[1:], project='moniker', prog='moniker-agent-bind9',
|
||||
default_config_files=config_files)
|
||||
utils.read_config('moniker-agent-bind9', sys.argv[1:])
|
||||
|
||||
logging.setup('moniker')
|
||||
|
||||
|
@ -14,24 +14,16 @@
|
||||
# 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 sys
|
||||
import eventlet
|
||||
from moniker.openstack.common import cfg
|
||||
from moniker.openstack.common import log as logging
|
||||
from moniker.openstack.common import service
|
||||
from moniker import utils
|
||||
from moniker.api import service as api_service
|
||||
|
||||
eventlet.monkey_patch()
|
||||
|
||||
config_files = cfg.find_config_files(project='moniker',
|
||||
prog='moniker-api')
|
||||
|
||||
if os.path.exists('./etc/moniker-api.conf'):
|
||||
config_files.append('./etc/moniker-api.conf')
|
||||
|
||||
cfg.CONF(sys.argv[1:], project='moniker', prog='moniker-api',
|
||||
default_config_files=config_files)
|
||||
utils.read_config('moniker-api', sys.argv[1:])
|
||||
|
||||
logging.setup('moniker')
|
||||
|
||||
|
@ -14,24 +14,16 @@
|
||||
# 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 sys
|
||||
import eventlet
|
||||
from moniker.openstack.common import cfg
|
||||
from moniker.openstack.common import log as logging
|
||||
from moniker.openstack.common import service
|
||||
from moniker import utils
|
||||
from moniker.central import service as central_service
|
||||
|
||||
eventlet.monkey_patch()
|
||||
|
||||
config_files = cfg.find_config_files(project='moniker',
|
||||
prog='moniker-central')
|
||||
|
||||
if os.path.exists('./etc/moniker-central.conf'):
|
||||
config_files.append('./etc/moniker-central.conf')
|
||||
|
||||
cfg.CONF(sys.argv[1:], project='moniker', prog='moniker-central',
|
||||
default_config_files=config_files)
|
||||
utils.read_config('moniker-central', sys.argv[1:])
|
||||
|
||||
logging.setup('moniker')
|
||||
|
||||
|
@ -20,7 +20,7 @@ from cliff.command import Command
|
||||
from moniker.openstack.common import log as logging
|
||||
from moniker.openstack.common import cfg
|
||||
from moniker import storage # Import for database_connection cfg def.
|
||||
from moniker.cli import utils
|
||||
from moniker import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -1,26 +0,0 @@
|
||||
# Copyright 2012 Managed I.T.
|
||||
#
|
||||
# Author: Kiall Mac Innes <kiall@managedit.ie>
|
||||
#
|
||||
# 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
|
||||
from moniker.openstack.common import cfg
|
||||
|
||||
|
||||
def read_config(prog):
|
||||
config_files = cfg.find_config_files(project='moniker', prog=prog)
|
||||
|
||||
if os.path.exists('./etc/%s.conf' % prog):
|
||||
config_files.append('./etc/%s.conf' % prog)
|
||||
|
||||
cfg.CONF(project='moniker', prog=prog, default_config_files=config_files)
|
@ -19,11 +19,11 @@ class Base(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ConfigNotFound(Base):
|
||||
class ConfigurationError(Base):
|
||||
pass
|
||||
|
||||
|
||||
class ConfigurationError(Base):
|
||||
class ConfigNotFound(ConfigurationError):
|
||||
pass
|
||||
|
||||
|
||||
|
@ -30,19 +30,17 @@ def notify(context, service, event_type, payload):
|
||||
|
||||
|
||||
def find_config(config_path):
|
||||
""" Find a configuration file using the given hint.
|
||||
"""
|
||||
Find a configuration file using the given hint.
|
||||
|
||||
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`
|
||||
|
||||
"""
|
||||
possible_locations = [
|
||||
config_path,
|
||||
os.path.join("etc", "moniker", config_path),
|
||||
os.path.join("etc", config_path),
|
||||
os.path.join(cfg.CONF.state_path, "etc", "moniker", config_path),
|
||||
os.path.join(cfg.CONF.state_path, "etc", config_path),
|
||||
os.path.join(cfg.CONF.state_path, config_path),
|
||||
@ -50,8 +48,17 @@ def find_config(config_path):
|
||||
]
|
||||
|
||||
for path in possible_locations:
|
||||
LOG.debug('Checking path: %s' % path)
|
||||
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)
|
||||
|
||||
raise exceptions.ConfigNotFound(config_path)
|
||||
msg = 'No configuration file found for %s' % config_path
|
||||
raise exceptions.ConfigNotFound(msg)
|
||||
|
||||
|
||||
def read_config(prog, argv=None):
|
||||
config_files = [find_config('%s.conf' % prog)]
|
||||
|
||||
cfg.CONF(argv, project='moniker', prog=prog,
|
||||
default_config_files=config_files)
|
||||
|
Loading…
Reference in New Issue
Block a user