예제 #1
0
def _get_impl():
    """Delay import of rpc_backend until configuration is loaded."""
    global _RPCIMPL
    if _RPCIMPL is None:
        try:
            _RPCIMPL = importutils.import_module(CONF.rpc_backend)
        except ImportError:
            # For backwards compatibility with older nova config.
            impl = CONF.rpc_backend.replace('nova.rpc',
                                            'nova.openstack.common.rpc')
            _RPCIMPL = importutils.import_module(impl)
    return _RPCIMPL
예제 #2
0
def _get_impl():
    """Delay import of rpc_backend until configuration is loaded."""
    global _RPCIMPL
    if _RPCIMPL is None:
        try:
            _RPCIMPL = importutils.import_module(CONF.rpc_backend)
        except ImportError:
            # For backwards compatibility with older nova config.
            impl = CONF.rpc_backend.replace('nova.rpc',
                                            'nova.openstack.common.rpc')
            _RPCIMPL = importutils.import_module(impl)
    return _RPCIMPL
예제 #3
0
파일: cli.py 프로젝트: beamdong/keystone
 def main():
     version = CONF.command.version
     extension = CONF.command.extension
     if not extension:
         abs_path = migration_helpers.find_migrate_repo()
     else:
         try:
             package_name = '.'.join((contrib.__name__, extension))
             package = importutils.import_module(package_name)
         except ImportError:
             raise ImportError(_("%s extension does not exist.")
                               % package_name)
         try:
             abs_path = migration_helpers.find_migrate_repo(package)
             try:
                 migration.db_version_control(abs_path)
             # Register the repo with the version control API
             # If it already knows about the repo, it will throw
             # an exception that we can safely ignore
             except exceptions.DatabaseAlreadyControlledError:
                 pass
         except exception.MigrationNotProvided as e:
             print(e)
             exit(0)
     migration.db_sync(abs_path, version=version)
예제 #4
0
 def setup_database(self):
     super(OAuth1Tests, self).setup_database()
     package_name = '.'.join((contrib.__name__, self.EXTENSION_NAME))
     package = importutils.import_module(package_name)
     abs_path = migration_helpers.find_migrate_repo(package)
     migration.db_version_control(sql.get_engine(), abs_path)
     migration.db_sync(sql.get_engine(), abs_path)
예제 #5
0
 def setup_database(self):
     super(OAuth1Tests, self).setup_database()
     package_name = "%s.%s.migrate_repo" % (contrib.__name__, self.EXTENSION_NAME)
     package = importutils.import_module(package_name)
     self.repo_path = os.path.abspath(os.path.dirname(package.__file__))
     migration.db_version_control(version=None, repo_path=self.repo_path)
     migration.db_sync(version=None, repo_path=self.repo_path)
예제 #6
0
 def setup_database(self):
     super(OAuth1Tests, self).setup_database()
     package_name = '.'.join((contrib.__name__, self.EXTENSION_NAME))
     package = importutils.import_module(package_name)
     abs_path = migration_helpers.find_migrate_repo(package)
     migration.db_version_control(abs_path)
     migration.db_sync(abs_path)
예제 #7
0
 def main():
     version = CONF.command.version
     extension = CONF.command.extension
     if not extension:
         abs_path = migration_helpers.find_migrate_repo()
     else:
         try:
             package_name = '.'.join((contrib.__name__, extension))
             package = importutils.import_module(package_name)
         except ImportError:
             raise ImportError(
                 _("%s extension does not exist.") % package_name)
         try:
             abs_path = migration_helpers.find_migrate_repo(package)
             try:
                 migration.db_version_control(abs_path)
             # Register the repo with the version control API
             # If it already knows about the repo, it will throw
             # an exception that we can safely ignore
             except exceptions.DatabaseAlreadyControlledError:
                 pass
         except exception.MigrationNotProvided as e:
             print(e)
             exit(0)
     migration.db_sync(abs_path, version=version)
