From 8e606f5a6af1689c3eb053eb7161c472277014fb Mon Sep 17 00:00:00 2001 From: Ivar Lazzaro Date: Tue, 2 Feb 2016 18:00:11 -0800 Subject: [PATCH] [apic-mapping] PTGs on preexisting BDs to not provide service contracts Change-Id: I6f18013440e4da6d8f15df9c4d2b2147e3dcc483 Closes-Bug: 1541166 --- .../drivers/cisco/apic/apic_mapping.py | 9 +++++---- .../services/grouppolicy/test_apic_mapping.py | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/gbpservice/neutron/services/grouppolicy/drivers/cisco/apic/apic_mapping.py b/gbpservice/neutron/services/grouppolicy/drivers/cisco/apic/apic_mapping.py index f86b365a2..edb28d0e8 100644 --- a/gbpservice/neutron/services/grouppolicy/drivers/cisco/apic/apic_mapping.py +++ b/gbpservice/neutron/services/grouppolicy/drivers/cisco/apic/apic_mapping.py @@ -733,10 +733,11 @@ class ApicMappingDriver(api.ResourceMappingDriver, self.apic_manager.ensure_epg_created(tenant, epg, bd_owner=bd_owner, bd_name=l2_policy) - self._configure_epg_service_contract( - context, context.current, l2p, epg, transaction=trs) - self._configure_epg_implicit_contract( - context, context.current, l2p, epg, transaction=trs) + if not self.name_mapper._is_apic_reference(l2_policy_object): + self._configure_epg_service_contract( + context, context.current, l2p, epg, transaction=trs) + self._configure_epg_implicit_contract( + context, context.current, l2p, epg, transaction=trs) l3p = context._plugin.get_l3_policy( context._plugin_context, l2_policy_object['l3_policy_id']) diff --git a/gbpservice/neutron/tests/unit/services/grouppolicy/test_apic_mapping.py b/gbpservice/neutron/tests/unit/services/grouppolicy/test_apic_mapping.py index 7fda2f247..333a55a5b 100644 --- a/gbpservice/neutron/tests/unit/services/grouppolicy/test_apic_mapping.py +++ b/gbpservice/neutron/tests/unit/services/grouppolicy/test_apic_mapping.py @@ -1060,6 +1060,26 @@ class TestPolicyTargetGroup(ApicMappingTestCase): self.assertNotEqual(sub_ptg_1, sub_ptg_2) self.assertFalse(sub_ptg_1 & sub_ptg_2) + def test_preexisting_l2p_no_service_contracts(self): + # Circumvent name validation + self.driver.name_mapper.has_valid_name = ( + self.driver.name_mapper._is_apic_reference) + self.driver.name_mapper.tenant = mock.Mock( + return_value=self._tenant_id) + self.driver.name_mapper.dn_manager.decompose_bridge_domain = mock.Mock( + return_value=['preexisting']) + self.driver._configure_epg_service_contract = mock.Mock() + self.driver._configure_epg_implicit_contract = mock.Mock() + l2p = self.create_l2_policy(name='apic:preexisting')['l2_policy'] + self.create_policy_target_group(l2_policy_id=l2p['id']) + self.assertFalse(self.driver._configure_epg_service_contract.called) + self.assertFalse(self.driver._configure_epg_implicit_contract.called) + + # Use non-preexisting L2P + self.create_policy_target_group() + self.assertTrue(self.driver._configure_epg_service_contract.called) + self.assertTrue(self.driver._configure_epg_implicit_contract.called) + def _create_explicit_subnet_ptg(self, cidr, shared=False): l2p = self.create_l2_policy(name="l2p", shared=shared) l2p_id = l2p['l2_policy']['id']