Add progress and cell_name into notifications

When the instance DB record is updated, we send notifications. To make
those more useful, I have added in cell_name and progress. These fields
where added after the initial notifications were added.

Change-Id: I3bc770e3b8f211c27e5e4aadd1819507d643cc75
Closes-Bug: #1366758
This commit is contained in:
John Garbutt 2014-09-08 12:23:15 +01:00 committed by John Garbutt
parent 6072f51626
commit 974c3b8cff
2 changed files with 33 additions and 0 deletions

View File

@ -335,6 +335,9 @@ def info_from_instance(context, instance_ref, network_info,
def null_safe_str(s):
return str(s) if s else ''
def null_safe_int(s):
return int(s) if s else ''
def null_safe_isotime(s):
if isinstance(s, datetime.datetime):
return timeutils.strtime(s)
@ -381,6 +384,7 @@ def info_from_instance(context, instance_ref, network_info,
host=instance_ref['host'],
node=instance_ref['node'],
availability_zone=instance_ref['availability_zone'],
cell_name=null_safe_str(instance_ref['cell_name']),
# Date properties
created_at=str(instance_ref['created_at']),
@ -400,6 +404,7 @@ def info_from_instance(context, instance_ref, network_info,
# Status properties
state=instance_ref['vm_state'],
state_description=null_safe_str(instance_ref.get('task_state')),
progress=null_safe_int(instance_ref['progress']),
# accessIPs
access_ip_v4=instance_ref['access_ip_v4'],

View File

@ -285,6 +285,34 @@ class NotificationsTestCase(test.TestCase):
self.assertEqual(self.net_info[0]['address'],
info["fixed_ips"][0]["vif_mac"])
def test_payload_has_cell_name_empty(self):
info = notifications.info_from_instance(self.context, self.instance,
self.net_info, None)
self.assertIn("cell_name", info)
self.assertIsNone(self.instance['cell_name'])
self.assertEqual("", info["cell_name"])
def test_payload_has_cell_name(self):
self.instance['cell_name'] = "cell1"
info = notifications.info_from_instance(self.context, self.instance,
self.net_info, None)
self.assertIn("cell_name", info)
self.assertEqual("cell1", info["cell_name"])
def test_payload_has_progress_empty(self):
info = notifications.info_from_instance(self.context, self.instance,
self.net_info, None)
self.assertIn("progress", info)
self.assertIsNone(self.instance['progress'])
self.assertEqual("", info["progress"])
def test_payload_has_progress(self):
self.instance['progress'] = 50
info = notifications.info_from_instance(self.context, self.instance,
self.net_info, None)
self.assertIn("progress", info)
self.assertEqual(50, info["progress"])
def test_send_access_ip_update(self):
notifications.send_update(self.context, self.instance, self.instance)
self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))