objects: don't call DeclarativeObject's __init__ twice for rbac objects
Due to the way we applied metaclasses to rbac aware objects, the __init__ was executed twice: once when the DeclarativeObject metaclass was applied to NeutronDbObject, and once when rbac metaclass was applied, when we were calling type() in rbac metaclass' __new__. To avoid that behaviour, we can introduce a separate base 'class' for rbac aware objects that would be a result of with_metaclass call using the rbac metaclass, and NeutronDbOjbect as the actual base. Then we use the base class in place of NeutronDbObject base class for all objects that are RBAC aware. This avoids the duplicate call issue. Change-Id: Ia12f56f7d40c38e679edc21e13871e27ad1820ee Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
This commit is contained in:
parent
844b799e35
commit
9f0647e181
|
@ -19,7 +19,6 @@ 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
|
||||
from six import add_metaclass
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.common import exceptions
|
||||
|
@ -28,15 +27,13 @@ from neutron.db import models_v2
|
|||
from neutron.db.qos import api as qos_db_api
|
||||
from neutron.db.qos import models as qos_db_model
|
||||
from neutron.db.rbac_db_models import QosPolicyRBAC
|
||||
from neutron.objects import base
|
||||
from neutron.objects.db import api as obj_db_api
|
||||
from neutron.objects.qos import rule as rule_obj_impl
|
||||
from neutron.objects import rbac_db
|
||||
|
||||
|
||||
@obj_base.VersionedObjectRegistry.register
|
||||
@add_metaclass(rbac_db.RbacNeutronMetaclass)
|
||||
class QosPolicy(base.NeutronDbObject):
|
||||
class QosPolicy(rbac_db.NeutronRbacObject):
|
||||
# Version 1.0: Initial version
|
||||
# Version 1.1: QosDscpMarkingRule introduced
|
||||
# Version 1.2: Added QosMinimumBandwidthRule
|
||||
|
|
|
@ -17,6 +17,7 @@ import itertools
|
|||
|
||||
from neutron_lib import exceptions as lib_exc
|
||||
from six import add_metaclass
|
||||
from six import with_metaclass
|
||||
from sqlalchemy import and_
|
||||
|
||||
from neutron._i18n import _
|
||||
|
@ -325,3 +326,6 @@ class RbacNeutronMetaclass(type):
|
|||
mcs.subscribe_to_rbac_events(cls)
|
||||
|
||||
return cls
|
||||
|
||||
|
||||
NeutronRbacObject = with_metaclass(RbacNeutronMetaclass, base.NeutronDbObject)
|
||||
|
|
|
@ -16,13 +16,11 @@ 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
|
||||
from six import add_metaclass
|
||||
import sqlalchemy as sa
|
||||
|
||||
from neutron.callbacks import events
|
||||
from neutron.db import rbac_db_models
|
||||
from neutron.extensions import rbac as ext_rbac
|
||||
from neutron.objects import base
|
||||
from neutron.objects.db import api as obj_db_api
|
||||
from neutron.objects import rbac_db
|
||||
from neutron.tests.unit.objects import test_base
|
||||
|
@ -42,8 +40,7 @@ class FakeRbacModel(rbac_db_models.RBACColumns, model_base.BASEV2):
|
|||
|
||||
|
||||
@obj_base.VersionedObjectRegistry.register_if(False)
|
||||
@add_metaclass(rbac_db.RbacNeutronMetaclass)
|
||||
class FakeNeutronDbObject(base.NeutronDbObject):
|
||||
class FakeNeutronDbObject(rbac_db.NeutronRbacObject):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
|
||||
|
|
Loading…
Reference in New Issue