Merge "Consistency groups API is not returning project_id filter groups."

This commit is contained in:
Jenkins 2017-03-21 21:33:48 +00:00 committed by Gerrit Code Review
commit 223a10111c
3 changed files with 73 additions and 3 deletions

View File

@ -131,6 +131,10 @@ class ConsistencyGroupsController(wsgi.Controller):
"""Returns a list of consistency groups through view builder."""
context = req.environ['cinder.context']
filters = req.params.copy()
# make another copy of filters, since it is being modified in
# consistencygroup_api while getting consistencygroups
group_filters = req.params.copy()
marker, limit, offset = common.get_pagination_params(filters)
sort_keys, sort_dirs = common.get_sort_params(filters)
@ -139,7 +143,7 @@ class ConsistencyGroupsController(wsgi.Controller):
offset=offset, sort_keys=sort_keys, sort_dirs=sort_dirs)
groups = self.group_api.get_all(
context, filters=filters, marker=marker, limit=limit,
context, filters=group_filters, marker=marker, limit=limit,
offset=offset, sort_keys=sort_keys, sort_dirs=sort_dirs)
if is_detail:

View File

@ -54,6 +54,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
self,
ctxt=None,
name='test_consistencygroup',
user_id=fake.USER_ID,
project_id=fake.PROJECT_ID,
description='this is a test consistency group',
volume_type_id=fake.VOLUME_TYPE_ID,
availability_zone='az1',
@ -63,8 +65,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
"""Create a consistency group object."""
ctxt = ctxt or self.ctxt
consistencygroup = objects.ConsistencyGroup(ctxt)
consistencygroup.user_id = fake.USER_ID
consistencygroup.project_id = fake.PROJECT_ID
consistencygroup.user_id = user_id
consistencygroup.project_id = project_id
consistencygroup.availability_zone = availability_zone
consistencygroup.name = name
consistencygroup.description = description
@ -75,6 +77,33 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
consistencygroup.create()
return consistencygroup
def _create_group(
self,
ctxt=None,
name='test_group',
user_id=fake.USER_ID,
project_id=fake.PROJECT_ID,
description='this is a test group',
group_type_id=fake.VOLUME_TYPE_ID,
availability_zone='az1',
host='fakehost',
status=fields.GroupStatus.CREATING,
**kwargs):
"""Create a consistency group object."""
ctxt = ctxt or self.ctxt
group = objects.Group(ctxt)
group.user_id = user_id
group.project_id = project_id
group.availability_zone = availability_zone
group.name = name
group.description = description
group.group_type_id = group_type_id
group.host = host
group.status = status
group.update(kwargs)
group.create()
return group
def test_show_consistencygroup(self):
consistencygroup = self._create_consistencygroup()
req = webob.Request.blank('/v2/%s/consistencygroups/%s' %
@ -294,6 +323,37 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
consistencygroup2.destroy()
consistencygroup3.destroy()
@ddt.data(False, True)
def test_list_consistencygroups_with_project_id(self, is_detail):
consistencygroup1 = self._create_consistencygroup()
consistencygroup2 = self._create_consistencygroup(
name="group", project_id=fake.PROJECT2_ID)
group1 = self._create_group()
group2 = self._create_group(name="group", project_id=fake.PROJECT2_ID)
url = ('/v2/%s/consistencygroups?'
'all_tenants=True&project_id=%s') % (fake.PROJECT_ID,
fake.PROJECT2_ID)
if is_detail:
url = ('/v2/%s/consistencygroups/detail?'
'all_tenants=True&project_id=%s') % (fake.PROJECT_ID,
fake.PROJECT2_ID)
req = webob.Request.blank(url)
req.method = 'GET'
req.headers['Content-Type'] = 'application/json'
res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt))
res_dict = jsonutils.loads(res.body)
self.assertEqual(200, res.status_int)
self.assertEqual(2, len(res_dict['consistencygroups']))
self.assertEqual("group",
res_dict['consistencygroups'][0]['name'])
self.assertEqual("group",
res_dict['consistencygroups'][1]['name'])
consistencygroup1.destroy()
consistencygroup2.destroy()
group1.destroy()
group2.destroy()
@ddt.data(False, True)
def test_list_consistencygroups_with_sort(self, is_detail):
consistencygroup1 = self._create_consistencygroup()

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixed consistency groups API which was always returning groups
scoped to project ID from user context instead of given input
project ID.