Python oslo_config.cfg.ConfigOpts() Examples

The following are 30 code examples of oslo_config.cfg.ConfigOpts(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oslo_config.cfg , or try the search function .
Example #1
Source File: test_cinder_protection_plugin.py    From karbor with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(CinderProtectionPluginTest, self).setUp()
        plugin_config = cfg.ConfigOpts()
        plugin_config_fixture = self.useFixture(fixture.Config(plugin_config))
        plugin_config_fixture.load_raw_values(
            group='cinder_backup_protection_plugin',
            poll_interval=0,
        )
        self.plugin = CinderBackupProtectionPlugin(plugin_config)
        cfg.CONF.set_default('cinder_endpoint',
                             'http://127.0.0.1:8776/v2',
                             'cinder_client')

        self.cntxt = RequestContext(user_id='demo',
                                    project_id='abcd',
                                    auth_token='efgh')
        self.cinder_client = client_factory.ClientFactory.create_client(
            "cinder", self.cntxt) 
Example #2
Source File: manage.py    From gnocchi with Apache License 2.0 6 votes vote down vote up
def change_sack_size():
    conf = cfg.ConfigOpts()
    conf.register_cli_opts([_SACK_NUMBER_OPT])
    conf = service.prepare_service(conf=conf, log_to_std=True)
    s = incoming.get_driver(conf)
    try:
        report = s.measures_report(details=False)
    except incoming.SackDetectionError:
        LOG.error('Unable to detect the number of storage sacks.\n'
                  'Ensure gnocchi-upgrade has been executed.')
        return
    remainder = report['summary']['measures']
    if remainder:
        LOG.error('Cannot change sack when non-empty backlog. Process '
                  'remaining %s measures and try again', remainder)
        return
    LOG.info("Removing current %d sacks", s.NUM_SACKS)
    s.remove_sacks()
    LOG.info("Creating new %d sacks", conf.sacks_number)
    s.upgrade(conf.sacks_number) 
Example #3
Source File: vault_secret_store.py    From barbican with Apache License 2.0 6 votes vote down vote up
def get_conf(self, conf=CONF):
        """Convert secret store conf into oslo conf

        Returns an oslo.config() object to pass to keymanager.API(conf)
        """
        vault_conf = cfg.ConfigOpts()
        options.set_defaults(
            vault_conf,
            backend='vault',
            vault_root_token_id=conf.vault_plugin.root_token_id,
            vault_approle_role_id=conf.vault_plugin.approle_role_id,
            vault_approle_secret_id=conf.vault_plugin.approle_secret_id,
            vault_kv_mountpoint=conf.vault_plugin.kv_mountpoint,
            vault_url=conf.vault_plugin.vault_url,
            vault_ssl_ca_crt_file=conf.vault_plugin.ssl_ca_crt_file,
            vault_use_ssl=conf.vault_plugin.use_ssl
        )
        return vault_conf 
Example #4
Source File: status.py    From kuryr-kubernetes with Apache License 2.0 6 votes vote down vote up
def main():
    opt = cfg.SubCommandOpt(
        'category', title='command',
        description='kuryr-k8s-status command or category to execute',
        handler=add_parsers)

    conf = cfg.ConfigOpts()
    conf.register_cli_opt(opt)
    conf(sys.argv[1:])

    os_vif.initialize()
    objects.register_locally_defined_vifs()

    try:
        return conf.category.action_fn()
    except Exception:
        print('Error:\n%s' % traceback.format_exc())
        # This is 255 so it's not confused with the upgrade check exit codes.
        return 255 
Example #5
Source File: eventlet_backdoor.py    From oslo.service with Apache License 2.0 6 votes vote down vote up
def _main():
    import eventlet
    eventlet.monkey_patch(all=True)
    # Monkey patch the original current_thread to use the up-to-date _active
    # global variable. See https://bugs.launchpad.net/bugs/1863021 and
    # https://github.com/eventlet/eventlet/issues/592
    import __original_module_threading as orig_threading
    import threading  # noqa
    orig_threading.current_thread.__globals__['_active'] = threading._active

    from oslo_config import cfg

    logging.basicConfig(level=logging.DEBUG)

    conf = cfg.ConfigOpts()
    conf.register_cli_opts(_options.eventlet_backdoor_opts)
    conf(sys.argv[1:])

    where_running_thread = _initialize_if_enabled(conf)
    if not where_running_thread:
        raise RuntimeError(_("Did not create backdoor at requested location"))
    else:
        _where_running, thread = where_running_thread
        thread.wait() 
Example #6
Source File: config.py    From castellan with Apache License 2.0 6 votes vote down vote up
def setup_config(config_file=''):
    global TEST_CONF
    TEST_CONF = cfg.ConfigOpts()

    TEST_CONF.register_group(identity_group)
    TEST_CONF.register_opts(identity_options, group=identity_group)

    config_to_load = []
    local_config = './etc/castellan/castellan-functional.conf'
    main_config = '/etc/castellan/castellan-functional.conf'
    if os.path.isfile(config_file):
        config_to_load.append(config_file)
    elif os.path.isfile(local_config):
        config_to_load.append(local_config)
    elif os.path.isfile(main_config):
        config_to_load.append(main_config)

    TEST_CONF(
        (),  # Required to load an anonymous configuration
        default_config_files=config_to_load
    ) 
Example #7
Source File: wsgi.py    From senlin with Apache License 2.0 6 votes vote down vote up
def paste_deploy_app(paste_config_file, app_name, conf):
    """Load a WSGI app from a PasteDeploy configuration.

    Use deploy.loadapp() to load the app from the PasteDeploy configuration,
    ensuring that the supplied ConfigOpts object is passed to the app and
    filter constructors.

    :param paste_config_file: a PasteDeploy config file
    :param app_name: the name of the app/pipeline to load from the file
    :param conf: a ConfigOpts object to supply to the app and its filters
    :returns: the WSGI app
    """
    setup_paste_factories(conf)
    try:
        return deploy.loadapp("config:%s" % paste_config_file, name=app_name)
    finally:
        teardown_paste_factories() 
Example #8
Source File: test_swift_client.py    From karbor with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(SwiftClientTest, self).setUp()
        service_catalog = [
            {
                'endpoints': [
                    {'publicURL': 'http://127.0.0.1:8080/v1/AUTH_abcd', }
                ],
                'type': 'object-store',
                'name': 'swift',
            },
        ]
        self._context = RequestContext(user_id='demo',
                                       project_id='abcd',
                                       auth_token='efgh',
                                       service_catalog=service_catalog)

        self.conf = cfg.ConfigOpts()
        swift.register_opts(self.conf) 
Example #9
Source File: test_k8s_client.py    From karbor with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(KubernetesClientTest, self).setUp()
        self._context = RequestContext(user_id='demo',
                                       project_id='abcd',
                                       auth_token='efgh',
                                       service_catalog=None)

        self.conf = cfg.ConfigOpts()
        k8s.register_opts(self.conf)
        self.host_url = 'https://192.168.98.35:6443'
        self.conf.set_default('k8s_host',
                              self.host_url,
                              'k8s_client')
        self.conf.set_override('k8s_ssl_ca_cert',
                               '/etc/provider.d/server-ca.crt',
                               'k8s_client')
        self.conf.set_override('k8s_cert_file',
                               '/etc/provider.d/client-admin.crt',
                               'k8s_client')
        self.conf.set_override('k8s_key_file',
                               '/etc/provider.d/client-admin.key',
                               'k8s_client') 
Example #10
Source File: eisoo.py    From karbor with Apache License 2.0 6 votes vote down vote up
def create(context, conf):
    config_dir = utils.find_config(CONF.provider_config_dir)
    config_file = os.path.abspath(os.path.join(config_dir,
                                               'eisoo.conf'))
    config = cfg.ConfigOpts()
    config(args=['--config-file=' + config_file])
    config.register_opts(eisoo_client_opts,
                         group=SERVICE + '_client')

    LOG.info('Creating eisoo client with url %s.',
             config.eisoo_client.eisoo_endpoint)
    abclient = client.ABClient(config.eisoo_client.eisoo_endpoint,
                               config.eisoo_client.eisoo_app_id,
                               config.eisoo_client.eisoo_app_secret)

    return abclient 
Example #11
Source File: test_api.py    From oslo.db with Apache License 2.0 5 votes vote down vote up
def test_dbapi_from_config(self):
        conf = cfg.ConfigOpts()

        dbapi = api.DBAPI.from_config(conf,
                                      backend_mapping={'sqlalchemy': __name__})
        self.assertIsNotNone(dbapi._backend) 
Example #12
Source File: test_glance_protection_plugin.py    From karbor with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(GlanceProtectionPluginTest, self).setUp()

        plugin_config = cfg.ConfigOpts()
        plugin_config_fixture = self.useFixture(fixture.Config(plugin_config))
        plugin_config_fixture.load_raw_values(
            group='image_backup_plugin',
            poll_interval=0,
        )
        plugin_config_fixture.load_raw_values(
            group='image_backup_plugin',
            backup_image_object_size=65536,
        )
        plugin_config_fixture.load_raw_values(
            group='image_backup_plugin',
            enable_server_snapshot=True,
        )
        self.plugin = GlanceProtectionPlugin(plugin_config)
        cfg.CONF.set_default('glance_endpoint',
                             'http://127.0.0.1:9292',
                             'glance_client')

        self.cntxt = RequestContext(user_id='demo',
                                    project_id='abcd',
                                    auth_token='efgh')
        self.glance_client = client_factory.ClientFactory.create_client(
            "glance", self.cntxt)
        self.checkpoint = FakeCheckpoint() 
Example #13
Source File: test_lockutils.py    From oslo.concurrency with Apache License 2.0 5 votes vote down vote up
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('foo', conf.oslo_concurrency.lock_path)
        self.assertTrue(conf.oslo_concurrency.disable_process_locking) 
Example #14
Source File: wsgi.py    From senlin with Apache License 2.0 5 votes vote down vote up
def setup_paste_factories(conf):
    """Set up the generic paste app and filter factories.

    The app factories are constructed at runtime to allow us to pass a
    ConfigOpts object to the WSGI classes.

    :param conf: a ConfigOpts object
    """
    global app_factory, filter_factory

    app_factory = AppFactory(conf)
    filter_factory = FilterFactory(conf) 
Example #15
Source File: test_database_protection_plugin.py    From karbor with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TroveProtectionPluginTest, self).setUp()

        plugin_config = cfg.ConfigOpts()
        plugin_config_fixture = self.useFixture(fixture.Config(plugin_config))
        plugin_config_fixture.load_raw_values(
            group='database_backup_plugin',
            poll_interval=0,
        )

        self.plugin = DatabaseBackupProtectionPlugin(plugin_config)

        cfg.CONF.set_default('trove_endpoint',
                             'http://127.0.0.1:8774/v2.1',
                             'trove_client')
        service_catalog = [
            {'type': 'database',
             'endpoints': [{'publicURL': 'http://127.0.0.1:8774/v2.1/abcd'}],
             },
        ]
        self.cntxt = RequestContext(user_id='demo',
                                    project_id='abcd',
                                    auth_token='efgh',
                                    service_catalog=service_catalog)
        self.trove_client = client_factory.ClientFactory.create_client(
            "trove", self.cntxt)
        self.checkpoint = FakeCheckpoint() 
