Пример #1
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        drivers = service.load_backends()

        # TODO(stevemar): currently, load oauth1 driver as well, eventually
        # we need to have this as optional.
        from keystone.contrib import oauth1
        drivers['oauth1_api'] = oauth1.Manager()

        from keystone.contrib import federation
        drivers['federation_api'] = federation.Manager()

        dependency.resolve_future_dependencies()

        for manager_name, manager in six.iteritems(drivers):
            setattr(self, manager_name, manager)
Пример #2
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # NOTE(blk-u): identity must be before assignment to ensure that the
        # identity driver is available to the assignment manager because the
        # assignment manager gets the default assignment driver from the
        # identity driver.
        for manager in [
                identity, assignment, catalog, credential, ec2, policy, token,
                token_provider, trust
        ]:
            # manager.__name__ is like keystone.xxx[.yyy],
            # converted to xxx[_yyy]
            manager_name = (
                '%s_api' %
                manager.__name__.replace('keystone.', '').replace('.', '_'))

            setattr(self, manager_name, manager.Manager())

        dependency.resolve_future_dependencies()
Пример #3
0
def load_backends(include_oauth1=False):

    # Ensure that the identity driver is created before the assignment manager.
    # The default assignment driver is determined by the identity driver, so
    # the identity driver must be available to the assignment manager.
    _IDENTITY_API = identity.Manager()

    DRIVERS = dict(
        assignment_api=assignment.Manager(),
        catalog_api=catalog.Manager(),
        credential_api=credential.Manager(),
        endpoint_filter_api=endpoint_filter.Manager(),
        identity_api=_IDENTITY_API,
        policy_api=policy.Manager(),
        token_api=token.Manager(),
        trust_api=trust.Manager(),
        token_provider_api=token.provider.Manager())

    if include_oauth1:
        from keystone.contrib import oauth1
        DRIVERS['oauth1_api'] = oauth1.Manager()

    dependency.resolve_future_dependencies()

    return DRIVERS
Пример #4
0
def load_backends(include_oauth1=False):

    # Ensure that the identity driver is created before the assignment manager.
    # The default assignment driver is determined by the identity driver, so
    # the identity driver must be available to the assignment manager.
    _IDENTITY_API = identity.Manager()

    DRIVERS = dict(
        assignment_api=assignment.Manager(),
        catalog_api=catalog.Manager(),
        credential_api=credential.Manager(),
        endpoint_filter_api=endpoint_filter.Manager(),
        identity_api=_IDENTITY_API,
        policy_api=policy.Manager(),
        token_api=token.Manager(),
        trust_api=trust.Manager(),
        token_provider_api=token.provider.Manager())

    if include_oauth1:
        from keystone.contrib import oauth1
        DRIVERS['oauth1_api'] = oauth1.Manager()

    dependency.resolve_future_dependencies()

    return DRIVERS
Пример #5
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        drivers = service.load_backends()

        # TODO(stevemar): currently, load oauth1 driver as well, eventually
        # we need to have this as optional.
        from keystone.contrib import oauth1
        drivers['oauth1_api'] = oauth1.Manager()

        dependency.resolve_future_dependencies()

        for manager_name, manager in drivers.iteritems():
            setattr(self, manager_name, manager)
Пример #6
0
    def test_unresolvable_dependency(self):
        @dependency.requires(uuid.uuid4().hex)
        class Consumer(object):
            pass

        with self.assertRaises(dependency.UnresolvableDependencyException):
            Consumer()
            dependency.resolve_future_dependencies()
Пример #7
0
    def test_unresolvable_dependency(self):
        @dependency.requires(uuid.uuid4().hex)
        class Consumer(object):
            pass

        with self.assertRaises(dependency.UnresolvableDependencyException):
            Consumer()
            dependency.resolve_future_dependencies()
Пример #8
0
    def test_optional_dependency_not_provided(self):
        requirement_name = uuid.uuid4().hex

        @dependency.optional(requirement_name)
        class C1(object):
            pass

        c1_inst = C1()

        dependency.resolve_future_dependencies()

        self.assertIsNone(getattr(c1_inst, requirement_name))
Пример #9
0
    def test_optional_dependency_not_provided(self):
        requirement_name = uuid.uuid4().hex

        @dependency.optional(requirement_name)
        class C1(object):
            pass

        c1_inst = C1()

        dependency.resolve_future_dependencies()

        self.assertIsNone(getattr(c1_inst, requirement_name))
Пример #10
0
def setup_backends(load_extra_backends_fn=lambda: {},
                   startup_application_fn=lambda: None):
    drivers = backends.load_backends()
    drivers.update(load_extra_backends_fn())
    res = startup_application_fn()
    drivers.update(dependency.resolve_future_dependencies())
    return drivers, res
Пример #11
0
def setup_backends(load_extra_backends_fn=lambda: {},
                   startup_application_fn=lambda: None):
    drivers = backends.load_backends()
    drivers.update(load_extra_backends_fn())
    res = startup_application_fn()
    drivers.update(dependency.resolve_future_dependencies())
    return drivers, res