예제 #8
0
 def setup_database(self):
     super(TestExtensionCase, self).setup_database()
     package_name = '.'.join((contrib.__name__, self.EXTENSION_NAME))
     package = importutils.import_module(package_name)
     abs_path = migration_helpers.find_migrate_repo(package)
     migration.db_version_control(abs_path)
     migration.db_sync(abs_path)
예제 #9
0
def sync_database_to_version(extension=None, version=None):
    if not extension:
        abs_path = find_migrate_repo()
        init_version = migrate_repo.DB_INIT_VERSION
    else:
        init_version = 0
        try:
            package_name = '.'.join((contrib.__name__, extension))
            package = importutils.import_module(package_name)
        except ImportError:
            raise ImportError(_("%s extension does not exist.")
                              % package_name)
        try:
            abs_path = find_migrate_repo(package)
            try:
                migration.db_version_control(sql.get_engine(), abs_path)
            # Register the repo with the version control API
            # If it already knows about the repo, it will throw
            # an exception that we can safely ignore
            except exceptions.DatabaseAlreadyControlledError:
                pass
        except exception.MigrationNotProvided as e:
            print(e)
            sys.exit(1)
    migration.db_sync(sql.get_engine(), abs_path, version=version,
                      init_version=init_version)
 def setup_database(self):
     super(TestExtensionCase, self).setup_database()
     package_name = '.'.join((contrib.__name__, self.EXTENSION_NAME))
     package = importutils.import_module(package_name)
     abs_path = migration_helpers.find_migrate_repo(package)
     migration.db_version_control(sql.get_engine(), abs_path)
     migration.db_sync(sql.get_engine(), abs_path)
예제 #11
0
 def _load_backend(self):
     with self._lock:
         if not self._backend:
             # Import the untranslated name if we don't have a mapping
             backend_path = self._backend_mapping.get(
                 self._backend_name, self._backend_name)
             backend_mod = importutils.import_module(backend_path)
             self._backend = backend_mod.get_backend()
예제 #12
0
파일: api.py 프로젝트: LiFengPro/keystone
 def _load_backend(self):
     with self._lock:
         if not self._backend:
             # Import the untranslated name if we don't have a mapping
             backend_path = self._backend_mapping.get(self._backend_name,
                                                      self._backend_name)
             backend_mod = importutils.import_module(backend_path)
             self._backend = backend_mod.get_backend()
 def setup_database(self):
     super(FederationTests, self).setup_database()
     package_name = "%s.%s.migrate_repo" % (contrib.__name__,
                                            self.EXTENSION_NAME)
     package = importutils.import_module(package_name)
     self.repo_path = os.path.abspath(os.path.dirname(package.__file__))
     migration.db_version_control(version=None, repo_path=self.repo_path)
     migration.db_sync(version=None, repo_path=self.repo_path)
예제 #14
0
 def __init__(self, backend_mapping=None):
     if backend_mapping is None:
         backend_mapping = {}
     backend_name = CONF.database.backend
     # Import the untranslated name if we don't have a
     # mapping.
     backend_path = backend_mapping.get(backend_name, backend_name)
     backend_mod = importutils.import_module(backend_path)
     self.__backend = backend_mod.get_backend()
예제 #15
0
 def setup_database(self):
     self.conf_files = super(TestExtensionCase, self).config_files()
     self.conf_files.append(
         tests.dirs.tests('test_associate_project_endpoint_extension.conf'))
     super(TestExtensionCase, self).setup_database()
     package_name = '.'.join((contrib.__name__, self.EXTENSION_NAME))
     package = importutils.import_module(package_name)
     migration.db_version_control(package=package)
     migration.db_sync(package=package)
 def setup_database(self):
     self.conf_files = super(TestExtensionCase, self).config_files()
     self.conf_files.append(
         tests.dirs.tests('test_associate_project_endpoint_extension.conf'))
     super(TestExtensionCase, self).setup_database()
     package_name = '.'.join((contrib.__name__, self.EXTENSION_NAME))
     package = importutils.import_module(package_name)
     abs_path = migration_helpers.find_migrate_repo(package)
     migration.db_version_control(abs_path)
     migration.db_sync(abs_path)