Example #16
Source File: provider.py    From karbor with Apache License 2.0 5 votes vote down vote up
def _load_providers(self):
        """load provider"""
        config_dir = utils.find_config(CONF.provider_config_dir)

        for config_file in os.listdir(config_dir):
            if not config_file.endswith('.conf'):
                continue
            config_path = os.path.abspath(os.path.join(config_dir,
                                                       config_file))
            provider_config = cfg.ConfigOpts()
            provider_config(args=['--config-file=' + config_path])
            provider_config.register_opts(provider_opts, 'provider')

            provider_enabled = provider_config.provider.enabled
            if not provider_enabled:
                LOG.info('Provider {0} is not enabled'.format(
                    provider_config.provider.name)
                )
                continue

            try:
                provider = PluggableProtectionProvider(provider_config)
            except Exception as e:
                LOG.error("Load provider: %(provider)s failed. "
                          "Reason: %(reason)s",
                          {'provider': provider_config.provider.name,
                           'reason': e})
            else:
                LOG.info('Loaded provider: %s successfully.',
                         provider_config.provider.name)
                self.providers[provider.id] = provider 
Example #17
Source File: test_pod_protection_plugin.py    From karbor with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(PodProtectionPluginTest, self).setUp()

        plugin_config = cfg.ConfigOpts()
        plugin_config_fixture = self.useFixture(fixture.Config(plugin_config))
        plugin_config_fixture.load_raw_values(
            group='poll_interval',
            poll_interval=0,
        )
        self.plugin = PodProtectionPlugin(plugin_config)

        k8s.register_opts(cfg.CONF)
        cfg.CONF.set_default('k8s_host',
                             'https://192.168.98.35:6443',
                             'k8s_client')
        cfg.CONF.set_default('k8s_ssl_ca_cert',
                             '/etc/provider.d/server-ca.crt',
                             'k8s_client')
        cfg.CONF.set_default('k8s_cert_file',
                             '/etc/provider.d/client-admin.crt',
                             'k8s_client')
        cfg.CONF.set_default('k8s_key_file',
                             '/etc/provider.d/client-admin.key',
                             'k8s_client')

        self.cntxt = RequestContext(user_id='demo',
                                    project_id='abcd',
                                    auth_token='efgh',
                                    service_catalog=None)
        self.k8s_client = None
        self.checkpoint = Checkpoint() 
