def test_multi_policy_multi_tenant(self):
        tenants = (['tenant_a', 'tenant_b', 'tenant_c']
                   if self.nat_enabled else ['tenant_a'])

        self._mock_external_dict([('supported', '192.168.0.2/24')])
        ext_routes = ['128.0.0.0/24', '128.0.1.0/24']
        es_list = [
            self.create_external_segment(
                name='supported', cidr='192.168.0.0/24', shared=True,
                expected_res_status=201,
                external_routes=[{
                    'destination': ext_routes[x],
                    'nexthop': '192.168.0.254'}])['external_segment']
            for x in range(2)]

        l3p_list = []
        for x in xrange(len(tenants)):
            l3p = self.create_l3_policy(
                shared=False,
                tenant_id=tenants[x],
                external_segments={x['id']: [] for x in es_list},
                expected_res_status=201)['l3_policy']
            l3p_list.append(l3p)

        # create external-policy
        ep_list = []
        mgr = self.driver.apic_manager
        for x in range(len(tenants)):
            ep = self.create_external_policy(
                name=APIC_EXTERNAL_EPG,
                external_segments=[e['id'] for e in es_list],
                tenant_id=tenants[x],
                expected_res_status=201)['external_policy']
            ep_list.append(ep)
            l3p = l3p_list[x]
            expected_calls = []
            for es in es_list:
                if self.nat_enabled:
                    if not self.pre_l3out:
                        expected_calls.append(
                            mock.call(es['id'], subnet='0.0.0.0/0',
                                external_epg="default-%s" % es['id'],
                                owner=self.common_tenant,
                                transaction=mock.ANY))
                    expected_calls.append(
                        mock.call("Shd-%s-%s" % (l3p['id'], es['id']),
                            subnet=es['external_routes'][0]['destination'],
                            external_epg=("Shd-%s-%s" % (l3p['id'], ep['id'])),
                            owner=tenants[x],
                            transaction=mock.ANY))
                elif not self.pre_l3out:
                    expected_calls.append(
                        mock.call(es['id'],
                            subnet=es['external_routes'][0]['destination'],
                            external_epg=ep['id'], owner=self.common_tenant,
                            transaction=mock.ANY))
            self._check_call_list(expected_calls,
                mgr.ensure_external_epg_created.call_args_list)
            mgr.ensure_external_epg_created.reset_mock()

        # delete external-policy
        expected_calls = []
        for x in range(len(tenants)):
            ep = ep_list[x]
            self.delete_external_policy(
                ep['id'], tenant_id=ep['tenant_id'],
                expected_res_status=webob.exc.HTTPNoContent.code)
            l3p = l3p_list[x]

            for es in es_list:
                if self.nat_enabled:
                    expected_calls.append(
                        mock.call("Shd-%s-%s" % (l3p['id'], es['id']),
                            external_epg=("Shd-%s-%s" % (l3p['id'], ep['id'])),
                            owner=tenants[x]))
                elif not self.pre_l3out:
                    expected_calls.append(
                        mock.call(es['id'], external_epg=ep['id'],
                            owner=self.common_tenant))
        if self.nat_enabled and not self.pre_l3out:
            for es in es_list:
                expected_calls.append(
                    mock.call(es['id'], external_epg="default-%s" % es['id'],
                              owner=self.common_tenant))
        self._check_call_list(expected_calls,
            mgr.ensure_external_epg_deleted.call_args_list)
dataset/ETHPy150Open openstack/group-based-policy/gbpservice/neutron/tests/unit/services/grouppolicy/test_apic_mapping.py/TestExternalPolicy.test_multi_policy_multi_tenant/original