diff options
| author | Wangpan <hzwangpan@corp.netease.com> | 2013-06-07 09:21:42 +0800 |
|---|---|---|
| committer | Wangpan <hzwangpan@corp.netease.com> | 2013-06-17 09:03:31 +0800 |
| commit | c1211f24aa9895e5bbc9f503e0f13d2d7a65504b (patch) | |
| tree | 2217a73239760ea76e66c51fdf94a5aecf917e28 | |
| parent | d147af21db2db77f578e527883cf2c68abc56496 (diff) | |
Add old display name to update notification
Add old display name to payload of update notification when it is
changed, so the notification consumer could know the display name is
changed which is the same as task_state.
Fixes bug 1191612
Change-Id: I47b8ad8ffc2988212b59fb141e83b8110994b8da
| -rw-r--r-- | nova/notifications.py | 12 | ||||
| -rw-r--r-- | nova/tests/test_notifications.py | 10 |
2 files changed, 17 insertions, 5 deletions
diff --git a/nova/notifications.py b/nova/notifications.py index 13e2a8fca..a90fa855e 100644 --- a/nova/notifications.py +++ b/nova/notifications.py @@ -106,8 +106,12 @@ def send_update(context, old_instance, new_instance, service=None, host=None): else: try: + old_display_name = None + if new_instance["display_name"] != old_instance["display_name"]: + old_display_name = old_instance["display_name"] _send_instance_update_notification(context, new_instance, - service=service, host=host) + service=service, host=host, + old_display_name=old_display_name) except Exception: LOG.exception(_("Failed to send state update notification"), instance=new_instance) @@ -155,7 +159,7 @@ def send_update_with_states(context, instance, old_vm_state, new_vm_state, def _send_instance_update_notification(context, instance, old_vm_state=None, old_task_state=None, new_vm_state=None, new_task_state=None, - service="compute", host=None): + service="compute", host=None, old_display_name=None): """Send 'compute.instance.update' notification to inform observers about instance state changes. """ @@ -185,6 +189,10 @@ def _send_instance_update_notification(context, instance, old_vm_state=None, bw = bandwidth_usage(instance, audit_start) payload["bandwidth"] = bw + # add old display name if it is changed + if old_display_name: + payload["old_display_name"] = old_display_name + publisher_id = notifier_api.publisher_id(service, host) notifier_api.notify(context, publisher_id, 'compute.instance.update', diff --git a/nova/tests/test_notifications.py b/nova/tests/test_notifications.py index 23fe4c82b..0d7c0e7a8 100644 --- a/nova/tests/test_notifications.py +++ b/nova/tests/test_notifications.py @@ -295,13 +295,17 @@ class NotificationsTestCase(test.TestCase): self.assertEquals(payload["access_ip_v6"], access_ip_v6) def test_send_name_update(self): - notifications.send_update(self.context, self.instance, self.instance) + param = {"display_name": "new_display_name"} + new_name_inst = self._wrapped_create(params=param) + notifications.send_update(self.context, self.instance, new_name_inst) self.assertEquals(1, len(test_notifier.NOTIFICATIONS)) notif = test_notifier.NOTIFICATIONS[0] payload = notif["payload"] - display_name = self.instance["display_name"] + old_display_name = self.instance["display_name"] + new_display_name = new_name_inst["display_name"] - self.assertEquals(payload["display_name"], display_name) + self.assertEquals(payload["old_display_name"], old_display_name) + self.assertEquals(payload["display_name"], new_display_name) def test_send_no_state_change(self): called = [False] |
