From b62965c2bf2706eb1ec5dd3e12bc8c339a98364e Mon Sep 17 00:00:00 2001 From: chenke Date: Tue, 21 May 2019 16:28:23 +0800 Subject: [PATCH] Add name for instance in Watcher datamodel Now Watcher's datamodel uses human_id to store the display_name of the intance. But the value of human_id is not reliable. About the reason, please see[1]. The solution is to add a 'name' field to save the display_name of the instance, and ensure that the value of this field is the same when the datamodel is created and when the datamodel is updated. About the 'human_id', We will remove it in the future. References: [1]. https://bugs.launchpad.net/watcher/+bug/1833665 20190619 Watcher meeting IRC Log: [1]. http://eavesdrop.openstack.org/irclogs/%23openstack-watcher/%23openstack-watcher.2019-06-19.log.html [2]. http://eavesdrop.openstack.org/meetings/watcher/2019/watcher.2019-06-19-08.00.log.html#l-47 Change-Id: I6976759629a4feedee09261cc1dac935e050202a Closes-Bug: #1833665 --- watcher/decision_engine/model/collector/nova.py | 3 +++ watcher/decision_engine/model/notification/nova.py | 5 +++++ watcher/tests/decision_engine/model/test_element.py | 1 + 3 files changed, 9 insertions(+) diff --git a/watcher/decision_engine/model/collector/nova.py b/watcher/decision_engine/model/collector/nova.py index 27b090697..750fb4266 100644 --- a/watcher/decision_engine/model/collector/nova.py +++ b/watcher/decision_engine/model/collector/nova.py @@ -344,7 +344,10 @@ class ModelBuilder(object): flavor = instance.flavor instance_attributes = { "uuid": instance.id, + # TODO(chenker) human_id is deprecated for removal. For the reason, + # please reference bug 1833665. "human_id": instance.human_id, + "name": instance.name, "memory": flavor["ram"], "disk": flavor["disk"], "disk_capacity": flavor["disk"], diff --git a/watcher/decision_engine/model/notification/nova.py b/watcher/decision_engine/model/notification/nova.py index 5c885bd14..7b8d0465f 100644 --- a/watcher/decision_engine/model/notification/nova.py +++ b/watcher/decision_engine/model/notification/nova.py @@ -71,7 +71,12 @@ class NovaNotification(base.NotificationEndpoint): instance.update({ 'state': instance_data['state'], 'hostname': instance_data['host_name'], + # TODO(chenker) human_id is deprecated for removal. For the reason, + # please reference bug 1833665. 'human_id': instance_data['display_name'], + # this is the user-provided display name of the server which is not + # guaranteed to be unique nor is it immutable. + 'name': instance_data['display_name'], 'memory': memory_mb, 'vcpus': num_cores, 'disk': disk_gb, diff --git a/watcher/tests/decision_engine/model/test_element.py b/watcher/tests/decision_engine/model/test_element.py index 6f28ce861..7da704fdd 100644 --- a/watcher/tests/decision_engine/model/test_element.py +++ b/watcher/tests/decision_engine/model/test_element.py @@ -51,6 +51,7 @@ class TestElement(base.TestCase): 'state': 'state', 'hostname': 'hostname', 'human_id': 'human_id', + 'name': 'name', 'memory': 111, 'vcpus': 222, 'disk': 333,