neutron_lib.db.api module¶
- neutron_lib.db.api.exc_to_retry(etypes)¶
Contextually reraise Exceptions as a RetryRequests.
- Parameters:
etypes – The class type to check the exception for.
- Returns:
None
- Raises:
A RetryRequest if any exception is caught in the context is a nested instance of etypes.
- neutron_lib.db.api.get_context_manager()¶
Transaction Context Manager accessor.
- Returns:
The transaction context manager.
- neutron_lib.db.api.get_reader_session()¶
Helper to get reader session.
- Returns:
The reader session.
- neutron_lib.db.api.get_writer_session()¶
Helper to get writer session.
- Returns:
The writer session.
- neutron_lib.db.api.is_retriable(e)¶
Determine if the exception is retriable.
- Parameters:
e – The exception to check.
- Returns:
True if e is retriable and False otherwise.
- neutron_lib.db.api.is_session_active(session)¶
Return if the session is active
Since sqlalchemy 1.4, “autocommit=False” by default; in sqlalchemy 2.0, that will be the only possible value. If session autocommit is False, the session transaction will not end at the end of a reader/writer context. In this case, a session could have an active transaction even when it is not inside a reader/writer context. In order to mimic the previous behaviour, this method checks if there is a transaction created and if the transaction has any active connection against the database server.
- neutron_lib.db.api.retry_db_errors(f)¶
Nesting-safe retry decorator with auto-arg-copy and logging.
Retry decorator for all functions which do not accept a context as an argument. If the function accepts a context, use ‘retry_if_session_inactive’ below.
If retriable errors are retried and exceed the count, they will be tagged with a flag so is_retriable will no longer recognize them as retriable. This prevents multiple applications of this decorator (and/or the one below) from retrying the same exception.
- neutron_lib.db.api.retry_if_session_inactive(context_var_name='context')¶
Retries only if the session in the context is inactive.
Calls a retry_db_errors wrapped version of the function if the context’s session passed in is inactive, otherwise it just calls the function directly. This is useful to avoid retrying things inside of a transaction which is ineffective for DB races/errors.
This should be used in all cases where retries are desired and the method accepts a context.
- neutron_lib.db.api.sqla_listen(*args)¶
Wrapper to track subscribers for test teardowns.
SQLAlchemy has no “unsubscribe all” option for its event listener framework so we need to keep track of the subscribers by having them call through here for test teardowns.
- Parameters:
args – The arguments to pass onto the listen call.
- Returns:
None
- neutron_lib.db.api.sqla_remove(*args)¶
Remove SQLA listeners.
- Parameters:
args – The args to pass onto remove.
- Returns:
None.
- neutron_lib.db.api.sqla_remove_all()¶
Removes all SQLA listeners.
- Returns:
None.