def test_set_defaults(self): conf = cfg.ConfigOpts() options.set_defaults(conf, connection='sqlite:///:memory:') self.assertTrue(len(conf.database.items()) > 1) self.assertEqual('sqlite:///:memory:', conf.database.connection)
def _parse_args(argv): conf = cfg.ConfigOpts() conf.register_cli_opts(opts) conf(argv, usage='Usage: %(prog)s [config-file|dest-dir]') if conf.configfile_or_destdir: def def_config_file(dest_dir): return os.path.join(dest_dir, 'openstack-common.conf') config_file = None if os.path.isfile(conf.configfile_or_destdir): config_file = conf.configfile_or_destdir elif (os.path.isdir(conf.configfile_or_destdir) and os.path.isfile(def_config_file(conf.configfile_or_destdir))): config_file = def_config_file(conf.configfile_or_destdir) if config_file: if not (conf.module or conf.modules): conf(argv + ['--config-file', config_file]) elif os.path.isdir(conf.configfile_or_destdir): conf(argv + ['--dest-dir', conf.configfile_or_destdir]) else: print( 'Specifying a config file and a list of modules to ' 'sync will not work correctly', file=sys.stderr) sys.exit(1) return conf
def setUp(self): super(BaseTestCase, self).setUp() self.config_fixture = self.useFixture( fixture_config.Config(cfg.ConfigOpts())) self.config = self.config_fixture.config self.CONF = self.config_fixture.conf log.register_options(self.CONF)
def __init__(self, routing_key, exchange, respQueueName, target=None, source=None, timeout=None): try: config_file = CONF.config_file[0] except AttributeError: config_file = "/etc/nova/nova.conf" configs = cfg.ConfigOpts() options = [ cfg.StrOpt('rabbit_host', default='localhost'), cfg.StrOpt('rabbit_password', required='true'), cfg.StrOpt('rabbit_user', default='guest') ] configs.register_opts(options) params_config = ['--config-file', config_file] configs(params_config) rh = configs.rabbit_host rp = configs.rabbit_password ru = configs.rabbit_user self._strBroker = "amqp://" + ru + ":" + rp + "@" + rh + ":5672//" if not timeout: self._timeout = 1 self._routing_key = routing_key self._exchange = exchange self._respQueueName = respQueueName
def init_conf(read_conf=True): default_config_files = None if read_conf: confpath = os.environ.get("SALADIER_INTEG_CONF") if not confpath: confpath = os.path.join( os.path.dirname( os.path.realpath(saladier_integrationtests.__file__)), "..", "etc", "saladier", "saladier_integration.conf.sample", ) if os.path.isfile(confpath): default_config_files = [confpath] conf = cfg.ConfigOpts() conf(args=[], project='saladier_integrationtests', default_config_files=default_config_files) for opt in IntegrationTestGroup: conf.register_opt(opt) return conf
def dynamic_conf(uri, options): """Given metadata, yields a dynamic configuration. :param uri: shard location :type uri: six.text_type :param options: additional shard metadata :type options: dict :returns: Configuration object suitable for constructing storage drivers :rtype: oslo.config.cfg.ConfigOpts """ # NOTE(cpp-cabrera): make it *very* clear to data storage # drivers that we are operating in a dynamic mode. general_opts = utils.dict_to_conf({'dynamic': True}) # NOTE(cpp-cabrera): parse general opts: 'drivers' storage_type = six.moves.urllib_parse.urlparse(uri).scheme driver_opts = utils.dict_to_conf({'storage': storage_type}) # NOTE(cpp-cabrera): parse storage-specific opts: # 'drivers:storage:{type}' storage_opts = utils.dict_to_conf({'uri': uri, 'options': options}) storage_group = u'drivers:storage:%s' % storage_type # NOTE(cpp-cabrera): register those options! conf = cfg.ConfigOpts() conf.register_opts(general_opts) conf.register_opts(driver_opts, group=u'drivers') conf.register_opts(storage_opts, group=storage_group) return conf
def test_config_model(self): conf = cfg.ConfigOpts() conf.register_opt(cfg.StrOpt('crackers', default='triscuit')) conf.register_opt(cfg.StrOpt('secrets', secret=True, default='should not show')) conf.register_group(cfg.OptGroup('cheese', title='Cheese Info')) conf.register_opt(cfg.IntOpt('sharpness', default=1), group='cheese') conf.register_opt(cfg.StrOpt('name', default='cheddar'), group='cheese') conf.register_opt(cfg.BoolOpt('from_cow', default=True), group='cheese') conf.register_opt(cfg.StrOpt('group_secrets', secret=True, default='should not show'), group='cheese') model = os_cgen.ConfigReportGenerator(conf)() model.set_current_view_type('text') target_str = ('\ncheese: \n' ' from_cow = True\n' ' group_secrets = ***\n' ' name = cheddar\n' ' sharpness = 1\n' '\n' 'default: \n' ' crackers = triscuit\n' ' secrets = ***') self.assertEqual(target_str, str(model))
def setUp(self): self.conf = cfg.ConfigOpts() config.register_agent_state_opts_helper(cfg.CONF) self.conf.register_opts(base_config.core_opts) self.conf.register_opts(cfg_agent.CiscoCfgAgent.OPTS, "cfg_agent") cfg.CONF.set_override('report_interval', 0, 'AGENT') super(TestCiscoCfgAgentWIthStateReporting, self).setUp() self.devmgr_plugin_api_cls_p = mock.patch( 'neutron.plugins.cisco.cfg_agent.cfg_agent.' 'CiscoDeviceManagementApi') devmgr_plugin_api_cls = self.devmgr_plugin_api_cls_p.start() self.devmgr_plugin_api = mock.Mock() devmgr_plugin_api_cls.return_value = self.devmgr_plugin_api self.devmgr_plugin_api.register_for_duty.return_value = True self.plugin_reportstate_api_cls_p = mock.patch( 'neutron.agent.rpc.PluginReportStateAPI') plugin_reportstate_api_cls = self.plugin_reportstate_api_cls_p.start() self.plugin_reportstate_api = mock.Mock() plugin_reportstate_api_cls.return_value = self.plugin_reportstate_api self.looping_call_p = mock.patch( 'neutron.openstack.common.loopingcall.FixedIntervalLoopingCall') self.looping_call_p.start() mock.patch('neutron.common.rpc.create_connection').start()
def setUp(self, conf=None): super(BaseTestCase, self).setUp() if conf is None: self.conf = cfg.ConfigOpts() else: self.conf = conf self.fconf = cfgfilter.ConfigFilter(self.conf)
def main(args=None): """The main function of oslo-config-generator.""" logging.basicConfig(level=logging.WARN) conf = cfg.ConfigOpts() register_cli_opts(conf) conf(args) generate(conf)
def parse_opts(argv): cli_opts = [ cfg.StrOpt('command', short='c', default='', help="This required argument is used to specify the " "coverage command to run. Only 'start', " "'stop', or 'report' are valid fields."), cfg.StrOpt('filename', default='tempest-coverage', help="Specify a filename to be used for generated report " "files"), cfg.BoolOpt('xml', default=False, help='Generate XML reports instead of text'), cfg.BoolOpt('html', default=False, help='Generate HTML reports instead of text'), cfg.BoolOpt('combine', default=False, help='Generate a single report for all services'), cfg.StrOpt('output', short='o', default=None, help='Optional directory to copy generated coverage data or' ' reports into. This directory must not already exist ' 'it will be created') ] CLI = cfg.ConfigOpts() CLI.register_cli_opts(cli_opts) CLI(argv[1:]) return CLI
def setUpClass(cls): cls.conf_file = 'poppy_mockdb.conf' super(TestBase, cls).setUpClass() cls.auth_config = config.AuthConfig() cls.auth_client = client.AuthClient() auth_token = cls.auth_client.get_auth_token(cls.auth_config.base_url, cls.auth_config.user_name, cls.auth_config.api_key) cls.config = config.PoppyConfig() cls.url = cls.config.base_url cls.client = client.CDNClient(cls.url, auth_token, serialize_format='json', deserialize_format='json') cls.server_config = config.PoppyServerConfig() if cls.server_config.run_server: conf_path = os.environ["POPPY_TESTS_CONFIGS_DIR"] config_file = os.path.join(conf_path, cls.conf_file) conf = cfg.ConfigOpts() conf(project='poppy', prog='poppy', args=[], default_config_files=[config_file]) poppy_server = server.CDNServer() poppy_server.start(conf)
def setUp(self): super(TestBasicRoutingOperations, self).setUp() self.conf = cfg.ConfigOpts() self.conf.register_opts(base_config.core_opts) self.conf.register_opts(cfg_agent.CiscoCfgAgent.OPTS) self.ex_gw_port = { 'id': _uuid(), 'network_id': _uuid(), 'fixed_ips': [{ 'ip_address': '19.4.4.4', 'subnet_id': _uuid() }], 'subnet': { 'cidr': '19.4.4.0/24', 'gateway_ip': '19.4.4.1' } } self.hosting_device = { 'id': "100", 'name': "CSR1kv_template", 'booting_time': 300, 'host_category': "VM", 'management_ip_address': '20.0.0.5', 'protocol_port': 22, 'credentials': { 'username': '******', "password": '******' }, } self.router = { 'id': _uuid(), 'enable_snat': True, 'routes': [], 'gw_port': self.ex_gw_port, 'hosting_device': self.hosting_device } self.agent = mock.Mock() #Patches & Mocks self.l3pluginApi_cls_p = mock.patch( 'neutron.plugins.cisco.cfg_agent.service_helpers.' 'routing_svc_helper.CiscoRoutingPluginApi') l3plugin_api_cls = self.l3pluginApi_cls_p.start() self.plugin_api = mock.Mock() l3plugin_api_cls.return_value = self.plugin_api self.plugin_api.get_routers = mock.MagicMock() self.looping_call_p = mock.patch( 'neutron.openstack.common.loopingcall.FixedIntervalLoopingCall') self.looping_call_p.start() mock.patch('neutron.common.rpc.create_connection').start() self.routing_helper = RoutingServiceHelper(HOST, self.conf, self.agent) self.routing_helper._internal_network_added = mock.Mock() self.routing_helper._external_gateway_added = mock.Mock() self.routing_helper._internal_network_removed = mock.Mock() self.routing_helper._external_gateway_removed = mock.Mock() self.driver = self._mock_driver_and_hosting_device(self.routing_helper)
def main(args=None): """The main function of oslo-config-generator.""" version = pkg_resources.get_distribution('oslo.config').version logging.basicConfig(level=logging.WARN) conf = cfg.ConfigOpts() register_cli_opts(conf) conf(args, version=version) generate(conf)
def setUp(self): super(GeneratorTestCase, self).setUp() self.conf = cfg.ConfigOpts() self.config_fixture = config_fixture.Config(self.conf) self.config = self.config_fixture.config self.useFixture(self.config_fixture) self.tempdir = self.useFixture(fixtures.TempDir())
def setUp(self): super(TestCase, self).setUp() self.useFixture(fixtures.FakeLogger('poppy')) if self.config_file: self.conf = self.load_conf(self.config_file) else: self.conf = cfg.ConfigOpts()
def _parse_config(): default_config = os.environ.get('HEAT_INVENTORY_CONFIG') if default_config: default_config = [default_config] configs = cfg.ConfigOpts() configs.register_cli_opts(opts) configs(prog='heat-ansible-inventory', default_config_files=default_config) return configs
def load_config(): conf = cfg.ConfigOpts() conf.register_opts(_AUTH_OPTIONS, group="auth") conf.register_opts(_MARCONI_OPTIONS, group="marconi") conf.register_opts(_HEADERS_OPTIONS, group="headers") conf_path = os.path.join(os.environ["MARCONI_TESTS_CONFIGS_DIR"], "functional-tests.conf") conf(args=[], default_config_files=[conf_path]) return conf
def setUp(self): super(TestFwaasL3AgentRpcCallback, self).setUp() self.addCleanup(mock.patch.stopall) self.conf = cfg.ConfigOpts() self.conf.register_opts(base_config.core_opts) agent_config.register_root_helper(self.conf) self.conf.root_helper = 'sudo' self.api = FWaasAgent(self.conf)
def _get_config_opts(self): config = cfg.ConfigOpts() config.register_opts(common_config.core_opts) config.register_opts(common_config.core_cli_opts) config.register_cli_opts(logging.common_cli_opts) config.register_cli_opts(logging.logging_cli_opts) config.register_opts(logging.generic_log_opts) config.register_opts(logging.log_opts) return config
def get_config_parser(): conf = cfg.ConfigOpts() conf.register_cli_opt( cfg.StrOpt( 'repo_root', default='.', help='directory containing the git repositories', )) return conf
def setUp(self, mock_driver, mock_provider): super(DefaultManagerServiceTests, self).setUp() # create mocked config and driver conf = cfg.ConfigOpts() manager_driver = driver.DefaultManagerDriver(conf, mock_driver, mock_provider) # stubbed driver self.sc = services.DefaultServicesController(manager_driver)
def setup_conf(): bind_opts = [ cfg.StrOpt('state_path', default='/var/lib/tacker', help=_('Top-level directory for maintaining dhcp state')), ] conf = cfg.ConfigOpts() conf.register_opts(bind_opts) return conf
def test_deprecated_names(self): paths = self.create_tempfiles([[ 'fake.conf', '\n'.join( ['[DEFAULT]', 'lock_path=foo', 'disable_process_locking=True']) ]]) conf = cfg.ConfigOpts() conf(['--config-file', paths[0]]) conf.register_opts(lockutils._opts, 'oslo_concurrency') self.assertEqual(conf.oslo_concurrency.lock_path, 'foo') self.assertTrue(conf.oslo_concurrency.disable_process_locking)
def test_cached(self): conf = cfg.ConfigOpts() oslo_cache.register_oslo_configs(conf) cache = oslo_cache.get_cache(conf.cache_url) sample_project = { u'name': u'Cats Abound', u'bits': b'\x80\x81\x82\x83\x84', b'key': u'Value. \x80', } def create_key(user, project=None): return user + ':' + str(project) class TestClass(object): def __init__(self, cache): self._cache = cache self.project_gets = 0 self.project_dels = 0 @decorators.caches(create_key, 60) def get_project(self, user, project=None): self.project_gets += 1 return sample_project @get_project.purges def del_project(self, user, project=None): self.project_dels += 1 instance = TestClass(cache) args = ('23', 'cats') project = instance.get_project(*args) self.assertEqual(project, sample_project) self.assertEqual(instance.project_gets, 1) # Should be in the cache now. project = msgpack.unpackb(cache.get(create_key(*args)), encoding='utf-8') self.assertEqual(project, sample_project) # Should read from the cache this time (counter will not # be incremented). project = instance.get_project(*args) self.assertEqual(project, sample_project) self.assertEqual(instance.project_gets, 1) # Use kwargs this time instance.del_project('23', project='cats') self.assertEqual(instance.project_dels, 1) # Should be a cache miss since we purged (above) project = instance.get_project(*args) self.assertEqual(instance.project_gets, 2)
def setUp(self): super(TestFwaasL3AgentRpcCallback, self).setUp() self.addCleanup(mock.patch.stopall) self.conf = cfg.ConfigOpts() self.conf.register_opts(base_config.core_opts) self.conf.register_opts(l3_agent.L3NATAgent.OPTS) agent_config.register_root_helper(self.conf) self.conf.root_helper = 'sudo' self.api = FWaasAgent(self.conf) self.api.fwaas_driver = test_firewall_agent_api.NoopFwaasDriver()
def load_conf(cls, filename): """Loads `filename` configuration file. :param filename: Name of the conf file to find (e.g., 'wsgi_memory.conf') :returns: Project's config object. """ conf = cfg.ConfigOpts() conf(args=[], default_config_files=[cls.conf_path(filename)]) return conf
def __init__(self, conf): """Construct a ConfigFilter object. :param conf: a ConfigOpts object """ self._conf = conf self._fconf = cfg.ConfigOpts() self._sync() self._imported_opts = set() self._imported_groups = dict()
class StoreBaseTest(base.BaseTestCase): #NOTE(flaper87): temporary until we # can move to a fully-local lib. # (Swift store's fault) _CONF = cfg.ConfigOpts() def setUp(self): super(StoreBaseTest, self).setUp() self.conf = self._CONF self.conf(args=[]) store.register_opts(self.conf) # Ensure stores + locations cleared location.SCHEME_TO_CLS_MAP = {} store.create_stores(self.conf) self.addCleanup(setattr, location, 'SCHEME_TO_CLS_MAP', dict()) self.test_dir = self.useFixture(fixtures.TempDir()).path self.addCleanup(self.conf.reset) def copy_data_file(self, file_name, dst_dir): src_file_name = os.path.join('glance_store/tests/etc', file_name) shutil.copy(src_file_name, dst_dir) dst_file_name = os.path.join(dst_dir, file_name) return dst_file_name def config(self, **kw): """Override some configuration values. The keyword arguments are the names of configuration options to override and their values. If a group argument is supplied, the overrides are applied to the specified configuration option group. All overrides are automatically cleared at the end of the current test by the fixtures cleanup process. """ group = kw.pop('group', 'glance_store') for k, v in kw.iteritems(): self.conf.set_override(k, v, group) def register_store_schemes(self, store): schemes = store.get_schemes() scheme_map = {} for scheme in schemes: loc_cls = store.get_store_location_class() scheme_map[scheme] = { 'store': store, 'location_class': loc_cls, } location.register_scheme_map(scheme_map)
def setUp(self): super(TestBasicRouterOperations, self).setUp() self.conf = cfg.ConfigOpts() self.conf.register_opts(base_config.core_opts) self.conf.register_opts(l3_agent.L3NATAgent.OPTS) agent_config.register_interface_driver_opts_helper(self.conf) agent_config.register_use_namespaces_opts_helper(self.conf) agent_config.register_root_helper(self.conf) self.conf.register_opts(interface.OPTS) self.conf.set_override('router_id', 'fake_id') self.conf.set_override('interface_driver', 'neutron.agent.linux.interface.NullDriver') self.conf.set_override('send_arp_for_ha', 1) self.conf.root_helper = 'sudo' self.device_exists_p = mock.patch( 'neutron.agent.linux.ip_lib.device_exists') self.device_exists = self.device_exists_p.start() self.utils_exec_p = mock.patch('neutron.agent.linux.utils.execute') self.utils_exec = self.utils_exec_p.start() self.external_process_p = mock.patch( 'neutron.agent.linux.external_process.ProcessManager') self.external_process = self.external_process_p.start() self.send_arp_p = mock.patch( 'neutron.agent.l3_agent.L3NATAgent._send_gratuitous_arp_packet') self.send_arp = self.send_arp_p.start() self.dvr_cls_p = mock.patch('neutron.agent.linux.interface.NullDriver') driver_cls = self.dvr_cls_p.start() self.mock_driver = mock.MagicMock() self.mock_driver.DEV_NAME_LEN = ( interface.LinuxInterfaceDriver.DEV_NAME_LEN) driver_cls.return_value = self.mock_driver self.ip_cls_p = mock.patch('neutron.agent.linux.ip_lib.IPWrapper') ip_cls = self.ip_cls_p.start() self.mock_ip = mock.MagicMock() ip_cls.return_value = self.mock_ip self.l3pluginApi_cls_p = mock.patch( 'neutron.agent.l3_agent.L3PluginApi') l3pluginApi_cls = self.l3pluginApi_cls_p.start() self.plugin_api = mock.Mock() l3pluginApi_cls.return_value = self.plugin_api self.looping_call_p = mock.patch( 'neutron.openstack.common.loopingcall.FixedIntervalLoopingCall') self.looping_call_p.start() self.addCleanup(mock.patch.stopall)