# under the License.
import contextlib
+import six
from oslo_config import cfg
+from oslo_db import exception as os_db_exception
from oslo_db.sqlalchemy import session
from sqlalchemy import exc
+from sqlalchemy import orm
_FACADE = None
finally:
with session_context as tx:
yield tx
+
+
+class convert_db_exception_to_retry(object):
+ """Converts other types of DB exceptions into RetryRequests."""
+
+ def __init__(self, stale_data=False):
+ self.to_catch = ()
+ if stale_data:
+ self.to_catch += (orm.exc.StaleDataError, )
+
+ def __call__(self, f):
+ @six.wraps(f)
+ def wrapper(*args, **kwargs):
+ try:
+ return f(*args, **kwargs)
+ except self.to_catch as e:
+ raise os_db_exception.RetryRequest(e)
+ return wrapper
return self._bind_port_if_needed(port_context)
@oslo_db_api.wrap_db_retry(max_retries=db_api.MAX_RETRIES,
- retry_on_deadlock=True)
+ retry_on_deadlock=True,
+ retry_on_request=True)
+ @db_api.convert_db_exception_to_retry(stale_data=True)
def update_port_status(self, context, port_id, status, host=None,
network=None):
"""