def _test_l3p_unplugged_from_es_on_delete(self, shared_es,
                                              shared_l3p, is_edge_nat=False):
        self._mock_external_dict([('supported1', '192.168.0.2/24'),
                                 ('supported2', '192.168.1.2/24')],
                                 is_edge_nat)
        es1 = self.create_external_segment(
            name='supported1', cidr='192.168.0.0/24', shared=shared_es,
            external_routes=[{'destination': '0.0.0.0/0',
                              'nexthop': '192.168.0.254'},
                             {'destination': '128.0.0.0/16',
                              'nexthop': None}])['external_segment']
        es2 = self.create_external_segment(
            shared=shared_es, name='supported2',
            cidr='192.168.1.0/24')['external_segment']

        l3p = self.create_l3_policy(shared=shared_l3p,
            tenant_id=es1['tenant_id'] if not shared_es else 'another_tenant',
            external_segments={es1['id']: ['169.254.0.3']},
            expected_res_status=201)['l3_policy']

        mgr = self.driver.apic_manager
        mgr.set_context_for_external_routed_network.reset_mock()

        req = self.new_delete_request('l3_policies', l3p['id'], self.fmt)
        res = req.get_response(self.ext_api)
        self.assertEqual(webob.exc.HTTPNoContent.code, res.status_int)

        owner = self.common_tenant if shared_es else es1['tenant_id']
        l3p_owner = self.common_tenant if shared_l3p else l3p['tenant_id']
        expected_delete_calls = []
        if not self.pre_l3out:
            expected_delete_calls.append(
                mock.call(es1['id'], owner=owner, transaction=mock.ANY))
        if self.nat_enabled:
            l3out_str = "Shd-%s-%s"
            if is_edge_nat:
                l3out_str = "Auto-%s-%s"
            expected_delete_calls.append(
                mock.call(l3out_str % (l3p['id'], es1['id']),
                    owner=l3p_owner, transaction=mock.ANY))
        self._check_call_list(
            expected_delete_calls,
            mgr.delete_external_routed_network.call_args_list)
        if self.nat_enabled:
            mgr.unset_l3out_for_bd.assert_called_once_with(owner,
                "NAT-bd-%s" % es1['id'],
                es1['name' if self.pre_l3out else 'id'], transaction=mock.ANY)
        if self.pre_l3out and not self.nat_enabled:
            call_name = mgr.set_context_for_external_routed_network
            call_name.assert_called_once_with(APIC_PRE_L3OUT_TENANT,
                es1['name'], None, transaction=mock.ANY)

        if is_edge_nat and self.nat_enabled:
            self.driver.l3out_vlan_alloc.release_vlan.assert_called_once_with(
                es1['name'], l3p['id'])

        mgr.delete_external_routed_network.reset_mock()
        mgr.unset_l3out_for_bd.reset_mock()
        self.driver.l3out_vlan_alloc.release_vlan.reset_mock()

        # Verify correct deletion for 2 ESs
        l3p = self.create_l3_policy(
            shared=shared_l3p,
            tenant_id=es1['tenant_id'] if not shared_es else 'another_tenant',
            external_segments={es1['id']: ['169.254.0.3'],
                               es2['id']: ['169.254.0.3']},
            expected_res_status=201)['l3_policy']
        mgr.set_context_for_external_routed_network.reset_mock()
        req = self.new_delete_request('l3_policies', l3p['id'], self.fmt)
        res = req.get_response(self.ext_api)
        self.assertEqual(webob.exc.HTTPNoContent.code, res.status_int)

        expected_delete_calls = []
        if not self.pre_l3out:
            expected_delete_calls.extend([
                mock.call(es1['id'], owner=owner, transaction=mock.ANY),
                mock.call(es2['id'], owner=owner, transaction=mock.ANY)])
        if self.nat_enabled:
            l3out_str = "Shd-%s-%s"
            if is_edge_nat:
                l3out_str = "Auto-%s-%s"
            expected_delete_calls.extend([
                mock.call(l3out_str % (l3p['id'], es1['id']),
                     owner=l3p_owner, transaction=mock.ANY),
                mock.call(l3out_str % (l3p['id'], es2['id']),
                     owner=l3p_owner, transaction=mock.ANY)])
        self._check_call_list(
            expected_delete_calls,
            mgr.delete_external_routed_network.call_args_list)
        if self.nat_enabled:
            expected_unset_calls = [
                mock.call(owner, "NAT-bd-%s" % es1['id'],
                    es1['name' if self.pre_l3out else 'id'],
                    transaction=mock.ANY),
                mock.call(owner, "NAT-bd-%s" % es2['id'],
                    es2['name' if self.pre_l3out else 'id'],
                    transaction=mock.ANY)]
            self._check_call_list(
                expected_unset_calls, mgr.unset_l3out_for_bd.call_args_list)
        if self.pre_l3out and not self.nat_enabled:
            expected_calls = [
                mock.call(APIC_PRE_L3OUT_TENANT,
                    es1['name'], None, transaction=mock.ANY),
                mock.call(APIC_PRE_L3OUT_TENANT,
                    es2['name'], None, transaction=mock.ANY)]
            self._check_call_list(
                expected_calls,
                mgr.set_context_for_external_routed_network.call_args_list)

        if is_edge_nat and self.nat_enabled:
            expected_release_vlan_calls = [mock.call(es1['name'], l3p['id']),
                                           mock.call(es2['name'], l3p['id'])]
            self._check_call_list(
                expected_release_vlan_calls,
                self.driver.l3out_vlan_alloc.release_vlan.call_args_list)

    # Although the naming convention used here has been chosen poorly,
    # I'm separating the tests in order to get the mock re-set.
dataset/ETHPy150Open openstack/group-based-policy/gbpservice/neutron/tests/unit/services/grouppolicy/test_apic_mapping.py/TestL3Policy._test_l3p_unplugged_from_es_on_delete/original