def _test_create_delete(self, shared=False):
        mgr = self.driver.apic_manager
        self._mock_external_dict([('supported', '192.168.0.2/24')])
        mgr.ext_net_dict['supported']['host_pool_cidr'] = '192.168.200.1/24'
        es = self.create_external_segment(name='supported',
            cidr='192.168.0.2/24',
            expected_res_status=201, shared=shared)['external_segment']
        self.create_external_segment(name='unsupport', expected_res_status=201,
                                     shared=shared)
        self.assertEqual('192.168.0.2/24', es['cidr'])
        self.assertIsNotNone(es['subnet_id'])
        subnet = self._get_object('subnets', es['subnet_id'],
            self.api)['subnet']
        self.assertEqual('169.254.0.0/16', subnet['cidr'])
        owner = es['tenant_id'] if not shared else self.common_tenant
        prs = "NAT-allow-%s" % es['id']
        if self.nat_enabled:
            ctx = "NAT-vrf-%s" % es['id']
            ctx_owner = owner
            contract_owner = owner
            if self.pre_l3out:
                ctx = APIC_PRE_VRF
                ctx_owner = APIC_PRE_VRF_TENANT
                contract_owner = APIC_PRE_L3OUT_TENANT
                self.assertFalse(mgr.ensure_context_enforced.called)
            else:
                mgr.ensure_context_enforced.assert_called_with(
                    owner=owner, ctx_id=ctx,
                    transaction=mock.ANY)
            mgr.ensure_bd_created_on_apic(
                owner, "NAT-bd-%s" % es['id'], ctx_owner=ctx_owner,
                ctx_name=ctx, transaction=mock.ANY)
            mgr.ensure_epg_created.assert_called_with(
                owner, "NAT-epg-%s" % es['id'], bd_name=es['id'] % "NAT-bd-%s",
                transaction=mock.ANY)
            mgr.create_tenant_filter.assert_called_with(
                prs, owner=contract_owner,
                entry="allow-all", transaction=mock.ANY)
            mgr.manage_contract_subject_bi_filter.assert_called_with(
                prs, prs, prs, owner=contract_owner, transaction=mock.ANY)
            expected_calls = [
                mock.call(owner, "NAT-epg-%s" % es['id'], prs,
                          transaction=mock.ANY),
                mock.call(owner, "NAT-epg-%s" % es['id'], prs,
                          provider=True, transaction=mock.ANY)]
            self._check_call_list(expected_calls,
                mgr.set_contract_for_epg.call_args_list)
            ctx = context.get_admin_context()
            internal_subnets = self._db_plugin.get_subnets(
                    ctx, filters={'name': [amap.HOST_SNAT_POOL]})
            self.assertEqual(1, len(internal_subnets))
        else:
            self.assertFalse(mgr.ensure_bd_created_on_apic.called)
            self.assertFalse(mgr.ensure_epg_created.called)
            self.assertFalse(mgr.create_tenant_filter.called)
            self.assertFalse(mgr.manage_contract_subject_bi_filter.called)
            self.assertFalse(mgr.set_contract_for_epg.called)

        subnet_id = es['subnet_id']
        self.delete_external_segment(es['id'],
            expected_res_status=webob.exc.HTTPNoContent.code)
        self._get_object('subnets', subnet_id, self.api,
                         expected_res_status=404)
        if self.nat_enabled:
            ctx = "NAT-vrf-%s" % es['id']
            ctx_owner = owner
            contract_owner = owner
            if self.pre_l3out:
                ctx = APIC_PRE_VRF
                ctx_owner = APIC_PRE_VRF_TENANT
                contract_owner = APIC_PRE_L3OUT_TENANT
                self.assertFalse(mgr.ensure_context_enforced.called)
            else:
                mgr.ensure_context_deleted.assert_called_with(
                    ctx_owner, ctx, transaction=mock.ANY)
            mgr.delete_bd_on_apic.assert_called_with(
                owner, "NAT-bd-%s" % es['id'], transaction=mock.ANY)
            mgr.delete_epg_for_network.assert_called_with(
                owner, "NAT-epg-%s" % es['id'], transaction=mock.ANY)
            mgr.delete_contract.assert_called_with(
                prs, owner=contract_owner, transaction=mock.ANY)
            mgr.delete_tenant_filter.assert_called_with(
                prs, owner=contract_owner, transaction=mock.ANY)
        else:
            self.assertFalse(mgr.delete_bd_on_apic.called)
            self.assertFalse(mgr.delete_epg_for_network.called)
            self.assertFalse(mgr.delete_contract.called)
            self.assertFalse(mgr.delete_tenant_filter.called)
dataset/ETHPy150Open openstack/group-based-policy/gbpservice/neutron/tests/unit/services/grouppolicy/test_apic_mapping.py/TestExternalSegment._test_create_delete/swapped operands of `%`