[apic-mapping] retrieve the right subnets during PTG allocation
Change-Id: Ib602402cc65c8d6946f9de89d3dc58e0d4859b05 Closes-Bug: 1544369
This commit is contained in:
parent
8e606f5a6a
commit
88bae4c30f
@ -2182,8 +2182,11 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
|||||||
|
|
||||||
def _get_l2p_subnets(self, plugin_context, l2p_id):
|
def _get_l2p_subnets(self, plugin_context, l2p_id):
|
||||||
l2p = self.gbp_plugin.get_l2_policy(plugin_context, l2p_id)
|
l2p = self.gbp_plugin.get_l2_policy(plugin_context, l2p_id)
|
||||||
|
return self._get_l2ps_subnets(plugin_context, [l2p])
|
||||||
|
|
||||||
|
def _get_l2ps_subnets(self, plugin_context, l2ps):
|
||||||
return self._core_plugin.get_subnets(
|
return self._core_plugin.get_subnets(
|
||||||
plugin_context, {'network_id': [l2p['network_id']]})
|
plugin_context, {'network_id': [x['network_id'] for x in l2ps]})
|
||||||
|
|
||||||
def _configure_implicit_contract(self, context, l2p, transaction=None):
|
def _configure_implicit_contract(self, context, l2p, transaction=None):
|
||||||
with self.apic_manager.apic.transaction(transaction) as trs:
|
with self.apic_manager.apic.transaction(transaction) as trs:
|
||||||
@ -2974,3 +2977,10 @@ class ApicMappingDriver(api.ResourceMappingDriver,
|
|||||||
rule_name, owner=tenant, transaction=trs,
|
rule_name, owner=tenant, transaction=trs,
|
||||||
entry=apic_manager.CP_ENTRY + '-' + str(x), **entry)
|
entry=apic_manager.CP_ENTRY + '-' + str(x), **entry)
|
||||||
x += 1
|
x += 1
|
||||||
|
|
||||||
|
def _get_l3p_allocated_subnets(self, context, l3p_id):
|
||||||
|
l2ps = self._get_l2_policies(context._plugin_context,
|
||||||
|
{'l3_policy_id': [l3p_id]})
|
||||||
|
subnets = [x['cidr'] for x in
|
||||||
|
self._get_l2ps_subnets(context._plugin_context, l2ps)]
|
||||||
|
return subnets
|
||||||
|
@ -1443,10 +1443,8 @@ class ResourceMappingDriver(api.PolicyDriver, local_api.LocalAPI,
|
|||||||
l3p['proxy_subnet_prefix_length'] if is_proxy
|
l3p['proxy_subnet_prefix_length'] if is_proxy
|
||||||
else l3p['subnet_prefix_length'])
|
else l3p['subnet_prefix_length'])
|
||||||
l3p_id = l3p['id']
|
l3p_id = l3p['id']
|
||||||
ptgs = context._plugin._get_l3p_ptgs(
|
|
||||||
context._plugin_context.elevated(), l3p_id)
|
|
||||||
allocated = netaddr.IPSet(
|
allocated = netaddr.IPSet(
|
||||||
iterable=self._get_ptg_cidrs(context, None, ptg_dicts=ptgs))
|
iterable=self._get_l3p_allocated_subnets(context, l3p_id))
|
||||||
available = pool - allocated
|
available = pool - allocated
|
||||||
available.compact()
|
available.compact()
|
||||||
|
|
||||||
@ -2568,3 +2566,8 @@ class ResourceMappingDriver(api.PolicyDriver, local_api.LocalAPI,
|
|||||||
master_mac = master_port['mac_address']
|
master_mac = master_port['mac_address']
|
||||||
master_ips = [x['ip_address'] for x in master_port['fixed_ips']]
|
master_ips = [x['ip_address'] for x in master_port['fixed_ips']]
|
||||||
return master_mac, master_ips
|
return master_mac, master_ips
|
||||||
|
|
||||||
|
def _get_l3p_allocated_subnets(self, context, l3p_id):
|
||||||
|
ptgs = context._plugin._get_l3p_ptgs(
|
||||||
|
context._plugin_context.elevated(), l3p_id)
|
||||||
|
return self._get_ptg_cidrs(context, None, ptg_dicts=ptgs)
|
@ -1161,6 +1161,22 @@ class TestL2Policy(ApicMappingTestCase):
|
|||||||
self.assertEqual('L3PolicyUpdateOfL2PolicyNotSupported',
|
self.assertEqual('L3PolicyUpdateOfL2PolicyNotSupported',
|
||||||
res['NeutronError']['type'])
|
res['NeutronError']['type'])
|
||||||
|
|
||||||
|
def test_subnet_deallocated(self):
|
||||||
|
l2p = self.create_l2_policy()['l2_policy']
|
||||||
|
ptg = self.create_policy_target_group(
|
||||||
|
l2_policy_id=l2p['id'])['policy_target_group']
|
||||||
|
subnet = netaddr.IPSet(
|
||||||
|
[self._show_subnet(x)['subnet']['cidr'] for x in ptg['subnets']])
|
||||||
|
self.delete_policy_target_group(ptg['id'])
|
||||||
|
|
||||||
|
l2p2 = self.create_l2_policy()['l2_policy']
|
||||||
|
ptg = self.create_policy_target_group(
|
||||||
|
l2_policy_id=l2p2['id'])['policy_target_group']
|
||||||
|
|
||||||
|
subnet2 = netaddr.IPSet(
|
||||||
|
[self._show_subnet(x)['subnet']['cidr'] for x in ptg['subnets']])
|
||||||
|
self.assertFalse(subnet & subnet2)
|
||||||
|
|
||||||
|
|
||||||
class TestL3Policy(ApicMappingTestCase):
|
class TestL3Policy(ApicMappingTestCase):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user