Example #18
Source File: test_cinder_freezer_protection_plugin.py    From karbor with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(VolumeFreezerProtectionPluginTest, self).setUp()

        plugin_config = cfg.ConfigOpts()
        plugin_config_fixture = self.useFixture(fixture.Config(plugin_config))
        plugin_config_fixture.load_raw_values(
            group='freezer_protection_plugin',
            poll_interval=0,
        )

        self.plugin = FreezerProtectionPlugin(plugin_config)
        self._public_url = 'http://127.0.0.1/v2.0'
        cfg.CONF.set_default('freezer_endpoint',
                             self._public_url,
                             'freezer_client')
        # due to freezer client bug, auth_uri should be specified
        cfg.CONF.set_default('auth_uri',
                             'http://127.0.0.1/v2.0',
                             'freezer_client')
        self.cntxt = RequestContext(user_id='demo',
                                    project_id='fake_project_id',
                                    auth_token='fake_token')

        self.freezer_client = client_factory.ClientFactory.create_client(
            'freezer', self.cntxt
        )
        self.checkpoint = FakeCheckpoint() 
Example #19
Source File: test_cinder_snapshot_protection_plugin.py    From karbor with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(CinderSnapshotProtectionPluginTest, self).setUp()

        plugin_config = cfg.ConfigOpts()
        plugin_config_fixture = self.useFixture(fixture.Config(plugin_config))
        plugin_config_fixture.load_raw_values(
            group='volume_snapshot_plugin',
            poll_interval=0,
        )

        self.plugin = VolumeSnapshotProtectionPlugin(plugin_config)

        cfg.CONF.set_default('cinder_endpoint',
                             'http://127.0.0.1:8774/v2.1',
                             'cinder_client')
        service_catalog = [
            {'type': 'volumev3',
             'endpoints': [{'publicURL': 'http://127.0.0.1:8774/v2.1/abcd'}],
             },
        ]
        self.cntxt = RequestContext(user_id='demo',
                                    project_id='abcd',
                                    auth_token='efgh',
                                    service_catalog=service_catalog)
        self.cinder_client = client_factory.ClientFactory.create_client(
            "cinder", self.cntxt)
        self.checkpoint = FakeCheckpoint() 
