def _test_l3p_unplugged_from_es_on_update(self, shared_es,
                                              shared_l3p, is_edge_nat=False):
        self._mock_external_dict([('supported1', '192.168.0.2/24'),
                                 ('supported', '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='supported', cidr='192.168.1.0/24')['external_segment']
        l3p = self.create_l3_policy(
            name='myl3p',
            tenant_id=es1['tenant_id'] if not shared_es else 'another_tenant',
            shared=shared_l3p,
            external_segments={es1['id']: ['169.254.0.3']},
            expected_res_status=201)['l3_policy']

        mgr = self.driver.apic_manager
        owner = self.common_tenant if shared_es else es1['tenant_id']
        l3p_owner = self.common_tenant if shared_l3p else l3p['tenant_id']
        mgr.ensure_external_routed_network_created.reset_mock()
        mgr.set_domain_for_external_routed_network.reset_mock()
        mgr.ensure_logical_node_profile_created.reset_mock()
        mgr.ensure_static_route_created.reset_mock()
        self.driver.l3out_vlan_alloc.reserve_vlan.reset_mock()
        mgr.apic.post_body.reset_mock()
        mgr.set_context_for_external_routed_network.reset_mock()

        l3p = self.update_l3_policy(
            l3p['id'], tenant_id=l3p['tenant_id'], expected_res_status=200,
            external_segments={es2['id']: ['169.254.0.4']})['l3_policy']
        l3out_str = "Shd-%s-%s"
        if is_edge_nat:
            l3out_str = "Auto-%s-%s"
        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:
            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.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'], l3p['id'], 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:
            self.driver.l3out_vlan_alloc.release_vlan.assert_called_once_with(
                es1['name'], l3p['id'])

        expected_l3out_calls = []
        if self.nat_enabled:
            if not is_edge_nat or not self.pre_l3out:
                expected_l3out_calls.append(
                    mock.call(l3out_str % (l3p['id'], es2['id']),
                              owner=l3p_owner, context=l3p['id'],
                              transaction=mock.ANY))
            if not self.pre_l3out:
                expected_l3out_calls.append(
                    mock.call(es2['id'], owner=owner,
                              context="NAT-vrf-%s" % es2['id'],
                              transaction=mock.ANY))
        elif not self.pre_l3out:
            expected_l3out_calls = [
                mock.call(es2['id'], owner=owner, context=l3p['id'],
                          transaction=mock.ANY)]
        self._check_call_list(expected_l3out_calls,
            mgr.ensure_external_routed_network_created.call_args_list)

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

        if not self.pre_l3out:
            expected_set_domain_calls = [
                mock.call(es2['id'], owner=owner, transaction=mock.ANY)]
            expected_logic_node_calls = [
                mock.call(es2['id'], mocked.APIC_EXT_SWITCH,
                          mocked.APIC_EXT_MODULE, mocked.APIC_EXT_PORT,
                          mocked.APIC_EXT_ENCAP, '192.168.1.2/24',
                          owner=owner, router_id=APIC_EXTERNAL_RID,
                          transaction=mock.ANY)]
            if is_edge_nat and self.nat_enabled:
                expected_set_domain_calls.append(
                    mock.call(l3out_str % (l3p['id'], es2['id']),
                              owner=owner, transaction=mock.ANY))
                expected_logic_node_calls.append(
                    mock.call(l3out_str % (l3p['id'], es2['id']),
                              mocked.APIC_EXT_SWITCH, mocked.APIC_EXT_MODULE,
                              mocked.APIC_EXT_PORT, mock.ANY, '192.168.1.2/24',
                              owner=owner, router_id=APIC_EXTERNAL_RID,
                              transaction=mock.ANY))

            self._check_call_list(expected_set_domain_calls,
                mgr.set_domain_for_external_routed_network.call_args_list)
            self._check_call_list(expected_logic_node_calls,
                mgr.ensure_logical_node_profile_created.call_args_list)
        else:
            if is_edge_nat and self.nat_enabled:
                final_req = re.sub('Shd-Sub',
                    l3out_str % (l3p['id'], es2['id']),
                    self.trimmed_l3out)
                mgr.apic.post_body.assert_called_once_with(
                    mgr.apic.l3extOut.mo, final_req, l3p_owner,
                    l3out_str % (l3p['id'], es2['id']))
            self.assertFalse(mgr.set_domain_for_external_routed_network.called)
            self.assertFalse(mgr.ensure_logical_node_profile_created.called)

        self.assertFalse(mgr.ensure_static_route_created.called)

        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)

        self.driver.l3out_vlan_alloc.release_vlan.reset_mock()
        mgr.delete_external_routed_network.reset_mock()
        mgr.unset_l3out_for_bd.reset_mock()
        self.update_l3_policy(
            l3p['id'], expected_res_status=200, tenant_id=l3p['tenant_id'],
            external_segments={es1['id']: ['169.254.0.5'],
                               es2['id']: ['169.254.0.6']})
        mgr.set_context_for_external_routed_network.reset_mock()
        self.update_l3_policy(
            l3p['id'], tenant_id=l3p['tenant_id'],
            expected_res_status=200, external_segments={})
        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:
            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_update/original