Merge "Fix host and cluster_name filter for snapshot list"
This commit is contained in:
commit
d0649c40b0
@ -3130,7 +3130,8 @@ def snapshot_get_all_by_project(context, project_id, filters=None, marker=None,
|
|||||||
paired with corresponding item in sort_keys
|
paired with corresponding item in sort_keys
|
||||||
:returns: list of matching snapshots
|
:returns: list of matching snapshots
|
||||||
"""
|
"""
|
||||||
if filters and not is_valid_model_filters(models.Snapshot, filters):
|
if filters and not is_valid_model_filters(
|
||||||
|
models.Snapshot, filters, exclude_list=('host', 'cluster_name')):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
authorize_project_context(context, project_id)
|
authorize_project_context(context, project_id)
|
||||||
|
@ -27,6 +27,7 @@ from cinder.tests.unit.api import fakes
|
|||||||
from cinder.tests.unit import fake_constants as fake
|
from cinder.tests.unit import fake_constants as fake
|
||||||
from cinder.tests.unit import fake_snapshot
|
from cinder.tests.unit import fake_snapshot
|
||||||
from cinder.tests.unit import fake_volume
|
from cinder.tests.unit import fake_volume
|
||||||
|
from cinder.tests.unit import utils as test_utils
|
||||||
from cinder import volume
|
from cinder import volume
|
||||||
|
|
||||||
UUID = '00000000-0000-0000-0000-000000000001'
|
UUID = '00000000-0000-0000-0000-000000000001'
|
||||||
@ -125,6 +126,23 @@ class SnapshotApiTest(test.TestCase):
|
|||||||
body = {"snapshot": snap}
|
body = {"snapshot": snap}
|
||||||
self.controller.create(req, body)
|
self.controller.create(req, body)
|
||||||
|
|
||||||
|
@ddt.data(('host', 'test_host1'), ('cluster_name', 'cluster1'))
|
||||||
|
@ddt.unpack
|
||||||
|
def test_snapshot_list_with_filter(self, filter_name, filter_value):
|
||||||
|
volume1 = test_utils.create_volume(self.ctx, host='test_host1',
|
||||||
|
cluster_name='cluster1')
|
||||||
|
volume2 = test_utils.create_volume(self.ctx, host='test_host2',
|
||||||
|
cluster_name='cluster2')
|
||||||
|
snapshot1 = test_utils.create_snapshot(self.ctx, volume1.id)
|
||||||
|
snapshot2 = test_utils.create_snapshot(self.ctx, volume2.id) # noqa
|
||||||
|
|
||||||
|
url = '/v3/snapshots?%s=%s' % (filter_name, filter_value)
|
||||||
|
req = fakes.HTTPRequest.blank(url, use_admin_context=True)
|
||||||
|
res_dict = self.controller.detail(req)
|
||||||
|
|
||||||
|
self.assertEqual(1, len(res_dict['snapshots']))
|
||||||
|
self.assertEqual(snapshot1.id, res_dict['snapshots'][0]['id'])
|
||||||
|
|
||||||
def test_snapshot_list_with_sort_name(self):
|
def test_snapshot_list_with_sort_name(self):
|
||||||
self._create_snapshot(name='test1')
|
self._create_snapshot(name='test1')
|
||||||
self._create_snapshot(name='test2')
|
self._create_snapshot(name='test2')
|
||||||
|
@ -70,6 +70,7 @@ def create_volume(ctxt,
|
|||||||
testcase_instance=None,
|
testcase_instance=None,
|
||||||
id=None,
|
id=None,
|
||||||
metadata=None,
|
metadata=None,
|
||||||
|
cluster_name=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""Create a volume object in the DB."""
|
"""Create a volume object in the DB."""
|
||||||
vol = {}
|
vol = {}
|
||||||
@ -102,6 +103,8 @@ def create_volume(ctxt,
|
|||||||
vol['replication_driver_data'] = replication_driver_data
|
vol['replication_driver_data'] = replication_driver_data
|
||||||
if previous_status:
|
if previous_status:
|
||||||
vol['previous_status'] = previous_status
|
vol['previous_status'] = previous_status
|
||||||
|
if cluster_name:
|
||||||
|
vol['cluster_name'] = cluster_name
|
||||||
|
|
||||||
if id:
|
if id:
|
||||||
with mock.patch('cinder.objects.Volume.obj_attr_is_set',
|
with mock.patch('cinder.objects.Volume.obj_attr_is_set',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user