From 1bc6b0e605529b32e03def0ebfc82a6e7ea31dff Mon Sep 17 00:00:00 2001 From: David TARDIVEL Date: Fri, 16 Dec 2016 10:11:38 +0100 Subject: [PATCH] Fix bad CDMC update on reception of service.update When we receive a incoming 'service.update' notification from nova, with disabled: false, we should set the related compute node status to ENABLED. Change-Id: Ib8075a5cf786f81ec41423805433f83ae721cbbd Closes-bug: #1650485 --- .../model/notification/nova.py | 2 +- ...=> scenario3_service-update-disabled.json} | 0 .../scenario3_service-update-enabled.json | 21 +++++++++++++++++++ .../notification/test_nova_notifications.py | 16 +++++++++++++- 4 files changed, 37 insertions(+), 2 deletions(-) rename watcher/tests/decision_engine/model/notification/data/{scenario3_service-update.json => scenario3_service-update-disabled.json} (100%) create mode 100644 watcher/tests/decision_engine/model/notification/data/scenario3_service-update-enabled.json diff --git a/watcher/decision_engine/model/notification/nova.py b/watcher/decision_engine/model/notification/nova.py index f73e4c273..3ec755e81 100644 --- a/watcher/decision_engine/model/notification/nova.py +++ b/watcher/decision_engine/model/notification/nova.py @@ -121,7 +121,7 @@ class NovaNotification(base.NotificationEndpoint): if node_data['forced_down'] else element.ServiceState.ONLINE.value) node.status = ( element.ServiceState.DISABLED.value - if node_data['host'] else element.ServiceState.ENABLED.value) + if node_data['disabled'] else element.ServiceState.ENABLED.value) def create_compute_node(self, node_hostname): """Update the compute node by querying the Nova API.""" diff --git a/watcher/tests/decision_engine/model/notification/data/scenario3_service-update.json b/watcher/tests/decision_engine/model/notification/data/scenario3_service-update-disabled.json similarity index 100% rename from watcher/tests/decision_engine/model/notification/data/scenario3_service-update.json rename to watcher/tests/decision_engine/model/notification/data/scenario3_service-update-disabled.json diff --git a/watcher/tests/decision_engine/model/notification/data/scenario3_service-update-enabled.json b/watcher/tests/decision_engine/model/notification/data/scenario3_service-update-enabled.json new file mode 100644 index 000000000..f3e7f2334 --- /dev/null +++ b/watcher/tests/decision_engine/model/notification/data/scenario3_service-update-enabled.json @@ -0,0 +1,21 @@ +{ + "priority": "INFO", + "payload": { + "nova_object.namespace": "nova", + "nova_object.name": "ServiceStatusPayload", + "nova_object.version": "1.0", + "nova_object.data": { + "host": "Node_0", + "disabled": false, + "last_seen_up": "2012-10-29T13:42:05Z", + "binary": "nova-compute", + "topic": "compute", + "disabled_reason": null, + "report_count": 1, + "forced_down": false, + "version": 15 + } + }, + "event_type": "service.update", + "publisher_id": "nova-compute:Node_0" +} diff --git a/watcher/tests/decision_engine/model/notification/test_nova_notifications.py b/watcher/tests/decision_engine/model/notification/test_nova_notifications.py index fae9d9a43..f99c5dca7 100644 --- a/watcher/tests/decision_engine/model/notification/test_nova_notifications.py +++ b/watcher/tests/decision_engine/model/notification/test_nova_notifications.py @@ -127,7 +127,7 @@ class TestNovaNotifications(NotificationTestCase): node0_uuid = 'Node_0' node0 = compute_model.get_node_by_uuid(node0_uuid) - message = self.load_message('scenario3_service-update.json') + message = self.load_message('scenario3_service-update-disabled.json') self.assertEqual('hostname_0', node0.hostname) self.assertEqual(element.ServiceState.ONLINE.value, node0.state) @@ -145,6 +145,20 @@ class TestNovaNotifications(NotificationTestCase): self.assertEqual(element.ServiceState.OFFLINE.value, node0.state) self.assertEqual(element.ServiceState.DISABLED.value, node0.status) + message = self.load_message('scenario3_service-update-enabled.json') + + handler.info( + ctxt=self.context, + publisher_id=message['publisher_id'], + event_type=message['event_type'], + payload=message['payload'], + metadata=self.FAKE_METADATA, + ) + + self.assertEqual('Node_0', node0.hostname) + self.assertEqual(element.ServiceState.ONLINE.value, node0.state) + self.assertEqual(element.ServiceState.ENABLED.value, node0.status) + def test_nova_instance_update(self): compute_model = self.fake_cdmc.generate_scenario_3_with_2_nodes() self.fake_cdmc.cluster_data_model = compute_model