Merge "OVO for Router Route"

This commit is contained in:
Jenkins 2016-10-14 17:35:11 +00:00 committed by Gerrit Code Review
commit 12f1827f5d
4 changed files with 107 additions and 0 deletions

57
neutron/objects/router.py Normal file
View File

@ -0,0 +1,57 @@
# 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.
import netaddr
from oslo_versionedobjects import base as obj_base
from oslo_versionedobjects import fields as obj_fields
from neutron.common import utils
from neutron.db.models import l3
from neutron.objects import base
from neutron.objects import common_types
@obj_base.VersionedObjectRegistry.register
class RouterRoute(base.NeutronDbObject):
# Version 1.0: Intial version
VERSION = '1.0'
db_model = l3.RouterRoute
fields = {
'router_id': obj_fields.UUIDField(),
'destination': common_types.IPNetworkField(),
'nexthop': obj_fields.IPAddressField()
}
primary_keys = ['router_id', 'destination', 'nexthop']
foreign_keys = {'Router': {'router_id': 'id'}}
@classmethod
def modify_fields_from_db(cls, db_obj):
result = super(RouterRoute, cls).modify_fields_from_db(db_obj)
if 'destination' in result:
result['destination'] = utils.AuthenticIPNetwork(
result['destination'])
if 'nexthop' in result:
result['nexthop'] = netaddr.IPAddress(result['nexthop'])
return result
@classmethod
def modify_fields_to_db(cls, fields):
result = super(RouterRoute, cls).modify_fields_to_db(fields)
if 'destination' in result:
result['destination'] = cls.filter_to_str(result['destination'])
if 'nexthop' in result:
result['nexthop'] = cls.filter_to_str(result['nexthop'])
return result

View File

@ -32,6 +32,7 @@ from neutron.common import utils
from neutron import context
from neutron.db import db_base_plugin_v2
from neutron.db import model_base
from neutron.db.models import l3 as l3_model
from neutron.db.models import segment as segments_model
from neutron import objects
from neutron.objects import base
@ -1151,6 +1152,15 @@ class BaseDbObjectTestCase(_BaseObjectTestCase,
self._segment = obj_db_api.create_object(
self.context, segments_model.NetworkSegment, test_segment)
def _create_test_router(self):
attrs = {
'name': 'test_router',
}
# TODO(sindhu): Replace with the router object once its ready
self._router = obj_db_api.create_object(self.context,
l3_model.Router,
attrs)
def _create_test_port(self, network):
self._port = self._create_port(network_id=network['id'])

View File

@ -49,6 +49,7 @@ object_data = {
'QosRuleType': '1.2-e6fd08fcca152c339cbd5e9b94b1b8e7',
'QosPolicy': '1.3-2eb3494f990acae59cb51381e7f99443',
'Route': '1.0-a9883a63b416126f9e345523ec09483b',
'RouterRoute': '1.0-07fc5337c801fb8c6ccfbcc5afb45907',
'SecurityGroup': '1.0-e26b90c409b31fd2e3c6fcec402ac0b9',
'SecurityGroupRule': '1.0-e9b8dace9d48b936c62ad40fe1f339d5',
'Subnet': '1.0-b71e720f45fff2a39759940e010be7d1',

View File

@ -0,0 +1,39 @@
# 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 import router
from neutron.tests.unit.objects import test_base as obj_test_base
from neutron.tests.unit import testlib_api
class RouterRouteIfaceObjectTestCase(
obj_test_base.BaseObjectIfaceTestCase):
_test_class = router.RouterRoute
class RouterRouteDbObjectTestCase(obj_test_base.BaseDbObjectTestCase,
testlib_api.SqlTestCase):
_test_class = router.RouterRoute
def setUp(self):
super(RouterRouteDbObjectTestCase, self).setUp()
for db_obj, obj_field, obj in zip(
self.db_objs, self.obj_fields, self.objs):
self._create_test_router()
db_obj['router_id'] = self._router['id']
obj_field['router_id'] = self._router['id']
obj['router_id'] = self._router['id']