Context: Remove logic for read_deleted and deprecate it
The read_deleted parameter in the Context object is simply unused. This patch removes associated logic, and for what is worth, adds deprecation warnings against explicit usage of read_deleted when creating a context instance, generate an admin context, and elevating a context instance. Change-Id: Ic69d22dc229ebe8fac1f6be0c4860d19732505b1 Closes-Bug: #1449462
This commit is contained in:
parent
185a761624
commit
6886655b49
|
@ -36,15 +36,12 @@ class ContextBase(oslo_context.RequestContext):
|
|||
|
||||
"""
|
||||
|
||||
def __init__(self, user_id, tenant_id, is_admin=None, read_deleted="no",
|
||||
roles=None, timestamp=None, request_id=None, tenant_name=None,
|
||||
@removals.removed_kwarg('read_deleted')
|
||||
def __init__(self, user_id, tenant_id, is_admin=None, roles=None,
|
||||
timestamp=None, request_id=None, tenant_name=None,
|
||||
user_name=None, overwrite=True, auth_token=None, **kwargs):
|
||||
"""Object initialization.
|
||||
|
||||
:param read_deleted: 'no' indicates deleted records are hidden, 'yes'
|
||||
indicates deleted records are visible, 'only' indicates that
|
||||
*only* deleted records are visible.
|
||||
|
||||
:param overwrite: Set to False to ensure that the greenthread local
|
||||
copy of the index is not overwritten.
|
||||
|
||||
|
@ -59,7 +56,6 @@ class ContextBase(oslo_context.RequestContext):
|
|||
self.user_name = user_name
|
||||
self.tenant_name = tenant_name
|
||||
|
||||
self.read_deleted = read_deleted
|
||||
if not timestamp:
|
||||
timestamp = datetime.datetime.utcnow()
|
||||
self.timestamp = timestamp
|
||||
|
@ -89,28 +85,12 @@ class ContextBase(oslo_context.RequestContext):
|
|||
def user_id(self, user_id):
|
||||
self.user = user_id
|
||||
|
||||
def _get_read_deleted(self):
|
||||
return self._read_deleted
|
||||
|
||||
def _set_read_deleted(self, read_deleted):
|
||||
if read_deleted not in ('no', 'yes', 'only'):
|
||||
raise ValueError(_("read_deleted can only be one of 'no', "
|
||||
"'yes' or 'only', not %r") % read_deleted)
|
||||
self._read_deleted = read_deleted
|
||||
|
||||
def _del_read_deleted(self):
|
||||
del self._read_deleted
|
||||
|
||||
read_deleted = property(_get_read_deleted, _set_read_deleted,
|
||||
_del_read_deleted)
|
||||
|
||||
def to_dict(self):
|
||||
context = super(ContextBase, self).to_dict()
|
||||
context.update({
|
||||
'user_id': self.user_id,
|
||||
'tenant_id': self.tenant_id,
|
||||
'project_id': self.project_id,
|
||||
'read_deleted': self.read_deleted,
|
||||
'roles': self.roles,
|
||||
'timestamp': str(self.timestamp),
|
||||
'tenant_name': self.tenant_name,
|
||||
|
@ -123,6 +103,7 @@ class ContextBase(oslo_context.RequestContext):
|
|||
def from_dict(cls, values):
|
||||
return cls(**values)
|
||||
|
||||
@removals.removed_kwarg('read_deleted')
|
||||
def elevated(self, read_deleted=None):
|
||||
"""Return a version of this context with admin flag set."""
|
||||
context = copy.copy(self)
|
||||
|
@ -131,9 +112,6 @@ class ContextBase(oslo_context.RequestContext):
|
|||
if 'admin' not in [x.lower() for x in context.roles]:
|
||||
context.roles = context.roles + ["admin"]
|
||||
|
||||
if read_deleted is not None:
|
||||
context.read_deleted = read_deleted
|
||||
|
||||
return context
|
||||
|
||||
|
||||
|
@ -145,17 +123,17 @@ class Context(ContextBase):
|
|||
return self._session
|
||||
|
||||
|
||||
@removals.removed_kwarg('read_deleted')
|
||||
@removals.removed_kwarg('load_admin_roles')
|
||||
def get_admin_context(read_deleted="no", load_admin_roles=True):
|
||||
return Context(user_id=None,
|
||||
tenant_id=None,
|
||||
is_admin=True,
|
||||
read_deleted=read_deleted,
|
||||
overwrite=False)
|
||||
|
||||
|
||||
@removals.removed_kwarg('read_deleted')
|
||||
def get_admin_context_without_session(read_deleted="no"):
|
||||
return ContextBase(user_id=None,
|
||||
tenant_id=None,
|
||||
is_admin=True,
|
||||
read_deleted=read_deleted)
|
||||
is_admin=True)
|
||||
|
|
|
@ -36,7 +36,6 @@ def get_admin_test_context(db_url):
|
|||
ctx = context.Context(user_id=None,
|
||||
tenant_id=None,
|
||||
is_admin=True,
|
||||
read_deleted="no",
|
||||
overwrite=False)
|
||||
facade = session.EngineFacade(db_url, mysql_sql_mode='STRICT_ALL_TABLES')
|
||||
ctx._session = facade.get_session(autocommit=False, expire_on_commit=True)
|
||||
|
|
|
@ -58,8 +58,7 @@ class PortBindingsTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase):
|
|||
def _get_non_admin_context(self):
|
||||
return context.Context(user_id=None,
|
||||
tenant_id=self._tenant_id,
|
||||
is_admin=False,
|
||||
read_deleted="no")
|
||||
is_admin=False)
|
||||
|
||||
def test_port_vif_details(self):
|
||||
with self.port(name='name') as port:
|
||||
|
@ -204,8 +203,7 @@ class PortBindingsHostTestCaseMixin(object):
|
|||
# By default user is admin - now test non admin user
|
||||
ctx = context.Context(user_id=None,
|
||||
tenant_id=self._tenant_id,
|
||||
is_admin=False,
|
||||
read_deleted="no")
|
||||
is_admin=False)
|
||||
non_admin_port = self._show(
|
||||
'ports', port_id, neutron_context=ctx)['port']
|
||||
self._check_response_no_portbindings_host(non_admin_port)
|
||||
|
@ -227,8 +225,7 @@ class PortBindingsHostTestCaseMixin(object):
|
|||
# By default user is admin - now test non admin user
|
||||
ctx = context.Context(user_id=None,
|
||||
tenant_id=self._tenant_id,
|
||||
is_admin=False,
|
||||
read_deleted="no")
|
||||
is_admin=False)
|
||||
ports = self._list('ports', neutron_context=ctx)['ports']
|
||||
self.assertEqual(2, len(ports))
|
||||
for non_admin_port in ports:
|
||||
|
@ -319,8 +316,7 @@ class PortBindingsVnicTestCaseMixin(object):
|
|||
# By default user is admin - now test non admin user
|
||||
ctx = context.Context(user_id=None,
|
||||
tenant_id=self._tenant_id,
|
||||
is_admin=False,
|
||||
read_deleted="no")
|
||||
is_admin=False)
|
||||
non_admin_port = self._show(
|
||||
'ports', port_id, neutron_context=ctx)['port']
|
||||
self._check_response_portbindings_vnic_type(non_admin_port)
|
||||
|
@ -342,8 +338,7 @@ class PortBindingsVnicTestCaseMixin(object):
|
|||
# By default user is admin - now test non admin user
|
||||
ctx = context.Context(user_id=None,
|
||||
tenant_id=self._tenant_id,
|
||||
is_admin=False,
|
||||
read_deleted="no")
|
||||
is_admin=False)
|
||||
ports = self._list('ports', neutron_context=ctx)['ports']
|
||||
self.assertEqual(2, len(ports))
|
||||
for non_admin_port in ports:
|
||||
|
|
Loading…
Reference in New Issue