Remove warning about session with and without enginefacade

Now we moved all code to the new enginefacade so we don't need this
check anymore.
And BTW. I think it wasn't working properly as even if we are using new
facade we still see plenty of those warnings in e.g. logs of the
neutron functional tests CI job.

Partially-Implements blueprint: enginefacade-switch

Change-Id: Ib2933e4f52e8d7585c13a0d1a3485389fa37b432
This commit is contained in:
Slawek Kaplonski 2021-03-10 12:56:49 +01:00 committed by Rodolfo Alonso
parent 8cfd261349
commit a05778013c
3 changed files with 10 additions and 17 deletions

View File

@ -15,7 +15,6 @@
import collections
import copy
import datetime
import warnings
from oslo_config import cfg
from oslo_context import context as oslo_context
@ -148,18 +147,17 @@ class Context(ContextBaseWithSession):
@property
def session(self):
# TODO(akamyshnikova): checking for session attribute won't be needed
# when reader and writer will be used
# TODO(ralonsoh): "Context.session" is provided by
# "enginefacade.transaction_context_provider" when a new transaction,
# READER or WRITER, is created. This property is just a temporary fix
# for those transactions that are not executed inside a transaction.
# By manually selecting the type of transaction we can speed up the
# code because by default a writer session is always created, even
# within read only operations.
if hasattr(super(), 'session'):
if self._session:
warnings.warn('context.session is used with and without '
'new enginefacade. Please update the code to '
'use new enginefacede consistently.',
DeprecationWarning)
return super().session
self._session = super().session
if self._session is None:
self._session = db_api.get_writer_session()
return self._session
def set_transaction_constraint(self, resource, resource_id, rev_number):

View File

@ -213,7 +213,8 @@ def retry_if_session_inactive(context_var_name='context'):
context = kwargs.get(context_var_name)
if context is None:
context = args[ctx_arg_index]
method = f if context.session.is_active else f_with_retry
method = (f if (context.session and context.session.is_active)
else f_with_retry)
return method(*args, **kwargs)
return wrapped
return decorator

View File

@ -214,12 +214,6 @@ class TestNeutronContext(_base.BaseTestCase):
self.assertDictSupersetOf(values, policy_values)
self.assertDictSupersetOf(additional_values, policy_values)
@mock.patch.object(context.ContextBaseWithSession, 'session')
def test_superclass_session(self, mocked_session):
ctx = context.Context('user_id', 'tenant_id')
# make sure context uses parent class session that is mocked
self.assertEqual(mocked_session, ctx.session)
def test_session_cached(self):
ctx = context.Context('user_id', 'tenant_id')
session1 = ctx.session