Fix subnet querying to use the subnet CIDR
This patch fixes Kuryr not to use the given CIDRs as they are but the subnet CIDR. Before applying this patch to Kuryr queried the existing subnets with the CIDRs for interfaces in the requests and that led duplicated subnets created. Change-Id: I8fc4b32ce8a4e016554d8a76e8063e916a69c370 Signed-off-by: Taku Fukushima <f.tac.mac@gmail.com> Closes-Bug: #1496727
This commit is contained in:
parent
a849d94730
commit
582607236f
@ -72,9 +72,13 @@ def _handle_allocation_from_pools(neutron_network_id, existing_subnets):
|
||||
|
||||
|
||||
def _process_subnet(neutron_network_id, endpoint_id, interface_cidr,
|
||||
new_subnets, existing_subnets):
|
||||
new_subnets, existing_subnets, pool_id=None):
|
||||
cidr = netaddr.IPNetwork(interface_cidr)
|
||||
subnet_network = str(cidr.network)
|
||||
subnet_cidr = '/'.join([subnet_network,
|
||||
str(cidr.prefixlen)])
|
||||
subnets = _get_subnets_by_attrs(
|
||||
network_id=neutron_network_id, cidr=interface_cidr)
|
||||
network_id=neutron_network_id, cidr=subnet_cidr)
|
||||
if subnets:
|
||||
existing_subnets += subnets
|
||||
else:
|
||||
|
@ -121,12 +121,12 @@ class TestKuryr(base.TestKuryrBase):
|
||||
fake_existing_subnets_response = {
|
||||
"subnets": []
|
||||
}
|
||||
fake_cidr_v4 = '192.168.1.2/24'
|
||||
fake_cidr_v4 = '192.168.1.0/24'
|
||||
app.neutron.list_subnets(
|
||||
network_id=fake_neutron_network_id,
|
||||
cidr=fake_cidr_v4).AndReturn(fake_existing_subnets_response)
|
||||
|
||||
fake_cidr_v6 = 'fe80::f816:3eff:fe20:57c4/64'
|
||||
fake_cidr_v6 = 'fe80::/64'
|
||||
app.neutron.list_subnets(
|
||||
network_id=fake_neutron_network_id,
|
||||
cidr=fake_cidr_v6).AndReturn(fake_existing_subnets_response)
|
||||
@ -187,8 +187,10 @@ class TestKuryr(base.TestKuryrBase):
|
||||
app.neutron.create_subnet(
|
||||
fake_subnet_request).AndReturn(fake_subnet_response)
|
||||
|
||||
subnet_v4_address = fake_cidr_v4.split('/')[0]
|
||||
subnet_v6_address = fake_cidr_v6.split('/')[0]
|
||||
fake_ipv4cidr = '192.168.1.2/24'
|
||||
fake_ipv6cidr = 'fe80::f816:3eff:fe20:57c4/64'
|
||||
subnet_v4_address = fake_ipv4cidr.split('/')[0]
|
||||
subnet_v6_address = fake_ipv6cidr.split('/')[0]
|
||||
self.mox.StubOutWithMock(app.neutron, 'create_port')
|
||||
fake_port_request = {
|
||||
'port': {
|
||||
@ -238,8 +240,8 @@ class TestKuryr(base.TestKuryrBase):
|
||||
'Options': {},
|
||||
'Interfaces': [{
|
||||
'ID': 0,
|
||||
'Address': '192.168.1.2/24',
|
||||
'AddressIPv6': 'fe80::f816:3eff:fe20:57c4/64',
|
||||
'Address': fake_ipv4cidr,
|
||||
'AddressIPv6': fake_ipv6cidr,
|
||||
'MacAddress': "fa:16:3e:20:57:c3"
|
||||
}]
|
||||
}
|
||||
|
@ -237,10 +237,10 @@ class TestKuryrEndpointCreateFailures(TestKuryrEndpointFailures):
|
||||
self.mox.StubOutWithMock(app.neutron, 'list_subnets')
|
||||
app.neutron.list_subnets(
|
||||
network_id=fake_neutron_network_id,
|
||||
cidr='192.168.1.2/24').AndReturn({'subnets': []})
|
||||
cidr='192.168.1.0/24').AndReturn({'subnets': []})
|
||||
app.neutron.list_subnets(
|
||||
network_id=fake_neutron_network_id,
|
||||
cidr='fe80::f816:3eff:fe20:57c4/64').AndReturn({'subnets': []})
|
||||
cidr='fe80::/64').AndReturn({'subnets': []})
|
||||
|
||||
self._create_subnet_with_exception(
|
||||
fake_neutron_network_id, fake_docker_endpoint_id, GivenException())
|
||||
@ -266,10 +266,10 @@ class TestKuryrEndpointCreateFailures(TestKuryrEndpointFailures):
|
||||
self.mox.StubOutWithMock(app.neutron, 'list_subnets')
|
||||
app.neutron.list_subnets(
|
||||
network_id=fake_neutron_network_id,
|
||||
cidr='192.168.1.2/24').AndReturn({'subnets': []})
|
||||
cidr='192.168.1.0/24').AndReturn({'subnets': []})
|
||||
app.neutron.list_subnets(
|
||||
network_id=fake_neutron_network_id,
|
||||
cidr='fe80::f816:3eff:fe20:57c4/64').AndReturn({'subnets': []})
|
||||
cidr='fe80::/64').AndReturn({'subnets': []})
|
||||
|
||||
(fake_neutron_subnet_v4_id,
|
||||
fake_neutron_subnet_v6_id) = self._create_subnet_with_exception(
|
||||
|
Loading…
x
Reference in New Issue
Block a user