diff --git a/bin/clear_rabbit_queues b/bin/clear_rabbit_queues index 9d0d803a54d0..503fa07d8156 100755 --- a/bin/clear_rabbit_queues +++ b/bin/clear_rabbit_queues @@ -55,7 +55,7 @@ delete_exchange_opt = \ help='delete nova exchange too.') FLAGS = flags.FLAGS -FLAGS.add_option(delete_exchange_opt) +FLAGS.register_cli_opt(delete_exchange_opt) def delete_exchange(exch): diff --git a/bin/nova-direct-api b/bin/nova-direct-api index 6a79ef6268ab..121a0b45c120 100755 --- a/bin/nova-direct-api +++ b/bin/nova-direct-api @@ -57,7 +57,7 @@ direct_api_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(direct_api_opts) +FLAGS.register_cli_opts(direct_api_opts) # An example of an API that only exposes read-only methods. diff --git a/bin/nova-manage b/bin/nova-manage index 6b15dea63baf..adf2e2530294 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -2201,7 +2201,7 @@ class ConfigCommands(object): pass def list(self): - for key, value in FLAGS.FlagValuesDict().iteritems(): + for key, value in FLAGS.iteritems(): if value is not None: print '%s = %s' % (key, value) diff --git a/nova/api/auth.py b/nova/api/auth.py index a1a375d7c839..518647ae19d4 100644 --- a/nova/api/auth.py +++ b/nova/api/auth.py @@ -34,7 +34,7 @@ use_forwarded_for_opt = cfg.BoolOpt('use_forwarded_for', 'Only enable this if you have a sanitizing proxy.') FLAGS = flags.FLAGS -FLAGS.add_option(use_forwarded_for_opt) +FLAGS.register_opt(use_forwarded_for_opt) class InjectContext(wsgi.Middleware): diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index bcd7b239e675..bbce2c0d4090 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -59,7 +59,7 @@ ec2_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(ec2_opts) +FLAGS.register_opts(ec2_opts) flags.DECLARE('use_forwarded_for', 'nova.api.auth') diff --git a/nova/api/openstack/compute/__init__.py b/nova/api/openstack/compute/__init__.py index 3884ffbad297..e23fe7b87f8d 100644 --- a/nova/api/openstack/compute/__init__.py +++ b/nova/api/openstack/compute/__init__.py @@ -44,7 +44,7 @@ allow_instance_snapshots_opt = \ help='Permit instance snapshot operations.') FLAGS = flags.FLAGS -FLAGS.add_option(allow_instance_snapshots_opt) +FLAGS.register_opt(allow_instance_snapshots_opt) class APIRouter(nova.api.openstack.APIRouter): diff --git a/nova/auth/ldapdriver.py b/nova/auth/ldapdriver.py index 78b35cadc1b4..4173ecbd9415 100644 --- a/nova/auth/ldapdriver.py +++ b/nova/auth/ldapdriver.py @@ -88,7 +88,7 @@ ldap_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(ldap_opts) +FLAGS.register_opts(ldap_opts) LOG = logging.getLogger("nova.ldapdriver") @@ -573,7 +573,7 @@ class LdapDriver(object): def __role_to_dn(self, role, project_id=None): """Convert role to corresponding dn""" if project_id is None: - return FLAGS.__getitem__("ldap_%s" % role).value + return FLAGS["ldap_%s" % role] else: project_dn = self.__project_to_dn(project_id) return 'cn=%s,%s' % (role, project_dn) diff --git a/nova/auth/manager.py b/nova/auth/manager.py index 40f1fc8427d7..fb49333b2116 100644 --- a/nova/auth/manager.py +++ b/nova/auth/manager.py @@ -92,7 +92,7 @@ auth_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(auth_opts) +FLAGS.register_opts(auth_opts) flags.DECLARE('osapi_compute_listen_port', 'nova.service') diff --git a/nova/cloudpipe/pipelib.py b/nova/cloudpipe/pipelib.py index 7d43866e6f39..0530be32cf4a 100644 --- a/nova/cloudpipe/pipelib.py +++ b/nova/cloudpipe/pipelib.py @@ -53,7 +53,7 @@ cloudpipe_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(cloudpipe_opts) +FLAGS.register_opts(cloudpipe_opts) LOG = logging.getLogger('nova.cloudpipe') diff --git a/nova/compute/api.py b/nova/compute/api.py index 240e924fea8d..926f5e3cc9ee 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -55,7 +55,7 @@ find_host_timeout_opt = cfg.StrOpt('find_host_timeout', help='Timeout after NN seconds when looking for a host.') FLAGS = flags.FLAGS -FLAGS.add_option(find_host_timeout_opt) +FLAGS.register_opt(find_host_timeout_opt) flags.DECLARE('enable_zone_routing', 'nova.scheduler.api') flags.DECLARE('consoleauth_topic', 'nova.consoleauth') diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 47448eb13da5..dbcb64c21fa1 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -119,7 +119,7 @@ compute_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(compute_opts) +FLAGS.register_opts(compute_opts) LOG = logging.getLogger('nova.compute.manager') diff --git a/nova/console/manager.py b/nova/console/manager.py index a181ee437c8c..99ef58d89273 100644 --- a/nova/console/manager.py +++ b/nova/console/manager.py @@ -41,7 +41,7 @@ console_manager_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(console_manager_opts) +FLAGS.register_opts(console_manager_opts) class ConsoleProxyManager(manager.Manager): diff --git a/nova/console/vmrc.py b/nova/console/vmrc.py index ead53d086c6b..b0a8ff4bc2b4 100644 --- a/nova/console/vmrc.py +++ b/nova/console/vmrc.py @@ -36,7 +36,7 @@ vmrc_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(vmrc_opts) +FLAGS.register_opts(vmrc_opts) class VMRCConsole(object): diff --git a/nova/console/vmrc_manager.py b/nova/console/vmrc_manager.py index 1614998308e7..5be937eed2e1 100644 --- a/nova/console/vmrc_manager.py +++ b/nova/console/vmrc_manager.py @@ -39,7 +39,7 @@ vmrc_manager_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(vmrc_manager_opts) +FLAGS.register_opts(vmrc_manager_opts) class ConsoleVMRCManager(manager.Manager): diff --git a/nova/console/xvp.py b/nova/console/xvp.py index 35e57f0868ee..1ee24338fc7b 100644 --- a/nova/console/xvp.py +++ b/nova/console/xvp.py @@ -50,7 +50,7 @@ xvp_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(xvp_opts) +FLAGS.register_opts(xvp_opts) class XVPConsoleProxy(object): diff --git a/nova/consoleauth/__init__.py b/nova/consoleauth/__init__.py index 0ef313d05693..5923aa0c8e01 100644 --- a/nova/consoleauth/__init__.py +++ b/nova/consoleauth/__init__.py @@ -27,4 +27,4 @@ consoleauth_topic_opt = cfg.StrOpt('consoleauth_topic', help='the topic console auth proxy nodes listen on') FLAGS = flags.FLAGS -FLAGS.add_option(consoleauth_topic_opt) +FLAGS.register_opt(consoleauth_topic_opt) diff --git a/nova/consoleauth/manager.py b/nova/consoleauth/manager.py index b3f85e1f95cf..0fd1a9caf5f5 100644 --- a/nova/consoleauth/manager.py +++ b/nova/consoleauth/manager.py @@ -41,7 +41,7 @@ consoleauth_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(consoleauth_opts) +FLAGS.register_opts(consoleauth_opts) class ConsoleAuthManager(manager.Manager): diff --git a/nova/crypto.py b/nova/crypto.py index 79e40337ba05..a03dd95c517e 100644 --- a/nova/crypto.py +++ b/nova/crypto.py @@ -76,7 +76,7 @@ crypto_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(crypto_opts) +FLAGS.register_opts(crypto_opts) def ca_folder(project_id=None): diff --git a/nova/db/api.py b/nova/db/api.py index c73844a8c4ef..0f9cc1acf7a6 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -71,9 +71,9 @@ db_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(db_opts) +FLAGS.register_opts(db_opts) -IMPL = utils.LazyPluggable(FLAGS['db_backend'], +IMPL = utils.LazyPluggable('db_backend', sqlalchemy='nova.db.sqlalchemy.api') diff --git a/nova/db/base.py b/nova/db/base.py index 01c39010ab32..6fdfa1b17d66 100644 --- a/nova/db/base.py +++ b/nova/db/base.py @@ -28,7 +28,7 @@ db_driver_opt = cfg.StrOpt('db_driver', help='driver to use for database access') FLAGS = flags.FLAGS -FLAGS.add_option(db_driver_opt) +FLAGS.register_opt(db_driver_opt) class Base(object): diff --git a/nova/db/migration.py b/nova/db/migration.py index dda413205a4a..722d7ee483ea 100644 --- a/nova/db/migration.py +++ b/nova/db/migration.py @@ -18,15 +18,10 @@ """Database setup and migration commands.""" -from nova import flags from nova import utils -FLAGS = flags.FLAGS -flags.DECLARE('db_backend', 'nova.db') - - -IMPL = utils.LazyPluggable(FLAGS['db_backend'], +IMPL = utils.LazyPluggable('db_backend', sqlalchemy='nova.db.sqlalchemy.migration') diff --git a/nova/flags.py b/nova/flags.py index 749bf5c5ff5a..6fc3100f8d06 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -3,7 +3,7 @@ # Copyright 2010 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. # All Rights Reserved. -# Copyright 2011 Red Hat, Inc. +# Copyright 2012 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -30,97 +30,21 @@ import os import socket import sys -import gflags - from nova.compat import flagfile from nova.openstack.common import cfg -class FlagValues(object): - class Flag: - def __init__(self, name, value, update_default=None): - self.name = name - self.value = value - self._update_default = update_default +class NovaConfigOpts(cfg.ConfigOpts): - def SetDefault(self, default): - if self._update_default: - self._update_default(self.name, default) - - def __init__(self): - self._conf = cfg.ConfigOpts() - self._conf.disable_interspersed_args() - self.Reset() - - def _parse(self): - if self._extra is not None: - return - - with flagfile.handle_flagfiles_managed(self._args) as args: - self._extra = self._conf(args) + def __init__(self, *args, **kwargs): + super(NovaConfigOpts, self).__init__(*args, **kwargs) + self.disable_interspersed_args() def __call__(self, argv): - self.Reset() - self._args = argv[1:] - self._parse() - return [argv[0]] + self._extra + with flagfile.handle_flagfiles_managed(argv[1:]) as args: + return argv[:1] + super(NovaConfigOpts, self).__call__(args) - def __getattr__(self, name): - self._parse() - return getattr(self._conf, name) - - def get(self, name, default): - value = getattr(self, name) - if value is not None: # value might be '0' or "" - return value - else: - return default - - def __contains__(self, name): - self._parse() - return hasattr(self._conf, name) - - def _update_default(self, name, default): - self._conf.set_default(name, default) - - def __iter__(self): - return self._conf.iterkeys() - - def __getitem__(self, name): - self._parse() - if not self.__contains__(name): - return None - return self.Flag(name, getattr(self, name), self._update_default) - - def Reset(self): - self._conf.reset() - self._args = [] - self._extra = None - - def ParseNewFlags(self): - pass - - def FlagValuesDict(self): - self._parse() - ret = {} - for name in self._conf: - ret[name] = getattr(self, name) - return ret - - def add_option(self, opt): - self._conf.register_opt(opt) - - def add_options(self, opts): - self._conf.register_opts(opts) - - def add_cli_option(self, opt): - self._conf.register_cli_opt(opt) - - def add_cli_options(self, opts): - self._conf.register_cli_opts(opts) - - -FLAGS = FlagValues() +FLAGS = NovaConfigOpts() class UnrecognizedFlag(Exception): @@ -191,9 +115,9 @@ debug_opts = [ help='use a fake rabbit'), ] -FLAGS.add_cli_options(log_opts) -FLAGS.add_cli_options(core_opts) -FLAGS.add_cli_options(debug_opts) +FLAGS.register_cli_opts(log_opts) +FLAGS.register_cli_opts(core_opts) +FLAGS.register_cli_opts(debug_opts) global_opts = [ cfg.StrOpt('my_ip', @@ -523,4 +447,4 @@ global_opts = [ help='Host reserved for specific images'), ] -FLAGS.add_options(global_opts) +FLAGS.register_opts(global_opts) diff --git a/nova/image/s3.py b/nova/image/s3.py index 2be1b5ede68b..33dfdfff0f4d 100644 --- a/nova/image/s3.py +++ b/nova/image/s3.py @@ -55,7 +55,7 @@ s3_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(s3_opts) +FLAGS.register_opts(s3_opts) class S3ImageService(object): diff --git a/nova/ipv6/api.py b/nova/ipv6/api.py index 9d32e69a0232..8983640e3224 100644 --- a/nova/ipv6/api.py +++ b/nova/ipv6/api.py @@ -24,12 +24,12 @@ ipv6_backend_opt = cfg.StrOpt('ipv6_backend', help='Backend to use for IPv6 generation') FLAGS = flags.FLAGS -FLAGS.add_option(ipv6_backend_opt) +FLAGS.register_opt(ipv6_backend_opt) def reset_backend(): global IMPL - IMPL = utils.LazyPluggable(FLAGS['ipv6_backend'], + IMPL = utils.LazyPluggable('ipv6_backend', rfc2462='nova.ipv6.rfc2462', account_identifier='nova.ipv6.account_identifier') diff --git a/nova/log.py b/nova/log.py index bd3162b6cdd8..a9f7af70f68b 100644 --- a/nova/log.py +++ b/nova/log.py @@ -82,7 +82,7 @@ log_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(log_opts) +FLAGS.register_opts(log_opts) # A list of things we want to replicate from logging. # levels diff --git a/nova/network/ldapdns.py b/nova/network/ldapdns.py index a6d92118635a..275587d50224 100644 --- a/nova/network/ldapdns.py +++ b/nova/network/ldapdns.py @@ -64,7 +64,7 @@ ldap_dns_opts = [ 'Statement of Authority'), ] -flags.FLAGS.add_options(ldap_dns_opts) +flags.FLAGS.register_opts(ldap_dns_opts) def utf8(instring): diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index 0400fdd93d9b..2b6e9ea66fab 100755 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -87,7 +87,7 @@ linux_net_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(linux_net_opts) +FLAGS.register_opts(linux_net_opts) binary_name = os.path.basename(inspect.stack()[-1][1]) diff --git a/nova/network/manager.py b/nova/network/manager.py index 88f49de51b05..51bcc1c8b5bb 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -162,7 +162,7 @@ network_opts = [ FLAGS = flags.FLAGS -FLAGS.add_options(network_opts) +FLAGS.register_opts(network_opts) class AddressAlreadyAllocated(exception.Error): diff --git a/nova/network/quantum/manager.py b/nova/network/quantum/manager.py index 7dc8a93b4c69..5ca4b663e7d0 100644 --- a/nova/network/quantum/manager.py +++ b/nova/network/quantum/manager.py @@ -56,7 +56,7 @@ quantum_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(quantum_opts) +FLAGS.register_opts(quantum_opts) class QuantumManager(manager.FloatingIP, manager.FlatManager): diff --git a/nova/network/quantum/melange_connection.py b/nova/network/quantum/melange_connection.py index d579b5f56951..fa19adb2ab39 100644 --- a/nova/network/quantum/melange_connection.py +++ b/nova/network/quantum/melange_connection.py @@ -35,7 +35,7 @@ melange_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(melange_opts) +FLAGS.register_opts(melange_opts) LOG = logging.getLogger(__name__) json_content_type = {'Content-type': "application/json"} diff --git a/nova/network/quantum/quantum_connection.py b/nova/network/quantum/quantum_connection.py index ba34d026c932..7156a1f75ad7 100644 --- a/nova/network/quantum/quantum_connection.py +++ b/nova/network/quantum/quantum_connection.py @@ -36,7 +36,7 @@ quantum_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(quantum_opts) +FLAGS.register_opts(quantum_opts) class QuantumClientConnection(object): diff --git a/nova/notifier/api.py b/nova/notifier/api.py index 4a59e0ba1305..582674a4e09f 100644 --- a/nova/notifier/api.py +++ b/nova/notifier/api.py @@ -33,7 +33,7 @@ notifier_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(notifier_opts) +FLAGS.register_opts(notifier_opts) WARN = 'WARN' INFO = 'INFO' diff --git a/nova/notifier/list_notifier.py b/nova/notifier/list_notifier.py index f971fd947026..ed19959dcc80 100644 --- a/nova/notifier/list_notifier.py +++ b/nova/notifier/list_notifier.py @@ -25,7 +25,7 @@ list_notifier_drivers_opt = cfg.MultiStrOpt('list_notifier_drivers', help='List of drivers to send notifications') FLAGS = flags.FLAGS -FLAGS.add_option(list_notifier_drivers_opt) +FLAGS.register_opt(list_notifier_drivers_opt) LOG = logging.getLogger('nova.notifier.list_notifier') diff --git a/nova/notifier/rabbit_notifier.py b/nova/notifier/rabbit_notifier.py index 2df43fdaf944..864e8004d04c 100644 --- a/nova/notifier/rabbit_notifier.py +++ b/nova/notifier/rabbit_notifier.py @@ -26,7 +26,7 @@ notification_topic_opt = cfg.StrOpt('notification_topic', help='RabbitMQ topic used for Nova notifications') FLAGS = flags.FLAGS -FLAGS.add_option(notification_topic_opt) +FLAGS.register_opt(notification_topic_opt) def notify(message): diff --git a/nova/objectstore/s3server.py b/nova/objectstore/s3server.py index 997324de57ce..4f1ce12d17f2 100644 --- a/nova/objectstore/s3server.py +++ b/nova/objectstore/s3server.py @@ -55,7 +55,7 @@ buckets_path_opt = cfg.StrOpt('buckets_path', default='$state_path/buckets', help='path to s3 buckets') FLAGS = flags.FLAGS -FLAGS.add_option(buckets_path_opt) +FLAGS.register_opt(buckets_path_opt) def get_wsgi_server(): diff --git a/nova/policy.py b/nova/policy.py index 09b3ab988d49..9f6e6c9e254a 100644 --- a/nova/policy.py +++ b/nova/policy.py @@ -34,7 +34,7 @@ policy_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(policy_opts) +FLAGS.register_opts(policy_opts) _POLICY_PATH = None _POLICY_CACHE = {} diff --git a/nova/quota.py b/nova/quota.py index 4a5eac4b4813..fc49de067096 100644 --- a/nova/quota.py +++ b/nova/quota.py @@ -57,7 +57,7 @@ quota_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(quota_opts) +FLAGS.register_opts(quota_opts) def _get_default_quotas(): diff --git a/nova/rpc/__init__.py b/nova/rpc/__init__.py index 0c9cd42da2a6..3ad6ddd2e215 100644 --- a/nova/rpc/__init__.py +++ b/nova/rpc/__init__.py @@ -28,7 +28,7 @@ rpc_backend_opt = cfg.StrOpt('rpc_backend', help="The messaging module to use, defaults to kombu.") FLAGS = flags.FLAGS -FLAGS.add_option(rpc_backend_opt) +FLAGS.register_opt(rpc_backend_opt) def create_connection(new=True): diff --git a/nova/rpc/common.py b/nova/rpc/common.py index 696639e03e3e..ca6d1d6a1b8d 100644 --- a/nova/rpc/common.py +++ b/nova/rpc/common.py @@ -39,7 +39,7 @@ rpc_opts = [ help='Seconds to wait for a response from call or multicall'), ] -flags.FLAGS.add_options(rpc_opts) +flags.FLAGS.register_opts(rpc_opts) class RemoteError(exception.NovaException): diff --git a/nova/rpc/impl_qpid.py b/nova/rpc/impl_qpid.py index 122174282b8b..3898893d2288 100644 --- a/nova/rpc/impl_qpid.py +++ b/nova/rpc/impl_qpid.py @@ -78,7 +78,7 @@ qpid_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(qpid_opts) +FLAGS.register_opts(qpid_opts) class ConsumerBase(object): diff --git a/nova/scheduler/api.py b/nova/scheduler/api.py index 59ddada5e899..b8d2c2b2b404 100644 --- a/nova/scheduler/api.py +++ b/nova/scheduler/api.py @@ -38,7 +38,7 @@ enable_zone_routing_opt = cfg.BoolOpt('enable_zone_routing', help='When True, routing to child zones will occur.') FLAGS = flags.FLAGS -FLAGS.add_option(enable_zone_routing_opt) +FLAGS.register_opt(enable_zone_routing_opt) LOG = logging.getLogger('nova.scheduler.api') diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index f73eebc52b73..fa5bd13add95 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -48,7 +48,7 @@ scheduler_driver_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(scheduler_driver_opts) +FLAGS.register_opts(scheduler_driver_opts) flags.DECLARE('instances_path', 'nova.compute.manager') diff --git a/nova/scheduler/filters/core_filter.py b/nova/scheduler/filters/core_filter.py index 52b02248cba9..c34f29daf7ab 100644 --- a/nova/scheduler/filters/core_filter.py +++ b/nova/scheduler/filters/core_filter.py @@ -28,7 +28,7 @@ cpu_allocation_ratio_opt = cfg.FloatOpt('cpu_allocation_ratio', help='Virtual CPU to Physical CPU allocation ratio') FLAGS = flags.FLAGS -FLAGS.add_option(cpu_allocation_ratio_opt) +FLAGS.register_opt(cpu_allocation_ratio_opt) class CoreFilter(abstract_filter.AbstractHostFilter): diff --git a/nova/scheduler/filters/ram_filter.py b/nova/scheduler/filters/ram_filter.py index 8ada9c5c84e4..eacc583e8346 100644 --- a/nova/scheduler/filters/ram_filter.py +++ b/nova/scheduler/filters/ram_filter.py @@ -26,7 +26,7 @@ ram_allocation_ratio_opt = cfg.FloatOpt("ram_allocation_ratio", help="virtual ram to physical ram allocation ratio") FLAGS = flags.FLAGS -FLAGS.add_option(ram_allocation_ratio_opt) +FLAGS.register_opt(ram_allocation_ratio_opt) class RamFilter(abstract_filter.AbstractHostFilter): diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py index 0595513497b8..06515b0016bc 100644 --- a/nova/scheduler/host_manager.py +++ b/nova/scheduler/host_manager.py @@ -47,7 +47,7 @@ host_manager_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(host_manager_opts) +FLAGS.register_opts(host_manager_opts) LOG = logging.getLogger('nova.scheduler.host_manager') diff --git a/nova/scheduler/least_cost.py b/nova/scheduler/least_cost.py index 4711ac4f365f..d147d6ceb2cb 100644 --- a/nova/scheduler/least_cost.py +++ b/nova/scheduler/least_cost.py @@ -44,7 +44,7 @@ least_cost_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(least_cost_opts) +FLAGS.register_opts(least_cost_opts) # TODO(sirp): Once we have enough of these rules, we can break them out into a # cost_functions.py file (perhaps in a least_cost_scheduler directory) diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index db78fc921040..32e509f23219 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -41,7 +41,7 @@ scheduler_driver_opt = cfg.StrOpt('scheduler_driver', help='Default driver to use for the scheduler') FLAGS = flags.FLAGS -FLAGS.add_option(scheduler_driver_opt) +FLAGS.register_opt(scheduler_driver_opt) class SchedulerManager(manager.Manager): diff --git a/nova/scheduler/multi.py b/nova/scheduler/multi.py index 08d4bf0e6633..43adf0b1ea9c 100644 --- a/nova/scheduler/multi.py +++ b/nova/scheduler/multi.py @@ -37,7 +37,7 @@ multi_scheduler_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(multi_scheduler_opts) +FLAGS.register_opts(multi_scheduler_opts) # A mapping of methods to topics so we can figure out which driver to use. _METHOD_MAP = {'run_instance': 'compute', diff --git a/nova/scheduler/scheduler_options.py b/nova/scheduler/scheduler_options.py index 863919fb3423..787a063c345d 100644 --- a/nova/scheduler/scheduler_options.py +++ b/nova/scheduler/scheduler_options.py @@ -35,7 +35,7 @@ scheduler_json_config_location_opt = cfg.StrOpt( help='Absolute path to scheduler configuration JSON file.') FLAGS = flags.FLAGS -FLAGS.add_option(scheduler_json_config_location_opt) +FLAGS.register_opt(scheduler_json_config_location_opt) LOG = logging.getLogger('nova.scheduler.scheduler_options') diff --git a/nova/scheduler/simple.py b/nova/scheduler/simple.py index a3685b983cfe..a02417eaf7e0 100644 --- a/nova/scheduler/simple.py +++ b/nova/scheduler/simple.py @@ -46,7 +46,7 @@ simple_scheduler_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(simple_scheduler_opts) +FLAGS.register_opts(simple_scheduler_opts) class SimpleScheduler(chance.ChanceScheduler): diff --git a/nova/scheduler/vsa.py b/nova/scheduler/vsa.py index 408a57c3577e..e3dcf52a11e4 100644 --- a/nova/scheduler/vsa.py +++ b/nova/scheduler/vsa.py @@ -48,7 +48,7 @@ vsa_scheduler_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(vsa_scheduler_opts) +FLAGS.register_opts(vsa_scheduler_opts) def BYTES_TO_GB(bytes): diff --git a/nova/scheduler/zone_manager.py b/nova/scheduler/zone_manager.py index e94039a6b454..55942a25d343 100644 --- a/nova/scheduler/zone_manager.py +++ b/nova/scheduler/zone_manager.py @@ -40,7 +40,7 @@ zone_manager_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(zone_manager_opts) +FLAGS.register_opts(zone_manager_opts) LOG = logging.getLogger('nova.scheduler.zone_manager') diff --git a/nova/service.py b/nova/service.py index 5dcaf21bdf29..dd943f952cef 100644 --- a/nova/service.py +++ b/nova/service.py @@ -76,7 +76,7 @@ service_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(service_opts) +FLAGS.register_opts(service_opts) class Launcher(object): diff --git a/nova/test.py b/nova/test.py index 7fe4b4abb03b..1bb46c97bc6f 100644 --- a/nova/test.py +++ b/nova/test.py @@ -53,7 +53,7 @@ test_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(test_opts) +FLAGS.register_opts(test_opts) LOG = log.getLogger('nova.tests') @@ -134,7 +134,7 @@ class TestCase(unittest.TestCase): self.stubs = stubout.StubOutForTesting() self.injected = [] self._services = [] - self._original_flags = FLAGS.FlagValuesDict() + self._overridden_opts = [] def tearDown(self): """Runs after each test method to tear down test environment.""" @@ -176,7 +176,8 @@ class TestCase(unittest.TestCase): def flags(self, **kw): """Override flag variables for a test.""" for k, v in kw.iteritems(): - setattr(FLAGS, k, v) + FLAGS.set_override(k, v) + self._overridden_opts.append(k) def reset_flags(self): """Resets all flag variables for the test. @@ -184,9 +185,9 @@ class TestCase(unittest.TestCase): Runs after each test. """ - FLAGS.Reset() - for k, v in self._original_flags.iteritems(): - setattr(FLAGS, k, v) + for k in self._overridden_opts: + FLAGS.set_override(k, None) + self._overridden_opts = [] def start_service(self, name, host=None, **kwargs): host = host and host or uuid.uuid4().hex diff --git a/nova/testing/runner.py b/nova/testing/runner.py index 5939fba840a9..2f40befb09e9 100644 --- a/nova/testing/runner.py +++ b/nova/testing/runner.py @@ -73,7 +73,9 @@ reldir = os.path.join(os.path.dirname(__file__), '..', '..') absdir = os.path.abspath(reldir) sys.path.insert(0, absdir) +from nova import flags from nova import log as logging +from nova.openstack.common import cfg class _AnsiColorizer(object): @@ -341,18 +343,15 @@ class NovaTestRunner(core.TextTestRunner): def run(): + flags.FLAGS.register_cli_opt(cfg.BoolOpt('hide-elapsed', default=False)) + argv = flags.FLAGS(sys.argv) logging.setup() + # If any argument looks like a test name but doesn't have "nova.tests" in # front of it, automatically add that so we don't have to type as much - show_elapsed = True - argv = [] - for x in sys.argv: - if x.startswith('test_'): - argv.append('nova.tests.%s' % x) - elif x.startswith('--hide-elapsed'): - show_elapsed = False - else: - argv.append(x) + for i, arg in enumerate(argv): + if arg.startswith('test_'): + argv[i] = append('nova.tests.%s' % arg) testdir = os.path.abspath(os.path.join("nova", "tests")) c = config.Config(stream=sys.stdout, @@ -364,7 +363,7 @@ def run(): runner = NovaTestRunner(stream=c.stream, verbosity=c.verbosity, config=c, - show_elapsed=show_elapsed) + show_elapsed=not flags.FLAGS.hide_elapsed) sys.exit(not core.run(config=c, testRunner=runner, argv=argv)) diff --git a/nova/tests/api/openstack/compute/contrib/test_createserverext.py b/nova/tests/api/openstack/compute/contrib/test_createserverext.py index 2393780a2410..02c2f55b2a57 100644 --- a/nova/tests/api/openstack/compute/contrib/test_createserverext.py +++ b/nova/tests/api/openstack/compute/contrib/test_createserverext.py @@ -31,7 +31,6 @@ from nova.tests.api.openstack import fakes FLAGS = flags.FLAGS -FLAGS.verbose = True FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' diff --git a/nova/tests/api/openstack/compute/contrib/test_extendedstatus.py b/nova/tests/api/openstack/compute/contrib/test_extendedstatus.py index 2ac7d2f30cad..1edec954c69f 100644 --- a/nova/tests/api/openstack/compute/contrib/test_extendedstatus.py +++ b/nova/tests/api/openstack/compute/contrib/test_extendedstatus.py @@ -25,7 +25,6 @@ from nova.tests.api.openstack import fakes FLAGS = flags.FLAGS -FLAGS.verbose = True UUID1 = '70f6db34-de8d-4fbd-aafb-4065bdfa6114' diff --git a/nova/tests/api/openstack/compute/test_image_metadata.py b/nova/tests/api/openstack/compute/test_image_metadata.py index 62f047a2aa70..16d8e47b8b4d 100644 --- a/nova/tests/api/openstack/compute/test_image_metadata.py +++ b/nova/tests/api/openstack/compute/test_image_metadata.py @@ -189,7 +189,7 @@ class ImageMetaDataTest(test.TestCase): self.controller.create, req, '123', data) def test_too_many_metadata_items_on_put(self): - FLAGS.quota_metadata_items = 1 + self.flags(quota_metadata_items=1) req = fakes.HTTPRequest.blank('/v2/fake/images/123/metadata/blah') req.method = 'PUT' body = {"meta": {"blah": "blah"}} diff --git a/nova/tests/baremetal/test_proxy_bare_metal.py b/nova/tests/baremetal/test_proxy_bare_metal.py index ad41a85c30df..580f89863530 100644 --- a/nova/tests/baremetal/test_proxy_bare_metal.py +++ b/nova/tests/baremetal/test_proxy_bare_metal.py @@ -47,8 +47,8 @@ fake_domains = [{'status': 1, 'name': 'instance-00000001', class DomainReadWriteTestCase(test.TestCase): def setUp(self): - self.flags(baremetal_driver='fake') super(DomainReadWriteTestCase, self).setUp() + self.flags(baremetal_driver='fake') def test_read_domain_with_empty_list(self): """Read a file that contains no domains""" @@ -143,8 +143,8 @@ class DomainReadWriteTestCase(test.TestCase): class BareMetalDomTestCase(test.TestCase): def setUp(self): - self.flags(baremetal_driver='fake') super(BareMetalDomTestCase, self).setUp() + self.flags(baremetal_driver='fake') # Stub out utils.execute self.stubs = stubout.StubOutForTesting() fake_utils.stub_out_utils_execute(self.stubs) @@ -263,8 +263,8 @@ class ProxyBareMetalTestCase(test.TestCase): 'instance_type_id': '5'} # m1.small def setUp(self): - self.flags(baremetal_driver='fake') super(ProxyBareMetalTestCase, self).setUp() + self.flags(baremetal_driver='fake') self.context = context.get_admin_context() fake_utils.stub_out_utils_execute(self.stubs) diff --git a/nova/tests/declare_flags.py b/nova/tests/declare_flags.py index cb6726a7c55c..9e8fee123aac 100644 --- a/nova/tests/declare_flags.py +++ b/nova/tests/declare_flags.py @@ -20,4 +20,4 @@ from nova import flags from nova.openstack.common import cfg FLAGS = flags.FLAGS -FLAGS.add_option(cfg.IntOpt('answer', default=42, help='test flag')) +FLAGS.register_opt(cfg.IntOpt('answer', default=42, help='test flag')) diff --git a/nova/tests/fake_flags.py b/nova/tests/fake_flags.py index b95aa77d0dcc..a067b41bb358 100644 --- a/nova/tests/fake_flags.py +++ b/nova/tests/fake_flags.py @@ -21,25 +21,25 @@ from nova import flags FLAGS = flags.FLAGS flags.DECLARE('volume_driver', 'nova.volume.manager') -FLAGS['volume_driver'].SetDefault('nova.volume.driver.FakeISCSIDriver') -FLAGS['connection_type'].SetDefault('fake') -FLAGS['fake_rabbit'].SetDefault(True) -FLAGS['rpc_backend'].SetDefault('nova.rpc.impl_fake') +FLAGS.set_default('volume_driver', 'nova.volume.driver.FakeISCSIDriver') +FLAGS.set_default('connection_type', 'fake') +FLAGS.set_default('fake_rabbit', True) +FLAGS.set_default('rpc_backend', 'nova.rpc.impl_fake') flags.DECLARE('auth_driver', 'nova.auth.manager') -FLAGS['auth_driver'].SetDefault('nova.auth.dbdriver.DbDriver') +FLAGS.set_default('auth_driver', 'nova.auth.dbdriver.DbDriver') flags.DECLARE('network_size', 'nova.network.manager') flags.DECLARE('num_networks', 'nova.network.manager') flags.DECLARE('fake_network', 'nova.network.manager') -FLAGS['network_size'].SetDefault(8) -FLAGS['num_networks'].SetDefault(2) -FLAGS['fake_network'].SetDefault(True) -FLAGS['image_service'].SetDefault('nova.image.fake.FakeImageService') +FLAGS.set_default('network_size', 8) +FLAGS.set_default('num_networks', 2) +FLAGS.set_default('fake_network', True) +FLAGS.set_default('image_service', 'nova.image.fake.FakeImageService') flags.DECLARE('iscsi_num_targets', 'nova.volume.driver') -FLAGS['iscsi_num_targets'].SetDefault(8) -FLAGS['verbose'].SetDefault(True) -FLAGS['sqlite_db'].SetDefault("tests.sqlite") -FLAGS['use_ipv6'].SetDefault(True) -FLAGS['flat_network_bridge'].SetDefault('br100') -FLAGS['sqlite_synchronous'].SetDefault(False) +FLAGS.set_default('iscsi_num_targets', 8) +FLAGS.set_default('verbose', True) +FLAGS.set_default('sqlite_db', "tests.sqlite") +FLAGS.set_default('use_ipv6', True) +FLAGS.set_default('flat_network_bridge', 'br100') +FLAGS.set_default('sqlite_synchronous', False) flags.DECLARE('policy_file', 'nova.policy') -FLAGS['policy_file'].SetDefault('nova/tests/policy.json') +FLAGS.set_default('policy_file', 'nova/tests/policy.json') diff --git a/nova/tests/runtime_flags.py b/nova/tests/runtime_flags.py index 279d51162b60..7cc8c321979b 100644 --- a/nova/tests/runtime_flags.py +++ b/nova/tests/runtime_flags.py @@ -20,4 +20,4 @@ from nova import flags from nova.openstack.common import cfg FLAGS = flags.FLAGS -FLAGS.add_option(cfg.IntOpt('runtime_answer', default=54, help='test flag')) +FLAGS.register_opt(cfg.IntOpt('runtime_answer', default=54, help='test flag')) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 33861000d2c8..98aaaf8177ba 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -898,7 +898,7 @@ class ComputeTestCase(BaseTestCase): vpn=False).\ AndRaise(quantum_client.QuantumServerException()) - FLAGS.stub_network = False + self.flags(stub_network=False) self.mox.ReplayAll() diff --git a/nova/tests/test_consoleauth.py b/nova/tests/test_consoleauth.py index 41aefa7fd068..951e00b333f5 100644 --- a/nova/tests/test_consoleauth.py +++ b/nova/tests/test_consoleauth.py @@ -42,16 +42,14 @@ class ConsoleauthTestCase(test.TestCase): super(ConsoleauthTestCase, self).setUp() self.manager = utils.import_object(FLAGS.consoleauth_manager) self.context = context.get_admin_context() - self.old_ttl = FLAGS.console_token_ttl def tearDown(self): super(ConsoleauthTestCase, self).tearDown() - FLAGS.console_token_ttl = self.old_ttl def test_tokens_expire(self): """Test that tokens expire correctly.""" token = 'mytok' - FLAGS.console_token_ttl = 1 + self.flags(console_token_ttl=1) self.manager.authorize_console(self.context, token, 'novnc', '127.0.0.1', 'host', '') self.assertTrue(self.manager.check_token(self.context, token)) diff --git a/nova/tests/test_flags.py b/nova/tests/test_flags.py index 48aa965a9cab..46acd77d225a 100644 --- a/nova/tests/test_flags.py +++ b/nova/tests/test_flags.py @@ -17,7 +17,6 @@ # License for the specific language governing permissions and limitations # under the License. -import exceptions import os import tempfile @@ -26,88 +25,18 @@ from nova.openstack.common import cfg from nova import test FLAGS = flags.FLAGS -FLAGS.add_option(cfg.StrOpt('flags_unittest', - default='foo', - help='for testing purposes only')) - -test_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'), - ] - -float_opt = cfg.FloatOpt('float', default=6.66, help='desc') -multistr_opt = cfg.MultiStrOpt('multi', default=['blaa'], help='desc') -list_opt = cfg.ListOpt('list', default=['foo'], help='desc') +FLAGS.register_opt(cfg.StrOpt('flags_unittest', + default='foo', + help='for testing purposes only')) class FlagsTestCase(test.TestCase): def setUp(self): super(FlagsTestCase, self).setUp() - self.FLAGS = flags.FlagValues() + self.FLAGS = flags.NovaConfigOpts() self.global_FLAGS = flags.FLAGS - def test_define(self): - self.FLAGS.add_cli_options(test_opts) - - self.assert_(self.FLAGS['string']) - self.assert_(self.FLAGS['int']) - self.assert_(self.FLAGS['false']) - self.assert_(self.FLAGS['true']) - self.assertEqual(self.FLAGS.string, 'default') - self.assertEqual(self.FLAGS.int, 1) - self.assertEqual(self.FLAGS.false, False) - self.assertEqual(self.FLAGS.true, True) - - argv = ['flags_test', - '--string', 'foo', - '--int', '2', - '--false', - '--notrue'] - - self.FLAGS(argv) - self.assertEqual(self.FLAGS.string, 'foo') - self.assertEqual(self.FLAGS.int, 2) - self.assertEqual(self.FLAGS.false, True) - self.assertEqual(self.FLAGS.true, False) - - def test_define_float(self): - self.FLAGS.add_cli_options(test_opts) - self.FLAGS.add_option(float_opt) - self.assertEqual(self.FLAGS.float, 6.66) - - def test_define_multistring(self): - self.FLAGS.add_cli_option(multistr_opt) - - self.assert_(self.FLAGS['multi']) - self.assertEqual(self.FLAGS.multi, ['blaa']) - - argv = ['flags_test', '--multi', 'foo', '--multi', 'bar'] - self.FLAGS(argv) - - self.assertEqual(self.FLAGS.multi, ['foo', 'bar']) - - def test_define_list(self): - self.FLAGS.add_cli_option(list_opt) - - self.assert_(self.FLAGS['list']) - self.assertEqual(self.FLAGS.list, ['foo']) - - argv = ['flags_test', '--list=a,b,c,d'] - self.FLAGS(argv) - - self.assertEqual(self.FLAGS.list, ['a', 'b', 'c', 'd']) - - def test_error(self): - self.FLAGS.add_cli_option(float_opt) - - self.assertEqual(self.FLAGS.float, 6.66) - - argv = ['flags_test', '--float=foo'] - self.assertRaises(exceptions.SystemExit, self.FLAGS, argv) - def test_declare(self): self.assert_('answer' not in self.global_FLAGS) flags.DECLARE('answer', 'nova.tests.declare_flags') @@ -115,7 +44,7 @@ class FlagsTestCase(test.TestCase): self.assertEqual(self.global_FLAGS.answer, 42) # Make sure we don't overwrite anything - self.global_FLAGS.answer = 256 + self.global_FLAGS.set_override('answer', 256) self.assertEqual(self.global_FLAGS.answer, 256) flags.DECLARE('answer', 'nova.tests.declare_flags') self.assertEqual(self.global_FLAGS.answer, 256) @@ -135,48 +64,51 @@ class FlagsTestCase(test.TestCase): self.assertEqual(self.global_FLAGS.runtime_answer, 54) def test_long_vs_short_flags(self): - self.global_FLAGS.Reset() - self.global_FLAGS.add_cli_option(cfg.StrOpt('duplicate_answer_long', - default='val', - help='desc')) + self.global_FLAGS.reset() + self.global_FLAGS.register_cli_opt(cfg.StrOpt('duplicate_answer_long', + default='val', + help='desc')) argv = ['flags_test', '--duplicate_answer=60', 'extra_arg'] args = self.global_FLAGS(argv) self.assert_('duplicate_answer' not in self.global_FLAGS) self.assert_(self.global_FLAGS.duplicate_answer_long, 60) - self.global_FLAGS.Reset() - self.global_FLAGS.add_cli_option(cfg.IntOpt('duplicate_answer', - default=60, - help='desc')) + self.global_FLAGS.reset() + self.global_FLAGS.register_cli_opt(cfg.IntOpt('duplicate_answer', + default=60, + help='desc')) args = self.global_FLAGS(argv) self.assertEqual(self.global_FLAGS.duplicate_answer, 60) self.assertEqual(self.global_FLAGS.duplicate_answer_long, 'val') def test_flag_leak_left(self): self.assertEqual(FLAGS.flags_unittest, 'foo') - FLAGS.flags_unittest = 'bar' + self.flags(flags_unittest='bar') self.assertEqual(FLAGS.flags_unittest, 'bar') def test_flag_leak_right(self): self.assertEqual(FLAGS.flags_unittest, 'foo') - FLAGS.flags_unittest = 'bar' + self.flags(flags_unittest='bar') self.assertEqual(FLAGS.flags_unittest, 'bar') def test_flag_overrides(self): self.assertEqual(FLAGS.flags_unittest, 'foo') self.flags(flags_unittest='bar') self.assertEqual(FLAGS.flags_unittest, 'bar') - self.assertEqual(FLAGS['flags_unittest'].value, 'bar') - self.assertEqual(FLAGS.FlagValuesDict()['flags_unittest'], 'bar') self.reset_flags() self.assertEqual(FLAGS.flags_unittest, 'foo') - self.assertEqual(FLAGS['flags_unittest'].value, 'foo') - self.assertEqual(FLAGS.FlagValuesDict()['flags_unittest'], 'foo') def test_flagfile(self): - self.FLAGS.add_options(test_opts) - self.FLAGS.add_option(multistr_opt) + 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') @@ -200,15 +132,15 @@ class FlagsTestCase(test.TestCase): os.remove(path) def test_defaults(self): - self.FLAGS.add_option(cfg.StrOpt('foo', default='bar', help='desc')) + self.FLAGS.register_opt(cfg.StrOpt('foo', default='bar', help='desc')) self.assertEqual(self.FLAGS.foo, 'bar') - self.FLAGS['foo'].SetDefault('blaa') + self.FLAGS.set_default('foo', 'blaa') self.assertEqual(self.FLAGS.foo, 'blaa') def test_templated_values(self): - self.FLAGS.add_option(cfg.StrOpt('foo', default='foo', help='desc')) - self.FLAGS.add_option(cfg.StrOpt('bar', default='bar', help='desc')) - self.FLAGS.add_option(cfg.StrOpt('blaa', - default='$foo$bar', help='desc')) + self.FLAGS.register_opt(cfg.StrOpt('foo', default='foo', help='desc')) + self.FLAGS.register_opt(cfg.StrOpt('bar', default='bar', help='desc')) + self.FLAGS.register_opt(cfg.StrOpt('blaa', + default='$foo$bar', help='desc')) self.assertEqual(self.FLAGS.blaa, 'foobar') diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py index 29b812a2bedc..cf2972dac0df 100644 --- a/nova/tests/test_instance_types.py +++ b/nova/tests/test_instance_types.py @@ -173,7 +173,7 @@ class InstanceTypeTestCase(test.TestCase): def test_will_not_get_bad_default_instance_type(self): """ensures error raised on bad default instance type""" - FLAGS.default_instance_type = 'unknown_flavor' + self.flags(default_instance_type='unknown_flavor') self.assertRaises(exception.ApiError, instance_types.get_default_instance_type) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 4ce882992147..2d50344d6d12 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -939,8 +939,7 @@ class LibvirtConnTestCase(test.TestCase): """Confirms pre_block_migration works correctly.""" # Replace instances_path since this testcase creates tmpfile tmpdir = tempfile.mkdtemp() - store = FLAGS.instances_path - FLAGS.instances_path = tmpdir + self.flags(instances_path=tmpdir) # Test data instance_ref = db.instance_create(self.context, self.test_instance) @@ -960,8 +959,6 @@ class LibvirtConnTestCase(test.TestCase): shutil.rmtree(tmpdir) db.instance_destroy(self.context, instance_ref['id']) - # Restore FLAGS.instances_path - FLAGS.instances_path = store @test.skip_if(missing_libvirt(), "Test requires libvirt") def test_get_instance_disk_info_works_correctly(self): diff --git a/nova/tests/test_service.py b/nova/tests/test_service.py index edede55b35c7..0fd79f42acc1 100644 --- a/nova/tests/test_service.py +++ b/nova/tests/test_service.py @@ -45,7 +45,7 @@ test_service_opts = [ help="Port number to bind test service to"), ] -flags.FLAGS.add_options(test_service_opts) +flags.FLAGS.register_opts(test_service_opts) class FakeManager(manager.Manager): diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 58d295a6f2a2..4603de1e1ecd 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -442,9 +442,9 @@ class LibvirtConnTestCase(_VirtDriverTestCase): # Point _VirtDriverTestCase at the right module self.driver_module = nova.virt.libvirt.connection - FLAGS.firewall_driver = nova.virt.libvirt.firewall.drivers[0] super(LibvirtConnTestCase, self).setUp() - self.flags(rescue_image_id="2", + self.flags(firewall_driver=nova.virt.libvirt.firewall.drivers[0], + rescue_image_id="2", rescue_kernel_id="3", rescue_ramdisk_id=None) diff --git a/nova/tests/test_vsa.py b/nova/tests/test_vsa.py index 13287461677d..0c08594ec361 100644 --- a/nova/tests/test_vsa.py +++ b/nova/tests/test_vsa.py @@ -40,8 +40,7 @@ class VsaTestCase(test.TestCase): self.stubs = stubout.StubOutForTesting() self.vsa_api = vsa.API() - FLAGS.quota_volumes = 100 - FLAGS.quota_gigabytes = 10000 + self.flags(quota_volumes=100, quota_gigabytes=10000) self.context = context.get_admin_context() @@ -119,7 +118,7 @@ class VsaTestCase(test.TestCase): def test_vsa_create_with_storage(self, multi_vol_creation=True): """Test creation of VSA with BE storage""" - FLAGS.vsa_multi_vol_creation = multi_vol_creation + self.flags(vsa_multi_vol_creation=multi_vol_creation) param = {'storage': [{'drive_name': 'SATA_500_7200', 'num_drives': 3}]} @@ -152,7 +151,7 @@ class VsaTestCase(test.TestCase): def test_vsa_generate_user_data(self): - FLAGS.vsa_multi_vol_creation = False + self.flags(vsa_multi_vol_creation=False) param = {'display_name': 'VSA name test', 'display_description': 'VSA desc test', 'vc_count': 2, diff --git a/nova/utils.py b/nova/utils.py index 674be4a04f80..7bbfed1e0123 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -57,8 +57,7 @@ ISO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f" FLAGS = flags.FLAGS - -FLAGS.add_option( +FLAGS.register_opt( cfg.BoolOpt('disable_process_locking', default=False, help='Whether to disable inter-process locks')) @@ -572,7 +571,7 @@ class LazyPluggable(object): def __get_backend(self): if not self.__backend: - backend_name = self.__pivot.value + backend_name = FLAGS[self.__pivot] if backend_name not in self.__backends: raise exception.Error(_('Invalid backend: %s') % backend_name) diff --git a/nova/virt/baremetal/nodes.py b/nova/virt/baremetal/nodes.py index 5d1519f069df..f78eaf74d6c7 100644 --- a/nova/virt/baremetal/nodes.py +++ b/nova/virt/baremetal/nodes.py @@ -23,13 +23,13 @@ from nova import exception FLAGS = flags.FLAGS -global_opts = [ +baremetal_opts = [ cfg.StrOpt('baremetal_driver', default='tilera', help='Bare-metal driver runs on') ] -FLAGS.add_options(global_opts) +FLAGS.register_opts(baremetal_opts) def get_baremetal_nodes(): diff --git a/nova/virt/baremetal/proxy.py b/nova/virt/baremetal/proxy.py index 78b5de7df00d..45142ea44391 100644 --- a/nova/virt/baremetal/proxy.py +++ b/nova/virt/baremetal/proxy.py @@ -58,7 +58,7 @@ LOG = logging.getLogger('nova.virt.baremetal.proxy') FLAGS = flags.FLAGS -global_opts = [ +baremetal_opts = [ cfg.StrOpt('baremetal_injected_network_template', default=utils.abspath('virt/interfaces.template'), help='Template file for injected network'), @@ -73,7 +73,7 @@ global_opts = [ help='Whether to allow in project network traffic') ] -FLAGS.add_options(global_opts) +FLAGS.register_opts(baremetal_opts) def get_connection(read_only): diff --git a/nova/virt/baremetal/tilera.py b/nova/virt/baremetal/tilera.py index 7e31a1553bac..ee711988b3cb 100644 --- a/nova/virt/baremetal/tilera.py +++ b/nova/virt/baremetal/tilera.py @@ -35,13 +35,13 @@ from nova import utils FLAGS = flags.FLAGS -global_opts = [ +tilera_opts = [ cfg.StrOpt('tile_monitor', default='/usr/local/TileraMDE/bin/tile-monitor', help='Tilera command line program for Bare-metal driver') ] -FLAGS.add_options(global_opts) +FLAGS.register_opts(tilera_opts) LOG = logging.getLogger('nova.virt.tilera') diff --git a/nova/virt/disk/api.py b/nova/virt/disk/api.py index 929e17a55b7e..1d61ddd04082 100644 --- a/nova/virt/disk/api.py +++ b/nova/virt/disk/api.py @@ -72,7 +72,7 @@ disk_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(disk_opts) +FLAGS.register_opts(disk_opts) _MKFS_COMMAND = {} _DEFAULT_MKFS_COMMAND = None diff --git a/nova/virt/disk/nbd.py b/nova/virt/disk/nbd.py index d43fd3250bf3..029fecaf2e03 100644 --- a/nova/virt/disk/nbd.py +++ b/nova/virt/disk/nbd.py @@ -34,7 +34,7 @@ nbd_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(nbd_opts) +FLAGS.register_opts(nbd_opts) class Mount(mount.Mount): diff --git a/nova/virt/firewall.py b/nova/virt/firewall.py index 6e785176f61b..2e4a5d648193 100644 --- a/nova/virt/firewall.py +++ b/nova/virt/firewall.py @@ -33,7 +33,7 @@ allow_same_net_traffic_opt = cfg.BoolOpt('allow_same_net_traffic', help='Whether to allow network traffic from same network') FLAGS = flags.FLAGS -FLAGS.add_option(allow_same_net_traffic_opt) +FLAGS.register_opt(allow_same_net_traffic_opt) class FirewallDriver(object): diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 9f8971295d75..0ae8dd1fbe7d 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -149,7 +149,7 @@ libvirt_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(libvirt_opts) +FLAGS.register_opts(libvirt_opts) flags.DECLARE('live_migration_retry_count', 'nova.compute.manager') flags.DECLARE('vncserver_proxyclient_address', 'nova.vnc') @@ -190,7 +190,7 @@ class LibvirtConnection(driver.ComputeDriver): self.container = None self.read_only = read_only if FLAGS.firewall_driver not in firewall.drivers: - FLAGS['firewall_driver'].SetDefault(firewall.drivers[0]) + FLAGS.set_default('firewall_driver', firewall.drivers[0]) fw_class = utils.import_class(FLAGS.firewall_driver) self.firewall_driver = fw_class(get_connection=self._get_connection) self.vif_driver = utils.import_object(FLAGS.libvirt_vif_driver) diff --git a/nova/virt/libvirt/imagecache.py b/nova/virt/libvirt/imagecache.py index 04b35f1efbb3..1b8e1f531a65 100644 --- a/nova/virt/libvirt/imagecache.py +++ b/nova/virt/libvirt/imagecache.py @@ -54,7 +54,7 @@ imagecache_opts = [ flags.DECLARE('instances_path', 'nova.compute.manager') FLAGS = flags.FLAGS -FLAGS.add_options(imagecache_opts) +FLAGS.register_opts(imagecache_opts) def read_stored_checksum(base_file): diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index 83031987d08c..0b94a173fb24 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -36,7 +36,7 @@ qemu_img_opt = cfg.StrOpt('qemu_img', help='binary to use for qemu-img commands') FLAGS = flags.FLAGS -FLAGS.add_option(qemu_img_opt) +FLAGS.register_opt(qemu_img_opt) def execute(*args, **kwargs): diff --git a/nova/virt/libvirt/vif.py b/nova/virt/libvirt/vif.py index 84d8310299a8..bd808d6ee89f 100644 --- a/nova/virt/libvirt/vif.py +++ b/nova/virt/libvirt/vif.py @@ -36,7 +36,7 @@ libvirt_ovs_bridge_opt = cfg.StrOpt('libvirt_ovs_bridge', help='Name of Integration Bridge used by Open vSwitch') FLAGS = flags.FLAGS -FLAGS.add_option(libvirt_ovs_bridge_opt) +FLAGS.register_opt(libvirt_ovs_bridge_opt) class LibvirtBridgeDriver(VIFDriver): diff --git a/nova/virt/vmwareapi/vif.py b/nova/virt/vmwareapi/vif.py index 7c5943ce9f33..77a57864de22 100644 --- a/nova/virt/vmwareapi/vif.py +++ b/nova/virt/vmwareapi/vif.py @@ -27,7 +27,7 @@ from nova.virt.vmwareapi import network_utils LOG = logging.getLogger("nova.virt.vmwareapi.vif") FLAGS = flags.FLAGS -FLAGS['vmwareapi_vlan_interface'].SetDefault('vmnic0') +FLAGS.set_default('vmwareapi_vlan_interface', 'vmnic0') class VMWareVlanBridgeDriver(VIFDriver): diff --git a/nova/virt/vmwareapi/vim.py b/nova/virt/vmwareapi/vim.py index 2a9633c0af49..d8684ce7c995 100644 --- a/nova/virt/vmwareapi/vim.py +++ b/nova/virt/vmwareapi/vim.py @@ -42,7 +42,7 @@ vmwareapi_wsdl_loc_opt = cfg.StrOpt('vmwareapi_wsdl_loc', 'Refer readme-vmware to setup') FLAGS = flags.FLAGS -FLAGS.add_option(vmwareapi_wsdl_loc_opt) +FLAGS.register_opt(vmwareapi_wsdl_loc_opt) if suds: diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index 1e984f1fb634..c6a0f5d9de54 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -43,7 +43,7 @@ vmware_vif_driver_opt = cfg.StrOpt('vmware_vif_driver', help='The VMWare VIF driver to configure the VIFs.') FLAGS = flags.FLAGS -FLAGS.add_option(vmware_vif_driver_opt) +FLAGS.register_opt(vmware_vif_driver_opt) LOG = logging.getLogger("nova.virt.vmwareapi.vmops") diff --git a/nova/virt/vmwareapi_conn.py b/nova/virt/vmwareapi_conn.py index 7275b363e468..d8aae453c47e 100644 --- a/nova/virt/vmwareapi_conn.py +++ b/nova/virt/vmwareapi_conn.py @@ -80,7 +80,7 @@ vmwareapi_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(vmwareapi_opts) +FLAGS.register_opts(vmwareapi_opts) TIME_BETWEEN_API_CALL_RETRIES = 2.0 diff --git a/nova/virt/xenapi/vif.py b/nova/virt/xenapi/vif.py index 1da07975a2ad..b3bd744298f4 100644 --- a/nova/virt/xenapi/vif.py +++ b/nova/virt/xenapi/vif.py @@ -32,7 +32,7 @@ xenapi_ovs_integration_bridge_opt = cfg.StrOpt('xenapi_ovs_integration_bridge', help='Name of Integration Bridge used by Open vSwitch') FLAGS = flags.FLAGS -FLAGS.add_option(xenapi_ovs_integration_bridge_opt) +FLAGS.register_opt(xenapi_ovs_integration_bridge_opt) LOG = logging.getLogger("nova.virt.xenapi.vif") diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index cd8d0d28c981..97e40f3ab329 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -72,7 +72,7 @@ xenapi_vm_utils_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(xenapi_vm_utils_opts) +FLAGS.register_opts(xenapi_vm_utils_opts) XENAPI_POWER_STATE = { 'Halted': power_state.SHUTDOWN, diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index dd8c01bac3f2..e1b8208b1b84 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -72,7 +72,7 @@ xenapi_vmops_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(xenapi_vmops_opts) +FLAGS.register_opts(xenapi_vmops_opts) flags.DECLARE('vncserver_proxyclient_address', 'nova.vnc') @@ -107,7 +107,7 @@ class VMOps(object): self.poll_rescue_last_ran = None VMHelper.XenAPI = self.XenAPI if FLAGS.firewall_driver not in firewall.drivers: - FLAGS['firewall_driver'].SetDefault(firewall.drivers[0]) + FLAGS.set_default('firewall_driver', firewall.drivers[0]) fw_class = utils.import_class(FLAGS.firewall_driver) self.firewall_driver = fw_class(xenapi_session=self._session) vif_impl = utils.import_class(FLAGS.xenapi_vif_driver) diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py index 7bd7b7962434..158c74ef82e5 100644 --- a/nova/virt/xenapi_conn.py +++ b/nova/virt/xenapi_conn.py @@ -152,7 +152,7 @@ xenapi_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(xenapi_opts) +FLAGS.register_opts(xenapi_opts) def get_connection(_): diff --git a/nova/vnc/__init__.py b/nova/vnc/__init__.py index ba7268e974c2..2b23d442e678 100644 --- a/nova/vnc/__init__.py +++ b/nova/vnc/__init__.py @@ -47,4 +47,4 @@ vnc_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(vnc_opts) +FLAGS.register_opts(vnc_opts) diff --git a/nova/vnc/xvp_proxy.py b/nova/vnc/xvp_proxy.py index dfaf9a47acbb..9454b401b57e 100644 --- a/nova/vnc/xvp_proxy.py +++ b/nova/vnc/xvp_proxy.py @@ -47,7 +47,7 @@ xvp_proxy_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(xvp_proxy_opts) +FLAGS.register_opts(xvp_proxy_opts) flags.DECLARE('consoleauth_topic', 'nova.consoleauth') diff --git a/nova/volume/driver.py b/nova/volume/driver.py index 1299525e3be9..7936ee360450 100644 --- a/nova/volume/driver.py +++ b/nova/volume/driver.py @@ -63,7 +63,7 @@ volume_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(volume_opts) +FLAGS.register_opts(volume_opts) class VolumeDriver(object): diff --git a/nova/volume/iscsi.py b/nova/volume/iscsi.py index 1ef4da16fff7..115d51c80b25 100644 --- a/nova/volume/iscsi.py +++ b/nova/volume/iscsi.py @@ -30,7 +30,7 @@ iscsi_helper_opt = cfg.StrOpt('iscsi_helper', help='iscsi target user-land tool to use') FLAGS = flags.FLAGS -FLAGS.add_option(iscsi_helper_opt) +FLAGS.register_opt(iscsi_helper_opt) class TargetAdmin(object): diff --git a/nova/volume/manager.py b/nova/volume/manager.py index 15f26f79e315..0de40406e540 100644 --- a/nova/volume/manager.py +++ b/nova/volume/manager.py @@ -67,7 +67,7 @@ volume_manager_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(volume_manager_opts) +FLAGS.register_opts(volume_manager_opts) class VolumeManager(manager.SchedulerDependentManager): diff --git a/nova/volume/san.py b/nova/volume/san.py index bc06d7e03b49..d92084199491 100644 --- a/nova/volume/san.py +++ b/nova/volume/san.py @@ -75,7 +75,7 @@ san_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(san_opts) +FLAGS.register_opts(san_opts) class SanISCSIDriver(ISCSIDriver): diff --git a/nova/vsa/api.py b/nova/vsa/api.py index 323defdc1ca5..e9d04a85e408 100644 --- a/nova/vsa/api.py +++ b/nova/vsa/api.py @@ -62,7 +62,7 @@ vsa_opts = [ ] FLAGS = flags.FLAGS -FLAGS.add_options(vsa_opts) +FLAGS.register_opts(vsa_opts) LOG = logging.getLogger('nova.vsa') diff --git a/nova/vsa/manager.py b/nova/vsa/manager.py index b6d2d12f6b5f..e9f7edc97b14 100644 --- a/nova/vsa/manager.py +++ b/nova/vsa/manager.py @@ -40,7 +40,7 @@ vsa_driver_opt = cfg.StrOpt('vsa_driver', help='Driver to use for controlling VSAs') FLAGS = flags.FLAGS -FLAGS.add_option(vsa_driver_opt) +FLAGS.register_opt(vsa_driver_opt) LOG = logging.getLogger('nova.vsa.manager')