Example #20
Source File: test_consistency_transformer.py    From vitrage with Apache License 2.0 5 votes vote down vote up
def setUpClass(cls):
        super(TestConsistencyTransformer, cls).setUpClass()
        cls.transformers = {}
        cls.conf = cfg.ConfigOpts()
        cls.conf.register_opts(cls.OPTS, group=CONSISTENCY_DATASOURCE)
        cls.transformers[CONSISTENCY_DATASOURCE] = \
            ConsistencyTransformer(cls.transformers)
        cls.actions = [GraphAction.DELETE_ENTITY,
                       GraphAction.REMOVE_DELETED_ENTITY] 
Example #21
Source File: test_options.py    From oslo.db with Apache License 2.0 5 votes vote down vote up
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) 
Example #22
Source File: test_sqlalchemy.py    From oslo.db with Apache License 2.0 5 votes vote down vote up
def test_creation_from_config(self, create_engine, get_maker):
        conf = cfg.ConfigOpts()
        conf.register_opts(db_options.database_opts, group='database')

        overrides = {
            'connection': 'sqlite:///:memory:',
            'slave_connection': None,
            'connection_debug': 100,
            'max_pool_size': 10,
            'mysql_sql_mode': 'TRADITIONAL',
        }
        for optname, optvalue in overrides.items():
            conf.set_override(optname, optvalue, group='database')

        session.EngineFacade.from_config(conf,
                                         autocommit=False,
                                         expire_on_commit=True)

        create_engine.assert_called_once_with(
            sql_connection='sqlite:///:memory:',
            connection_debug=100,
            max_pool_size=10,
            mysql_sql_mode='TRADITIONAL',
            mysql_enable_ndb=False,
            sqlite_fk=False,
            connection_recycle_time=mock.ANY,
            retry_interval=mock.ANY,
            max_retries=mock.ANY,
            max_overflow=mock.ANY,
            connection_trace=mock.ANY,
            sqlite_synchronous=mock.ANY,
            pool_timeout=mock.ANY,
            thread_checkin=mock.ANY,
            json_serializer=None,
            json_deserializer=None,
            connection_parameters='',
            logging_name=mock.ANY,
        )
        get_maker.assert_called_once_with(engine=create_engine(),
                                          autocommit=False,
                                          expire_on_commit=True) 
