Remove old flagfile support
Cherry-picks 7e3e9b8 from Nova. Change-Id: Id5a0ffabf7c6eab0bbda1b130a39a6581b26e350
This commit is contained in:
parent
78918b8861
commit
da97aa46d8
1
Authors
1
Authors
@ -15,6 +15,7 @@ Eric Day <eday@oddments.org>
|
||||
Eric Windisch <eric@cloudscaling.com>
|
||||
Ewan Mellor <ewan.mellor@citrix.com>
|
||||
François Charlier <francois.charlier@enovance.com>
|
||||
Ghe Rivero <ghe@debian.org>
|
||||
Isaku Yamahata <yamahata@valinux.co.jp>
|
||||
Jason Koelker <jason@koelker.net>
|
||||
Jesse Andrews <anotherjesse@gmail.com>
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user