]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Context cleanup
authorZhiteng Huang <zhithuang@ebaysf.com>
Fri, 21 Nov 2014 18:53:40 +0000 (02:53 +0800)
committerZhiteng Huang <zhithuang@ebaysf.com>
Mon, 24 Nov 2014 00:59:08 +0000 (08:59 +0800)
Before the fix of bug #1386932 (285cfaf0954d4c3e320b205c288240c1828476fe)
was committed, there are a few hacks in Cinder where an original copy
of (un-elevated) context has to be saved before doing
context.elevated().  Now that we have the fix in place, it's time to
clean up those old hacks.

Change-Id: Ie3e5cb7398647b4619d294c572e920e6c3b6b9c9
Related-bug: #1386392

cinder/tests/test_volume.py
cinder/volume/api.py
cinder/volume/manager.py

index 11e9c25e797d602e9d7b2d5e8d3cacdfbe646b82..a858668c2a488dd380090943944b67063e40d9f7 100644 (file)
@@ -1058,7 +1058,6 @@ class VolumeTestCase(BaseVolumeTestCase):
 
         orig_elevated = self.context.elevated
 
-        ctxt_deepcopy = self.context.deepcopy()
         gthreads = []
 
         def mock_elevated(*args, **kwargs):
@@ -1067,7 +1066,7 @@ class VolumeTestCase(BaseVolumeTestCase):
 
             # we expect this to block and then fail
             t = eventlet.spawn(self.volume.create_volume,
-                               ctxt_deepcopy,
+                               self.context,
                                volume_id=dst_vol_id, source_volid=src_vol_id)
             gthreads.append(t)
 
@@ -1107,7 +1106,6 @@ class VolumeTestCase(BaseVolumeTestCase):
 
         orig_elevated = self.context.elevated
 
-        ctxt_deepcopy = self.context.deepcopy()
         gthreads = []
 
         def mock_elevated(*args, **kwargs):
@@ -1115,7 +1113,7 @@ class VolumeTestCase(BaseVolumeTestCase):
             self.stubs.Set(self.context, 'elevated', orig_elevated)
 
             # We expect this to block and then fail
-            t = eventlet.spawn(self.volume.create_volume, ctxt_deepcopy,
+            t = eventlet.spawn(self.volume.create_volume, self.context,
                                volume_id=dst_vol_id, snapshot_id=snap_id)
             gthreads.append(t)
 
@@ -2586,26 +2584,6 @@ class VolumeTestCase(BaseVolumeTestCase):
 
         self.assertEqual(volumes_reserved, 100)
 
-    def test_create_volume_from_unelevated_context(self):
-        """Test context does't change after volume creation failure."""
-        def fake_create_volume(*args, **kwargs):
-            raise exception.CinderException('fake exception')
-
-        # create context for testing
-        ctxt = self.context.deepcopy()
-        if 'admin' in ctxt.roles:
-            ctxt.roles.remove('admin')
-            ctxt.is_admin = False
-        # create one copy of context for future comparison
-        self.saved_ctxt = ctxt.deepcopy()
-
-        self.stubs.Set(self.volume.driver, 'create_volume', fake_create_volume)
-
-        volume_src = tests_utils.create_volume(self.context,
-                                               **self.volume_params)
-        self.assertRaises(exception.CinderException,
-                          self.volume.create_volume, ctxt, volume_src['id'])
-
     @mock.patch(
         'cinder.volume.driver.VolumeDriver.create_replica_test_volume')
     def test_create_volume_from_sourcereplica(self, _create_replica_test):
index 0abf67eea0abd1fe1fd11eb403fff42c0c4ddf0c..1f2ab593cfdbe866688152d77a9ed069e2b245cd 100644 (file)
@@ -320,7 +320,6 @@ class API(base.Base):
         self.db.volume_update(context, volume['id'], fields)
 
     def get(self, context, volume_id, viewable_admin_meta=False):
-        old_ctxt = context.deepcopy()
         if viewable_admin_meta:
             ctxt = context.elevated()
         else:
@@ -328,7 +327,7 @@ class API(base.Base):
         rv = self.db.volume_get(ctxt, volume_id)
         volume = dict(rv.iteritems())
         try:
-            check_policy(old_ctxt, 'get', volume)
+            check_policy(context, 'get', volume)
         except exception.PolicyNotAuthorized:
             # raise VolumeNotFound instead to make sure Cinder behaves
             # as it used to
index b5a68b5b7ff69a07ac825502f17bc8c6c7e62cfb..a564ca1cd36b5a45712653a1cb3d4f125f113d53 100644 (file)
@@ -347,8 +347,7 @@ class VolumeManager(manager.SchedulerDependentManager):
                       source_replicaid=None, consistencygroup_id=None):
 
         """Creates the volume."""
-        context_saved = context.deepcopy()
-        context = context.elevated()
+        context_elevated = context.elevated()
         if filter_properties is None:
             filter_properties = {}
 
@@ -356,7 +355,7 @@ class VolumeManager(manager.SchedulerDependentManager):
             # NOTE(flaper87): Driver initialization is
             # verified by the task itself.
             flow_engine = create_volume.get_flow(
-                context,
+                context_elevated,
                 self.db,
                 self.driver,
                 self.scheduler_rpcapi,
@@ -368,7 +367,7 @@ class VolumeManager(manager.SchedulerDependentManager):
                 source_replicaid=source_replicaid,
                 consistencygroup_id=consistencygroup_id,
                 allow_reschedule=allow_reschedule,
-                reschedule_context=context_saved,
+                reschedule_context=context,
                 request_spec=request_spec,
                 filter_properties=filter_properties)
         except Exception: