Merge "Turn CIDR in query filter into proper subnet" into stable/rocky
This commit is contained in:
commit
3888448ba4
|
@ -15,6 +15,8 @@
|
|||
|
||||
import functools
|
||||
|
||||
import netaddr
|
||||
|
||||
from neutron_lib.api.definitions import network as net_def
|
||||
from neutron_lib.api.definitions import port as port_def
|
||||
from neutron_lib.api.definitions import subnet as subnet_def
|
||||
|
@ -277,6 +279,10 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
|
|||
page_reverse=False):
|
||||
pager = base_obj.Pager(sorts, limit, page_reverse, marker)
|
||||
filters = filters or {}
|
||||
# turn the CIDRs into a proper subnets
|
||||
if filters.get('cidr'):
|
||||
filters.update(
|
||||
{'cidr': [netaddr.IPNetwork(x).cidr for x in filters['cidr']]})
|
||||
# TODO(ihrachys) remove explicit reader usage when subnet OVO switches
|
||||
# to engine facade by default
|
||||
with db_api.context_manager.reader.using(context):
|
||||
|
|
|
@ -5141,6 +5141,19 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
|
|||
self._test_list_resources('subnet', [],
|
||||
query_params=query_params)
|
||||
|
||||
def test_list_subnets_filtering_by_cidr_used_on_create(self):
|
||||
with self.network() as network:
|
||||
with self.subnet(network=network,
|
||||
gateway_ip='10.0.0.1',
|
||||
cidr='10.0.0.11/24') as v1,\
|
||||
self.subnet(network=network,
|
||||
gateway_ip='10.0.1.1',
|
||||
cidr='10.0.1.11/24') as v2:
|
||||
subnets = (v1, v2)
|
||||
query_params = ('cidr=10.0.0.11/24&cidr=10.0.1.11/24')
|
||||
self._test_list_resources('subnet', subnets,
|
||||
query_params=query_params)
|
||||
|
||||
def test_list_subnets_filtering_by_unknown_filter(self):
|
||||
if self._skip_filter_validation:
|
||||
self.skipTest("Plugin does not support filter validation")
|
||||
|
|
Loading…
Reference in New Issue