예제 #17
0
def _import_module(mod_str):
    try:
        if mod_str.startswith('bin.'):
            imp.load_source(mod_str[4:], os.path.join('bin', mod_str[4:]))
            return sys.modules[mod_str[4:]]
        else:
            return importutils.import_module(mod_str)
    except Exception as e:
        sys.stderr.write("Error importing module %s: %s\n" % (mod_str, str(e)))
        return None
예제 #18
0
def _import_module(mod_str):
    try:
        if mod_str.startswith('bin.'):
            imp.load_source(mod_str[4:], os.path.join('bin', mod_str[4:]))
            return sys.modules[mod_str[4:]]
        else:
            return importutils.import_module(mod_str)
    except Exception as e:
        sys.stderr.write("Error importing module %s: %s\n" % (mod_str, str(e)))
        return None
예제 #19
0
 def setup_database(self):
     self.conf_files = super(TestExtensionCase, self).config_files()
     self.conf_files.append(
         tests.dirs.tests('test_associate_project_endpoint_extension.conf'))
     super(TestExtensionCase, self).setup_database()
     package_name = "%s.%s.migrate_repo" % (contrib.__name__,
                                            self.EXTENSION_NAME)
     package = importutils.import_module(package_name)
     self.repo_path = os.path.abspath(os.path.dirname(package.__file__))
     migration.db_version_control(version=None, repo_path=self.repo_path)
     migration.db_sync(version=None, repo_path=self.repo_path)
 def setup_database(self):
     self.conf_files = super(TestExtensionCase, self).config_files()
     self.conf_files.append(
         tests.dirs.tests('test_associate_project_endpoint_extension.conf'))
     super(TestExtensionCase, self).setup_database()
     package_name = "%s.%s.migrate_repo" % (contrib.__name__,
                                            self.EXTENSION_NAME)
     package = importutils.import_module(package_name)
     self.repo_path = os.path.abspath(
         os.path.dirname(package.__file__))
     migration.db_version_control(version=None, repo_path=self.repo_path)
     migration.db_sync(version=None, repo_path=self.repo_path)
예제 #21
0
def get_db_version(extension=None):
    if not extension:
        return migration.db_version(sql.get_engine(), find_migrate_repo(), 0)

    try:
        package_name = '.'.join((contrib.__name__, extension))
        package = importutils.import_module(package_name)
    except ImportError:
        raise ImportError(_("%s extension does not exist.") % package_name)

    return migration.db_version(sql.get_engine(), find_migrate_repo(package),
                                0)
예제 #22
0
def get_db_version(extension=None):
    if not extension:
        return migration.db_version(sql.get_engine(), find_migrate_repo(), 0)

    try:
        package_name = '.'.join((contrib.__name__, extension))
        package = importutils.import_module(package_name)
    except ImportError:
        raise ImportError(_("%s extension does not exist.")
                          % package_name)

    return migration.db_version(
        sql.get_engine(), find_migrate_repo(package), 0)
예제 #23
0
파일: cli.py 프로젝트: ntt-sic/keystone
 def main():
     extension = CONF.command.extension
     if extension:
         try:
             package_name = "%s.%s.migrate_repo" % (contrib.__name__, extension)
             package = importutils.import_module(package_name)
             repo_path = os.path.abspath(os.path.dirname(package.__file__))
             print(migration.db_version(repo_path))
         except ImportError:
             print(_("This extension does not provide migrations."))
             exit(1)
     else:
         print(migration.db_version())
예제 #24
0
 def main():
     extension = CONF.command.extension
     if extension:
         try:
             package_name = ("%s.%s.migrate_repo" %
                             (contrib.__name__, extension))
             package = importutils.import_module(package_name)
             repo_path = os.path.abspath(os.path.dirname(package.__file__))
             print(migration.db_version(repo_path))
         except ImportError:
             print(_("This extension does not provide migrations."))
             exit(1)
     else:
         print(migration.db_version())
