From 7e3e9b8e9cea4f1bf78d127ffb915b79c854fdbe Mon Sep 17 00:00:00 2001 From: Ghe Rivero Date: Tue, 1 May 2012 14:34:55 +0200 Subject: Remove old flagfile support. Implements blueprint remove-old-flagfile nova-manage can still be used to convert old flagfiles style files to new .ini files: $ ./bin/nova-manage config convert --help Usage: nova-manage config convert [options] Options: -h, --help show this help message and exit --infile= old-style flagfile to convert to config --outfile= path for output file. Writes configto stdout if not specified. Change-Id: Ib8fbbd858b1db7faef70d7d97955e5042bf378f2 Signed-off-by: Ghe Rivero --- bin/clear_rabbit_queues | 2 +- bin/instance-usage-audit | 2 +- bin/nova-all | 2 +- bin/nova-api | 2 +- bin/nova-api-ec2 | 2 +- bin/nova-api-metadata | 2 +- bin/nova-api-os-compute | 2 +- bin/nova-api-os-volume | 2 +- bin/nova-cert | 2 +- bin/nova-compute | 2 +- bin/nova-console | 2 +- bin/nova-consoleauth | 2 +- bin/nova-dhcpbridge | 2 +- bin/nova-manage | 8 ++++---- bin/nova-network | 2 +- bin/nova-objectstore | 2 +- bin/nova-scheduler | 2 +- bin/nova-volume | 2 +- bin/nova-xvpvncproxy | 2 +- nova/flags.py | 4 +--- nova/tests/test_flags.py | 32 -------------------------------- nova/utils.py | 10 +++++----- tools/xenserver/vm_vdi_cleaner.py | 2 +- 23 files changed, 29 insertions(+), 63 deletions(-) diff --git a/bin/clear_rabbit_queues b/bin/clear_rabbit_queues index 29298f18f..37394add6 100755 --- a/bin/clear_rabbit_queues +++ b/bin/clear_rabbit_queues @@ -71,7 +71,7 @@ def delete_queues(queues): x.queue_delete(q) if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() args = flags.FLAGS(sys.argv) logging.setup() rpc.register_opts(flags.FLAGS) diff --git a/bin/instance-usage-audit b/bin/instance-usage-audit index 5b30c3586..76a33a36f 100755 --- a/bin/instance-usage-audit +++ b/bin/instance-usage-audit @@ -65,7 +65,7 @@ FLAGS = flags.FLAGS if __name__ == '__main__': rpc.register_opts(FLAGS) admin_context = context.get_admin_context() - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() begin, end = utils.last_completed_audit_period() diff --git a/bin/nova-all b/bin/nova-all index 143ab2bed..529d98ed0 100755 --- a/bin/nova-all +++ b/bin/nova-all @@ -51,7 +51,7 @@ from nova.vnc import xvp_proxy LOG = logging.getLogger('nova.all') if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/nova-api b/bin/nova-api index d8635978e..7a601c3a6 100755 --- a/bin/nova-api +++ b/bin/nova-api @@ -42,7 +42,7 @@ from nova import service from nova import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/nova-api-ec2 b/bin/nova-api-ec2 index 9f82a69e4..e1a1549c7 100755 --- a/bin/nova-api-ec2 +++ b/bin/nova-api-ec2 @@ -38,7 +38,7 @@ from nova import service from nova import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/nova-api-metadata b/bin/nova-api-metadata index 199c3918c..c4ca541f4 100755 --- a/bin/nova-api-metadata +++ b/bin/nova-api-metadata @@ -38,7 +38,7 @@ from nova import service from nova import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/nova-api-os-compute b/bin/nova-api-os-compute index 7bfff2a42..9c49815fe 100755 --- a/bin/nova-api-os-compute +++ b/bin/nova-api-os-compute @@ -38,7 +38,7 @@ from nova import service from nova import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/nova-api-os-volume b/bin/nova-api-os-volume index 33909c5b5..21d5dc3de 100755 --- a/bin/nova-api-os-volume +++ b/bin/nova-api-os-volume @@ -38,7 +38,7 @@ from nova import service from nova import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/nova-cert b/bin/nova-cert index 725bf4aee..f6a5cbbd8 100755 --- a/bin/nova-cert +++ b/bin/nova-cert @@ -38,7 +38,7 @@ from nova import service from nova import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/nova-compute b/bin/nova-compute index 0c69a8129..8f7e9177d 100755 --- a/bin/nova-compute +++ b/bin/nova-compute @@ -40,7 +40,7 @@ from nova import service from nova import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/nova-console b/bin/nova-console index 22f6ef171..06e352f48 100755 --- a/bin/nova-console +++ b/bin/nova-console @@ -39,7 +39,7 @@ from nova import service from nova import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() server = service.Service.create(binary='nova-console') diff --git a/bin/nova-consoleauth b/bin/nova-consoleauth index fbc9ad849..9c566cb7c 100755 --- a/bin/nova-consoleauth +++ b/bin/nova-consoleauth @@ -39,7 +39,7 @@ from nova import utils if __name__ == "__main__": - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() diff --git a/bin/nova-dhcpbridge b/bin/nova-dhcpbridge index 2f1ef6cec..fab334bf5 100755 --- a/bin/nova-dhcpbridge +++ b/bin/nova-dhcpbridge @@ -96,7 +96,7 @@ def init_leases(network_id): def main(): """Parse environment and arguments and call the approproate action.""" flagfile = os.environ.get('FLAGFILE', FLAGS.dhcpbridge_flagfile) - utils.default_flagfile(flagfile) + utils.default_cfgfile(flagfile) argv = FLAGS(sys.argv) logging.setup() diff --git a/bin/nova-manage b/bin/nova-manage index 7b33fa4d3..e076e066e 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -1666,11 +1666,11 @@ def methods_of(obj): def main(): """Parse options and call the appropriate class/method.""" - flagfile = utils.default_flagfile() + cfgfile = utils.default_cfgfile() - if flagfile and not os.access(flagfile, os.R_OK): - st = os.stat(flagfile) - print "Could not read %s. Re-running with sudo" % flagfile + if cfgfile and not os.access(cfgfile, os.R_OK): + st = os.stat(cfgfile) + print "Could not read %s. Re-running with sudo" % cfgfile try: os.execvp('sudo', ['sudo', '-u', '#%s' % st.st_uid] + sys.argv) except Exception: diff --git a/bin/nova-network b/bin/nova-network index 0f1482515..d176eb27c 100755 --- a/bin/nova-network +++ b/bin/nova-network @@ -40,7 +40,7 @@ from nova import service from nova import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/nova-objectstore b/bin/nova-objectstore index 70553ea08..e52160c25 100755 --- a/bin/nova-objectstore +++ b/bin/nova-objectstore @@ -42,7 +42,7 @@ from nova import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/nova-scheduler b/bin/nova-scheduler index c1033a304..52db4de7e 100755 --- a/bin/nova-scheduler +++ b/bin/nova-scheduler @@ -42,7 +42,7 @@ from nova import service from nova import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/nova-volume b/bin/nova-volume index 8caa0f44a..1c6ffb58f 100755 --- a/bin/nova-volume +++ b/bin/nova-volume @@ -40,7 +40,7 @@ from nova import service from nova import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/nova-xvpvncproxy b/bin/nova-xvpvncproxy index cfd3edc3d..9db07f148 100755 --- a/bin/nova-xvpvncproxy +++ b/bin/nova-xvpvncproxy @@ -42,7 +42,7 @@ FLAGS = flags.FLAGS if __name__ == "__main__": rpc.register_opts(FLAGS) - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() diff --git a/nova/flags.py b/nova/flags.py index 652d3465d..5b7421afc 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -30,7 +30,6 @@ import os import socket import sys -from nova.compat import flagfile from nova.openstack.common import cfg @@ -41,8 +40,7 @@ class NovaConfigOpts(cfg.CommonConfigOpts): self.disable_interspersed_args() def __call__(self, argv): - with flagfile.handle_flagfiles_managed(argv[1:]) as args: - return argv[:1] + super(NovaConfigOpts, self).__call__(args) + return argv[:1] + super(NovaConfigOpts, self).__call__(argv[1:]) FLAGS = NovaConfigOpts() diff --git a/nova/tests/test_flags.py b/nova/tests/test_flags.py index 153db953a..c980e522a 100644 --- a/nova/tests/test_flags.py +++ b/nova/tests/test_flags.py @@ -99,38 +99,6 @@ class FlagsTestCase(test.TestCase): self.reset_flags() self.assertEqual(FLAGS.flags_unittest, 'foo') - def test_flagfile(self): - opts = [ - cfg.StrOpt('string', default='default', help='desc'), - cfg.IntOpt('int', default=1, help='desc'), - cfg.BoolOpt('false', default=False, help='desc'), - cfg.BoolOpt('true', default=True, help='desc'), - cfg.MultiStrOpt('multi', default=['blaa'], help='desc'), - ] - - self.FLAGS.register_opts(opts) - - (fd, path) = tempfile.mkstemp(prefix='nova', suffix='.flags') - - try: - os.write(fd, '--string=foo\n--int=2\n--false\n--notrue\n') - os.write(fd, '--multi=bar\n') - os.close(fd) - - self.FLAGS(['flags_test', '--flagfile=' + path]) - - self.assertEqual(self.FLAGS.string, 'foo') - self.assertEqual(self.FLAGS.int, 2) - self.assertEqual(self.FLAGS.false, True) - self.assertEqual(self.FLAGS.true, False) - self.assertEqual(self.FLAGS.multi, ['bar']) - - # Re-parse to test multistring isn't append multiple times - self.FLAGS(['flags_test', '--flagfile=' + path]) - self.assertEqual(self.FLAGS.multi, ['bar']) - finally: - os.remove(path) - def test_defaults(self): self.FLAGS.register_opt(cfg.StrOpt('foo', default='bar', help='desc')) self.assertEqual(self.FLAGS.foo, 'bar') diff --git a/nova/utils.py b/nova/utils.py index 69011fb61..bf50ea4e3 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -309,12 +309,12 @@ def novadir(): return os.path.abspath(nova.__file__).split('nova/__init__.py')[0] -def default_flagfile(filename='nova.conf', args=None): +def default_cfgfile(filename='nova.conf', args=None): if args is None: args = sys.argv for arg in args: - if arg.find('flagfile') != -1: - return arg[arg.index('flagfile') + len('flagfile') + 1:] + if arg.find('config-file') != -1: + return arg[arg.index('config-file') + len('config-file') + 1:] else: if not os.path.isabs(filename): # turn relative filename into an absolute path @@ -325,8 +325,8 @@ def default_flagfile(filename='nova.conf', args=None): if not os.path.exists(filename): filename = '/etc/nova/nova.conf' if os.path.exists(filename): - flagfile = '--flagfile=%s' % filename - args.insert(1, flagfile) + cfgfile = '--config-file=%s' % filename + args.insert(1, cfgfile) return filename diff --git a/tools/xenserver/vm_vdi_cleaner.py b/tools/xenserver/vm_vdi_cleaner.py index 69de51250..295bf6b62 100755 --- a/tools/xenserver/vm_vdi_cleaner.py +++ b/tools/xenserver/vm_vdi_cleaner.py @@ -40,7 +40,7 @@ FLAGS = flags.FLAGS # flagfile. To isolate this awful practice, we're supplying a dummy # argument list. dummy = ["fakearg"] -utils.default_flagfile(args=dummy) +utils.default_cfgfile(args=dummy) FLAGS(dummy) -- cgit