Integration of Allocation/Endpoints OVO
This patch integrates the Oslo-Versioned Objects created for VlanAllocation, VxlanAllocation, VxlanEndpoints, GreAllocation, GreEndpoints, GeneveAllocation and GeneveEndpoints into the code base. Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db Change-Id: I0d592bae452876b24c28ca4cc4bf6392b5ab6493 Co-Authored-By: Victor Morales <victor.morales@intel.com>changes/10/367810/42
parent
fd0003aba7
commit
995e646b11
|
@ -24,6 +24,7 @@ from oslo_log import log
|
|||
from neutron._i18n import _LE
|
||||
from neutron.common import exceptions as exc
|
||||
from neutron.db import api as db_api
|
||||
from neutron.objects import base as base_obj
|
||||
from neutron.plugins.common import utils as p_utils
|
||||
from neutron.plugins.ml2 import driver_api as api
|
||||
|
||||
|
@ -58,8 +59,11 @@ class SegmentTypeDriver(BaseTypeDriver):
|
|||
|
||||
def __init__(self, model):
|
||||
super(SegmentTypeDriver, self).__init__()
|
||||
self.model = model
|
||||
self.primary_keys = set(dict(model.__table__.columns))
|
||||
if issubclass(model, base_obj.NeutronDbObject):
|
||||
self.model = model.db_model
|
||||
else:
|
||||
self.model = model
|
||||
self.primary_keys = set(dict(self.model.__table__.columns))
|
||||
self.primary_keys.remove("allocated")
|
||||
|
||||
# TODO(ataraday): get rid of this method when old TypeDriver won't be used
|
||||
|
|
|
@ -20,8 +20,7 @@ from oslo_log import log
|
|||
|
||||
from neutron._i18n import _LE
|
||||
from neutron.conf.plugins.ml2.drivers import driver_type
|
||||
from neutron.db.models.plugins.ml2 import geneveallocation \
|
||||
as geneve_model
|
||||
from neutron.objects.plugins.ml2 import geneveallocation as geneve_obj
|
||||
from neutron.plugins.common import constants as p_const
|
||||
from neutron.plugins.ml2.drivers import type_tunnel
|
||||
|
||||
|
@ -33,8 +32,8 @@ driver_type.register_ml2_drivers_geneve_opts()
|
|||
class GeneveTypeDriver(type_tunnel.EndpointTunnelTypeDriver):
|
||||
|
||||
def __init__(self):
|
||||
super(GeneveTypeDriver, self).__init__(geneve_model.GeneveAllocation,
|
||||
geneve_model.GeneveEndpoints)
|
||||
super(GeneveTypeDriver, self).__init__(geneve_obj.GeneveAllocation,
|
||||
geneve_obj.GeneveEndpoint)
|
||||
self.max_encap_size = cfg.CONF.ml2_type_geneve.max_header_size
|
||||
|
||||
def get_type(self):
|
||||
|
|
|
@ -19,7 +19,7 @@ from oslo_log import log
|
|||
|
||||
from neutron._i18n import _LE
|
||||
from neutron.conf.plugins.ml2.drivers import driver_type
|
||||
from neutron.db.models.plugins.ml2 import gre_allocation_endpoints as gre_model
|
||||
from neutron.objects.plugins.ml2 import greallocation as gre_obj
|
||||
from neutron.plugins.common import constants as p_const
|
||||
from neutron.plugins.ml2.drivers import type_tunnel
|
||||
|
||||
|
@ -32,7 +32,7 @@ class GreTypeDriver(type_tunnel.EndpointTunnelTypeDriver):
|
|||
|
||||
def __init__(self):
|
||||
super(GreTypeDriver, self).__init__(
|
||||
gre_model.GreAllocation, gre_model.GreEndpoints)
|
||||
gre_obj.GreAllocation, gre_obj.GreEndpoint)
|
||||
|
||||
def get_type(self):
|
||||
return p_const.TYPE_GRE
|
||||
|
|
|
@ -30,6 +30,7 @@ from sqlalchemy import or_
|
|||
from neutron._i18n import _, _LI, _LW
|
||||
from neutron.common import topics
|
||||
from neutron.db import api as db_api
|
||||
from neutron.objects import base as base_obj
|
||||
from neutron.plugins.common import constants as p_const
|
||||
from neutron.plugins.common import utils as plugin_utils
|
||||
from neutron.plugins.ml2.drivers import helpers
|
||||
|
@ -339,7 +340,10 @@ class EndpointTunnelTypeDriver(ML2TunnelTypeDriver):
|
|||
|
||||
def __init__(self, segment_model, endpoint_model):
|
||||
super(EndpointTunnelTypeDriver, self).__init__(segment_model)
|
||||
self.endpoint_model = endpoint_model
|
||||
if issubclass(endpoint_model, base_obj.NeutronDbObject):
|
||||
self.endpoint_model = endpoint_model.db_model
|
||||
else:
|
||||
self.endpoint_model = endpoint_model
|
||||
self.segmentation_key = next(iter(self.primary_keys))
|
||||
|
||||
def get_endpoint_by_host(self, host):
|
||||
|
|
|
@ -25,7 +25,7 @@ from six import moves
|
|||
from neutron._i18n import _, _LE, _LI, _LW
|
||||
from neutron.conf.plugins.ml2.drivers import driver_type
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.models.plugins.ml2 import vlanallocation as vlan_alloc_model
|
||||
from neutron.objects.plugins.ml2 import vlanallocation as vlanalloc
|
||||
from neutron.plugins.common import constants as p_const
|
||||
from neutron.plugins.common import utils as plugin_utils
|
||||
from neutron.plugins.ml2.drivers import helpers
|
||||
|
@ -47,7 +47,7 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
|
|||
"""
|
||||
|
||||
def __init__(self):
|
||||
super(VlanTypeDriver, self).__init__(vlan_alloc_model.VlanAllocation)
|
||||
super(VlanTypeDriver, self).__init__(vlanalloc.VlanAllocation)
|
||||
self._parse_network_vlan_ranges()
|
||||
|
||||
def _parse_network_vlan_ranges(self):
|
||||
|
@ -66,11 +66,11 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
|
|||
with db_api.context_manager.writer.using(ctx):
|
||||
# get existing allocations for all physical networks
|
||||
allocations = dict()
|
||||
allocs = ctx.session.query(vlan_alloc_model.VlanAllocation)
|
||||
allocs = vlanalloc.VlanAllocation.get_objects(ctx)
|
||||
for alloc in allocs:
|
||||
if alloc.physical_network not in allocations:
|
||||
allocations[alloc.physical_network] = set()
|
||||
allocations[alloc.physical_network].add(alloc)
|
||||
allocations[alloc.physical_network] = list()
|
||||
allocations[alloc.physical_network].append(alloc)
|
||||
|
||||
# process vlan ranges for each configured physical network
|
||||
for (physical_network,
|
||||
|
@ -103,23 +103,22 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
|
|||
# values to True while our transaction is
|
||||
# open so we don't accidentally delete
|
||||
# allocated segments. If someone has already
|
||||
# allocated, count will return 0 so we don't
|
||||
# delete.
|
||||
count = allocs.filter_by(
|
||||
# allocated, update_objects will return 0 so we
|
||||
# don't delete.
|
||||
if vlanalloc.VlanAllocation.update_objects(
|
||||
ctx, values={'allocated': False},
|
||||
allocated=False, vlan_id=alloc.vlan_id,
|
||||
physical_network=physical_network
|
||||
).update({"allocated": False})
|
||||
if count:
|
||||
ctx.session.delete(alloc)
|
||||
physical_network=physical_network):
|
||||
alloc.delete()
|
||||
del allocations[physical_network]
|
||||
|
||||
# add missing allocatable vlans to table
|
||||
for vlan_id in sorted(vlan_ids):
|
||||
alloc = vlan_alloc_model.VlanAllocation(
|
||||
physical_network=physical_network,
|
||||
vlan_id=vlan_id,
|
||||
allocated=False)
|
||||
ctx.session.add(alloc)
|
||||
alloc = vlanalloc.VlanAllocation(
|
||||
ctx,
|
||||
physical_network=physical_network,
|
||||
vlan_id=vlan_id, allocated=False)
|
||||
alloc.create()
|
||||
|
||||
# remove from table unallocated vlans for any unconfigured
|
||||
# physical networks
|
||||
|
@ -220,21 +219,23 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
|
|||
|
||||
ranges = self.network_vlan_ranges.get(physical_network, [])
|
||||
inside = any(lo <= vlan_id <= hi for lo, hi in ranges)
|
||||
count = False
|
||||
|
||||
with db_api.context_manager.writer.using(context):
|
||||
query = (context.session.query(vlan_alloc_model.VlanAllocation).
|
||||
filter_by(physical_network=physical_network,
|
||||
vlan_id=vlan_id))
|
||||
if inside:
|
||||
count = query.update({"allocated": False})
|
||||
if count:
|
||||
alloc = vlanalloc.VlanAllocation.get_object(
|
||||
context, physical_network=physical_network, vlan_id=vlan_id)
|
||||
if alloc:
|
||||
if inside and alloc.allocated:
|
||||
count = True
|
||||
alloc.allocated = False
|
||||
alloc.update()
|
||||
LOG.debug("Releasing vlan %(vlan_id)s on physical "
|
||||
"network %(physical_network)s to pool",
|
||||
{'vlan_id': vlan_id,
|
||||
'physical_network': physical_network})
|
||||
else:
|
||||
count = query.delete()
|
||||
if count:
|
||||
else:
|
||||
count = True
|
||||
alloc.delete()
|
||||
LOG.debug("Releasing vlan %(vlan_id)s on physical "
|
||||
"network %(physical_network)s outside pool",
|
||||
{'vlan_id': vlan_id,
|
||||
|
|
|
@ -19,7 +19,7 @@ from oslo_log import log
|
|||
|
||||
from neutron._i18n import _LE
|
||||
from neutron.conf.plugins.ml2.drivers import driver_type
|
||||
from neutron.db.models.plugins.ml2 import vxlanallocation as vxlan_model
|
||||
from neutron.objects.plugins.ml2 import vxlanallocation as vxlan_obj
|
||||
from neutron.plugins.common import constants as p_const
|
||||
from neutron.plugins.ml2.drivers import type_tunnel
|
||||
|
||||
|
@ -32,7 +32,7 @@ class VxlanTypeDriver(type_tunnel.EndpointTunnelTypeDriver):
|
|||
|
||||
def __init__(self):
|
||||
super(VxlanTypeDriver, self).__init__(
|
||||
vxlan_model.VxlanAllocation, vxlan_model.VxlanEndpoints)
|
||||
vxlan_obj.VxlanAllocation, vxlan_obj.VxlanEndpoint)
|
||||
|
||||
def get_type(self):
|
||||
return p_const.TYPE_VXLAN
|
||||
|
|
|
@ -20,7 +20,7 @@ from neutron_lib.plugins.ml2 import api
|
|||
from testtools import matchers
|
||||
|
||||
from neutron.db import api as db_api
|
||||
from neutron.db.models.plugins.ml2 import vlanallocation as vlan_alloc_model
|
||||
from neutron.objects.plugins.ml2 import vlanallocation as vlan_alloc_obj
|
||||
from neutron.plugins.common import constants as p_const
|
||||
from neutron.plugins.common import utils as plugin_utils
|
||||
from neutron.plugins.ml2 import config
|
||||
|
@ -37,6 +37,7 @@ UPDATED_VLAN_RANGES = {
|
|||
PROVIDER_NET: [],
|
||||
TENANT_NET: [(VLAN_MIN + 5, VLAN_MAX + 5)],
|
||||
}
|
||||
CORE_PLUGIN = 'ml2'
|
||||
|
||||
|
||||
class VlanTypeTest(testlib_api.SqlTestCase):
|
||||
|
@ -52,6 +53,7 @@ class VlanTypeTest(testlib_api.SqlTestCase):
|
|||
self.driver._sync_vlan_allocations()
|
||||
self.context = context.Context()
|
||||
self.driver.physnet_mtus = []
|
||||
self.setup_coreplugin(CORE_PLUGIN)
|
||||
|
||||
def test_parse_network_exception_handling(self):
|
||||
with mock.patch.object(plugin_utils,
|
||||
|
@ -62,10 +64,10 @@ class VlanTypeTest(testlib_api.SqlTestCase):
|
|||
|
||||
@db_api.context_manager.reader
|
||||
def _get_allocation(self, context, segment):
|
||||
return context.session.query(
|
||||
vlan_alloc_model.VlanAllocation).filter_by(
|
||||
return vlan_alloc_obj.VlanAllocation.get_object(
|
||||
context,
|
||||
physical_network=segment[api.PHYSICAL_NETWORK],
|
||||
vlan_id=segment[api.SEGMENTATION_ID]).first()
|
||||
vlan_id=segment[api.SEGMENTATION_ID])
|
||||
|
||||
def test_partial_segment_is_partial_segment(self):
|
||||
segment = {api.NETWORK_TYPE: p_const.TYPE_VLAN}
|
||||
|
|
Loading…
Reference in New Issue