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
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)
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)
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)
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)
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)
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)
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)
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 _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)
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()
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)
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
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)
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)
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)
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())
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())
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()
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()
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)
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
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))
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))
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
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
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)
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
def __init__(self, hashtype='SHA256'): self.hashfn = importutils.import_module('Crypto.Hash.' + hashtype) self.max_okm_length = 255 * self.hashfn.digest_size
def __init__(self, enctype='AES', hashtype='SHA256'): self.cipher = importutils.import_module('Crypto.Cipher.' + enctype) self.hashfn = importutils.import_module('Crypto.Hash.' + hashtype)
def __init__(self, enctype="AES", hashtype="SHA256"): self.cipher = importutils.import_module("Crypto.Cipher." + enctype) self.hashfn = importutils.import_module("Crypto.Hash." + hashtype)
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)