From f68cda0242658ef3fdaff77e2e68d478f29fda6e Mon Sep 17 00:00:00 2001 From: Artur Korzeniewski Date: Thu, 11 Aug 2016 08:34:48 +0200 Subject: [PATCH] Introduce ovo objects for network segments This patch adds an object definition for network segments. It does not integrate the object into existing database code to quicken its delivery for push notifications effort. Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db Partially-Implements: blueprint push-notifications Change-Id: I7708b7a50aa9c9c72bdd1eb5bf9dffd9a43e9285 Co-Authored-By: Artur Korzeniewski --- neutron/objects/network/network_segment.py | 37 +++++++++++++++++++ .../objects/network/test_network_segment.py | 36 ++++++++++++++++++ neutron/tests/unit/objects/test_objects.py | 1 + 3 files changed, 74 insertions(+) create mode 100644 neutron/objects/network/network_segment.py create mode 100644 neutron/tests/unit/objects/network/test_network_segment.py diff --git a/neutron/objects/network/network_segment.py b/neutron/objects/network/network_segment.py new file mode 100644 index 00000000000..9f8c0c6d4f4 --- /dev/null +++ b/neutron/objects/network/network_segment.py @@ -0,0 +1,37 @@ +# 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 import segments_db as segment_model +from neutron.objects import base + + +@obj_base.VersionedObjectRegistry.register +class NetworkSegment(base.NeutronDbObject): + # Version 1.0: Initial version + VERSION = '1.0' + + db_model = segment_model.NetworkSegment + + fields = { + 'id': obj_fields.UUIDField(), + 'network_id': obj_fields.UUIDField(), + 'network_type': obj_fields.StringField(), + 'physical_network': obj_fields.StringField(nullable=True), + 'segmentation_id': obj_fields.IntegerField(nullable=True), + 'is_dynamic': obj_fields.BooleanField(default=False), + 'segment_index': obj_fields.IntegerField(default=0) + } + + foreign_keys = {'network_id': 'id'} diff --git a/neutron/tests/unit/objects/network/test_network_segment.py b/neutron/tests/unit/objects/network/test_network_segment.py new file mode 100644 index 00000000000..1008af9572f --- /dev/null +++ b/neutron/tests/unit/objects/network/test_network_segment.py @@ -0,0 +1,36 @@ +# 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. + +import itertools + +from neutron.objects.network import network_segment +from neutron.tests.unit.objects import test_base as obj_test_base +from neutron.tests.unit import testlib_api + + +class NetworkSegmentIfaceObjectTestCase(obj_test_base.BaseObjectIfaceTestCase): + + _test_class = network_segment.NetworkSegment + + +class NetworkSegmentDbObjectTestCase(obj_test_base.BaseDbObjectTestCase, + testlib_api.SqlTestCase): + + _test_class = network_segment.NetworkSegment + + def setUp(self): + super(NetworkSegmentDbObjectTestCase, self).setUp() + self._create_test_network() + for obj in itertools.chain(self.db_objs, self.obj_fields): + obj['network_id'] = self._network['id'] diff --git a/neutron/tests/unit/objects/test_objects.py b/neutron/tests/unit/objects/test_objects.py index 2820d2dd52b..3d6c044985f 100644 --- a/neutron/tests/unit/objects/test_objects.py +++ b/neutron/tests/unit/objects/test_objects.py @@ -32,6 +32,7 @@ object_data = { 'ExtraDhcpOpt': '1.0-632f689cbeb36328995a7aed1d0a78d3', 'IPAllocationPool': '1.0-371016a6480ed0b4299319cb46d9215d', 'NetworkPortSecurity': '1.0-b30802391a87945ee9c07582b4ff95e3', + 'NetworkSegment': '1.0-865567a6f70eb85cf33fb7a5575a4eab', 'PortSecurity': '1.0-b30802391a87945ee9c07582b4ff95e3', 'AllowedAddressPair': '1.0-9f9186b6f952fbf31d257b0458b852c0', 'QosBandwidthLimitRule': '1.1-4e44a8f5c2895ab1278399f87b40a13d',