def _test_l3p_plugged_to_es_at_creation(self, shared_es,
                                            shared_l3p, is_edge_nat=False):
        # Verify L3P is correctly plugged to ES on APIC during create
        self._mock_external_dict([('supported', '192.168.0.2/24')],
                                 is_edge_nat)
        es = self.create_external_segment(
            name='supported', 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']

        # Create with explicit address
        l3p = self.create_l3_policy(
            name='myl3p',
            shared=shared_l3p,
            tenant_id=es['tenant_id'] if not shared_es else 'another_tenant',
            external_segments={es['id']: []},
            expected_res_status=201)['l3_policy']

        self.assertEqual(1, len(l3p['external_segments'][es['id']]))
        self.assertEqual('169.254.0.2', l3p['external_segments'][es['id']][0])

        owner = self.common_tenant if shared_es else es['tenant_id']
        l3p_owner = self.common_tenant if shared_l3p else l3p['tenant_id']
        mgr = self.driver.apic_manager
        call_name = mgr.ensure_external_routed_network_created
        l3out_str = "Shd-%s-%s"
        if is_edge_nat:
            l3out_str = "Auto-%s-%s"
        if self.nat_enabled:
            expected_l3out_calls = []
            if not is_edge_nat or not self.pre_l3out:
                expected_l3out_calls.append(
                    mock.call(l3out_str % (l3p['id'], es['id']),
                              owner=l3p_owner, context=l3p['id'],
                              transaction=mock.ANY))
            if not self.pre_l3out:
                expected_l3out_calls.append(
                    mock.call(es['id'], owner=owner,
                              context="NAT-vrf-%s" % es['id'],
                              transaction=mock.ANY))
        elif not self.pre_l3out:
            expected_l3out_calls = [
                mock.call(es['id'], owner=owner, context=l3p['id'],
                          transaction=mock.ANY)]
        else:
            call_name = mgr.set_context_for_external_routed_network
            expected_l3out_calls = [
                mock.call(APIC_PRE_L3OUT_TENANT, es['name'], l3p['id'],
                          transaction=mock.ANY)]
        self._check_call_list(expected_l3out_calls, call_name.call_args_list)

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

        if not self.pre_l3out:
            expected_set_domain_calls = [
                mock.call(es['id'], owner=owner, transaction=mock.ANY)]
            expected_logic_node_calls = [
                mock.call(es['id'], mocked.APIC_EXT_SWITCH,
                          mocked.APIC_EXT_MODULE, mocked.APIC_EXT_PORT,
                          mocked.APIC_EXT_ENCAP, '192.168.0.2/24',
                          owner=owner, router_id=APIC_EXTERNAL_RID,
                          transaction=mock.ANY)]
            expected_route_calls = [
                mock.call(es['id'], mocked.APIC_EXT_SWITCH, '192.168.0.254',
                          owner=owner, subnet='0.0.0.0/0',
                          transaction=mock.ANY),
                mock.call(es['id'], mocked.APIC_EXT_SWITCH, '192.168.0.1',
                          owner=owner, subnet='128.0.0.0/16',
                          transaction=mock.ANY)]

            if is_edge_nat and self.nat_enabled:
                expected_set_domain_calls.append(
                    mock.call(l3out_str % (l3p['id'], es['id']),
                              owner=owner, transaction=mock.ANY))
                expected_logic_node_calls.append(
                    mock.call(l3out_str % (l3p['id'], es['id']),
                              mocked.APIC_EXT_SWITCH, mocked.APIC_EXT_MODULE,
                              mocked.APIC_EXT_PORT, mock.ANY, '192.168.0.2/24',
                              owner=owner, router_id=APIC_EXTERNAL_RID,
                              transaction=mock.ANY))
                expected_route_calls.append(
                    mock.call(l3out_str % (l3p['id'], es['id']),
                              mocked.APIC_EXT_SWITCH, '192.168.0.254',
                              owner=owner, subnet='0.0.0.0/0',
                              transaction=mock.ANY))
                expected_route_calls.append(
                    mock.call(l3out_str % (l3p['id'], es['id']),
                              mocked.APIC_EXT_SWITCH, '192.168.0.1',
                              owner=owner, subnet='128.0.0.0/16',
                              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)
            self._check_call_list(expected_route_calls,
                mgr.ensure_static_route_created.call_args_list)
        else:
            if is_edge_nat and self.nat_enabled:
                final_req = re.sub('Shd-Sub',
                    l3out_str % (l3p['id'], es['id']), self.trimmed_l3out)
                mgr.apic.post_body.assert_called_once_with(
                    mgr.apic.l3extOut.mo, final_req, l3p_owner,
                    l3out_str % (l3p['id'], es['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.set_l3out_for_bd.assert_called_once_with(owner,
                "NAT-bd-%s" % es['id'],
                es['name' if self.pre_l3out else 'id'], transaction=mock.ANY)

    # 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_plugged_to_es_at_creation/original