Fixes for Rick review #2
This commit is contained in:
parent
b0b35af603
commit
2fcb4898cb
@ -44,7 +44,7 @@ use when configuring the server application.
|
||||
adapt for your own uses.
|
||||
|
||||
If you do `not` specifiy a configuration file on the command line, Glance will
|
||||
do its best to locate a ``glance.cnf`` configuration file in one of the
|
||||
do its best to locate a ``glance.conf`` configuration file in one of the
|
||||
following directories, stopping at the first config file it finds:
|
||||
|
||||
* .
|
||||
@ -65,10 +65,10 @@ If no configuration file is found, you will see any error, like so::
|
||||
Here is an example showing how you can manually start the ``glance-api`` server
|
||||
in a shell.::
|
||||
|
||||
$> sudo glance-api etc/glance.cnf.sample --debug
|
||||
$> sudo glance-api etc/glance.conf.sample --debug
|
||||
2011-02-09 14:58:29 DEBUG [glance-api] ********************************************************************************
|
||||
2011-02-09 14:58:29 DEBUG [glance-api] Configuration options gathered from config file:
|
||||
2011-02-09 14:58:29 DEBUG [glance-api] /home/jpipes/repos/glance/trunk/etc/glance.cnf.sample
|
||||
2011-02-09 14:58:29 DEBUG [glance-api] /home/jpipes/repos/glance/trunk/etc/glance.conf.sample
|
||||
2011-02-09 14:58:29 DEBUG [glance-api] ================================================
|
||||
2011-02-09 14:58:29 DEBUG [glance-api] bind_host 0.0.0.0
|
||||
2011-02-09 14:58:29 DEBUG [glance-api] bind_port 9292
|
||||
@ -83,7 +83,7 @@ in a shell.::
|
||||
(16333) wsgi starting up on http://0.0.0.0:9292/
|
||||
|
||||
Simply supply the configuration file as the first argument
|
||||
(``etc/glance.cnf.sample`` in the above example) and then any common options
|
||||
(``etc/glance.conf.sample`` in the above example) and then any common options
|
||||
you want to use (``--debug`` was used above to show some of the debugging
|
||||
output that the server shows when starting up. Call the server program
|
||||
with ``--help`` to see all available options you can specify on the
|
||||
@ -125,8 +125,8 @@ in the following way::
|
||||
Here is an example that shows how to start the ``glance-registry`` server
|
||||
with the ``glance-control`` wrapper script. ::
|
||||
|
||||
$> sudo glance-control registry start etc/glance.cnf.sample
|
||||
Starting glance-registry with /home/jpipes/repos/glance/trunk/etc/glance.cnf.sample
|
||||
$> sudo glance-control registry start etc/glance.conf.sample
|
||||
Starting glance-registry with /home/jpipes/repos/glance/trunk/etc/glance.conf.sample
|
||||
|
||||
The same ``paste.deploy`` configuration files are used by ``glance-control``
|
||||
to start the Glance server programs, and you can specify (as the example above
|
||||
@ -160,6 +160,6 @@ Restarting a server
|
||||
You can restart a server with the ``glance-control`` program, as demonstrated
|
||||
here::
|
||||
|
||||
$> sudo glance-control registry restart etc/glance.cnf.sample
|
||||
$> sudo glance-control registry restart etc/glance.conf.sample
|
||||
Stopping glance-registry pid: 17611 signal: 15
|
||||
Starting glance-registry with /home/jpipes/repos/glance/trunk/etc/glance.cnf.sample
|
||||
Starting glance-registry with /home/jpipes/repos/glance/trunk/etc/glance.conf.sample
|
||||
|
@ -238,68 +238,6 @@ def setup_logging(options):
|
||||
"unrecognized log handler '%(log_handler)s'" % locals())
|
||||
|
||||
|
||||
def get_config_file_options(conf_file=None, conf_dirs=None, app_name=None):
|
||||
"""
|
||||
Look for configuration files in a number of standard directories and
|
||||
return a mapping of configuration options found in the files.
|
||||
|
||||
The files that are searched for are in the following order, with
|
||||
options found in later files overriding options found in earlier
|
||||
files::
|
||||
|
||||
/etc/glance.cnf
|
||||
/etc/glance/glance.cnf
|
||||
~/glance.cnf
|
||||
~/.glance/glance.cnf
|
||||
./glance.cnf
|
||||
supplied conf_file param, if any.
|
||||
|
||||
:param conf_file: (optional) config file to read options from. Options
|
||||
from this config file override all others
|
||||
:param conf_dirs: (optional) sequence of directory paths to search for
|
||||
config files. Generally just used in testing
|
||||
:param app_name: (optional) name of application we're interested in.
|
||||
Supplying this will ensure that only the [DEFAULT]
|
||||
section and the [app_name] sections of the config
|
||||
files will be read. If not supplied (the default), all
|
||||
sections are read for configuration options.
|
||||
|
||||
:retval Mapping of configuration options read from config files
|
||||
"""
|
||||
|
||||
# Note that we do this in reverse priority order because
|
||||
# later configs overwrite the values of previously-read
|
||||
# configuration options
|
||||
|
||||
fix_path = lambda p: os.path.abspath(os.path.expanduser(p))
|
||||
config_file_dirs = conf_dirs or \
|
||||
['/etc',
|
||||
'/etc/glance/',
|
||||
fix_path('~'),
|
||||
fix_path(os.path.join('~', '.glance')),
|
||||
fix_path(os.getcwd())]
|
||||
|
||||
config_files = []
|
||||
results = {}
|
||||
for cfg_dir in config_file_dirs:
|
||||
cfg_file = os.path.join(cfg_dir, 'glance.cnf')
|
||||
if os.path.exists(cfg_file):
|
||||
config_files.append(cfg_file)
|
||||
|
||||
if conf_file:
|
||||
config_files.append(fix_path(conf_file))
|
||||
|
||||
cp = ConfigParser.ConfigParser()
|
||||
for config_file in config_files:
|
||||
if not cp.read(config_file):
|
||||
msg = 'Unable to read config file: %s' % config_file
|
||||
raise RuntimeError(msg)
|
||||
|
||||
results.update(cp.defaults())
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def find_config_file(options, args):
|
||||
"""
|
||||
Return the first config file found.
|
||||
@ -307,7 +245,7 @@ def find_config_file(options, args):
|
||||
We search for the paste config file in the following order:
|
||||
* If --config-file option is used, use that
|
||||
* If args[0] is a file, use that
|
||||
* Search for glance.cnf in standard directories:
|
||||
* Search for glance.conf in standard directories:
|
||||
* .
|
||||
* ~.glance/
|
||||
* ~
|
||||
@ -325,7 +263,7 @@ def find_config_file(options, args):
|
||||
if os.path.exists(args[0]):
|
||||
return fix_path(args[0])
|
||||
|
||||
# Handle standard directory search for glance.cnf
|
||||
# Handle standard directory search for glance.conf
|
||||
config_file_dirs = [fix_path(os.getcwd()),
|
||||
fix_path(os.path.join('~', '.glance')),
|
||||
fix_path('~'),
|
||||
@ -333,7 +271,7 @@ def find_config_file(options, args):
|
||||
'/etc']
|
||||
|
||||
for cfg_dir in config_file_dirs:
|
||||
cfg_file = os.path.join(cfg_dir, 'glance.cnf')
|
||||
cfg_file = os.path.join(cfg_dir, 'glance.conf')
|
||||
if os.path.exists(cfg_file):
|
||||
return cfg_file
|
||||
|
||||
@ -345,7 +283,7 @@ def load_paste_app(app_name, options, args):
|
||||
We search for the paste config file in the following order:
|
||||
* If --config-file option is used, use that
|
||||
* If args[0] is a file, use that
|
||||
* Search for glance.cnf in standard directories:
|
||||
* Search for glance.conf in standard directories:
|
||||
* .
|
||||
* ~.glance/
|
||||
* ~
|
||||
@ -377,7 +315,8 @@ def load_paste_app(app_name, options, args):
|
||||
logger.debug("Configuration options gathered from config file:")
|
||||
logger.debug(conf_file)
|
||||
logger.debug("================================================")
|
||||
items = dict([(k, v) for k, v in conf.items() if k not in ('__file__', 'here')])
|
||||
items = dict([(k, v) for k, v in conf.items()
|
||||
if k not in ('__file__', 'here')])
|
||||
for key, value in sorted(items.items()):
|
||||
logger.debug("%(key)-30s %(value)s" % locals())
|
||||
logger.debug("*" * 80)
|
||||
|
1
setup.py
1
setup.py
@ -87,6 +87,7 @@ setup(
|
||||
],
|
||||
scripts=['bin/glance-api',
|
||||
'bin/glance-combined',
|
||||
'bin/glance-control',
|
||||
'bin/glance-manage',
|
||||
'bin/glance-registry',
|
||||
'bin/glance-upload'])
|
||||
|
@ -62,7 +62,7 @@ class TestConfig(unittest.TestCase):
|
||||
parser = optparse.OptionParser()
|
||||
config.add_common_options(parser)
|
||||
self.assertRaises(SystemExit, config.parse_options,
|
||||
parser,['--unknown'])
|
||||
parser, ['--unknown'])
|
||||
|
||||
def test_options_to_conf(self):
|
||||
parser = optparse.OptionParser()
|
||||
@ -72,118 +72,3 @@ class TestConfig(unittest.TestCase):
|
||||
|
||||
expected_options = {'verbose': 'False', 'debug': 'False'}
|
||||
self.assertEquals(expected_options, conf_options)
|
||||
|
||||
def test_get_config_file_options(self):
|
||||
|
||||
# Test when no conf files are found...
|
||||
expected_options = {}
|
||||
conf_options = config.get_config_file_options(conf_dirs=['tests'])
|
||||
self.assertEquals(expected_options, conf_options)
|
||||
|
||||
# Test when a conf file is supplied and only DEFAULT
|
||||
# section is present
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
contents = """[DEFAULT]
|
||||
verbose = True
|
||||
"""
|
||||
f.write(contents)
|
||||
f.flush()
|
||||
conf_file = f.name
|
||||
|
||||
expected_options = {'verbose': 'True'}
|
||||
conf_options = config.get_config_file_options(conf_file)
|
||||
self.assertEquals(expected_options, conf_options)
|
||||
|
||||
# Test when a conf file is supplied and it has a DEFAULT
|
||||
# section and another section called glance-api, with
|
||||
# no specified app_name when calling get_config_file_options()
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
contents = """[DEFAULT]
|
||||
verbose = True
|
||||
|
||||
[glance-api]
|
||||
default_store = swift
|
||||
"""
|
||||
f.write(contents)
|
||||
f.flush()
|
||||
conf_file = f.name
|
||||
|
||||
expected_options = {'verbose': 'True',
|
||||
'default_store': 'swift'}
|
||||
conf_options = config.get_config_file_options(conf_file)
|
||||
self.assertEquals(expected_options, conf_options)
|
||||
|
||||
# Test when a conf file is supplied and it has a DEFAULT
|
||||
# section and another section called glance-api, with
|
||||
# specified app_name is NOT glance-api
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
contents = """[DEFAULT]
|
||||
verbose = True
|
||||
|
||||
[glance-api]
|
||||
default_store = swift
|
||||
"""
|
||||
f.write(contents)
|
||||
f.flush()
|
||||
conf_file = f.name
|
||||
|
||||
expected_options = {'verbose': 'True'}
|
||||
app_name = 'glance-registry'
|
||||
conf_options = config.get_config_file_options(conf_file,
|
||||
app_name=app_name)
|
||||
self.assertEquals(expected_options, conf_options)
|
||||
|
||||
# Test when a conf file is supplied and it has a DEFAULT
|
||||
# section and two other sections. Check that the later section
|
||||
# overrides the value of the former section...
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
contents = """[DEFAULT]
|
||||
verbose = True
|
||||
|
||||
[glance-api]
|
||||
default_store = swift
|
||||
|
||||
[glance-combined]
|
||||
default_store = s3
|
||||
"""
|
||||
f.write(contents)
|
||||
f.flush()
|
||||
conf_file = f.name
|
||||
|
||||
expected_options = {'verbose': 'True',
|
||||
'default_store': 's3'}
|
||||
conf_options = config.get_config_file_options(conf_file)
|
||||
self.assertEquals(expected_options, conf_options)
|
||||
|
||||
def test_parse_options_with_defaults(self):
|
||||
# Test the integration of parse_options() with a set
|
||||
# of defaults. These defaults generally come from a
|
||||
# configuration file
|
||||
defaults = {'verbose': 'on'}
|
||||
parser = optparse.OptionParser()
|
||||
config.add_common_options(parser)
|
||||
parsed_options, args = config.parse_options(parser, defaults=defaults)
|
||||
|
||||
expected_options = {'verbose': True, 'debug': False}
|
||||
self.assertEquals(expected_options, parsed_options)
|
||||
|
||||
# Write a sample conf file and merge the conf file defaults
|
||||
# with the parsed options.
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
contents = """[DEFAULT]
|
||||
verbose = True
|
||||
debug = off
|
||||
"""
|
||||
f.write(contents)
|
||||
f.flush()
|
||||
conf_file = f.name
|
||||
|
||||
expected_options = {'verbose': True,
|
||||
'debug': False}
|
||||
conf_options = config.get_config_file_options(conf_file)
|
||||
parser = optparse.OptionParser()
|
||||
config.add_common_options(parser)
|
||||
parsed_options, args = config.parse_options(parser,
|
||||
defaults=conf_options)
|
||||
|
||||
self.assertEquals(expected_options, parsed_options)
|
||||
|
Loading…
Reference in New Issue
Block a user