Example #23
Source File: config.py    From barbican with Apache License 2.0 5 votes vote down vote up
def new_config():
    conf = cfg.ConfigOpts()
    log.register_options(conf)
    conf.register_opts(context_opts)
    conf.register_opts(common_opts)
    conf.register_opts(host_opts)
    conf.register_opts(db_opts)
    conf.register_opts(_options.eventlet_backdoor_opts)
    conf.register_opts(_options.periodic_opts)

    conf.register_opts(_options.ssl_opts, "ssl")

    conf.register_group(retry_opt_group)
    conf.register_opts(retry_opts, group=retry_opt_group)

    conf.register_group(queue_opt_group)
    conf.register_opts(queue_opts, group=queue_opt_group)

    conf.register_group(ks_queue_opt_group)
    conf.register_opts(ks_queue_opts, group=ks_queue_opt_group)

    conf.register_group(quota_opt_group)
    conf.register_opts(quota_opts, group=quota_opt_group)

    # Update default values from libraries that carry their own oslo.config
    # initialization and configuration.
    set_middleware_defaults()

    return conf 
Example #24
Source File: bifrost_inventory.py    From bifrost with Apache License 2.0 5 votes vote down vote up
def _parse_config():
    config = cfg.ConfigOpts()
    log.register_options(config)
    config.register_cli_opts(opts)
    config(prog='bifrost_inventory.py')
    log.set_defaults()
    log.setup(config, "bifrost_inventory.py")
    return config 
