Merge "OVO for FlatAllocation"
This commit is contained in:
commit
9b163bb86a
|
@ -0,0 +1,32 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from oslo_versionedobjects import base as obj_base
|
||||
from oslo_versionedobjects import fields as obj_fields
|
||||
|
||||
from neutron.db.models.plugins.ml2 import flatallocation
|
||||
from neutron.objects import base
|
||||
|
||||
|
||||
@obj_base.VersionedObjectRegistry.register
|
||||
class FlatAllocation(base.NeutronDbObject):
|
||||
# Version 1.0: Initial Version
|
||||
VERSION = '1.0'
|
||||
|
||||
db_model = flatallocation.FlatAllocation
|
||||
|
||||
fields = {
|
||||
'physical_network': obj_fields.StringField()
|
||||
}
|
||||
|
||||
primary_keys = ['physical_network']
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
from neutron_lib import exceptions as exc
|
||||
from oslo_config import cfg
|
||||
from oslo_db import exception as db_exc
|
||||
from oslo_log import log
|
||||
import six
|
||||
|
||||
|
@ -24,6 +23,8 @@ from neutron.common import _deprecate
|
|||
from neutron.common import exceptions as n_exc
|
||||
from neutron.conf.plugins.ml2.drivers import driver_type
|
||||
from neutron.db.models.plugins.ml2 import flatallocation as type_flat_model
|
||||
from neutron.objects import exceptions as obj_base
|
||||
from neutron.objects.plugins.ml2 import flatallocation as flat_obj
|
||||
from neutron.plugins.common import constants as p_const
|
||||
from neutron.plugins.ml2 import driver_api as api
|
||||
from neutron.plugins.ml2.drivers import helpers
|
||||
|
@ -92,17 +93,17 @@ class FlatTypeDriver(helpers.BaseTypeDriver):
|
|||
|
||||
def reserve_provider_segment(self, context, segment):
|
||||
physical_network = segment[api.PHYSICAL_NETWORK]
|
||||
with context.session.begin(subtransactions=True):
|
||||
try:
|
||||
LOG.debug("Reserving flat network on physical "
|
||||
"network %s", physical_network)
|
||||
alloc = type_flat_model.FlatAllocation(
|
||||
physical_network=physical_network)
|
||||
alloc.save(context.session)
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise n_exc.FlatNetworkInUse(
|
||||
physical_network=physical_network)
|
||||
segment[api.MTU] = self.get_mtu(alloc.physical_network)
|
||||
try:
|
||||
LOG.debug("Reserving flat network on physical "
|
||||
"network %s", physical_network)
|
||||
alloc = flat_obj.FlatAllocation(
|
||||
context,
|
||||
physical_network=physical_network)
|
||||
alloc.create()
|
||||
except obj_base.NeutronDbObjectDuplicateEntry:
|
||||
raise n_exc.FlatNetworkInUse(
|
||||
physical_network=physical_network)
|
||||
segment[api.MTU] = self.get_mtu(alloc.physical_network)
|
||||
return segment
|
||||
|
||||
def allocate_tenant_segment(self, context):
|
||||
|
@ -112,15 +113,17 @@ class FlatTypeDriver(helpers.BaseTypeDriver):
|
|||
def release_segment(self, context, segment):
|
||||
physical_network = segment[api.PHYSICAL_NETWORK]
|
||||
with context.session.begin(subtransactions=True):
|
||||
count = (context.session.query(type_flat_model.FlatAllocation).
|
||||
filter_by(physical_network=physical_network).
|
||||
delete())
|
||||
if count:
|
||||
LOG.debug("Releasing flat network on physical network %s",
|
||||
physical_network)
|
||||
else:
|
||||
LOG.warning(_LW("No flat network found on physical network %s"),
|
||||
physical_network)
|
||||
obj = flat_obj.FlatAllocation.get_object(
|
||||
context,
|
||||
physical_network=physical_network)
|
||||
if obj:
|
||||
obj.delete()
|
||||
LOG.debug("Releasing flat network on physical network %s",
|
||||
physical_network)
|
||||
else:
|
||||
LOG.warning(_LW(
|
||||
"No flat network found on physical network %s"),
|
||||
physical_network)
|
||||
|
||||
def get_mtu(self, physical_network):
|
||||
seg_mtu = super(FlatTypeDriver, self).get_mtu()
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
# Copyright (c) 2016 Intel Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from neutron.objects.plugins.ml2 import flatallocation
|
||||
from neutron.tests.unit.objects import test_base
|
||||
from neutron.tests.unit import testlib_api
|
||||
|
||||
|
||||
class FlatAllocationIfaceObjTestCase(test_base.BaseObjectIfaceTestCase):
|
||||
|
||||
_test_class = flatallocation.FlatAllocation
|
||||
|
||||
|
||||
class FlatAllocationDbObjTestCase(test_base.BaseDbObjectTestCase,
|
||||
testlib_api.SqlTestCase):
|
||||
|
||||
_test_class = flatallocation.FlatAllocation
|
|
@ -34,6 +34,7 @@ object_data = {
|
|||
'DistributedPortBinding': '1.0-4df058ae1aeae3ae1c15b8f6a4c692d9',
|
||||
'DNSNameServer': '1.0-bf87a85327e2d812d1666ede99d9918b',
|
||||
'ExtraDhcpOpt': '1.0-632f689cbeb36328995a7aed1d0a78d3',
|
||||
'FlatAllocation': '1.0-bf666f24f4642b047eeca62311fbcb41',
|
||||
'FloatingIPDNS': '1.0-ee3db848500fa1825235f701828c06d5',
|
||||
'GeneveAllocation': '1.0-d5f76e8eac60a778914d61dd8e23e90f',
|
||||
'GeneveEndpoint': '1.0-040f026996b5952e2ae4ccd40ac61ca6',
|
||||
|
|
|
@ -17,7 +17,7 @@ from neutron_lib import exceptions as exc
|
|||
|
||||
from neutron.common import exceptions as n_exc
|
||||
from neutron import context
|
||||
from neutron.db.models.plugins.ml2 import flatallocation as type_flat_model
|
||||
from neutron.objects.plugins.ml2 import flatallocation as flat_obj
|
||||
from neutron.plugins.common import constants as p_const
|
||||
from neutron.plugins.ml2 import config
|
||||
from neutron.plugins.ml2 import driver_api as api
|
||||
|
@ -27,12 +27,14 @@ from neutron.tests.unit import testlib_api
|
|||
|
||||
|
||||
FLAT_NETWORKS = ['flat_net1', 'flat_net2']
|
||||
CORE_PLUGIN = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2'
|
||||
|
||||
|
||||
class FlatTypeTest(testlib_api.SqlTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(FlatTypeTest, self).setUp()
|
||||
self.setup_coreplugin(CORE_PLUGIN)
|
||||
config.cfg.CONF.set_override('flat_networks', FLAT_NETWORKS,
|
||||
group='ml2_type_flat')
|
||||
self.driver = type_flat.FlatTypeDriver()
|
||||
|
@ -40,8 +42,8 @@ class FlatTypeTest(testlib_api.SqlTestCase):
|
|||
self.driver.physnet_mtus = []
|
||||
|
||||
def _get_allocation(self, context, segment):
|
||||
return context.session.query(type_flat_model.FlatAllocation).filter_by(
|
||||
physical_network=segment[api.PHYSICAL_NETWORK]).first()
|
||||
return flat_obj.FlatAllocation.get_object(
|
||||
context, physical_network=segment[api.PHYSICAL_NETWORK])
|
||||
|
||||
def test_is_partial_segment(self):
|
||||
segment = {api.NETWORK_TYPE: p_const.TYPE_FLAT,
|
||||
|
|
Loading…
Reference in New Issue