예제 #25
0
def _get_drivers():
    """Instantiate, cache, and return drivers based on the CONF."""
    global _drivers
    if _drivers is None:
        _drivers = {}
        for notification_driver in CONF.notification_driver:
            try:
                driver = importutils.import_module(notification_driver)
                _drivers[notification_driver] = driver
            except ImportError:
                LOG.exception(_("Failed to load notifier %s. "
                                "These notifications will not be sent.") %
                              notification_driver)
    return _drivers.values()
예제 #26
0
def _get_drivers():
    """Instantiate, cache, and return drivers based on the CONF."""
    global _drivers
    if _drivers is None:
        _drivers = {}
        for notification_driver in CONF.notification_driver:
            try:
                driver = importutils.import_module(notification_driver)
                _drivers[notification_driver] = driver
            except ImportError:
                LOG.exception(
                    _("Failed to load notifier %s. "
                      "These notifications will not be sent.") %
                    notification_driver)
    return _drivers.values()
예제 #27
0
def print_db_version(extension=None):
    if not extension:
        print(migration.db_version(find_migrate_repo(), 0))
    else:
        try:
            package_name = '.'.join((contrib.__name__, extension))
            package = importutils.import_module(package_name)
        except ImportError:
            raise ImportError(_("%s extension does not exist.")
                              % package_name)
        try:
            print(migration.db_version(
                find_migrate_repo(package), 0))
        except exception.MigrationNotProvided as e:
            print(e)
            sys.exit(1)
예제 #28
0
def sync_database_to_version(extension=None, version=None):
    if not extension:
        abs_path = find_migrate_repo()
        init_version = migrate_repo.DB_INIT_VERSION
    else:
        init_version = 0
        try:
            package_name = '.'.join((contrib.__name__, extension))
            package = importutils.import_module(package_name)
        except ImportError:
            raise ImportError(_("%s extension does not exist.")
                              % package_name)
        try:
            abs_path = find_migrate_repo(package)
            try:
                migration.db_version_control(sql.get_engine(), abs_path)
            # Register the repo with the version control API
            # If it already knows about the repo, it will throw
            # an exception that we can safely ignore
            except exceptions.DatabaseAlreadyControlledError:
                pass
        except exception.MigrationNotProvided as e:
            print(e)
            sys.exit(1)

    engine = sql.get_engine()
    try:
        migration.db_sync(engine, abs_path, version=version,
                          init_version=init_version)
    except ValueError:
        # NOTE(morganfainberg): ValueError is raised from the sanity check (
        # verifies that tables are utf8 under mysql). The region table was not
        # initially built with InnoDB and utf8 as part of the table arguments
        # when the migration was initially created. Bug #1334779 is a scenario
        # where the deployer can get wedged, unable to upgrade or downgrade.
        # This is a workaround to "fix" that table if we're under MySQL.
        if (not extension and engine.name == 'mysql' and
                six.text_type(get_db_version()) == '37'):
            _fix_migration_37(engine)
            # Try the migration a second time now that we've done the
            # un-wedge work.
            migration.db_sync(engine, abs_path, version=version,
                              init_version=init_version)
        else:
            raise
예제 #29
0
파일: cli.py 프로젝트: beamdong/keystone
 def main():
     extension = CONF.command.extension
     if extension:
         try:
             package_name = '.'.join((contrib.__name__, extension))
             package = importutils.import_module(package_name)
         except ImportError:
             raise ImportError(_("%s extension does not exist.")
                               % package_name)
         try:
             print(migration.db_version(
                 migration_helpers.find_migrate_repo(package), 0))
         except exception.MigrationNotProvided as e:
             print(e)
             exit(0)
     else:
         print(migration.db_version(
             migration_helpers.find_migrate_repo(), 0))
