From 4c45d1ee80ad51049ff03af8b3d2d3ad782231fc Mon Sep 17 00:00:00 2001 From: Shashank Kumar Shankar Date: Thu, 18 Aug 2016 20:40:16 +0000 Subject: [PATCH] OVO for Provisioning Block DB Model This patch introduces OVO for Provisioning Block DB Model. Change-Id: I1ac68ad1acfa116c09e0adfa119db0b2cad125d4 Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db --- neutron/objects/provisioning_blocks.py | 32 +++++++++++++++++ neutron/tests/unit/objects/test_base.py | 12 +++++++ neutron/tests/unit/objects/test_objects.py | 1 + .../unit/objects/test_provisioning_blocks.py | 35 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 neutron/objects/provisioning_blocks.py create mode 100644 neutron/tests/unit/objects/test_provisioning_blocks.py diff --git a/neutron/objects/provisioning_blocks.py b/neutron/objects/provisioning_blocks.py new file mode 100644 index 00000000000..0914eab150b --- /dev/null +++ b/neutron/objects/provisioning_blocks.py @@ -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 import provisioning_block as pb_model +from neutron.objects import base + + +@obj_base.VersionedObjectRegistry.register +class ProvisioningBlock(base.NeutronDbObject): + # Version 1.0: Initial version + VERSION = '1.0' + + db_model = pb_model.ProvisioningBlock + + fields = { + 'standard_attr_id': obj_fields.IntegerField(), + 'entity': obj_fields.StringField() + } + + primary_keys = ['standard_attr_id', 'entity'] diff --git a/neutron/tests/unit/objects/test_base.py b/neutron/tests/unit/objects/test_base.py index 3b6c9cc5c79..f4b569f147c 100644 --- a/neutron/tests/unit/objects/test_base.py +++ b/neutron/tests/unit/objects/test_base.py @@ -34,6 +34,7 @@ from neutron.db import db_base_plugin_v2 from neutron.db import model_base from neutron.db.models import external_net as ext_net_model from neutron.db.models import l3 as l3_model +from neutron.db import standard_attr from neutron import objects from neutron.objects import base from neutron.objects import common_types @@ -1209,6 +1210,17 @@ class BaseDbObjectTestCase(_BaseObjectTestCase, def _create_test_port(self, network): self._port = self._create_port(network_id=network['id']) + def _create_test_standard_attribute(self): + attrs = { + 'id': tools.get_random_integer(), + 'resource_type': tools.get_random_string(4), + 'revision_number': tools.get_random_integer() + } + self._standard_attribute = obj_db_api.create_object( + self.context, + standard_attr.StandardAttribute, + attrs) + def _make_object(self, fields): fields = get_non_synthetic_fields(self._test_class, fields) return self._test_class(self.context, diff --git a/neutron/tests/unit/objects/test_objects.py b/neutron/tests/unit/objects/test_objects.py index 5598242efde..91f3859ddb7 100644 --- a/neutron/tests/unit/objects/test_objects.py +++ b/neutron/tests/unit/objects/test_objects.py @@ -47,6 +47,7 @@ object_data = { 'PortDNS': '1.0-201cf6d057fde75539c3d1f2bbf05902', 'PortSecurity': '1.0-b30802391a87945ee9c07582b4ff95e3', 'ProviderResourceAssociation': '1.0-05ab2d5a3017e5ce9dd381328f285f34', + 'ProvisioningBlock': '1.0-c19d6d05bfa8143533471c1296066125', 'QosBandwidthLimitRule': '1.2-4e44a8f5c2895ab1278399f87b40a13d', 'QosDscpMarkingRule': '1.2-0313c6554b34fd10c753cb63d638256c', 'QosMinimumBandwidthRule': '1.2-314c3419f4799067cc31cc319080adff', diff --git a/neutron/tests/unit/objects/test_provisioning_blocks.py b/neutron/tests/unit/objects/test_provisioning_blocks.py new file mode 100644 index 00000000000..979085d6f26 --- /dev/null +++ b/neutron/tests/unit/objects/test_provisioning_blocks.py @@ -0,0 +1,35 @@ +# 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 import provisioning_blocks +from neutron.tests.unit.objects import test_base as obj_test_base +from neutron.tests.unit import testlib_api + + +class ProvisioningBlockIfaceObjectTestCase( + obj_test_base.BaseObjectIfaceTestCase): + + _test_class = provisioning_blocks.ProvisioningBlock + + +class ProvisioningBlockDbObjectTestCase(obj_test_base.BaseDbObjectTestCase, + testlib_api.SqlTestCase): + + _test_class = provisioning_blocks.ProvisioningBlock + + def setUp(self): + super(ProvisioningBlockDbObjectTestCase, self).setUp() + self._create_test_standard_attribute() + for obj in itertools.chain(self.db_objs, self.obj_fields, self.objs): + obj['standard_attr_id'] = self._standard_attribute['id']