From a6590b2664d4820157ee2e06fe73e62a93465dea Mon Sep 17 00:00:00 2001 From: Xinran WANG Date: Wed, 27 Feb 2019 17:34:36 +0800 Subject: [PATCH] Bug fix: Change object definition according to the newest DB. Controlpath should associate with device, not the deployable. AttachHandle should associate with cpid_id, and should have "in_use" field. Change-Id: I0ce29bfb0a1e89971d680aba6bd2a63d339fe88d --- cyborg/db/sqlalchemy/api.py | 4 ++-- cyborg/objects/attach_handle.py | 5 ++++- cyborg/objects/control_path.py | 2 +- cyborg/tests/unit/db/utils.py | 4 +++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cyborg/db/sqlalchemy/api.py b/cyborg/db/sqlalchemy/api.py index 6075304b..4d9ca0d8 100644 --- a/cyborg/db/sqlalchemy/api.py +++ b/cyborg/db/sqlalchemy/api.py @@ -175,7 +175,7 @@ class Connection(api.Connection): query_prefix = model_query(context, models.AttachHandle) filters = copy.deepcopy(filters) - exact_match_filter_names = ['uuid', 'id', 'deployable_id'] + exact_match_filter_names = ['uuid', 'id', 'deployable_id', 'cpid_id'] # Filter the query query_prefix = self._exact_filter(models.AttachHandle, query_prefix, @@ -293,7 +293,7 @@ class Connection(api.Connection): query_prefix = model_query(context, models.AttachHandle) filters = copy.deepcopy(filters) - exact_match_filter_names = ['uuid', 'id', 'deployable_id'] + exact_match_filter_names = ['uuid', 'id', 'device_id'] # Filter the query query_prefix = self._exact_filter(models.ControlpathID, query_prefix, diff --git a/cyborg/objects/attach_handle.py b/cyborg/objects/attach_handle.py index 80f33c27..5fd9f052 100644 --- a/cyborg/objects/attach_handle.py +++ b/cyborg/objects/attach_handle.py @@ -36,14 +36,17 @@ class AttachHandle(base.CyborgObject, object_base.VersionedObjectDictCompat): 'id': object_fields.IntegerField(nullable=False), 'uuid': object_fields.UUIDField(nullable=False), 'deployable_id': object_fields.IntegerField(nullable=False), + 'cpid_id': object_fields.IntegerField(nullable=False), 'attach_type': object_fields.EnumField(valid_values=ATTACH_TYPE, nullable=False), # attach_info should be JSON here. - 'attach_info': object_fields.StringField(nullable=False) + 'attach_info': object_fields.StringField(nullable=False), + 'in_use': object_fields.BooleanField(nullable=False) } def create(self, context): """Create a AttachHandle record in the DB.""" + self.in_use = False values = self.obj_get_changes() db_ah = self.dbapi.attach_handle_create(context, values) self._from_db_object(self, db_ah) diff --git a/cyborg/objects/control_path.py b/cyborg/objects/control_path.py index 4d5b0cdc..be1d3469 100644 --- a/cyborg/objects/control_path.py +++ b/cyborg/objects/control_path.py @@ -35,7 +35,7 @@ class ControlpathID(base.CyborgObject, object_base.VersionedObjectDictCompat): fields = { 'id': object_fields.IntegerField(nullable=False), 'uuid': object_fields.UUIDField(nullable=False), - 'deployable_id': object_fields.IntegerField(nullable=False), + 'device_id': object_fields.IntegerField(nullable=False), 'cpid_type': object_fields.EnumField(valid_values=CPID_TYPE, nullable=False), 'cpid_info': object_fields.StringField(nullable=False) diff --git a/cyborg/tests/unit/db/utils.py b/cyborg/tests/unit/db/utils.py index 47d535aa..6de23c9f 100644 --- a/cyborg/tests/unit/db/utils.py +++ b/cyborg/tests/unit/db/utils.py @@ -87,6 +87,8 @@ def get_test_attach_handle(**kw): 'uuid': kw.get('uuid', '10efe63d-dfea-4a37-ad94-4116fba5098'), 'id': kw.get('id', 1), 'deployable_id': kw.get('deployable_id', 1), + 'cpid_id': kw.get('cpid_id', 1), + 'in_use': kw.get('in_use', False), 'attach_type': kw.get('attach_type', "PCI"), 'attach_info': kw.get('attach_info', "attach_info"), 'created_at': kw.get('create_at', None), @@ -98,7 +100,7 @@ def get_test_control_path(**kw): return { 'uuid': kw.get('uuid', '10efe63d-dfea-4a37-ad94-4116fba5098'), 'id': kw.get('id', 1), - 'deployable_id': kw.get('deployable_id', 1), + 'device_id': kw.get('device_id', 1), 'cpid_type': kw.get('cpid_type', "PCI"), 'cpid_info': kw.get('cpid_info', "cpid_info"), 'created_at': kw.get('create_at', None),