From 8c7c33c85678e37da3a40e2167d37f01146ca9cc Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Thu, 30 Jul 2015 10:46:49 +0200 Subject: [PATCH] QosPolicy: made shared field required and with default value = False Change-Id: Icc71ae923d88e2db193d4a33726f8455af4c5dd8 Partially-Implements: blueprint quantum-qos-api --- .../versions/liberty/expand/48153cb5f051_qos_db_changes.py | 2 +- neutron/db/qos/models.py | 2 +- neutron/objects/base.py | 4 ++++ neutron/objects/qos/policy.py | 2 +- neutron/tests/unit/objects/qos/test_policy.py | 5 +++++ 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/neutron/db/migration/alembic_migrations/versions/liberty/expand/48153cb5f051_qos_db_changes.py b/neutron/db/migration/alembic_migrations/versions/liberty/expand/48153cb5f051_qos_db_changes.py index 9a8fb102a..03711ca03 100755 --- a/neutron/db/migration/alembic_migrations/versions/liberty/expand/48153cb5f051_qos_db_changes.py +++ b/neutron/db/migration/alembic_migrations/versions/liberty/expand/48153cb5f051_qos_db_changes.py @@ -37,7 +37,7 @@ def upgrade(): sa.Column('id', sa.String(length=36), primary_key=True), sa.Column('name', sa.String(length=attrs.NAME_MAX_LEN)), sa.Column('description', sa.String(length=attrs.DESCRIPTION_MAX_LEN)), - sa.Column('shared', sa.Boolean()), + sa.Column('shared', sa.Boolean(), nullable=False), sa.Column('tenant_id', sa.String(length=attrs.TENANT_ID_MAX_LEN), index=True)) diff --git a/neutron/db/qos/models.py b/neutron/db/qos/models.py index bf0a62d01..f40ee0f49 100755 --- a/neutron/db/qos/models.py +++ b/neutron/db/qos/models.py @@ -28,7 +28,7 @@ class QosPolicy(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): __tablename__ = 'qos_policies' name = sa.Column(sa.String(attrs.NAME_MAX_LEN)) description = sa.Column(sa.String(attrs.DESCRIPTION_MAX_LEN)) - shared = sa.Column(sa.Boolean) + shared = sa.Column(sa.Boolean, nullable=False) class QosNetworkPolicyBinding(model_base.BASEV2): diff --git a/neutron/objects/base.py b/neutron/objects/base.py index cf51cf3d2..264bbf9af 100644 --- a/neutron/objects/base.py +++ b/neutron/objects/base.py @@ -23,6 +23,10 @@ class NeutronObject(obj_base.VersionedObject, obj_base.VersionedObjectDictCompat, obj_base.ComparableVersionedObject): + def __init__(self, context=None, **kwargs): + super(NeutronObject, self).__init__(context, **kwargs) + self.obj_set_defaults() + def to_dict(self): return dict(self.items()) diff --git a/neutron/objects/qos/policy.py b/neutron/objects/qos/policy.py index 51602a3ea..fb2fca222 100644 --- a/neutron/objects/qos/policy.py +++ b/neutron/objects/qos/policy.py @@ -60,7 +60,7 @@ class QosPolicy(base.NeutronDbObject): 'tenant_id': obj_fields.UUIDField(), 'name': obj_fields.StringField(), 'description': obj_fields.StringField(), - 'shared': obj_fields.BooleanField() + 'shared': obj_fields.BooleanField(default=False) } fields_no_update = ['id', 'tenant_id'] diff --git a/neutron/tests/unit/objects/qos/test_policy.py b/neutron/tests/unit/objects/qos/test_policy.py index 9369f03a8..c3c747b90 100644 --- a/neutron/tests/unit/objects/qos/test_policy.py +++ b/neutron/tests/unit/objects/qos/test_policy.py @@ -245,3 +245,8 @@ class QosPolicyDbObjectTestCase(test_base.BaseDbObjectTestCase, self.assertEqual(rule_dict, obj_dict['bandwidth_limit_rules'][0]) + + def test_shared_default(self): + self.db_obj.pop('shared') + obj = self._test_class(self.context, **self.db_obj) + self.assertEqual(False, obj.shared) -- 2.45.2