예제 #30
0
 def main():
     extension = CONF.command.extension
     if extension:
         try:
             package_name = '.'.join((contrib.__name__, extension))
             package = importutils.import_module(package_name)
         except ImportError:
             raise ImportError(
                 _("%s extension does not exist.") % package_name)
         try:
             print(
                 migration.db_version(
                     migration_helpers.find_migrate_repo(package), 0))
         except exception.MigrationNotProvided as e:
             print(e)
             exit(0)
     else:
         print(
             migration.db_version(migration_helpers.find_migrate_repo(), 0))
예제 #31
0
def deserialize_remote_exception(conf, data):
    failure = jsonutils.loads(str(data))

    trace = failure.get('tb', [])
    message = failure.get('message', "") + "\n" + "\n".join(trace)
    name = failure.get('class')
    module = failure.get('module')

    # NOTE(ameade): We DO NOT want to allow just any module to be imported, in
    # order to prevent arbitrary code execution.
    if module not in conf.allowed_rpc_exception_modules:
        return RemoteError(name, failure.get('message'), trace)

    try:
        mod = importutils.import_module(module)
        klass = getattr(mod, name)
        if not issubclass(klass, Exception):
            raise TypeError("Can only deserialize Exceptions")

        failure = klass(*failure.get('args', []), **failure.get('kwargs', {}))
    except (AttributeError, TypeError, ImportError):
        return RemoteError(name, failure.get('message'), trace)

    ex_type = type(failure)
    str_override = lambda self: message
    new_ex_type = type(ex_type.__name__ + _REMOTE_POSTFIX, (ex_type, ), {
        '__str__': str_override,
        '__unicode__': str_override
    })
    new_ex_type.__module__ = '%s%s' % (module, _REMOTE_POSTFIX)
    try:
        # NOTE(ameade): Dynamically create a new exception type and swap it in
        # as the new type for the exception. This only works on user defined
        # Exceptions and not core python exceptions. This is important because
        # we cannot necessarily change an exception message so we must override
        # the __str__ method.
        failure.__class__ = new_ex_type
    except TypeError:
        # NOTE(ameade): If a core exception then just add the traceback to the
        # first exception argument.
        failure.args = (message, ) + failure.args[1:]
    return failure
예제 #32
0
def deserialize_remote_exception(conf, data):
    failure = jsonutils.loads(str(data))

    trace = failure.get("tb", [])
    message = failure.get("message", "") + "\n" + "\n".join(trace)
    name = failure.get("class")
    module = failure.get("module")

    # NOTE(ameade): We DO NOT want to allow just any module to be imported, in
    # order to prevent arbitrary code execution.
    if module not in conf.allowed_rpc_exception_modules:
        return RemoteError(name, failure.get("message"), trace)

    try:
        mod = importutils.import_module(module)
        klass = getattr(mod, name)
        if not issubclass(klass, Exception):
            raise TypeError("Can only deserialize Exceptions")

        failure = klass(*failure.get("args", []), **failure.get("kwargs", {}))
    except (AttributeError, TypeError, ImportError):
        return RemoteError(name, failure.get("message"), trace)

    ex_type = type(failure)
    str_override = lambda self: message
    new_ex_type = type(
        ex_type.__name__ + _REMOTE_POSTFIX, (ex_type,), {"__str__": str_override, "__unicode__": str_override}
    )
    new_ex_type.__module__ = "%s%s" % (module, _REMOTE_POSTFIX)
    try:
        # NOTE(ameade): Dynamically create a new exception type and swap it in
        # as the new type for the exception. This only works on user defined
        # Exceptions and not core python exceptions. This is important because
        # we cannot necessarily change an exception message so we must override
        # the __str__ method.
        failure.__class__ = new_ex_type
    except TypeError:
        # NOTE(ameade): If a core exception then just add the traceback to the
        # first exception argument.
        failure.args = (message,) + failure.args[1:]
    return failure
