Fix notification logic
Notifications were always treated as if they're about state changes due to a typo. Additionally exception handler did not work correctly. Regression tests included. Change-Id: I0b92a1baa17768d9cf4e709b3331480548dd041e
This commit is contained in:
@@ -63,7 +63,7 @@ def send_update(context, old_instance, new_instance, service=None, host=None):
|
|||||||
|
|
||||||
old_vm_state = old_instance["vm_state"]
|
old_vm_state = old_instance["vm_state"]
|
||||||
new_vm_state = new_instance["vm_state"]
|
new_vm_state = new_instance["vm_state"]
|
||||||
old_task_state = old_instance["task_state"],
|
old_task_state = old_instance["task_state"]
|
||||||
new_task_state = new_instance["task_state"]
|
new_task_state = new_instance["task_state"]
|
||||||
|
|
||||||
# we should check if we need to send a state change or a regular
|
# we should check if we need to send a state change or a regular
|
||||||
@@ -90,7 +90,7 @@ def send_update(context, old_instance, new_instance, service=None, host=None):
|
|||||||
service=service, host=host)
|
service=service, host=host)
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.exception(_("Failed to send state update notification"),
|
LOG.exception(_("Failed to send state update notification"),
|
||||||
instance=instance)
|
instance=new_instance)
|
||||||
|
|
||||||
|
|
||||||
def send_update_with_states(context, instance, old_vm_state, new_vm_state,
|
def send_update_with_states(context, instance, old_vm_state, new_vm_state,
|
||||||
|
|||||||
@@ -268,3 +268,22 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
display_name = self.instance["display_name"]
|
display_name = self.instance["display_name"]
|
||||||
|
|
||||||
self.assertEquals(payload["display_name"], display_name)
|
self.assertEquals(payload["display_name"], display_name)
|
||||||
|
|
||||||
|
def test_send_no_state_change(self):
|
||||||
|
called = [False]
|
||||||
|
|
||||||
|
def sending_no_state_change(context, instance, **kwargs):
|
||||||
|
called[0] = True
|
||||||
|
self.stubs.Set(notifications, '_send_instance_update_notification',
|
||||||
|
sending_no_state_change)
|
||||||
|
notifications.send_update(self.context, self.instance, self.instance)
|
||||||
|
self.assertTrue(called[0])
|
||||||
|
|
||||||
|
def test_fail_sending_update(self):
|
||||||
|
def fail_sending(context, instance, **kwargs):
|
||||||
|
raise Exception('failed to notify')
|
||||||
|
self.stubs.Set(notifications, '_send_instance_update_notification',
|
||||||
|
fail_sending)
|
||||||
|
|
||||||
|
notifications.send_update(self.context, self.instance, self.instance)
|
||||||
|
self.assertEquals(0, len(test_notifier.NOTIFICATIONS))
|
||||||
|
|||||||
Reference in New Issue
Block a user