Merge "ProviderResourceAssociation to OVO"

This commit is contained in:
Jenkins 2016-11-22 02:12:11 +00:00 committed by Gerrit Code Review
commit d388d3a757
6 changed files with 88 additions and 19 deletions

View File

@ -18,8 +18,8 @@ from itertools import chain
from oslo_log import log as logging
from neutron.common import _deprecate
from neutron.db import api as db_api
from neutron.db.models import servicetype as st_model
from neutron.objects import servicetype as servicetype_obj
from neutron.services import provider_configuration as pconf
LOG = logging.getLogger(__name__)
@ -73,11 +73,9 @@ class ServiceTypeManager(object):
return providers[0]
def get_provider_names_by_resource_ids(self, context, resource_ids):
query = (
context.session.query(st_model.ProviderResourceAssociation).
filter(st_model.ProviderResourceAssociation.resource_id.in_(
resource_ids)))
return {rec.resource_id: rec.provider_name for rec in query}
objs = servicetype_obj.ProviderResourceAssociation.get_objects(
context, resource_id=resource_ids)
return {rec.resource_id: rec.provider_name for rec in objs}
def add_resource_association(self, context, service_type, provider_name,
resource_id):
@ -87,13 +85,12 @@ class ServiceTypeManager(object):
raise pconf.ServiceProviderNotFound(provider=provider_name,
service_type=service_type)
with db_api.context_manager.writer.using(context):
# we don't actually need service type for association.
# resource_id is unique and belongs to specific service
# which knows its type
assoc = st_model.ProviderResourceAssociation(
provider_name=provider_name, resource_id=resource_id)
context.session.add(assoc)
# we don't actually need service type for association.
# resource_id is unique and belongs to specific service
# which knows its type
servicetype_obj.ProviderResourceAssociation(
context, provider_name=provider_name,
resource_id=resource_id).create()
# NOTE(blogan): the ProviderResourceAssociation relationship will not
# be populated if a resource was created before this. The expire_all
# will force the session to go retrieve the new data when that
@ -106,12 +103,10 @@ class ServiceTypeManager(object):
def del_resource_associations(self, context, resource_ids):
if not resource_ids:
return
with db_api.context_manager.writer.using(context):
(context.session.query(st_model.ProviderResourceAssociation).
filter(
st_model.ProviderResourceAssociation.resource_id.in_(
resource_ids)).
delete(synchronize_session='fetch'))
objs = servicetype_obj.ProviderResourceAssociation.get_objects(
context, resource_id=resource_ids)
for obj in objs:
obj.delete()
_deprecate._MovedGlobals()

View File

@ -0,0 +1,35 @@
# Copyright (c) 2016 Intel Corporation.
# All Rights Reserved.
#
# 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 import servicetype as models
from neutron.objects import base
@obj_base.VersionedObjectRegistry.register
class ProviderResourceAssociation(base.NeutronDbObject):
# Version 1.0: Initial version
VERSION = '1.0'
db_model = models.ProviderResourceAssociation
primary_keys = ['provider_name', 'resource_id']
fields = {
'provider_name': obj_fields.StringField(),
'resource_id': obj_fields.UUIDField(),
}

View File

@ -36,6 +36,8 @@ from neutron.tests.unit import testlib_api
_uuid = test_base._uuid
_get_path = test_base._get_path
PLUGIN_NAME = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2'
class ServiceTypeManagerTestCase(testlib_api.SqlTestCase):
def setUp(self):
@ -43,6 +45,7 @@ class ServiceTypeManagerTestCase(testlib_api.SqlTestCase):
provconf.NeutronModule, 'service_providers').start()
super(ServiceTypeManagerTestCase, self).setUp()
self.ctx = context.get_admin_context()
self.setup_coreplugin(PLUGIN_NAME)
def _set_override(self, service_providers):
self.service_providers.return_value = service_providers

View File

@ -46,6 +46,7 @@ object_data = {
'PortBindingLevel': '1.0-de66a4c61a083b8f34319fa9dde5b060',
'PortDNS': '1.0-201cf6d057fde75539c3d1f2bbf05902',
'PortSecurity': '1.0-b30802391a87945ee9c07582b4ff95e3',
'ProviderResourceAssociation': '1.0-05ab2d5a3017e5ce9dd381328f285f34',
'QosBandwidthLimitRule': '1.2-4e44a8f5c2895ab1278399f87b40a13d',
'QosDscpMarkingRule': '1.2-0313c6554b34fd10c753cb63d638256c',
'QosMinimumBandwidthRule': '1.2-314c3419f4799067cc31cc319080adff',

View File

@ -0,0 +1,31 @@
# Copyright (c) 2016 Intel Corporation.
# All Rights Reserved.
#
# 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 import servicetype
from neutron.tests.unit.objects import test_base as obj_test_base
from neutron.tests.unit import testlib_api
class ProviderResourceAssociationIfaceObjectTestCase(
obj_test_base.BaseObjectIfaceTestCase):
_test_class = servicetype.ProviderResourceAssociation
class ProviderResourceAssociationDbObjectTestCase(
obj_test_base.BaseDbObjectTestCase,
testlib_api.SqlTestCase):
_test_class = servicetype.ProviderResourceAssociation

View File

@ -27,10 +27,14 @@ from neutron.tests import base
from neutron.tests.unit import testlib_api
DB_PLUGIN_KLASS = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2'
class TestDriverController(testlib_api.SqlTestCase):
def setUp(self):
super(TestDriverController, self).setUp()
self.setup_coreplugin(DB_PLUGIN_KLASS)
self.fake_l3 = mock.Mock()
self.dc = driver_controller.DriverController(self.fake_l3)
self.ctx = context.get_admin_context()