diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index cad894d2a..ec644e9c2 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -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. diff --git a/README.rst b/README.rst index 60447f3d5..52b77be5e 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/ironic_discoverd/main.py b/ironic_discoverd/main.py index 4e97c7610..8b471bf0f 100644 --- a/ironic_discoverd/main.py +++ b/ironic_discoverd/main.py @@ -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 " syntax is deprecated use' + ' "ironic-discoverd --config-file " instead') + if not conf.getboolean('discoverd', 'authenticate'): LOG.warning('Starting unauthenticated, please check configuration') diff --git a/ironic_discoverd/test/test_main.py b/ironic_discoverd/test/test_main.py index 462c5ab9b..23bf0419a 100644 --- a/ironic_discoverd/test/test_main.py +++ b/ironic_discoverd/test/test_main.py @@ -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)