Пример #12
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers = service.load_backends()

        drivers.update(dependency.resolve_future_dependencies())

        for manager_name, manager in six.iteritems(drivers):
            setattr(self, manager_name, manager)
        self.addCleanup(self.cleanup_instance(*drivers.keys()))

        # The credential backend only supports SQL, so we always have to load
        # the tables.
        self.engine = sql.get_engine()
        self.addCleanup(sql.cleanup)
        self.addCleanup(self.cleanup_instance('engine'))

        sql.ModelBase.metadata.create_all(bind=self.engine)
        self.addCleanup(sql.ModelBase.metadata.drop_all, bind=self.engine)
Пример #13
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers = service.load_backends()

        drivers.update(dependency.resolve_future_dependencies())

        for manager_name, manager in six.iteritems(drivers):
            setattr(self, manager_name, manager)
        self.addCleanup(self.cleanup_instance(*drivers.keys()))

        # The credential backend only supports SQL, so we always have to load
        # the tables.
        self.engine = sql.get_engine()
        self.addCleanup(sql.cleanup)
        self.addCleanup(self.cleanup_instance('engine'))

        sql.ModelBase.metadata.create_all(bind=self.engine)
        self.addCleanup(sql.ModelBase.metadata.drop_all, bind=self.engine)
    def test_circular_dependency(self):
        p1_name = uuid.uuid4().hex
        p2_name = uuid.uuid4().hex

        @dependency.provider(p1_name)
        @dependency.requires(p2_name)
        class P1(object):
            pass

        @dependency.provider(p2_name)
        @dependency.requires(p1_name)
        class P2(object):
            pass

        p1 = P1()
        p2 = P2()

        dependency.resolve_future_dependencies()

        self.assertIs(getattr(p1, p2_name), p2)
        self.assertIs(getattr(p2, p1_name), p1)
Пример #15
0
    def test_circular_dependency(self):
        p1_name = uuid.uuid4().hex
        p2_name = uuid.uuid4().hex

        @dependency.provider(p1_name)
        @dependency.requires(p2_name)
        class P1(object):
            pass

        @dependency.provider(p2_name)
        @dependency.requires(p1_name)
        class P2(object):
            pass

        p1 = P1()
        p2 = P2()

        dependency.resolve_future_dependencies()

        self.assertIs(getattr(p1, p2_name), p2)
        self.assertIs(getattr(p2, p1_name), p1)
Пример #16
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # NOTE(blk-u): identity must be before assignment to ensure that the
        # identity driver is available to the assignment manager because the
        # assignment manager gets the default assignment driver from the
        # identity driver.
        for manager in [identity, assignment, catalog, credential, ec2, policy,
                        token, token_provider, trust, oauth1]:
            # manager.__name__ is like keystone.xxx[.yyy],
            # converted to xxx[_yyy]
            manager_name = ('%s_api' %
                            manager.__name__.replace('keystone.', '').
                            replace('.', '_'))

            setattr(self, manager_name, manager.Manager())

        dependency.resolve_future_dependencies()
Пример #17
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers = service.load_backends()

        # TODO(stevemar): currently, load oauth1 driver as well, eventually
        # we need to have this as optional.
        from keystone.contrib import oauth1
        drivers['oauth1_api'] = oauth1.Manager()

        from keystone.contrib import federation
        drivers['federation_api'] = federation.Manager()

        dependency.resolve_future_dependencies()

        for manager_name, manager in six.iteritems(drivers):
            setattr(self, manager_name, manager)

        # The credential backend only supports SQL, so we always have to load
        # the tables.
        self.engine = session.get_engine()
        self.addCleanup(session.cleanup)

        sql.ModelBase.metadata.create_all(bind=self.engine)
        self.addCleanup(sql.ModelBase.metadata.drop_all, bind=self.engine)
Пример #18
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers = service.load_backends()

        # TODO(stevemar): currently, load oauth1 driver as well, eventually
        # we need to have this as optional.
        from keystone.contrib import oauth1
        drivers['oauth1_api'] = oauth1.Manager()

        from keystone.contrib import federation
        drivers['federation_api'] = federation.Manager()

        dependency.resolve_future_dependencies()

        for manager_name, manager in six.iteritems(drivers):
            setattr(self, manager_name, manager)

        # The credential backend only supports SQL, so we always have to load
        # the tables.
        self.engine = session.get_engine()
        self.addCleanup(session.cleanup)

        sql.ModelBase.metadata.create_all(bind=self.engine)
        self.addCleanup(sql.ModelBase.metadata.drop_all, bind=self.engine)
