From da97aa46d8210abf848520c06a29638f925c42ed Mon Sep 17 00:00:00 2001 From: Ghe Rivero Date: Mon, 16 Jul 2012 20:31:51 +0100 Subject: [PATCH] Remove old flagfile support Cherry-picks 7e3e9b8 from Nova. Change-Id: Id5a0ffabf7c6eab0bbda1b130a39a6581b26e350 --- Authors | 1 + bin/cinder-all | 2 +- bin/cinder-api | 2 +- bin/cinder-manage | 8 ++++---- bin/cinder-scheduler | 2 +- bin/cinder-volume | 2 +- bin/clear_rabbit_queues | 2 +- cinder/flags.py | 4 +--- cinder/tests/test_flags.py | 32 -------------------------------- cinder/utils.py | 10 +++++----- 10 files changed, 16 insertions(+), 49 deletions(-) diff --git a/Authors b/Authors index 310e6bd7e..24eb71e78 100644 --- a/Authors +++ b/Authors @@ -15,6 +15,7 @@ Eric Day Eric Windisch Ewan Mellor François Charlier +Ghe Rivero Isaku Yamahata Jason Koelker Jesse Andrews diff --git a/bin/cinder-all b/bin/cinder-all index 8bec9bbb3..4ea8104f3 100755 --- a/bin/cinder-all +++ b/bin/cinder-all @@ -49,7 +49,7 @@ from cinder import utils LOG = logging.getLogger('cinder.all') if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/cinder-api b/bin/cinder-api index ba28b1a44..be8a138d0 100755 --- a/bin/cinder-api +++ b/bin/cinder-api @@ -38,7 +38,7 @@ from cinder import service from cinder import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/cinder-manage b/bin/cinder-manage index 0cc6d82c8..078a405a2 100755 --- a/bin/cinder-manage +++ b/bin/cinder-manage @@ -546,11 +546,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/cinder-scheduler b/bin/cinder-scheduler index f423bef63..716d04b69 100755 --- a/bin/cinder-scheduler +++ b/bin/cinder-scheduler @@ -42,7 +42,7 @@ from cinder import service from cinder import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/cinder-volume b/bin/cinder-volume index 53aa635a6..346cf8630 100755 --- a/bin/cinder-volume +++ b/bin/cinder-volume @@ -40,7 +40,7 @@ from cinder import service from cinder import utils if __name__ == '__main__': - utils.default_flagfile() + utils.default_cfgfile() flags.FLAGS(sys.argv) logging.setup() utils.monkey_patch() diff --git a/bin/clear_rabbit_queues b/bin/clear_rabbit_queues index d652d6e14..a942fca6c 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/cinder/flags.py b/cinder/flags.py index e3178cb31..dd532896f 100644 --- a/cinder/flags.py +++ b/cinder/flags.py @@ -30,7 +30,6 @@ import os import socket import sys -from cinder.compat import flagfile from cinder.openstack.common import cfg @@ -43,8 +42,7 @@ class CinderConfigOpts(cfg.CommonConfigOpts): self.disable_interspersed_args() def __call__(self, argv): - with flagfile.handle_flagfiles_managed(argv[1:]) as args: - return argv[:1] + super(CinderConfigOpts, self).__call__(args) + return argv[:1] + super(CinderConfigOpts, self).__call__(argv[1:]) FLAGS = CinderConfigOpts() diff --git a/cinder/tests/test_flags.py b/cinder/tests/test_flags.py index e94c3484e..704966c81 100644 --- a/cinder/tests/test_flags.py +++ b/cinder/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='cinder', 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/cinder/utils.py b/cinder/utils.py index f80fb1431..8102722da 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -307,12 +307,12 @@ def cinderdir(): return os.path.abspath(cinder.__file__).split('cinder/__init__.py')[0] -def default_flagfile(filename='cinder.conf', args=None): +def default_cfgfile(filename='cinder.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 @@ -323,8 +323,8 @@ def default_flagfile(filename='cinder.conf', args=None): if not os.path.exists(filename): filename = '/etc/cinder/cinder.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 -- 2.45.2