The oslo_db.sqlalchemy.provision Module

The oslo_db.sqlalchemy.provision Module

Provision test environment for specific DB backends

class oslo_db.sqlalchemy.provision.Backend(database_type, url)

Bases: object

Represent a particular database backend that may be provisionable.

The Backend object maintains a database type (e.g. database without specific driver type, such as “sqlite”, “postgresql”, etc.), a target URL, a base Engine for that URL object that can be used to provision databases and a BackendImpl which knows how to perform operations against this type of Engine.

classmethod all_viable_backends()

Return an iterator of all Backend objects that are present

and provisionable.

classmethod backend_for_database_type(database_type)

Return the Backend for the given database type.

backends_by_database_type = {'postgresql': <oslo_db.sqlalchemy.provision.Backend object>, 'sqlite': <oslo_db.sqlalchemy.provision.Backend object>, 'mysql': <oslo_db.sqlalchemy.provision.Backend object>}
create_named_database(ident, conditional=False)

Create a database with the given name.

database_exists(ident)

Return True if a database of the given name exists.

drop_all_objects(engine)

Drop all database objects.

Drops all database objects remaining on the default schema of the given engine.

drop_named_database(ident, conditional=False)

Drop a database with the given name.

provisioned_database_url(ident)

Given the identifier of an anoymous database, return a URL.

For hostname-based URLs, this typically involves switching just the ‘database’ portion of the URL with the given name and creating a URL.

For SQLite URLs, the identifier may be used to create a filename or may be ignored in the case of a memory database.

provisioned_engine(ident)

Given the URL of a particular database backend and the string

name of a particular ‘database’ within that backend, return an Engine instance whose connections will refer directly to the named database.

class oslo_db.sqlalchemy.provision.BackendImpl(drivername)

Bases: object

Provide database-specific implementations of key provisioning

functions.

BackendImpl is owned by a Backend instance which delegates to it for all database-specific features.

classmethod all_impls()

Return an iterator of all possible BackendImpl objects.

These are BackendImpls that are implemented, but not necessarily provisionable.

create_named_database(engine, ident, conditional=False)

Create a database with the given name.

create_opportunistic_driver_url()

Produce a string url known as the ‘opportunistic’ URL.

This URL is one that corresponds to an established OpenStack convention for a pre-established database login, which, when detected as available in the local environment, is automatically used as a test platform for a specific type of driver.

default_engine_kwargs = {}
dispose(engine)
drop_additional_objects(conn)
drop_all_objects(engine)

Drop all database objects.

Drops all database objects remaining on the default schema of the given engine.

Per-db implementations will also need to drop items specific to those systems, such as sequences, custom types (e.g. pg ENUM), etc.

drop_named_database(engine, ident, conditional=False)

Drop a database with the given name.

impl = <oslo_db.sqlalchemy.utils.DialectSingleFunctionDispatcher object>
provisioned_database_url(base_url, ident)

Return a provisioned database URL.

Given the URL of a particular database backend and the string name of a particular ‘database’ within that backend, return an URL which refers directly to the named database.

For hostname-based URLs, this typically involves switching just the ‘database’ portion of the URL with the given name and creating an engine.

For URLs that instead deal with DSNs, the rules may be more custom; for example, the engine may need to connect to the root URL and then emit a command to switch to the named database.

provisioned_engine(base_url, ident)

Return a provisioned engine.

Given the URL of a particular database backend and the string name of a particular ‘database’ within that backend, return an Engine instance whose connections will refer directly to the named database.

For hostname-based URLs, this typically involves switching just the ‘database’ portion of the URL with the given name and creating an engine.

For URLs that instead deal with DSNs, the rules may be more custom; for example, the engine may need to connect to the root URL and then emit a command to switch to the named database.

supports_drop_fk = True
class oslo_db.sqlalchemy.provision.BackendResource(database_type, ad_hoc_url=None)

Bases: testresources.TestResourceManager

clean(resource)
isDirty()
make(dependency_resources)
class oslo_db.sqlalchemy.provision.DatabaseResource(database_type, _enginefacade=None, provision_new_database=True, ad_hoc_url=None)

Bases: testresources.TestResourceManager

Database resource which connects and disconnects to a URL.

For SQLite, this means the database is created implicitly, as a result of SQLite’s usual behavior. If the database is a file-based URL, it will remain after the resource has been torn down.

For all other kinds of databases, the resource indicates to connect and disconnect from that database.

clean(resource)
isDirty()
make(dependency_resources)
class oslo_db.sqlalchemy.provision.ProvisionedDatabase(backend, enginefacade, engine, db_token)

Bases: object

Represents a database engine pointing to a DB ready to run tests.

backend: an instance of Backend

enginefacade: an instance of _TransactionFactory

engine: a SQLAlchemy Engine

db_token: if provision_new_database were used, this is the randomly
generated name of the database. Note that with SQLite memory connections, this token is ignored. For a database that wasn’t actually created, will be None.
backend
db_token
engine
enginefacade
class oslo_db.sqlalchemy.provision.Schema

Bases: object

“Represents a database schema that has or will be populated.

This is a marker object as required by testresources but otherwise serves no purpose.

database
class oslo_db.sqlalchemy.provision.SchemaResource(database_resource, generate_schema, teardown=False)

Bases: testresources.TestResourceManager

clean(resource)
isDirty()
make(dependency_resources)
class oslo_db.sqlalchemy.provision.TransactionResource(*args, **kwargs)

Bases: testresources.TestResourceManager

clean(resource)
isDirty()
make(dependency_resources)
Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.