]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Make models_v2 explicitly import rbac_db_models
authorKevin Benton <blak111@gmail.com>
Mon, 24 Aug 2015 10:13:14 +0000 (03:13 -0700)
committerKevin Benton <blak111@gmail.com>
Mon, 24 Aug 2015 10:13:14 +0000 (03:13 -0700)
The Network model was implicitly relying on a core plugin to import
the db_base_plugin_v2 module which would import the rbac model module
so "NetworkRBAC" would be defined by the time something would query
the DB. However, this isn't the case for scripts or agents that are
importing models_v2 and trying to query the DB directly so they will
now break with an sqlaclhemy error about a missing model.

This patch makes models_v2 import the rbac_db_models module directly
so the model will always be defined.

This would have resulted in a circular import because the
rbac_db_models module required the HasId and HasTenant classes
in models_v2. So this patch also moves these helper classes
into model_base.

Change-Id: I338ce1c0ba55647e6410a63f937737f75a63057d
Closes-Bug: #1488032

neutron/db/model_base.py
neutron/db/models_v2.py
neutron/db/rbac_db_models.py

index e1abbd5533a504b1369c940ad1f7a94acb52d5c0..7671e8b32967e0aa43b3c2623b1276be7b421d7c 100644 (file)
 # limitations under the License.
 
 from oslo_db.sqlalchemy import models
+from oslo_utils import uuidutils
+import sqlalchemy as sa
 from sqlalchemy.ext import declarative
 from sqlalchemy import orm
 
+from neutron.api.v2 import attributes as attr
+
+
+class HasTenant(object):
+    """Tenant mixin, add to subclasses that have a tenant."""
+
+    # NOTE(jkoelker) tenant_id is just a free form string ;(
+    tenant_id = sa.Column(sa.String(attr.TENANT_ID_MAX_LEN), index=True)
+
+
+class HasId(object):
+    """id mixin, add to subclasses that have an id."""
+
+    id = sa.Column(sa.String(36),
+                   primary_key=True,
+                   default=uuidutils.generate_uuid)
+
+
+class HasStatusDescription(object):
+    """Status with description mixin."""
+
+    status = sa.Column(sa.String(16), nullable=False)
+    status_description = sa.Column(sa.String(attr.DESCRIPTION_MAX_LEN))
+
 
 class NeutronBase(models.ModelBase):
     """Base class for Neutron Models."""
index 361d172cd624eedd681c3c65daebf2c097c25e16..a2ace9b11353c354dd17bfbe3a05dd7bdd2b878a 100644 (file)
@@ -13,7 +13,6 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-from oslo_utils import uuidutils
 import sqlalchemy as sa
 from sqlalchemy.ext.associationproxy import association_proxy
 from sqlalchemy import orm
@@ -21,28 +20,14 @@ from sqlalchemy import orm
 from neutron.api.v2 import attributes as attr
 from neutron.common import constants
 from neutron.db import model_base
+from neutron.db import rbac_db_models
 
 
-class HasTenant(object):
-    """Tenant mixin, add to subclasses that have a tenant."""
-
-    # NOTE(jkoelker) tenant_id is just a free form string ;(
-    tenant_id = sa.Column(sa.String(attr.TENANT_ID_MAX_LEN), index=True)
-
-
-class HasId(object):
-    """id mixin, add to subclasses that have an id."""
-
-    id = sa.Column(sa.String(36),
-                   primary_key=True,
-                   default=uuidutils.generate_uuid)
-
-
-class HasStatusDescription(object):
-    """Status with description mixin."""
-
-    status = sa.Column(sa.String(16), nullable=False)
-    status_description = sa.Column(sa.String(attr.DESCRIPTION_MAX_LEN))
+# NOTE(kevinbenton): these are here for external projects that expect them
+# to be found in this module.
+HasTenant = model_base.HasTenant
+HasId = model_base.HasId
+HasStatusDescription = model_base.HasStatusDescription
 
 
 class IPAvailabilityRange(model_base.BASEV2):
@@ -265,6 +250,6 @@ class Network(model_base.BASEV2, HasId, HasTenant):
     admin_state_up = sa.Column(sa.Boolean)
     mtu = sa.Column(sa.Integer, nullable=True)
     vlan_transparent = sa.Column(sa.Boolean, nullable=True)
-    rbac_entries = orm.relationship("NetworkRBAC", backref='network',
-                                    lazy='joined',
+    rbac_entries = orm.relationship(rbac_db_models.NetworkRBAC,
+                                    backref='network', lazy='joined',
                                     cascade='all, delete, delete-orphan')
index 9e0aa44866e044e1a3c747a93b62573b1d69683b..37314664337fb8944dc8d7a5dba835959d72e07c 100644 (file)
@@ -20,7 +20,6 @@ from sqlalchemy.orm import validates
 
 from neutron.common import exceptions as n_exc
 from neutron.db import model_base
-from neutron.db import models_v2
 
 
 class InvalidActionForType(n_exc.InvalidInput):
@@ -28,7 +27,7 @@ class InvalidActionForType(n_exc.InvalidInput):
                 "'%(object_type)s'. Valid actions: %(valid_actions)s")
 
 
-class RBACColumns(models_v2.HasId, models_v2.HasTenant):
+class RBACColumns(model_base.HasId, model_base.HasTenant):
     """Mixin that object-specific RBAC tables should inherit.
 
     All RBAC tables should inherit directly from this one because