Add support to regions for sort_dir and sort_keys
This also refactors how we add pagination related query parameters to each schema set of request args. Closes-Bug: 1667027 Change-Id: Iecb628f05de02d1a153b3b63ab6dd67c33c53053
This commit is contained in:
parent
f398eb8fc7
commit
1a4f4392c4
|
@ -761,6 +761,41 @@ DefinitionsPaginationLinks = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def add_pagination_args(resource, args,
|
||||||
|
minimum_page_size=10,
|
||||||
|
default_page_size=30,
|
||||||
|
maximum_page_size=100,
|
||||||
|
marker_type="integer"):
|
||||||
|
args.update({
|
||||||
|
"limit": {
|
||||||
|
"minimum": minimum_page_size,
|
||||||
|
"default": default_page_size,
|
||||||
|
"maximum": maximum_page_size,
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Number of {}s to return in a page".format(
|
||||||
|
resource,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
"marker": {
|
||||||
|
"type": marker_type,
|
||||||
|
"description": "Last {} ID of the previous page".format(
|
||||||
|
resource,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
"sort_dir": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["asc", "desc"],
|
||||||
|
"description": ("Direction to sort the {}s based on keys "
|
||||||
|
"specified to sort on.").format(resource),
|
||||||
|
},
|
||||||
|
"sort_keys": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Keys used to sort the {}s by.".format(resource),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
def paginated_resource(list_name, schema):
|
def paginated_resource(list_name, schema):
|
||||||
return {
|
return {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
@ -851,7 +886,7 @@ validators = {
|
||||||
("regions", "GET"): {
|
("regions", "GET"): {
|
||||||
"args": {
|
"args": {
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"properties": {
|
"properties": add_pagination_args("region", {
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "name of the region to get",
|
"description": "name of the region to get",
|
||||||
|
@ -864,18 +899,7 @@ validators = {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "ID of the region to get",
|
"description": "ID of the region to get",
|
||||||
},
|
},
|
||||||
"limit": {
|
}),
|
||||||
"minimum": 10,
|
|
||||||
"default": 30,
|
|
||||||
"maximum": 100,
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Number of regions to return in a page",
|
|
||||||
},
|
|
||||||
"marker": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Last region ID of the previous page",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
("regions", "POST"): {
|
("regions", "POST"): {
|
||||||
|
@ -887,7 +911,7 @@ validators = {
|
||||||
("hosts", "GET"): {
|
("hosts", "GET"): {
|
||||||
"args": {
|
"args": {
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"properties": {
|
"properties": add_pagination_args("host", {
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "name of the hosts to get",
|
"description": "name of the hosts to get",
|
||||||
|
@ -920,29 +944,7 @@ validators = {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "ID of host to get",
|
"description": "ID of host to get",
|
||||||
},
|
},
|
||||||
"limit": {
|
}),
|
||||||
"minimum": 10,
|
|
||||||
"default": 30,
|
|
||||||
"maximum": 100,
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Number of hosts to return in a page",
|
|
||||||
},
|
|
||||||
"marker": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Last host ID of the previous page",
|
|
||||||
},
|
|
||||||
"sort_dir": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["asc", "desc"],
|
|
||||||
"description": "Direction to sort the hosts based on keys "
|
|
||||||
"specified to sort on.",
|
|
||||||
},
|
|
||||||
"sort_keys": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Keys used to sort the hosts by.",
|
|
||||||
},
|
|
||||||
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
("cells_id", "DELETE"): {
|
("cells_id", "DELETE"): {
|
||||||
|
@ -969,7 +971,7 @@ validators = {
|
||||||
("cells", "GET"): {
|
("cells", "GET"): {
|
||||||
"args": {
|
"args": {
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"properties": {
|
"properties": add_pagination_args("cell", {
|
||||||
"region_id": {
|
"region_id": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "name of the region to get cells for",
|
"description": "name of the region to get cells for",
|
||||||
|
@ -986,28 +988,7 @@ validators = {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "name of the cell to get",
|
"description": "name of the cell to get",
|
||||||
},
|
},
|
||||||
"limit": {
|
}),
|
||||||
"minimum": 10,
|
|
||||||
"default": 30,
|
|
||||||
"maximum": 100,
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Number of cells to return in a page",
|
|
||||||
},
|
|
||||||
"marker": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Last cell ID of the previous page",
|
|
||||||
},
|
|
||||||
"sort_dir": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["asc", "desc"],
|
|
||||||
"description": "Direction to sort the cells based on keys "
|
|
||||||
"specified to sort on.",
|
|
||||||
},
|
|
||||||
"sort_keys": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Keys used to sort the cells by.",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
("regions_id", "DELETE"): {
|
("regions_id", "DELETE"): {
|
||||||
|
@ -1031,38 +1012,17 @@ validators = {
|
||||||
("projects", "GET"): {
|
("projects", "GET"): {
|
||||||
"args": {
|
"args": {
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"properties": {
|
"properties": add_pagination_args("project", {
|
||||||
"name": {
|
"name": {
|
||||||
"default": None,
|
"default": None,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "name of the project to get",
|
"description": "name of the project to get",
|
||||||
},
|
},
|
||||||
"limit": {
|
|
||||||
"minimum": 10,
|
|
||||||
"default": 30,
|
|
||||||
"maximum": 100,
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Number of projects to return in a page",
|
|
||||||
},
|
|
||||||
"marker": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Last project ID of the previous page",
|
|
||||||
},
|
|
||||||
"vars": {
|
"vars": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "variable filters to get a project",
|
"description": "variable filters to get a project",
|
||||||
},
|
},
|
||||||
"sort_dir": {
|
}, marker_type="string"),
|
||||||
"type": "string",
|
|
||||||
"enum": ["asc", "desc"],
|
|
||||||
"description": "Direction to sort the projects based on "
|
|
||||||
"keys specified to sort on.",
|
|
||||||
},
|
|
||||||
"sort_keys": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Keys used to sort the projects by.",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
("projects", "POST"): {
|
("projects", "POST"): {
|
||||||
|
@ -1076,7 +1036,7 @@ validators = {
|
||||||
("users", "GET"): {
|
("users", "GET"): {
|
||||||
"args": {
|
"args": {
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"properties": {
|
"properties": add_pagination_args("user", {
|
||||||
"id": {
|
"id": {
|
||||||
"default": None,
|
"default": None,
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
@ -1087,28 +1047,7 @@ validators = {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "name of the user to get",
|
"description": "name of the user to get",
|
||||||
},
|
},
|
||||||
"limit": {
|
}),
|
||||||
"minimum": 10,
|
|
||||||
"default": 30,
|
|
||||||
"maximum": 100,
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Number of users to return in a page",
|
|
||||||
},
|
|
||||||
"marker": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Last user ID of the previous page",
|
|
||||||
},
|
|
||||||
"sort_dir": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["asc", "desc"],
|
|
||||||
"description": "Direction to sort the users based on keys "
|
|
||||||
"specified to sort on.",
|
|
||||||
},
|
|
||||||
"sort_keys": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Keys used to sort the users by.",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
("users", "POST"): {
|
("users", "POST"): {
|
||||||
|
@ -1122,7 +1061,7 @@ validators = {
|
||||||
("network_devices", "GET"): {
|
("network_devices", "GET"): {
|
||||||
"args": {
|
"args": {
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"properties": {
|
"properties": add_pagination_args("network device", {
|
||||||
"id": {
|
"id": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "id of the net device to get",
|
"description": "id of the net device to get",
|
||||||
|
@ -1151,28 +1090,7 @@ validators = {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "cell id of the device to get",
|
"description": "cell id of the device to get",
|
||||||
},
|
},
|
||||||
"limit": {
|
}),
|
||||||
"minimum": 10,
|
|
||||||
"default": 30,
|
|
||||||
"maximum": 100,
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Number of devices to return in a page",
|
|
||||||
},
|
|
||||||
"marker": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Last device ID of the previous page",
|
|
||||||
},
|
|
||||||
"sort_dir": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["asc", "desc"],
|
|
||||||
"description": "Direction to sort the devices based on "
|
|
||||||
"keys specified to sort on.",
|
|
||||||
},
|
|
||||||
"sort_keys": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Keys used to sort the devices by.",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
("network_devices_id", "DELETE"): {
|
("network_devices_id", "DELETE"): {
|
||||||
|
@ -1268,7 +1186,7 @@ validators = {
|
||||||
("network_interfaces", "GET"): {
|
("network_interfaces", "GET"): {
|
||||||
"args": {
|
"args": {
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"properties": {
|
"properties": add_pagination_args("network interface", {
|
||||||
"id": {
|
"id": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "id of the net interface to get",
|
"description": "id of the net interface to get",
|
||||||
|
@ -1285,28 +1203,7 @@ validators = {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Type of the interface to get",
|
"description": "Type of the interface to get",
|
||||||
},
|
},
|
||||||
"limit": {
|
}),
|
||||||
"minimum": 10,
|
|
||||||
"default": 30,
|
|
||||||
"maximum": 100,
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Number of interfaces to return in a page",
|
|
||||||
},
|
|
||||||
"marker": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Last interface ID of the previous page",
|
|
||||||
},
|
|
||||||
"sort_dir": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["asc", "desc"],
|
|
||||||
"description": "Direction to sort the interfaces based on "
|
|
||||||
"keys specified to sort on.",
|
|
||||||
},
|
|
||||||
"sort_keys": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Keys used to sort the hosts by.",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
("network_interfaces", "POST"): {
|
("network_interfaces", "POST"): {
|
||||||
|
@ -1354,7 +1251,7 @@ validators = {
|
||||||
("networks", "GET"): {
|
("networks", "GET"): {
|
||||||
"args": {
|
"args": {
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"properties": {
|
"properties": add_pagination_args("network", {
|
||||||
"id": {
|
"id": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "id of the network to get",
|
"description": "id of the network to get",
|
||||||
|
@ -1379,28 +1276,7 @@ validators = {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "cell idof the network to get",
|
"description": "cell idof the network to get",
|
||||||
},
|
},
|
||||||
"limit": {
|
}),
|
||||||
"minimum": 10,
|
|
||||||
"default": 30,
|
|
||||||
"maximum": 100,
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Number of networks to return in a page",
|
|
||||||
},
|
|
||||||
"marker": {
|
|
||||||
"type": "integer",
|
|
||||||
"description": "Last network ID of the previous page",
|
|
||||||
},
|
|
||||||
"sort_dir": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["asc", "desc"],
|
|
||||||
"description": "Direction to sort the networks based on "
|
|
||||||
"keys specified to sort on.",
|
|
||||||
},
|
|
||||||
"sort_keys": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Keys used to sort the hosts by.",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
("networks", "POST"): {
|
("networks", "POST"): {
|
||||||
|
|
|
@ -164,3 +164,20 @@ class TestPagination(RegionTests):
|
||||||
parsed_prev = urllib.parse.urlparse(link_rel['href'])
|
parsed_prev = urllib.parse.urlparse(link_rel['href'])
|
||||||
self.assertIn('marker={}'.format(first_region['id']),
|
self.assertIn('marker={}'.format(first_region['id']),
|
||||||
parsed_prev.query)
|
parsed_prev.query)
|
||||||
|
|
||||||
|
def test_follow_all_region_links(self):
|
||||||
|
url = self.url + '/v1/regions'
|
||||||
|
response = self.get(url)
|
||||||
|
self.assertSuccessOk(response)
|
||||||
|
json = response.json()
|
||||||
|
regions = json['regions']
|
||||||
|
while regions:
|
||||||
|
for link in json['links']:
|
||||||
|
if link['rel'] == 'next':
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
response = self.get(link['href'])
|
||||||
|
self.assertSuccessOk(response)
|
||||||
|
json = response.json()
|
||||||
|
regions = json['regions']
|
||||||
|
|
Loading…
Reference in New Issue