From 5e08a9b0e7d4f99d217ca73c6aa37e52a13c5d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Kap=C5=82o=C5=84ski?= Date: Tue, 14 Nov 2017 20:36:39 +0000 Subject: [PATCH] [OVO] Switch to use own registry Neutron will now use own registry for versionedobjects. It avoids problems with loading wrong OVO objects from different projects (like os_vif) when names are the same. Change-Id: I9d4fab591fbe52271c613251321a6d03078976f7 Closes-Bug: #1731948 --- neutron/objects/address_scope.py | 3 +- neutron/objects/agent.py | 3 +- neutron/objects/auto_allocate.py | 3 +- neutron/objects/base.py | 77 ++++++++++++++++++- neutron/objects/flavor.py | 7 +- neutron/objects/floatingip.py | 3 +- neutron/objects/ipam.py | 7 +- neutron/objects/l3_hamode.py | 7 +- neutron/objects/l3agent.py | 3 +- neutron/objects/logapi/logging_resource.py | 3 +- neutron/objects/metering.py | 5 +- neutron/objects/network.py | 15 ++-- neutron/objects/plugins/ml2/flatallocation.py | 3 +- .../objects/plugins/ml2/geneveallocation.py | 5 +- neutron/objects/plugins/ml2/greallocation.py | 5 +- neutron/objects/plugins/ml2/vlanallocation.py | 3 +- .../objects/plugins/ml2/vxlanallocation.py | 5 +- .../port/extensions/allowedaddresspairs.py | 3 +- .../port/extensions/data_plane_status.py | 3 +- .../objects/port/extensions/extra_dhcp_opt.py | 3 +- .../objects/port/extensions/port_security.py | 4 +- neutron/objects/ports.py | 13 ++-- neutron/objects/provisioning_blocks.py | 3 +- neutron/objects/qos/binding.py | 5 +- neutron/objects/qos/policy.py | 5 +- neutron/objects/qos/rule.py | 7 +- neutron/objects/qos/rule_type.py | 5 +- neutron/objects/quota.py | 9 +-- neutron/objects/router.py | 11 ++- neutron/objects/securitygroup.py | 7 +- neutron/objects/servicetype.py | 3 +- neutron/objects/subnet.py | 11 ++- neutron/objects/subnetpool.py | 5 +- neutron/objects/tag.py | 3 +- neutron/objects/trunk.py | 5 +- .../api/rpc/handlers/test_resources_rpc.py | 4 +- .../extensions/test_standardattributes.py | 3 +- neutron/tests/unit/objects/test_base.py | 67 ++++++++++------ neutron/tests/unit/objects/test_objects.py | 4 +- neutron/tests/unit/objects/test_rbac_db.py | 4 +- 40 files changed, 203 insertions(+), 141 deletions(-) diff --git a/neutron/objects/address_scope.py b/neutron/objects/address_scope.py index 8fe47b33330..a7a8ad6ece1 100644 --- a/neutron/objects/address_scope.py +++ b/neutron/objects/address_scope.py @@ -12,7 +12,6 @@ # 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 address_scope as models @@ -20,7 +19,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class AddressScope(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/agent.py b/neutron/objects/agent.py index bbae88f39df..18ade02a1ec 100644 --- a/neutron/objects/agent.py +++ b/neutron/objects/agent.py @@ -13,7 +13,6 @@ # under the License. from neutron_lib import constants as const -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields from sqlalchemy import func @@ -27,7 +26,7 @@ from neutron.objects import common_types from neutron.objects import utils as obj_utils -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class Agent(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/auto_allocate.py b/neutron/objects/auto_allocate.py index 33fda388cff..1fce63ec51c 100644 --- a/neutron/objects/auto_allocate.py +++ b/neutron/objects/auto_allocate.py @@ -13,7 +13,6 @@ # 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.objects import base @@ -21,7 +20,7 @@ from neutron.objects import common_types from neutron.services.auto_allocate import models -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class AutoAllocatedTopology(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/base.py b/neutron/objects/base.py index 3124e51134b..ce12b103884 100644 --- a/neutron/objects/base.py +++ b/neutron/objects/base.py @@ -20,8 +20,11 @@ from neutron_lib import exceptions as n_exc from neutron_lib.objects import exceptions as o_exc from oslo_db import exception as obj_exc from oslo_db.sqlalchemy import utils as db_utils +from oslo_log import log as logging from oslo_serialization import jsonutils +from oslo_utils import versionutils from oslo_versionedobjects import base as obj_base +from oslo_versionedobjects import exception as obj_exception from oslo_versionedobjects import fields as obj_fields import six @@ -31,6 +34,9 @@ from neutron.db import standard_attr from neutron.objects.db import api as obj_db_api from neutron.objects.extensions import standardattributes + +LOG = logging.getLogger(__name__) + _NO_DB_MODEL = object() @@ -43,7 +49,7 @@ def get_updatable_fields(cls, fields): def get_object_class_by_model(model): - for obj_class in obj_base.VersionedObjectRegistry.obj_classes().values(): + for obj_class in NeutronObjectRegistry.obj_classes().values(): obj_class = obj_class[0] if getattr(obj_class, 'db_model', _NO_DB_MODEL) is model: return obj_class @@ -93,6 +99,34 @@ class Pager(object): return self.__dict__ == other.__dict__ +class NeutronObjectRegistry(obj_base.VersionedObjectRegistry): + + _registry = None + + def __new__(cls, *args, **kwargs): + # TODO(slaweq): this should be moved back to oslo.versionedobjects + # lib as soon as bug https://bugs.launchpad.net/neutron/+bug/1731948 + # will be fixed and OVO's registry class will support defining custom + # registries for objects. + + # NOTE(slaweq): it is overridden method + # oslo_versionedobjects.base.VersionedObjectRegistry.__new__ + # We need to overwrite it to use separate registry for Neutron's + # objects. + # This is necessary to avoid clash in naming objects between Neutron + # and e.g. os-vif (for example Route or Subnet objects are used in + # both) + if not NeutronObjectRegistry._registry: + NeutronObjectRegistry._registry = object.__new__( + NeutronObjectRegistry, *args, **kwargs) + NeutronObjectRegistry._registry._obj_classes = \ + collections.defaultdict(list) + self = object.__new__(cls, *args, **kwargs) + self._obj_classes = ( + NeutronObjectRegistry._registry._obj_classes) + return self + + @six.add_metaclass(abc.ABCMeta) class NeutronObject(obj_base.VersionedObject, obj_base.VersionedObjectDictCompat, @@ -143,6 +177,45 @@ class NeutronObject(obj_base.VersionedObject, return (isinstance(cls.fields[field], obj_fields.ListOfObjectsField) or isinstance(cls.fields[field], obj_fields.ObjectField)) + @classmethod + def obj_class_from_name(cls, objname, objver): + """Returns a class from the registry based on a name and version.""" + # NOTE(slaweq): it is override method + # oslo_versionedobjects.base.VersionedObject.obj_class_from_name + # We need to override it to use Neutron's objects registry class + # (NeutronObjectRegistry) instead of original VersionedObjectRegistry + # class from oslo_versionedobjects + # This is necessary to avoid clash in naming objects between Neutron + # and e.g. os-vif (for example Route or Subnet objects are used in + # both) + if objname not in NeutronObjectRegistry.obj_classes(): + LOG.error('Unable to instantiate unregistered object type ' + '%(objtype)s', dict(objtype=objname)) + raise obj_exception.UnsupportedObjectError(objtype=objname) + + # NOTE(comstud): If there's not an exact match, return the highest + # compatible version. The objects stored in the class are sorted + # such that highest version is first, so only set compatible_match + # once below. + compatible_match = None + + for objclass in NeutronObjectRegistry.obj_classes()[objname]: + if objclass.VERSION == objver: + return objclass + if (not compatible_match and + versionutils.is_compatible(objver, objclass.VERSION)): + compatible_match = objclass + + if compatible_match: + return compatible_match + + # As mentioned above, latest version is always first in the list. + latest_ver = ( + NeutronObjectRegistry.obj_classes()[objname][0].VERSION) + raise obj_exception.IncompatibleObjectVersion(objname=objname, + objver=objver, + supported=latest_ver) + @classmethod def clean_obj_from_primitive(cls, primitive, context=None): obj = cls.obj_from_primitive(primitive, context) @@ -581,7 +654,7 @@ class NeutronDbObject(NeutronObject): # subclasses=True for field in self.synthetic_fields: try: - objclasses = obj_base.VersionedObjectRegistry.obj_classes( + objclasses = NeutronObjectRegistry.obj_classes( ).get(self.fields[field].objname) except AttributeError: # NOTE(rossella_s) this is probably because this field is not diff --git a/neutron/objects/flavor.py b/neutron/objects/flavor.py index b0f539000a5..b625d9dbfe6 100644 --- a/neutron/objects/flavor.py +++ b/neutron/objects/flavor.py @@ -13,7 +13,6 @@ # 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 flavor as models @@ -21,7 +20,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class FlavorServiceProfileBinding(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -36,7 +35,7 @@ class FlavorServiceProfileBinding(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class ServiceProfile(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -66,7 +65,7 @@ class ServiceProfile(base.NeutronDbObject): self.obj_reset_changes(['flavor_ids']) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class Flavor(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/floatingip.py b/neutron/objects/floatingip.py index b1c3d3d0ff9..885899f496b 100644 --- a/neutron/objects/floatingip.py +++ b/neutron/objects/floatingip.py @@ -12,14 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_versionedobjects import base as obj_base from neutron.db.models import dns as models from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class FloatingIPDNS(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/ipam.py b/neutron/objects/ipam.py index ef0025de9e9..2628ff1f48d 100644 --- a/neutron/objects/ipam.py +++ b/neutron/objects/ipam.py @@ -14,7 +14,6 @@ # under the License. import netaddr -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields from neutron.ipam.drivers.neutrondb_ipam import db_models @@ -22,7 +21,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class IpamAllocationPool(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -59,7 +58,7 @@ class IpamAllocationPool(base.NeutronDbObject): return result -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class IpamAllocation(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -89,7 +88,7 @@ class IpamAllocation(base.NeutronDbObject): return result -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class IpamSubnet(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/l3_hamode.py b/neutron/objects/l3_hamode.py index e50aa4cbde4..837ea93173f 100644 --- a/neutron/objects/l3_hamode.py +++ b/neutron/objects/l3_hamode.py @@ -12,7 +12,6 @@ # 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.common import constants @@ -22,7 +21,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class L3HARouterAgentPortBinding(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -53,7 +52,7 @@ class L3HARouterAgentPortBinding(base.NeutronDbObject): return query.all() -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class L3HARouterNetwork(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -68,7 +67,7 @@ class L3HARouterNetwork(base.NeutronDbObject): primary_keys = ['network_id', 'project_id'] -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class L3HARouterVRIdAllocation(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/l3agent.py b/neutron/objects/l3agent.py index e6db1780201..e7627d99597 100644 --- a/neutron/objects/l3agent.py +++ b/neutron/objects/l3agent.py @@ -10,7 +10,6 @@ # 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 import sqlalchemy as sa from sqlalchemy.orm import joinedload @@ -24,7 +23,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class RouterL3AgentBinding(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/logapi/logging_resource.py b/neutron/objects/logapi/logging_resource.py index a2df707bbfb..21a47b3d43c 100644 --- a/neutron/objects/logapi/logging_resource.py +++ b/neutron/objects/logapi/logging_resource.py @@ -13,7 +13,6 @@ # 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 loggingapi as log_db @@ -23,7 +22,7 @@ from neutron.objects.logapi import event_types from neutron.services.logapi.common import constants as log_const -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class Log(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/metering.py b/neutron/objects/metering.py index 45afc06c1ea..5a460a901eb 100644 --- a/neutron/objects/metering.py +++ b/neutron/objects/metering.py @@ -12,7 +12,6 @@ # 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.common import utils @@ -21,7 +20,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class MeteringLabelRule(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -57,7 +56,7 @@ class MeteringLabelRule(base.NeutronDbObject): return result -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class MeteringLabel(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/network.py b/neutron/objects/network.py index 7af9973e7d8..e78aac1ba83 100644 --- a/neutron/objects/network.py +++ b/neutron/objects/network.py @@ -14,7 +14,6 @@ from neutron_lib.api.definitions import availability_zone as az_def from neutron_lib.api.validators import availability_zone as az_validator -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields from neutron.db import api as db_api @@ -33,7 +32,7 @@ from neutron.objects.qos import binding from neutron.objects import rbac_db -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class NetworkDhcpAgentBinding(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -57,7 +56,7 @@ class NetworkDhcpAgentBinding(base.NeutronDbObject): return cls.get_objects(context, dhcp_agent_id=dhcp_agent_ids) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class NetworkSegment(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -145,7 +144,7 @@ class NetworkSegment(base.NeutronDbObject): **kwargs) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class NetworkPortSecurity(base_ps._PortSecurity): # Version 1.0: Initial version VERSION = "1.0" @@ -155,7 +154,7 @@ class NetworkPortSecurity(base_ps._PortSecurity): fields_need_translation = {'id': 'network_id'} -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class ExternalNetwork(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -172,7 +171,7 @@ class ExternalNetwork(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class Network(rbac_db.NeutronRbacObject): # Version 1.0: Initial version VERSION = '1.0' @@ -306,7 +305,7 @@ class Network(rbac_db.NeutronRbacObject): return set() -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class SegmentHostMapping(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -321,7 +320,7 @@ class SegmentHostMapping(base.NeutronDbObject): primary_keys = ['segment_id', 'host'] -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class NetworkDNSDomain(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/plugins/ml2/flatallocation.py b/neutron/objects/plugins/ml2/flatallocation.py index 1342fb30b53..88db04d0a9b 100644 --- a/neutron/objects/plugins/ml2/flatallocation.py +++ b/neutron/objects/plugins/ml2/flatallocation.py @@ -11,14 +11,13 @@ # 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 +@base.NeutronObjectRegistry.register class FlatAllocation(base.NeutronDbObject): # Version 1.0: Initial Version VERSION = '1.0' diff --git a/neutron/objects/plugins/ml2/geneveallocation.py b/neutron/objects/plugins/ml2/geneveallocation.py index 4d91bfdb49f..99f58dc8139 100644 --- a/neutron/objects/plugins/ml2/geneveallocation.py +++ b/neutron/objects/plugins/ml2/geneveallocation.py @@ -12,7 +12,6 @@ # 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 geneveallocation @@ -20,7 +19,7 @@ from neutron.objects import base from neutron.objects.plugins.ml2 import base as ml2_base -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class GeneveAllocation(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -35,7 +34,7 @@ class GeneveAllocation(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class GeneveEndpoint(ml2_base.EndpointBase): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/plugins/ml2/greallocation.py b/neutron/objects/plugins/ml2/greallocation.py index cb12bc5fa4b..87391045f54 100644 --- a/neutron/objects/plugins/ml2/greallocation.py +++ b/neutron/objects/plugins/ml2/greallocation.py @@ -12,7 +12,6 @@ # 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 gre_allocation_endpoints as gre_model @@ -20,7 +19,7 @@ from neutron.objects import base from neutron.objects.plugins.ml2 import base as ml2_base -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class GreAllocation(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -35,7 +34,7 @@ class GreAllocation(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class GreEndpoint(ml2_base.EndpointBase): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/plugins/ml2/vlanallocation.py b/neutron/objects/plugins/ml2/vlanallocation.py index 2f23c5ddba1..402e316b873 100644 --- a/neutron/objects/plugins/ml2/vlanallocation.py +++ b/neutron/objects/plugins/ml2/vlanallocation.py @@ -12,7 +12,6 @@ # 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 vlanallocation as vlan_alloc_model @@ -20,7 +19,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class VlanAllocation(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/plugins/ml2/vxlanallocation.py b/neutron/objects/plugins/ml2/vxlanallocation.py index cdb74398bd7..15a44123748 100644 --- a/neutron/objects/plugins/ml2/vxlanallocation.py +++ b/neutron/objects/plugins/ml2/vxlanallocation.py @@ -12,7 +12,6 @@ # 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 vxlanallocation as vxlan_model @@ -21,7 +20,7 @@ from neutron.objects import common_types from neutron.objects.plugins.ml2 import base as ml2_base -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class VxlanAllocation(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -36,7 +35,7 @@ class VxlanAllocation(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class VxlanEndpoint(ml2_base.EndpointBase): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/port/extensions/allowedaddresspairs.py b/neutron/objects/port/extensions/allowedaddresspairs.py index 357cb4e865b..a15cacaecdc 100644 --- a/neutron/objects/port/extensions/allowedaddresspairs.py +++ b/neutron/objects/port/extensions/allowedaddresspairs.py @@ -10,7 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_versionedobjects import base as obj_base from neutron.common import utils from neutron.db.models import allowed_address_pair as models @@ -18,7 +17,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class AllowedAddressPair(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/port/extensions/data_plane_status.py b/neutron/objects/port/extensions/data_plane_status.py index bd585812301..b82b0dd91ad 100644 --- a/neutron/objects/port/extensions/data_plane_status.py +++ b/neutron/objects/port/extensions/data_plane_status.py @@ -12,7 +12,6 @@ # 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 data_plane_status as db_models @@ -20,7 +19,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class PortDataPlaneStatus(base.NeutronDbObject): # Version 1.0: Initial version VERSION = "1.0" diff --git a/neutron/objects/port/extensions/extra_dhcp_opt.py b/neutron/objects/port/extensions/extra_dhcp_opt.py index 2c8fe8b696b..02ff0935be6 100644 --- a/neutron/objects/port/extensions/extra_dhcp_opt.py +++ b/neutron/objects/port/extensions/extra_dhcp_opt.py @@ -10,7 +10,6 @@ # 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.extra_dhcp_opt import models @@ -18,7 +17,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class ExtraDhcpOpt(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/port/extensions/port_security.py b/neutron/objects/port/extensions/port_security.py index 628ce0279eb..293fafdeed9 100644 --- a/neutron/objects/port/extensions/port_security.py +++ b/neutron/objects/port/extensions/port_security.py @@ -10,13 +10,13 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_versionedobjects import base as obj_base from neutron.db.port_security import models +from neutron.objects import base from neutron.objects.extensions import port_security as base_ps -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class PortSecurity(base_ps._PortSecurity): # Version 1.0: Initial version VERSION = "1.0" diff --git a/neutron/objects/ports.py b/neutron/objects/ports.py index 9f3f6870ce7..3810ebc0f71 100644 --- a/neutron/objects/ports.py +++ b/neutron/objects/ports.py @@ -15,7 +15,6 @@ import netaddr from neutron_lib import constants from oslo_utils import versionutils -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields from neutron.common import utils @@ -61,7 +60,7 @@ class PortBindingBase(base.NeutronDbObject): return fields -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class PortBinding(PortBindingBase): # Version 1.0: Initial version VERSION = '1.0' @@ -82,7 +81,7 @@ class PortBinding(PortBindingBase): primary_keys = ['port_id', 'host'] -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class DistributedPortBinding(PortBindingBase): # Version 1.0: Initial version VERSION = '1.0' @@ -106,7 +105,7 @@ class DistributedPortBinding(PortBindingBase): primary_keys = ['host', 'port_id'] -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class PortBindingLevel(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -143,7 +142,7 @@ class PortBindingLevel(base.NeutronDbObject): context, _pager, validate_filters, **kwargs) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class IPAllocation(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -205,7 +204,7 @@ class IPAllocation(base.NeutronDbObject): return True -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class PortDNS(base.NeutronDbObject): # Version 1.0: Initial version # Version 1.1: Add dns_domain attribute @@ -235,7 +234,7 @@ class PortDNS(base.NeutronDbObject): primitive.pop('dns_domain', None) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class Port(base.NeutronDbObject): # Version 1.0: Initial version # Version 1.1: Add data_plane_status field diff --git a/neutron/objects/provisioning_blocks.py b/neutron/objects/provisioning_blocks.py index 0914eab150b..949ba70eee1 100644 --- a/neutron/objects/provisioning_blocks.py +++ b/neutron/objects/provisioning_blocks.py @@ -10,14 +10,13 @@ # 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 +@base.NeutronObjectRegistry.register class ProvisioningBlock(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/qos/binding.py b/neutron/objects/qos/binding.py index abe1cb1e88f..418c181ca01 100644 --- a/neutron/objects/qos/binding.py +++ b/neutron/objects/qos/binding.py @@ -13,14 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_versionedobjects import base as obj_base from neutron.db.qos import models as qos_db_model from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class QosPolicyPortBinding(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -36,7 +35,7 @@ class QosPolicyPortBinding(base.NeutronDbObject): fields_no_update = ['policy_id', 'port_id'] -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class QosPolicyNetworkBinding(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/qos/policy.py b/neutron/objects/qos/policy.py index 213365c9cfe..ae009e440f0 100644 --- a/neutron/objects/qos/policy.py +++ b/neutron/objects/qos/policy.py @@ -18,7 +18,6 @@ import itertools from neutron_lib import constants as n_const from oslo_db import exception as db_exc from oslo_utils import versionutils -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import exception from oslo_versionedobjects import fields as obj_fields @@ -35,7 +34,7 @@ from neutron.objects.qos import rule as rule_obj_impl from neutron.objects import rbac_db -@obj_base.VersionedObjectRegistry.register +@base_db.NeutronObjectRegistry.register class QosPolicy(rbac_db.NeutronRbacObject): # Version 1.0: Initial version # Version 1.1: QosDscpMarkingRule introduced @@ -346,7 +345,7 @@ class QosPolicy(rbac_db.NeutronRbacObject): primitive.pop('is_default', None) -@obj_base.VersionedObjectRegistry.register +@base_db.NeutronObjectRegistry.register class QosPolicyDefault(base_db.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/qos/rule.py b/neutron/objects/qos/rule.py index f5e6baacf8f..21b88c6451a 100644 --- a/neutron/objects/qos/rule.py +++ b/neutron/objects/qos/rule.py @@ -20,7 +20,6 @@ from neutron_lib import constants from neutron_lib.services.qos import constants as qos_consts from neutron_lib.utils import helpers from oslo_utils import versionutils -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import exception from oslo_versionedobjects import fields as obj_fields import six @@ -100,7 +99,7 @@ class QosRule(base.NeutronDbObject): and is_network_policy_only)) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class QosBandwidthLimitRule(QosRule): db_model = qos_db_model.QosBandwidthLimitRule @@ -124,7 +123,7 @@ class QosBandwidthLimitRule(QosRule): objtype="QosBandwidthLimitRule") -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class QosDscpMarkingRule(QosRule): db_model = qos_db_model.QosDscpMarkingRule @@ -143,7 +142,7 @@ class QosDscpMarkingRule(QosRule): objname="QosDscpMarkingRule") -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class QosMinimumBandwidthRule(QosRule): db_model = qos_db_model.QosMinimumBandwidthRule diff --git a/neutron/objects/qos/rule_type.py b/neutron/objects/qos/rule_type.py index e34b980edf6..9c6efd94912 100644 --- a/neutron/objects/qos/rule_type.py +++ b/neutron/objects/qos/rule_type.py @@ -15,7 +15,6 @@ from neutron_lib.plugins import directory from neutron_lib.services.qos import constants as qos_consts from oslo_log import log as logging from oslo_utils import versionutils -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields from neutron.objects import base @@ -32,7 +31,7 @@ class RuleTypeField(obj_fields.BaseEnumField): super(RuleTypeField, self).__init__(**kwargs) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class QosRuleType(base.NeutronObject): # Version 1.0: Initial version # Version 1.1: Added QosDscpMarkingRule @@ -79,7 +78,7 @@ class QosRuleType(base.NeutronObject): primitive.pop('drivers', None) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class QosRuleTypeDriver(base.NeutronObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/quota.py b/neutron/objects/quota.py index 29b5a150cf6..518f8057a7f 100644 --- a/neutron/objects/quota.py +++ b/neutron/objects/quota.py @@ -12,7 +12,6 @@ # 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 import sqlalchemy as sa from sqlalchemy import sql @@ -23,7 +22,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class ResourceDelta(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -41,7 +40,7 @@ class ResourceDelta(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class Reservation(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -108,7 +107,7 @@ class Reservation(base.NeutronDbObject): for (resource, exp, total_reserved) in resv_query) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class Quota(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -123,7 +122,7 @@ class Quota(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class QuotaUsage(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/router.py b/neutron/objects/router.py index 814ce1dbc35..41d9dc4edae 100644 --- a/neutron/objects/router.py +++ b/neutron/objects/router.py @@ -14,7 +14,6 @@ import netaddr from neutron_lib.api.definitions import availability_zone as az_def from neutron_lib.api.validators import availability_zone as az_validator -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields from sqlalchemy import func @@ -29,7 +28,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class RouterRoute(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -65,7 +64,7 @@ class RouterRoute(base.NeutronDbObject): return result -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class RouterExtraAttributes(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -124,7 +123,7 @@ class RouterExtraAttributes(base.NeutronDbObject): return [(router, agent_count) for router, agent_count in query] -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class RouterPort(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -155,7 +154,7 @@ class RouterPort(base.NeutronDbObject): return [r[0] for r in query] -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class DVRMacAddress(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -186,7 +185,7 @@ class DVRMacAddress(base.NeutronDbObject): return result -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class FloatingIP(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/securitygroup.py b/neutron/objects/securitygroup.py index 6293e55e8a6..3e726852bdd 100644 --- a/neutron/objects/securitygroup.py +++ b/neutron/objects/securitygroup.py @@ -10,7 +10,6 @@ # 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.common import utils @@ -20,7 +19,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class SecurityGroup(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -65,7 +64,7 @@ class SecurityGroup(base.NeutronDbObject): self.obj_reset_changes(['is_default']) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class DefaultSecurityGroup(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -82,7 +81,7 @@ class DefaultSecurityGroup(base.NeutronDbObject): primary_keys = ['project_id'] -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class SecurityGroupRule(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/servicetype.py b/neutron/objects/servicetype.py index d49a9d8a200..22e64d27689 100644 --- a/neutron/objects/servicetype.py +++ b/neutron/objects/servicetype.py @@ -13,7 +13,6 @@ # 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 @@ -21,7 +20,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class ProviderResourceAssociation(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/subnet.py b/neutron/objects/subnet.py index fcceb1b755a..9c1fb99447e 100644 --- a/neutron/objects/subnet.py +++ b/neutron/objects/subnet.py @@ -12,7 +12,6 @@ import netaddr -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields from neutron.common import utils @@ -24,7 +23,7 @@ from neutron.objects import common_types from neutron.objects import rbac_db -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class DNSNameServer(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -56,7 +55,7 @@ class DNSNameServer(base.NeutronDbObject): **kwargs) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class Route(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -95,7 +94,7 @@ class Route(base.NeutronDbObject): return result -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class IPAllocationPool(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -139,7 +138,7 @@ class IPAllocationPool(base.NeutronDbObject): return result -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class SubnetServiceType(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -163,7 +162,7 @@ class SubnetServiceType(base.NeutronDbObject): # - added 'shared' to synthetic_fields # - registered extra_filter_name for 'shared' attribute # - added loading shared attribute based on network 'rbac_entries' -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class Subnet(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/subnetpool.py b/neutron/objects/subnetpool.py index 797c9153f36..f82e8e00a53 100644 --- a/neutron/objects/subnetpool.py +++ b/neutron/objects/subnetpool.py @@ -14,7 +14,6 @@ # under the License. import netaddr -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields from neutron.db import api as db_api @@ -23,7 +22,7 @@ from neutron.objects import base from neutron.objects import common_types -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class SubnetPool(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -86,7 +85,7 @@ class SubnetPool(base.NeutronDbObject): self._attach_prefixes(fields['prefixes']) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class SubnetPoolPrefix(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/tag.py b/neutron/objects/tag.py index f65f960f0a5..348ebb14ce5 100644 --- a/neutron/objects/tag.py +++ b/neutron/objects/tag.py @@ -10,14 +10,13 @@ # 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 tag as tag_model from neutron.objects import base -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class Tag(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' diff --git a/neutron/objects/trunk.py b/neutron/objects/trunk.py index 1663f433c14..f1bfc9f1173 100644 --- a/neutron/objects/trunk.py +++ b/neutron/objects/trunk.py @@ -17,7 +17,6 @@ from neutron_lib import exceptions as n_exc from neutron_lib.objects import exceptions as o_exc from oslo_db import exception as o_db_exc from oslo_utils import versionutils -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields from neutron.db import api as db_api @@ -27,7 +26,7 @@ from neutron.services.trunk import exceptions as t_exc from neutron.services.trunk import models -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class SubPort(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -82,7 +81,7 @@ class SubPort(base.NeutronDbObject): trunk_id=self.trunk_id) -@obj_base.VersionedObjectRegistry.register +@base.NeutronObjectRegistry.register class Trunk(base.NeutronDbObject): # Version 1.0: Initial version # Version 1.1: Changed tenant_id to project_id diff --git a/neutron/tests/unit/api/rpc/handlers/test_resources_rpc.py b/neutron/tests/unit/api/rpc/handlers/test_resources_rpc.py index b7263567859..af9d11a57df 100644 --- a/neutron/tests/unit/api/rpc/handlers/test_resources_rpc.py +++ b/neutron/tests/unit/api/rpc/handlers/test_resources_rpc.py @@ -17,7 +17,6 @@ import mock from neutron_lib import context from oslo_utils import uuidutils from oslo_versionedobjects import fields as obj_fields -from oslo_versionedobjects import fixture import testtools from neutron.api.rpc.callbacks import resources @@ -27,6 +26,7 @@ from neutron.common import topics from neutron.objects import base as objects_base from neutron.objects import common_types from neutron.tests import base +from neutron.tests.unit.objects import test_base as objects_test_base TEST_EVENT = 'test_event' @@ -76,7 +76,7 @@ class ResourcesRpcBaseTestCase(base.BaseTestCase): super(ResourcesRpcBaseTestCase, self).setUp() self.obj_registry = self.useFixture( - fixture.VersionedObjectRegistryFixture()) + objects_test_base.NeutronObjectRegistryFixture()) self.context = context.get_admin_context() mock.patch.object(resources_rpc.resources, diff --git a/neutron/tests/unit/objects/extensions/test_standardattributes.py b/neutron/tests/unit/objects/extensions/test_standardattributes.py index b04a1c4c3bb..ee421f9a95f 100644 --- a/neutron/tests/unit/objects/extensions/test_standardattributes.py +++ b/neutron/tests/unit/objects/extensions/test_standardattributes.py @@ -13,7 +13,6 @@ # under the License. from neutron_lib.db import model_base -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields import sqlalchemy as sa @@ -33,7 +32,7 @@ class FakeDbModelWithStandardAttributes( tag_support = False -@obj_base.VersionedObjectRegistry.register_if(False) +@objects_base.NeutronObjectRegistry.register_if(False) class FakeObjectWithStandardAttributes(objects_base.NeutronDbObject): VERSION = '1.0' db_model = FakeDbModelWithStandardAttributes diff --git a/neutron/tests/unit/objects/test_base.py b/neutron/tests/unit/objects/test_base.py index 1277f4e1095..6c9ca83b898 100644 --- a/neutron/tests/unit/objects/test_base.py +++ b/neutron/tests/unit/objects/test_base.py @@ -15,6 +15,7 @@ import copy import itertools import random +import fixtures import mock import netaddr from neutron_lib import constants @@ -28,7 +29,6 @@ from oslo_utils import uuidutils from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import exception from oslo_versionedobjects import fields as obj_fields -from oslo_versionedobjects import fixture import testtools from neutron.db import _model_query as model_query @@ -67,7 +67,7 @@ class ObjectFieldsModel(dict): pass -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeSmallNeutronObject(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -89,7 +89,7 @@ class FakeSmallNeutronObject(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeSmallNeutronObjectWithMultipleParents(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -109,7 +109,7 @@ class FakeSmallNeutronObjectWithMultipleParents(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeParent(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -128,7 +128,7 @@ class FakeParent(base.NeutronDbObject): synthetic_fields = ['children'] -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeWeirdKeySmallNeutronObject(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -148,7 +148,30 @@ class FakeWeirdKeySmallNeutronObject(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register_if(False) +class NeutronObjectRegistryFixture(fixtures.Fixture): + """Use a NeutronObjectRegistry as a temp registry pattern fixture. + + It is fixture similar to + oslo_versionedobjects.fixture.VersionedObjectRegistryFixture + but it uses Neutron's base registry class + """ + + def setUp(self): + super(NeutronObjectRegistryFixture, self).setUp() + self._base_test_obj_backup = copy.deepcopy( + base.NeutronObjectRegistry._registry._obj_classes) + self.addCleanup(self._restore_obj_registry) + + @staticmethod + def register(cls_name): + base.NeutronObjectRegistry.register(cls_name) + + def _restore_obj_registry(self): + base.NeutronObjectRegistry._registry._obj_classes = \ + self._base_test_obj_backup + + +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronDbObject(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -169,7 +192,7 @@ class FakeNeutronDbObject(base.NeutronDbObject): synthetic_fields = ['obj_field'] -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronObjectNonStandardPrimaryKey(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -189,7 +212,7 @@ class FakeNeutronObjectNonStandardPrimaryKey(base.NeutronDbObject): synthetic_fields = ['obj_field', 'field2'] -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronObjectCompositePrimaryKey(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -208,7 +231,7 @@ class FakeNeutronObjectCompositePrimaryKey(base.NeutronDbObject): synthetic_fields = ['obj_field'] -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronObjectUniqueKey(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -230,7 +253,7 @@ class FakeNeutronObjectUniqueKey(base.NeutronDbObject): synthetic_fields = ['obj_field'] -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronObjectRenamedField(base.NeutronDbObject): """ Testing renaming the parameter from DB to NeutronDbObject @@ -256,7 +279,7 @@ class FakeNeutronObjectRenamedField(base.NeutronDbObject): fields_need_translation = {'field_ovo': 'field_db'} -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronObjectCompositePrimaryKeyWithId(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -274,7 +297,7 @@ class FakeNeutronObjectCompositePrimaryKeyWithId(base.NeutronDbObject): synthetic_fields = ['obj_field'] -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronObjectMultipleForeignKeys(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -291,7 +314,7 @@ class FakeNeutronObjectMultipleForeignKeys(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronObjectSyntheticField(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -307,7 +330,7 @@ class FakeNeutronObjectSyntheticField(base.NeutronDbObject): synthetic_fields = ['obj_field'] -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronObjectSyntheticField2(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -322,7 +345,7 @@ class FakeNeutronObjectSyntheticField2(base.NeutronDbObject): synthetic_fields = ['obj_field'] -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronObjectWithProjectId(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -336,7 +359,7 @@ class FakeNeutronObjectWithProjectId(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronObject(base.NeutronObject): # Version 1.0: Initial version VERSION = '1.0' @@ -363,7 +386,7 @@ class FakeNeutronObject(base.NeutronObject): ] -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronObjectDictOfMiscValues(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -376,7 +399,7 @@ class FakeNeutronObjectDictOfMiscValues(base.NeutronDbObject): } -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronObjectListOfDictOfMiscValues(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -543,7 +566,7 @@ class _BaseObjectTestCase(object): self.valid_field_filter = {valid_field: self.obj_fields[-1][valid_field]} self.obj_registry = self.useFixture( - fixture.VersionedObjectRegistryFixture()) + NeutronObjectRegistryFixture()) self.obj_registry.register(FakeSmallNeutronObject) self.obj_registry.register(FakeWeirdKeySmallNeutronObject) self.obj_registry.register(FakeNeutronObjectMultipleForeignKeys) @@ -649,7 +672,7 @@ class _BaseObjectTestCase(object): def _get_ovo_object_class(self, objclass, field): try: name = objclass.fields[field].objname - return obj_base.VersionedObjectRegistry.obj_classes().get(name)[0] + return base.NeutronObjectRegistry.obj_classes().get(name)[0] except TypeError: # NOTE(korzen) some synthetic fields are not handled by # this method, for example the ones that have subclasses, see @@ -1230,7 +1253,7 @@ class UniqueKeysTestCase(test_base.BaseTestCase): get_unique_keys.return_value = [['field1'], ['field2', 'db_field3']] - @obj_base.VersionedObjectRegistry.register_if(False) + @base.NeutronObjectRegistry.register_if(False) class UniqueKeysTestObject(base.NeutronDbObject): # Version 1.0: Initial version VERSION = '1.0' @@ -1932,7 +1955,7 @@ class UniqueObjectBase(test_base.BaseTestCase): def setUp(self): super(UniqueObjectBase, self).setUp() obj_registry = self.useFixture( - fixture.VersionedObjectRegistryFixture()) + NeutronObjectRegistryFixture()) self.db_model = FakeModel class RegisteredObject(base.NeutronDbObject): diff --git a/neutron/tests/unit/objects/test_objects.py b/neutron/tests/unit/objects/test_objects.py index bfe76b8cd43..e918b944b4d 100644 --- a/neutron/tests/unit/objects/test_objects.py +++ b/neutron/tests/unit/objects/test_objects.py @@ -15,10 +15,10 @@ import os import pprint -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fixture from neutron import objects +from neutron.objects import base from neutron.tests import base as test_base @@ -114,7 +114,7 @@ class TestObjectVersions(test_base.BaseTestCase): def test_versions(self): checker = fixture.ObjectVersionChecker( - obj_base.VersionedObjectRegistry.obj_classes()) + base.NeutronObjectRegistry.obj_classes()) fingerprints = checker.get_hashes() if os.getenv('GENERATE_HASHES'): diff --git a/neutron/tests/unit/objects/test_rbac_db.py b/neutron/tests/unit/objects/test_rbac_db.py index 7b291f82759..6ce931b71c5 100644 --- a/neutron/tests/unit/objects/test_rbac_db.py +++ b/neutron/tests/unit/objects/test_rbac_db.py @@ -16,12 +16,12 @@ from neutron_lib.callbacks import events from neutron_lib import context as n_context from neutron_lib.db import model_base from neutron_lib import exceptions as n_exc -from oslo_versionedobjects import base as obj_base from oslo_versionedobjects import fields as obj_fields import sqlalchemy as sa from neutron.db import rbac_db_models from neutron.extensions import rbac as ext_rbac +from neutron.objects import base from neutron.objects import common_types from neutron.objects.db import api as obj_db_api from neutron.objects import rbac_db @@ -41,7 +41,7 @@ class FakeRbacModel(rbac_db_models.RBACColumns, model_base.BASEV2): return (rbac_db_models.ACCESS_SHARED,) -@obj_base.VersionedObjectRegistry.register_if(False) +@base.NeutronObjectRegistry.register_if(False) class FakeNeutronDbObject(rbac_db.NeutronRbacObject): # Version 1.0: Initial version VERSION = '1.0'