Allows passing of config file via --config-file option.

Maintains backwards compatibility with the old style invocation,
by adding a config_shim method. Logs a warning if the old style
invocation is used.

Change-Id: I11666a2fff0e9bdc6b26cb46505dcb03fa06fa50
Closes-Bug: #1411194
This commit is contained in:
John Trowbridge 2015-01-16 15:46:48 -05:00
parent f5977db1be
commit 74ea75ba0e
4 changed files with 34 additions and 6 deletions

View File

@ -55,7 +55,7 @@ Github::
Run the service with::
.tox/py27/bin/ironic-discoverd example.conf
.tox/py27/bin/ironic-discoverd --config-file example.conf
Of course you may have to modify ``example.conf`` to match your OpenStack
environment.

View File

@ -133,7 +133,7 @@ unit, so you can::
Otherwise run as ``root``::
ironic-discoverd /etc/ironic-discoverd/discoverd.conf
ironic-discoverd --config-file /etc/ironic-discoverd/discoverd.conf
*ironic-discoverd* has a simple client library bundled within it.
It provides function ``ironic_discoverd.client.discover``, accepting list

View File

@ -14,6 +14,7 @@
import eventlet
eventlet.monkey_patch(thread=False)
import argparse
import functools
import json
import logging
@ -147,11 +148,22 @@ def check_ironic_available():
eventlet.greenthread.sleep(retry_period)
def main():
if len(sys.argv) < 2:
sys.exit("Usage: %s config-file" % sys.argv[0])
def config_shim(args):
"""Make new argument parsing method backwards compatible."""
if len(args) == 2 and args[1][0] != '-':
return ['--config-file', args[1]]
conf.read(sys.argv[1])
def main():
old_args = config_shim(sys.argv)
parser = argparse.ArgumentParser(description='''Hardware introspection
service for OpenStack Ironic.
''')
parser.add_argument('--config-file', dest='config', required=True)
# if parse_args is passed None it uses sys.argv instead.
args = parser.parse_args(old_args)
conf.read(args.config)
debug = conf.getboolean('discoverd', 'debug')
logging.basicConfig(level=logging.DEBUG if debug else logging.INFO)
@ -161,6 +173,10 @@ def main():
logging.getLogger('ironicclient.common.http').setLevel(
logging.INFO if debug else logging.ERROR)
if old_args:
LOG.warning('"ironic-discoverd <config-file>" syntax is deprecated use'
' "ironic-discoverd --config-file <config-file>" instead')
if not conf.getboolean('discoverd', 'authenticate'):
LOG.warning('Starting unauthenticated, please check configuration')

View File

@ -167,3 +167,15 @@ class TestPlugins(unittest.TestCase):
def test_manager_is_cached(self):
self.assertIs(plugins_base.processing_hooks_manager(),
plugins_base.processing_hooks_manager())
class TestConfigShim(unittest.TestCase):
def test_old_style_invocation(self):
self.assertEqual(main.config_shim(
['ironic-discoverd', '/etc/conf']),
['--config-file', '/etc/conf'])
def test_new_style_returns_None(self):
self.assertEqual(main.config_shim(
['ironic-discoverd', '--config-file', '/etc/conf']),
None)