# Path: apic_ml2/neutron/db/l3out_vlan_allocation.py
# LOG = log.getLogger(__name__)
# class L3OutVlanAllocation(model_base.BASEV2):
# class NoVlanAvailable(exc.ResourceExhausted):
# class L3outVlanAlloc(helpers.SegmentTypeDriver):
#     def __init__(self):
#     def _parse_vlan_ranges(self, ext_net_dict):
#     def sync_vlan_allocations(self, ext_net_dict):
#     def get_type(self):
#     def reserve_vlan(self, l3out_network, vrf, vrf_tenant=None):
#     def release_vlan(self, l3out_network, vrf, vrf_tenant=None):
#     def get_vlan_allocated(l3out_network, vrf, vrf_tenant=None):
#     def _get_vrf_name_db(vrf, vrf_tenant):
#     def initialize(self):
#     def is_partial_segment(self, segment):
#     def validate_provider_segment(self, segment):
#     def reserve_provider_segment(self, session, segment):
#     def allocate_tenant_segment(self, session):
#     def release_segment(self, session, segment):


from neutron import context
from neutron.tests.unit import testlib_api
from oslo_log import log
from apic_ml2.neutron.db import l3out_vlan_allocation as l3out_vlan_alloc

    def test_reserve_vlan(self):
        vlan_ranges = self.l3out_vlan_alloc.l3out_vlan_ranges[
            'Mgmt-Out']
        vlan_min = 4096
        vlan_max = 0
        for (min, max) in vlan_ranges:
            LOG.info(("vlan range: %d - %d"), min, max)
            if max > vlan_max:
                vlan_max = max
            if min < vlan_min:
                vlan_min = min

        vlan_id1 = self.l3out_vlan_alloc.reserve_vlan('Mgmt-Out', 'admin',
                                                      'tenant1')
        LOG.info(("vlan reserved: %d"), vlan_id1)
        self.assertTrue(vlan_min <= vlan_id1 <= vlan_max)

        # it should reserve the same vlan with the same l3 network + vrf
        vlan_id2 = self.l3out_vlan_alloc.reserve_vlan('Mgmt-Out', 'admin',
                                                      'tenant1')
        self.assertEqual(vlan_id1, vlan_id2)

        vlan_id3 = self.l3out_vlan_alloc.reserve_vlan('Mgmt-Out', 'demo')
        LOG.info(("vlan reserved: %d"), vlan_id3)
        self.assertTrue(vlan_min <= vlan_id3 <= vlan_max)

    def test_exception_thrown_reserve_vlan_when_full(self):
        vlan_id1 = self.l3out_vlan_alloc.reserve_vlan('Mgmt-Out', 'test1',
                                                      'tenant1')

# Path: apic_ml2/neutron/db/l3out_vlan_allocation.py
# LOG = log.getLogger(__name__)
# class L3OutVlanAllocation(model_base.BASEV2):
# class NoVlanAvailable(exc.ResourceExhausted):
# class L3outVlanAlloc(helpers.SegmentTypeDriver):
#     def __init__(self):
#     def _parse_vlan_ranges(self, ext_net_dict):
#     def sync_vlan_allocations(self, ext_net_dict):
#     def get_type(self):
#     def reserve_vlan(self, l3out_network, vrf, vrf_tenant=None):
#     def release_vlan(self, l3out_network, vrf, vrf_tenant=None):
#     def get_vlan_allocated(l3out_network, vrf, vrf_tenant=None):
#     def _get_vrf_name_db(vrf, vrf_tenant):
#     def initialize(self):
#     def is_partial_segment(self, segment):
#     def validate_provider_segment(self, segment):
#     def reserve_provider_segment(self, session, segment):
#     def allocate_tenant_segment(self, session):
#     def release_segment(self, session, segment):


# Path: apic_ml2/neutron/tests/unit/db/test_l3out_vlan_allocation.py
from neutron import context
from neutron.tests.unit import testlib_api
from oslo_log import log
from apic_ml2.neutron.db import l3out_vlan_allocation as l3out_vlan_alloc


    def test_reserve_vlan(self):
        vlan_ranges = self.l3out_vlan_alloc.l3out_vlan_ranges[
            'Mgmt-Out']
        vlan_min = 4096
        vlan_max = 0
        for (min, max) in vlan_ranges:
            LOG.info(("vlan range: %d - %d"), min, max)
            if max > vlan_max:
                vlan_max = max
            if min < vlan_min:
                vlan_min = min

        vlan_id1 = self.l3out_vlan_alloc.reserve_vlan('Mgmt-Out', 'admin',
                                                      'tenant1')
        LOG.info(("vlan reserved: %d"), vlan_id1)
        self.assertTrue(vlan_min <= vlan_id1 <= vlan_max)

        # it should reserve the same vlan with the same l3 network + vrf
        vlan_id2 = self.l3out_vlan_alloc.reserve_vlan('Mgmt-Out', 'admin',
                                                      'tenant1')
        self.assertEqual(vlan_id1, vlan_id2)

        vlan_id3 = self.l3out_vlan_alloc.reserve_vlan('Mgmt-Out', 'demo')
        LOG.info(("vlan reserved: %d"), vlan_id3)
        self.assertTrue(vlan_min <= vlan_id3 <= vlan_max)

    def test_exception_thrown_reserve_vlan_when_full(self):
        vlan_id1 = self.l3out_vlan_alloc.reserve_vlan('Mgmt-Out', 'test1',
                                                      'tenant1')

        vlan_id2 = self.l3out_vlan_alloc.reserve_vlan('Mgmt-Out', 'test2',