Пример #19
0
    def test_optional_and_required(self):
        p1_name = uuid.uuid4().hex
        p2_name = uuid.uuid4().hex
        optional_name = uuid.uuid4().hex

        @dependency.provider(p1_name)
        @dependency.requires(p2_name)
        @dependency.optional(optional_name)
        class P1(object):
            pass

        @dependency.provider(p2_name)
        @dependency.requires(p1_name)
        class P2(object):
            pass

        p1 = P1()
        p2 = P2()

        dependency.resolve_future_dependencies()

        self.assertIs(getattr(p1, p2_name), p2)
        self.assertIs(getattr(p2, p1_name), p1)
        self.assertIsNone(getattr(p1, optional_name))
Пример #20
0
    def test_optional_and_required(self):
        p1_name = uuid.uuid4().hex
        p2_name = uuid.uuid4().hex
        optional_name = uuid.uuid4().hex

        @dependency.provider(p1_name)
        @dependency.requires(p2_name)
        @dependency.optional(optional_name)
        class P1(object):
            pass

        @dependency.provider(p2_name)
        @dependency.requires(p1_name)
        class P2(object):
            pass

        p1 = P1()
        p2 = P2()

        dependency.resolve_future_dependencies()

        self.assertIs(getattr(p1, p2_name), p2)
        self.assertIs(getattr(p2, p1_name), p1)
        self.assertIsNone(getattr(p1, optional_name))
Пример #21
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers = backends.load_backends()

        drivers.update(dependency.resolve_future_dependencies())

        for manager_name, manager in six.iteritems(drivers):
            setattr(self, manager_name, manager)
        self.addCleanup(self.cleanup_instance(*drivers.keys()))
Пример #22
0
    def load_backends(self):
        """Initializes each manager and assigns them to an attribute."""

        # TODO(blk-u): Shouldn't need to clear the registry here, but some
        # tests call load_backends multiple times. These should be fixed to
        # only call load_backends once.
        dependency.reset()

        # TODO(morganfainberg): Shouldn't need to clear the registry here, but
        # some tests call load_backends multiple times.  Since it is not
        # possible to re-configure a backend, we need to clear the list.  This
        # should eventually be removed once testing has been cleaned up.
        kvs_core.KEY_VALUE_STORE_REGISTRY.clear()

        self.clear_auth_plugin_registry()
        drivers = backends.load_backends()

        drivers.update(dependency.resolve_future_dependencies())

        for manager_name, manager in six.iteritems(drivers):
            setattr(self, manager_name, manager)
        self.addCleanup(self.cleanup_instance(*drivers.keys()))
 def for_test():
     Consumer()
     dependency.resolve_future_dependencies()
Пример #24
0
def get_application(configure=True):
    import os
    import sys
    import java.util
    from java.io import File
    from org.python.util import jython

    jar_location = (jython()
                    .getClass()
                    .getProtectionDomain()
                    .getCodeSource()
                    .getLocation()
                    .getPath())
    sys.executable = jar_location

    import pbr.version
    pbr.version.VersionInfo.version_string = lambda x: ''

    from keystone import backends
    from keystone import config
    from keystone.common import sql
    from oslo.db import options as db_options
    from keystone.common import dependency
    import logging
    from paste import deploy
    from java.lang import System

    logging.basicConfig()
    if configure:
        config.configure()
    CONF = config.CONF

    sql.initialize()

    prop_dir = System.getProperty("config_dir", "etc")

    if len(sys.argv) > 0:
        saved_argv = sys.argv
        sys.argv = [sys.argv[0]]

    config_file = ['{prop_dir}/keystone.conf'.format(prop_dir=prop_dir)]
    CONF(project='keystone', prog='keystone', default_config_files=config_file)

    name = 'main'
    name = 'admin'

    config.setup_logging()
    if CONF.debug:
        CONF.log_opt_values(logging.getLogger(CONF.prog), logging.DEBUG)
    elif CONF.verbose:
        CONF.log_opt_values(logging.getLogger(CONF.prog), logging.INFO)
    else:
        CONF.log_opt_values(logging.getLogger(CONF.prog), logging.WARNING)

    backends.load_backends()

    application = deploy.loadapp('config:{prop_dir}/keystone-paste.ini'.format(
        prop_dir=prop_dir), name=name, relative_to='.')

    dependency.resolve_future_dependencies()

    if len(sys.argv) > 0:
        sys.argv = saved_argv

    return application
Пример #25
0
from keystone.common import sql
from keystone import config
from keystone.openstack.common import log
from keystone import service


CONF = config.CONF

config.configure()
sql.initialize()
config.set_default_for_default_log_levels()

CONF(project='keystone')
config.setup_logging()

environment.use_stdlib()
name = os.path.basename(__file__)

if CONF.debug:
    CONF.log_opt_values(log.getLogger(CONF.prog), logging.DEBUG)


drivers = backends.load_backends()

# NOTE(ldbragst): 'application' is required in this context by WSGI spec.
# The following is a reference to Python Paste Deploy documentation
# http://pythonpaste.org/deploy/
application = service.loadapp('config:%s' % config.find_paste_config(), name)

dependency.resolve_future_dependencies()
Пример #26
0
 def for_test():
     Consumer()
     dependency.resolve_future_dependencies()