]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Context: Remove logic for read_deleted and deprecate it
authorSalvatore Orlando <salv.orlando@gmail.com>
Tue, 28 Apr 2015 11:59:35 +0000 (04:59 -0700)
committerSalvatore Orlando <salv.orlando@gmail.com>
Tue, 9 Jun 2015 20:50:03 +0000 (13:50 -0700)
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

neutron/context.py
neutron/tests/functional/db/test_ipam.py
neutron/tests/unit/_test_extension_portbindings.py

index ee6ca8ed7d4f166a049f21be87d15d1de522841c..3debe4ccd90df44619cc19476fb7db1e06037005 100644 (file)
@@ -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)
index 3c3a9d163a4e26022f3d652736eacd40311fbe3f..c30b72b5579e24fdb0dc62fa7e3983de7f5549c8 100644 (file)
@@ -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)
index b3d82abcca7ab9a076437623f76a77c353c3f9ce..42840d410f5a62575816a98f111e2df319f73438 100644 (file)
@@ -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: