Merge "Add offset & limit docs & tests"
This commit is contained in:
@@ -29,6 +29,8 @@ Request
|
|||||||
.. rest_parameters:: parameters.yaml
|
.. rest_parameters:: parameters.yaml
|
||||||
|
|
||||||
- tenant_id: tenant_id
|
- tenant_id: tenant_id
|
||||||
|
- limit: limit_simple
|
||||||
|
- offset: offset_simple
|
||||||
|
|
||||||
.. TODO(cdent): How do we indicate optionality of a URI parameter?
|
.. TODO(cdent): How do we indicate optionality of a URI parameter?
|
||||||
|
|
||||||
@@ -80,6 +82,14 @@ Normal response codes: 200
|
|||||||
Error response codes: badRequest(400), unauthorized(401), forbidden(403),
|
Error response codes: badRequest(400), unauthorized(401), forbidden(403),
|
||||||
NotImplemented(501)
|
NotImplemented(501)
|
||||||
|
|
||||||
|
Request
|
||||||
|
-------
|
||||||
|
|
||||||
|
.. rest_parameters:: parameters.yaml
|
||||||
|
|
||||||
|
- limit: limit_simple
|
||||||
|
- offset: offset_simple
|
||||||
|
|
||||||
Response
|
Response
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@@ -28,6 +28,14 @@ Normal response codes: 200
|
|||||||
|
|
||||||
Error response codes: unauthorized(401), forbidden(403), itemNotFound(404)
|
Error response codes: unauthorized(401), forbidden(403), itemNotFound(404)
|
||||||
|
|
||||||
|
Request
|
||||||
|
-------
|
||||||
|
|
||||||
|
.. rest_parameters:: parameters.yaml
|
||||||
|
|
||||||
|
- limit: limit_simple
|
||||||
|
- offset: offset_simple
|
||||||
|
|
||||||
Response
|
Response
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@@ -35,6 +35,8 @@ Request
|
|||||||
|
|
||||||
|
|
||||||
- server_id: server_id_path
|
- server_id: server_id_path
|
||||||
|
- limit: limit_simple
|
||||||
|
- offset: offset_simple
|
||||||
|
|
||||||
Response
|
Response
|
||||||
--------
|
--------
|
||||||
|
@@ -25,6 +25,8 @@ Request
|
|||||||
.. rest_parameters:: parameters.yaml
|
.. rest_parameters:: parameters.yaml
|
||||||
|
|
||||||
- server_id: server_id_path
|
- server_id: server_id_path
|
||||||
|
- limit: limit_simple
|
||||||
|
- offset: offset_simple
|
||||||
|
|
||||||
Response
|
Response
|
||||||
--------
|
--------
|
||||||
|
@@ -26,6 +26,14 @@ Normal response codes: 200
|
|||||||
|
|
||||||
Error response codes: unauthorized(401), forbidden(403)
|
Error response codes: unauthorized(401), forbidden(403)
|
||||||
|
|
||||||
|
Request
|
||||||
|
-------
|
||||||
|
|
||||||
|
.. rest_parameters:: parameters.yaml
|
||||||
|
|
||||||
|
- limit: limit_simple
|
||||||
|
- offset: offset_simple
|
||||||
|
|
||||||
Response
|
Response
|
||||||
--------
|
--------
|
||||||
|
|
||||||
@@ -126,6 +134,14 @@ Normal response codes: 200
|
|||||||
|
|
||||||
Error response codes: unauthorized(401), forbidden(403)
|
Error response codes: unauthorized(401), forbidden(403)
|
||||||
|
|
||||||
|
Request
|
||||||
|
-------
|
||||||
|
|
||||||
|
.. rest_parameters:: parameters.yaml
|
||||||
|
|
||||||
|
- limit: limit_simple
|
||||||
|
- offset: offset_simple
|
||||||
|
|
||||||
Response
|
Response
|
||||||
--------
|
--------
|
||||||
|
|
||||||
@@ -237,6 +253,14 @@ Normal response codes: 200
|
|||||||
|
|
||||||
Error response codes: unauthorized(401), forbidden(403)
|
Error response codes: unauthorized(401), forbidden(403)
|
||||||
|
|
||||||
|
Request
|
||||||
|
-------
|
||||||
|
|
||||||
|
.. rest_parameters:: parameters.yaml
|
||||||
|
|
||||||
|
- limit: limit_simple
|
||||||
|
- offset: offset_simple
|
||||||
|
|
||||||
Response
|
Response
|
||||||
--------
|
--------
|
||||||
|
|
||||||
@@ -315,6 +339,14 @@ Normal response codes: 200
|
|||||||
|
|
||||||
Error response codes: unauthorized(401), forbidden(403)
|
Error response codes: unauthorized(401), forbidden(403)
|
||||||
|
|
||||||
|
Request
|
||||||
|
-------
|
||||||
|
|
||||||
|
.. rest_parameters:: parameters.yaml
|
||||||
|
|
||||||
|
- limit: limit_simple
|
||||||
|
- offset: offset_simple
|
||||||
|
|
||||||
Response
|
Response
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@@ -114,6 +114,16 @@ class CellsTestV21(BaseCellsTest):
|
|||||||
self.assertNotIn('capabilities', cell)
|
self.assertNotIn('capabilities', cell)
|
||||||
self.assertNotIn('password', cell)
|
self.assertNotIn('password', cell)
|
||||||
|
|
||||||
|
def test_index_offset_and_limit(self):
|
||||||
|
req = self._get_request('cells?offset=1&limit=1')
|
||||||
|
res_dict = self.controller.index(req)
|
||||||
|
|
||||||
|
self.assertEqual(len(res_dict['cells']), 1)
|
||||||
|
cell = res_dict['cells'][0]
|
||||||
|
self.assertEqual(cell['name'], self.fake_cells[1]['name'])
|
||||||
|
self.assertNotIn('capabilities', cell)
|
||||||
|
self.assertNotIn('password', cell)
|
||||||
|
|
||||||
def test_detail(self):
|
def test_detail(self):
|
||||||
req = self._get_request("cells/detail")
|
req = self._get_request("cells/detail")
|
||||||
res_dict = self.controller.detail(req)
|
res_dict = self.controller.detail(req)
|
||||||
@@ -124,6 +134,16 @@ class CellsTestV21(BaseCellsTest):
|
|||||||
self.assertEqual(cell['capabilities'], self.fake_capabilities[i])
|
self.assertEqual(cell['capabilities'], self.fake_capabilities[i])
|
||||||
self.assertNotIn('password', cell)
|
self.assertNotIn('password', cell)
|
||||||
|
|
||||||
|
def test_detail_offset_and_limit(self):
|
||||||
|
req = self._get_request("cells/detail?offset=1&limit=1")
|
||||||
|
res_dict = self.controller.detail(req)
|
||||||
|
|
||||||
|
self.assertEqual(len(res_dict['cells']), 1)
|
||||||
|
cell = res_dict['cells'][0]
|
||||||
|
self.assertEqual(cell['name'], self.fake_cells[1]['name'])
|
||||||
|
self.assertEqual(cell['capabilities'], self.fake_capabilities[1])
|
||||||
|
self.assertNotIn('password', cell)
|
||||||
|
|
||||||
def test_show_bogus_cell_raises(self):
|
def test_show_bogus_cell_raises(self):
|
||||||
req = self._get_request("cells/bogus")
|
req = self._get_request("cells/bogus")
|
||||||
self.assertRaises(exc.HTTPNotFound, self.controller.show, req, 'bogus')
|
self.assertRaises(exc.HTTPNotFound, self.controller.show, req, 'bogus')
|
||||||
|
@@ -140,6 +140,13 @@ class TestNeutronSecurityGroupsV21(
|
|||||||
list_dict = self.controller.index(req)
|
list_dict = self.controller.index(req)
|
||||||
self.assertEqual(len(list_dict['security_groups']), 2)
|
self.assertEqual(len(list_dict['security_groups']), 2)
|
||||||
|
|
||||||
|
def test_get_security_group_list_offset_and_limit(self):
|
||||||
|
path = '/v2/fake/os-security-groups?offset=1&limit=1'
|
||||||
|
self._create_sg_template().get('security_group')
|
||||||
|
req = fakes.HTTPRequest.blank(path)
|
||||||
|
list_dict = self.controller.index(req)
|
||||||
|
self.assertEqual(len(list_dict['security_groups']), 1)
|
||||||
|
|
||||||
def test_get_security_group_list_all_tenants(self):
|
def test_get_security_group_list_all_tenants(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@@ -321,6 +321,12 @@ class TestSecurityGroupsV21(test.TestCase):
|
|||||||
self.req, {'security_group': sg})
|
self.req, {'security_group': sg})
|
||||||
|
|
||||||
def test_get_security_group_list(self):
|
def test_get_security_group_list(self):
|
||||||
|
self._test_get_security_group_list()
|
||||||
|
|
||||||
|
def test_get_security_group_list_offset_and_limit(self):
|
||||||
|
self._test_get_security_group_list(limited=True)
|
||||||
|
|
||||||
|
def _test_get_security_group_list(self, limited=False):
|
||||||
groups = []
|
groups = []
|
||||||
for i, name in enumerate(['default', 'test']):
|
for i, name in enumerate(['default', 'test']):
|
||||||
sg = security_group_template(id=i + 1,
|
sg = security_group_template(id=i + 1,
|
||||||
@@ -328,7 +334,10 @@ class TestSecurityGroupsV21(test.TestCase):
|
|||||||
description=name + '-desc',
|
description=name + '-desc',
|
||||||
rules=[])
|
rules=[])
|
||||||
groups.append(sg)
|
groups.append(sg)
|
||||||
expected = {'security_groups': groups}
|
if limited:
|
||||||
|
expected = {'security_groups': [groups[1]]}
|
||||||
|
else:
|
||||||
|
expected = {'security_groups': groups}
|
||||||
|
|
||||||
def return_security_groups(context, project_id):
|
def return_security_groups(context, project_id):
|
||||||
return [security_group_db(sg) for sg in groups]
|
return [security_group_db(sg) for sg in groups]
|
||||||
@@ -336,7 +345,12 @@ class TestSecurityGroupsV21(test.TestCase):
|
|||||||
self.stub_out('nova.db.security_group_get_by_project',
|
self.stub_out('nova.db.security_group_get_by_project',
|
||||||
return_security_groups)
|
return_security_groups)
|
||||||
|
|
||||||
res_dict = self.controller.index(self.req)
|
path = '/v2/fake/os-security-groups'
|
||||||
|
if limited:
|
||||||
|
path += '?offset=1&limit=1'
|
||||||
|
req = fakes.HTTPRequest.blank(path, use_admin_context=True)
|
||||||
|
|
||||||
|
res_dict = self.controller.index(req)
|
||||||
|
|
||||||
self.assertEqual(res_dict, expected)
|
self.assertEqual(res_dict, expected)
|
||||||
|
|
||||||
|
@@ -161,12 +161,16 @@ class ServerGroupTestV21(test.TestCase):
|
|||||||
ig_uuid = self._create_instance_group(ctx, members)
|
ig_uuid = self._create_instance_group(ctx, members)
|
||||||
return (ig_uuid, instances, members)
|
return (ig_uuid, instances, members)
|
||||||
|
|
||||||
|
def _test_list_server_group_all(self, api_version='2.1'):
|
||||||
|
self._test_list_server_group(api_version=api_version, limited=False)
|
||||||
|
|
||||||
|
def _test_list_server_group_offset_and_limit(self, api_version='2.1'):
|
||||||
|
self._test_list_server_group(api_version=api_version, limited=True)
|
||||||
|
|
||||||
@mock.patch.object(nova.db, 'instance_group_get_all_by_project_id')
|
@mock.patch.object(nova.db, 'instance_group_get_all_by_project_id')
|
||||||
@mock.patch.object(nova.db, 'instance_group_get_all')
|
@mock.patch.object(nova.db, 'instance_group_get_all')
|
||||||
def _test_list_server_group_all(self,
|
def _test_list_server_group(self, mock_get_all, mock_get_by_project,
|
||||||
mock_get_all,
|
api_version='2.1', limited=False):
|
||||||
mock_get_by_project,
|
|
||||||
api_version='2.1'):
|
|
||||||
policies = ['anti-affinity']
|
policies = ['anti-affinity']
|
||||||
members = []
|
members = []
|
||||||
metadata = {} # always empty
|
metadata = {} # always empty
|
||||||
@@ -202,8 +206,12 @@ class ServerGroupTestV21(test.TestCase):
|
|||||||
tenant_groups = [sg2]
|
tenant_groups = [sg2]
|
||||||
all_groups = [sg1, sg2]
|
all_groups = [sg1, sg2]
|
||||||
|
|
||||||
all = {'server_groups': all_groups}
|
if limited:
|
||||||
tenant_specific = {'server_groups': tenant_groups}
|
all = {'server_groups': [sg2]}
|
||||||
|
tenant_specific = {'server_groups': []}
|
||||||
|
else:
|
||||||
|
all = {'server_groups': all_groups}
|
||||||
|
tenant_specific = {'server_groups': tenant_groups}
|
||||||
|
|
||||||
def return_all_server_groups():
|
def return_all_server_groups():
|
||||||
return [server_group_db(sg) for sg in all_groups]
|
return [server_group_db(sg) for sg in all_groups]
|
||||||
@@ -216,7 +224,8 @@ class ServerGroupTestV21(test.TestCase):
|
|||||||
mock_get_by_project.return_value = return_tenant_server_groups()
|
mock_get_by_project.return_value = return_tenant_server_groups()
|
||||||
|
|
||||||
path = '/os-server-groups?all_projects=True'
|
path = '/os-server-groups?all_projects=True'
|
||||||
|
if limited:
|
||||||
|
path += '&offset=1&limit=1'
|
||||||
req = fakes.HTTPRequest.blank(path, version=api_version)
|
req = fakes.HTTPRequest.blank(path, version=api_version)
|
||||||
admin_req = fakes.HTTPRequest.blank(path, use_admin_context=True,
|
admin_req = fakes.HTTPRequest.blank(path, use_admin_context=True,
|
||||||
version=api_version)
|
version=api_version)
|
||||||
@@ -454,6 +463,9 @@ class ServerGroupTestV21(test.TestCase):
|
|||||||
def test_list_server_group_all(self):
|
def test_list_server_group_all(self):
|
||||||
self._test_list_server_group_all(api_version='2.1')
|
self._test_list_server_group_all(api_version='2.1')
|
||||||
|
|
||||||
|
def test_list_server_group_offset_and_limit(self):
|
||||||
|
self._test_list_server_group_offset_and_limit(api_version='2.1')
|
||||||
|
|
||||||
def test_list_server_groups_rbac_default(self):
|
def test_list_server_groups_rbac_default(self):
|
||||||
# test as admin
|
# test as admin
|
||||||
self.controller.index(self.admin_req)
|
self.controller.index(self.admin_req)
|
||||||
@@ -550,5 +562,8 @@ class ServerGroupTestV213(ServerGroupTestV21):
|
|||||||
def test_list_server_group_all(self):
|
def test_list_server_group_all(self):
|
||||||
self._test_list_server_group_all(api_version='2.13')
|
self._test_list_server_group_all(api_version='2.13')
|
||||||
|
|
||||||
|
def test_list_server_group_offset_and_limit(self):
|
||||||
|
self._test_list_server_group_offset_and_limit(api_version='2.13')
|
||||||
|
|
||||||
def test_list_server_group_by_tenant(self):
|
def test_list_server_group_by_tenant(self):
|
||||||
self._test_list_server_group_by_tenant(api_version='2.13')
|
self._test_list_server_group_by_tenant(api_version='2.13')
|
||||||
|
@@ -114,12 +114,31 @@ class SnapshotApiTestV21(test.NoDBTestCase):
|
|||||||
resp_snapshot = resp_snapshots.pop()
|
resp_snapshot = resp_snapshots.pop()
|
||||||
self.assertEqual(102, resp_snapshot['id'])
|
self.assertEqual(102, resp_snapshot['id'])
|
||||||
|
|
||||||
|
def test_snapshot_detail_offset_and_limit(self):
|
||||||
|
path = '/v2/fake/os-snapshots/detail?offset=1&limit=1'
|
||||||
|
req = fakes.HTTPRequest.blank(path)
|
||||||
|
resp_dict = self.controller.detail(req)
|
||||||
|
self.assertIn('snapshots', resp_dict)
|
||||||
|
resp_snapshots = resp_dict['snapshots']
|
||||||
|
self.assertEqual(1, len(resp_snapshots))
|
||||||
|
|
||||||
|
resp_snapshot = resp_snapshots.pop()
|
||||||
|
self.assertEqual(101, resp_snapshot['id'])
|
||||||
|
|
||||||
def test_snapshot_index(self):
|
def test_snapshot_index(self):
|
||||||
resp_dict = self.controller.index(self.req)
|
resp_dict = self.controller.index(self.req)
|
||||||
self.assertIn('snapshots', resp_dict)
|
self.assertIn('snapshots', resp_dict)
|
||||||
resp_snapshots = resp_dict['snapshots']
|
resp_snapshots = resp_dict['snapshots']
|
||||||
self.assertEqual(3, len(resp_snapshots))
|
self.assertEqual(3, len(resp_snapshots))
|
||||||
|
|
||||||
|
def test_snapshot_index_offset_and_limit(self):
|
||||||
|
path = '/v2/fake/os-snapshots?offset=1&limit=1'
|
||||||
|
req = fakes.HTTPRequest.blank(path)
|
||||||
|
resp_dict = self.controller.index(req)
|
||||||
|
self.assertIn('snapshots', resp_dict)
|
||||||
|
resp_snapshots = resp_dict['snapshots']
|
||||||
|
self.assertEqual(1, len(resp_snapshots))
|
||||||
|
|
||||||
|
|
||||||
class TestSnapshotAPIDeprecation(test.NoDBTestCase):
|
class TestSnapshotAPIDeprecation(test.NoDBTestCase):
|
||||||
|
|
||||||
|
@@ -89,6 +89,14 @@ class ServerVirtualInterfaceTestV21(test.NoDBTestCase):
|
|||||||
res_dict = self.controller.index(req, 'fake_uuid')
|
res_dict = self.controller.index(req, 'fake_uuid')
|
||||||
self.assertEqual(self.expected_response, res_dict)
|
self.assertEqual(self.expected_response, res_dict)
|
||||||
|
|
||||||
|
def test_get_virtual_interfaces_list_offset_and_limit(self):
|
||||||
|
path = '/v2/fake/os-virtual-interfaces?offset=1&limit=1'
|
||||||
|
req = fakes.HTTPRequest.blank(path, version=self.wsgi_api_version)
|
||||||
|
res_dict = self.controller.index(req, 'fake_uuid')
|
||||||
|
name = 'virtual_interfaces'
|
||||||
|
limited_response = {name: [self.expected_response[name][1]]}
|
||||||
|
self.assertEqual(limited_response, res_dict)
|
||||||
|
|
||||||
def test_vif_instance_not_found(self):
|
def test_vif_instance_not_found(self):
|
||||||
self.mox.StubOutWithMock(compute_api.API, 'get')
|
self.mox.StubOutWithMock(compute_api.API, 'get')
|
||||||
fake_context = context.RequestContext('fake', 'fake')
|
fake_context = context.RequestContext('fake', 'fake')
|
||||||
|
Reference in New Issue
Block a user