orig_elevated = self.context.elevated
- ctxt_deepcopy = self.context.deepcopy()
gthreads = []
def mock_elevated(*args, **kwargs):
# 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)
orig_elevated = self.context.elevated
- ctxt_deepcopy = self.context.deepcopy()
gthreads = []
def mock_elevated(*args, **kwargs):
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)
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):
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:
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
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 = {}
# 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,
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: