Add pagging and sorting support for "network_ip_availability"

Added pagging and sorting support for the extension
"network_ip_availability".

Closes-Bug: #1940518

Change-Id: Ic520ceb060c4a914d72ef66f58eeaa667382c53b
This commit is contained in:
Rodolfo Alonso Hernandez 2021-08-27 11:03:54 +00:00 committed by Slawek Kaplonski
parent dd46eb69fc
commit 82f72896db
4 changed files with 37 additions and 3 deletions

View File

@ -50,7 +50,7 @@ msgpack-python==0.4.0
munch==2.1.0
netaddr==0.7.18
netifaces==0.10.4
neutron-lib==2.13.0
neutron-lib==2.15.0
openstacksdk==0.31.2
os-client-config==1.28.0
os-ken==2.0.0

View File

@ -34,7 +34,10 @@ class Network_ip_availability(api_extensions.APIExtensionDescriptor):
apidef.RESOURCE_PLURAL,
apidef.RESOURCE_NAME,
plugin.NetworkIPAvailabilityPlugin.get_instance(),
resource_attributes)
resource_attributes,
allow_pagination=True,
allow_sorting=True,
)
return [extensions.ResourceExtension(apidef.COLLECTION_NAME,
controller,
attr_map=resource_attributes)]

View File

@ -407,3 +407,34 @@ class TestNetworkIPAvailabilityAPI(
avails_list, net_v6_2, 2, cidr_ipv6_net.size - 1)
self._validate_from_availabilities(
avails_list, net_v4_2, 2, 253)
def test_usages_query_limit(self):
with self.network() as net1, self.network() as net2, \
self.network() as net3, self.network() as net4:
networks = (net1, net2, net3, net4)
for idx in range(1, len(networks) + 1):
params = 'limit=%s' % idx
request = self.new_list_request(API_RESOURCE, params=params)
response = self.deserialize(self.fmt,
request.get_response(self.ext_api))
self.assertEqual(idx, len(response[IP_AVAILS_KEY]))
def test_usages_query_sorting(self):
with self.network() as net1, self.network() as net2, \
self.network() as net3, self.network() as net4:
networks = (net1, net2, net3, net4)
network_ids = sorted([net['network']['id'] for net in networks])
params = 'sort_key=network_id;sort_dir=asc'
request = self.new_list_request(API_RESOURCE, params=params)
response = self.deserialize(self.fmt,
request.get_response(self.ext_api))
res = [net['network_id'] for net in response[IP_AVAILS_KEY]]
self.assertEqual(network_ids, res)
params = 'sort_key=network_id;sort_dir=desc'
request = self.new_list_request(API_RESOURCE, params=params)
response = self.deserialize(self.fmt,
request.get_response(self.ext_api))
res = [net['network_id'] for net in response[IP_AVAILS_KEY]]
self.assertEqual(list(reversed(network_ids)), res)

View File

@ -16,7 +16,7 @@ Jinja2>=2.10 # BSD License (3 clause)
keystonemiddleware>=5.1.0 # Apache-2.0
netaddr>=0.7.18 # BSD
netifaces>=0.10.4 # MIT
neutron-lib>=2.13.0 # Apache-2.0
neutron-lib>=2.15.0 # Apache-2.0
python-neutronclient>=6.7.0 # Apache-2.0
tenacity>=6.0.0 # Apache-2.0
SQLAlchemy>=1.3.23 # MIT