Merge "Fix revert to snapshot for non admins"
This commit is contained in:
commit
ea745de6ca
@ -630,3 +630,38 @@ class SnapshotTestCase(base.BaseVolumeTestCase):
|
||||
snapshot.refresh()
|
||||
self.assertEqual(fields.SnapshotStatus.ERROR_DELETING,
|
||||
snapshot.status)
|
||||
|
||||
@ddt.data({'all_tenants': '1', 'name': 'snap1'},
|
||||
{'all_tenants': 'true', 'name': 'snap1'},
|
||||
{'all_tenants': 'false', 'name': 'snap1'},
|
||||
{'all_tenants': '0', 'name': 'snap1'},
|
||||
{'name': 'snap1'})
|
||||
@mock.patch.object(objects, 'SnapshotList')
|
||||
@mock.patch.object(context.RequestContext, 'authorize')
|
||||
def test_get_all_snapshots_non_admin(self, search_opts, auth_mock,
|
||||
snaplist_mock):
|
||||
ctxt = context.RequestContext(user_id=None, is_admin=False,
|
||||
project_id=mock.sentinel.project_id,
|
||||
read_deleted='no', overwrite=False)
|
||||
volume_api = cinder.volume.api.API()
|
||||
res = volume_api.get_all_snapshots(ctxt,
|
||||
search_opts,
|
||||
mock.sentinel.marker,
|
||||
mock.sentinel.limit,
|
||||
mock.sentinel.sort_keys,
|
||||
mock.sentinel.sort_dirs,
|
||||
mock.sentinel.offset)
|
||||
|
||||
auth_mock.assert_called_once_with(
|
||||
cinder.volume.api.snapshot_policy.GET_ALL_POLICY)
|
||||
snaplist_mock.get_all.assert_not_called()
|
||||
snaplist_mock.get_all_by_project.assert_called_once_with(
|
||||
ctxt,
|
||||
mock.sentinel.project_id,
|
||||
{'name': 'snap1'},
|
||||
mock.sentinel.marker,
|
||||
mock.sentinel.limit,
|
||||
mock.sentinel.sort_keys,
|
||||
mock.sentinel.sort_dirs,
|
||||
mock.sentinel.offset)
|
||||
self.assertEqual(snaplist_mock.get_all_by_project.return_value, res)
|
||||
|
@ -678,9 +678,10 @@ class API(base.Base):
|
||||
|
||||
search_opts = search_opts or {}
|
||||
|
||||
if context.is_admin and 'all_tenants' in search_opts:
|
||||
# Need to remove all_tenants to pass the filtering below.
|
||||
del search_opts['all_tenants']
|
||||
# Need to remove all_tenants to pass the filtering below.
|
||||
all_tenants = strutils.bool_from_string(search_opts.pop('all_tenants',
|
||||
'false'))
|
||||
if context.is_admin and all_tenants:
|
||||
snapshots = objects.SnapshotList.get_all(
|
||||
context, search_opts, marker, limit, sort_keys, sort_dirs,
|
||||
offset)
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fix revert to snapshot not working for non admin users when using the
|
||||
snapshot's name (bug #1889758).
|
Loading…
x
Reference in New Issue
Block a user