예제 #33
0
 def main():
     version = CONF.command.version
     extension = CONF.command.extension
     if not extension:
         migration.db_sync(version=version)
     else:
         package_name = "%s.%s.migrate_repo" % (contrib.__name__, extension)
         try:
             package = importutils.import_module(package_name)
             repo_path = os.path.abspath(os.path.dirname(package.__file__))
         except ImportError:
             print(_("This extension does not provide migrations."))
             exit(0)
         try:
             # Register the repo with the version control API
             # If it already knows about the repo, it will throw
             # an exception that we can safely ignore
             migration.db_version_control(version=None, repo_path=repo_path)
         except exceptions.DatabaseAlreadyControlledError:
             pass
         migration.db_sync(version=None, repo_path=repo_path)
예제 #34
0
파일: cli.py 프로젝트: gabrielhao/keystone
 def main():
     version = CONF.command.version
     extension = CONF.command.extension
     if not extension:
         migration.db_sync(version=version)
     else:
         package_name = "%s.%s.migrate_repo" % (contrib.__name__, extension)
         try:
             package = importutils.import_module(package_name)
             repo_path = os.path.abspath(os.path.dirname(package.__file__))
         except ImportError:
             print(_("This extension does not provide migrations."))
             exit(0)
         try:
             # Register the repo with the version control API
             # If it already knows about the repo, it will throw
             # an exception that we can safely ignore
             migration.db_version_control(version=None, repo_path=repo_path)
         except exceptions.DatabaseAlreadyControlledError:
             pass
         migration.db_sync(version=None, repo_path=repo_path)
예제 #35
0
파일: api.py 프로젝트: aboumawada/keystone
 def __get_backend(self):
     """Get the actual backend.  May be a module or an instance of
     a class.  Doesn't matter to us.  We do this synchronized as it's
     possible multiple greenthreads started very quickly trying to do
     DB calls and eventlet can switch threads before self.__backend gets
     assigned.
     """
     if self.__backend:
         # Another thread assigned it
         return self.__backend
     backend_name = CONF.database.backend
     self.__use_tpool = CONF.database.use_tpool
     if self.__use_tpool:
         from eventlet import tpool
         self.__tpool = tpool
     # Import the untranslated name if we don't have a
     # mapping.
     backend_path = self.__backend_mapping.get(backend_name, backend_name)
     backend_mod = importutils.import_module(backend_path)
     self.__backend = backend_mod.get_backend()
     return self.__backend
예제 #36
0
 def __get_backend(self):
     """Get the actual backend.  May be a module or an instance of
     a class.  Doesn't matter to us.  We do this synchronized as it's
     possible multiple greenthreads started very quickly trying to do
     DB calls and eventlet can switch threads before self.__backend gets
     assigned.
     """
     if self.__backend:
         # Another thread assigned it
         return self.__backend
     backend_name = CONF.database.backend
     self.__use_tpool = CONF.database.use_tpool
     if self.__use_tpool:
         from eventlet import tpool
         self.__tpool = tpool
     # Import the untranslated name if we don't have a
     # mapping.
     backend_path = self.__backend_mapping.get(backend_name,
                                               backend_name)
     backend_mod = importutils.import_module(backend_path)
     self.__backend = backend_mod.get_backend()
     return self.__backend
예제 #37
0
 def __init__(self, hashtype='SHA256'):
     self.hashfn = importutils.import_module('Crypto.Hash.' + hashtype)
     self.max_okm_length = 255 * self.hashfn.digest_size
예제 #38
0
 def __init__(self, enctype='AES', hashtype='SHA256'):
     self.cipher = importutils.import_module('Crypto.Cipher.' + enctype)
     self.hashfn = importutils.import_module('Crypto.Hash.' + hashtype)
예제 #39
0
 def __init__(self, enctype="AES", hashtype="SHA256"):
     self.cipher = importutils.import_module("Crypto.Cipher." + enctype)
     self.hashfn = importutils.import_module("Crypto.Hash." + hashtype)
예제 #40
0
 def setup_database(self):
     super(FederationTests, self).setup_database()
     package_name = '.'.join((contrib.__name__, self.EXTENSION_NAME))
     package = importutils.import_module(package_name)
     migration.db_version_control(package=package)
     migration.db_sync(package=package)