Example #25
Source File: inventory.py    From bifrost with Apache License 2.0 5 votes vote down vote up
def _parse_config():
    config = cfg.ConfigOpts()
    log.register_options(config)
    config.register_cli_opts(opts)
    config(prog='bifrost_inventory.py')
    log.set_defaults()
    log.setup(config, "bifrost_inventory.py")
    return config 
Example #26
Source File: base.py    From oslo.middleware with Apache License 2.0 5 votes vote down vote up
def __init__(self, application, conf=None):
        """Base middleware constructor

        :param  conf: a dict of options or a cfg.ConfigOpts object
        """
        self.application = application

        # NOTE(sileht): If the configuration come from oslo.config
        # just use it.
        if isinstance(conf, cfg.ConfigOpts):
            self.conf = {}
            self.oslo_conf = conf
        else:
            self.conf = conf or {}
            if "oslo_config_project" in self.conf:
                if 'oslo_config_file' in self.conf:
                    default_config_files = [self.conf['oslo_config_file']]
                else:
                    default_config_files = None

                if 'oslo_config_program' in self.conf:
                    program = self.conf['oslo_config_program']
                else:
                    program = None

                self.oslo_conf = cfg.ConfigOpts()
                self.oslo_conf([],
                               project=self.conf['oslo_config_project'],
                               prog=program,
                               default_config_files=default_config_files,
                               validate_default_values=True)

            else:
                # Fallback to global object
                self.oslo_conf = cfg.CONF 
Example #27
Source File: test_aodh_driver.py    From vitrage with Apache License 2.0 5 votes vote down vote up
def setUpClass(cls):
        super(AodhDriverTest, cls).setUpClass()
        cls.conf = cfg.ConfigOpts()
        cls.conf.register_opts(cls.OPTS, group=AODH_DATASOURCE) 
Example #28
Source File: test_aodh_transformer.py    From vitrage with Apache License 2.0 5 votes vote down vote up
def setUpClass(cls):
        super(TestAodhAlarmPushTransformer, cls).setUpClass()
        cls.transformers = {}
        cls.conf = cfg.ConfigOpts()
        cls.conf.register_opts(cls.OPTS, group=AODH_DATASOURCE)
        cls.transformers[AODH_DATASOURCE] = \
            AodhTransformer(cls.transformers) 
Example #29
Source File: test_aodh_transformer.py    From vitrage with Apache License 2.0 5 votes vote down vote up
def setUpClass(cls):
        super(TestAodhAlarmTransformer, cls).setUpClass()
        cls.transformers = {}
        cls.conf = cfg.ConfigOpts()
        cls.conf.register_opts(cls.OPTS, group=AODH_DATASOURCE)
        cls.transformers[AODH_DATASOURCE] = \
            AodhTransformer(cls.transformers) 
Example #30
Source File: test_static_transformer.py    From vitrage with Apache License 2.0 5 votes vote down vote up
def setUpClass(cls):
        super(TestStaticTransformer, cls).setUpClass()
        cls.transformers = {}
        cls.conf = cfg.ConfigOpts()
        cls.conf.register_opts(cls.OPTS, group=STATIC_DATASOURCE)
        cls.transformer = StaticTransformer(cls.transformers)
        cls.transformers[STATIC_DATASOURCE] = cls.transformer
        cls.transformers[NOVA_HOST_DATASOURCE] = \
            HostTransformer(cls.transformers)

    # noinspection PyAttributeOutsideInit