From 9a509fe4222ebd5344734a9d9fde8aaf2c61b069 Mon Sep 17 00:00:00 2001 From: Chaolei Li Date: Fri, 19 Jan 2018 09:40:07 +0800 Subject: [PATCH] Add uuid field in ContainerAction object In etcd, we use 'uuid' to filter container_action instead of 'id' field. Updating ContainerAction by adding uuid field to support container_action etcd api. Change-Id: I748ed1a892a562ad14cb9921009e989862f7035c --- zun/objects/container_action.py | 6 ++++-- zun/tests/unit/db/utils.py | 20 ++++++++++++++++++-- zun/tests/unit/objects/test_objects.py | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/zun/objects/container_action.py b/zun/objects/container_action.py index dfc69f75f..5931bb9a8 100644 --- a/zun/objects/container_action.py +++ b/zun/objects/container_action.py @@ -27,7 +27,8 @@ LOG = logging.getLogger(__name__) class ContainerAction(base.ZunPersistentObject, base.ZunObject): # Version 1.0: Initial version - VERSION = '1.0' + # Version 1.1: Add uuid column. + VERSION = '1.1' fields = { 'id': fields.IntegerField(), @@ -39,12 +40,13 @@ class ContainerAction(base.ZunPersistentObject, base.ZunObject): 'start_time': fields.DateTimeField(nullable=True), 'finish_time': fields.DateTimeField(nullable=True), 'message': fields.StringField(nullable=True), + 'uuid': fields.StringField(nullable=True), } @staticmethod def _from_db_object(context, action, db_action): for field in action.fields: - setattr(action, field, db_action[field]) + setattr(action, field, getattr(db_action, field, None)) action.obj_reset_changes() return action diff --git a/zun/tests/unit/db/utils.py b/zun/tests/unit/db/utils.py index 434c9a8e6..e3648c1d4 100644 --- a/zun/tests/unit/db/utils.py +++ b/zun/tests/unit/db/utils.py @@ -403,8 +403,13 @@ def create_test_capsule(**kwargs): return dbapi.create_capsule(kwargs['context'], capsule) +class FakeObject(object): + def __getitem__(self, key): + return getattr(self, key) + + def get_test_action(**kwargs): - return { + action_values = { 'created_at': kwargs.get('created_at'), 'updated_at': kwargs.get('updated_at'), 'id': kwargs.get('id', 123), @@ -419,9 +424,15 @@ def get_test_action(**kwargs): 'message': kwargs.get('message', 'fake-message'), } + fake_action = FakeObject() + for k, v in action_values.items(): + setattr(fake_action, k, v) + return fake_action + def get_test_action_event(**kwargs): - return { + + event_values = { 'created_at': kwargs.get('created_at'), 'updated_at': kwargs.get('updated_at'), 'id': kwargs.get('id', 123), @@ -432,3 +443,8 @@ def get_test_action_event(**kwargs): 'result': kwargs.get('result', 'Error'), 'traceback': kwargs.get('traceback', 'fake-tb'), } + + fake_event = FakeObject() + for k, v in event_values.items(): + setattr(fake_event, k, v) + return fake_event diff --git a/zun/tests/unit/objects/test_objects.py b/zun/tests/unit/objects/test_objects.py index 8d4fcc96b..0a5aa782a 100644 --- a/zun/tests/unit/objects/test_objects.py +++ b/zun/tests/unit/objects/test_objects.py @@ -360,7 +360,7 @@ object_data = { 'PciDevicePoolList': '1.0-15ecf022a68ddbb8c2a6739cfc9f8f5e', 'ContainerPCIRequest': '1.0-b060f9f9f734bedde79a71a4d3112ee0', 'ContainerPCIRequests': '1.0-7b8f7f044661fe4e24e6949c035af2c4', - 'ContainerAction': '1.0-8d6facdc65855c6c6afbed8531209279', + 'ContainerAction': '1.1-b0c721f9e10c6c0d1e41e512c49eb877', 'ContainerActionEvent': '1.0-2974d0a6f5d4821fd4e223a88c10181a' }