|
36 | 36 | from nova import exception
|
37 | 37 | from nova.image import glance
|
38 | 38 | from nova.network import model
|
| 39 | +from nova.notifications.objects import base as notifications_objects_base |
39 | 40 | from nova import objects
|
40 | 41 | from nova.objects import base
|
41 | 42 | from nova.objects import block_device as block_device_obj
|
@@ -472,6 +473,31 @@ def test_notify_usage_exists_deleted_instance(self):
|
472 | 473 | glance.generate_glance_url(self.context), uuids.fake_image_ref)
|
473 | 474 | self.assertEqual(payload['image_ref_url'], image_ref_url)
|
474 | 475 |
|
| 476 | + def test_notify_about_instance_action_best_effort(self): |
| 477 | + instance = create_instance(self.context) |
| 478 | + bdms = block_device_obj.block_device_make_list( |
| 479 | + self.context, |
| 480 | + [fake_block_device.FakeDbBlockDeviceDict( |
| 481 | + {'source_type': 'volume', |
| 482 | + 'device_name': '/dev/vda', |
| 483 | + 'instance_uuid': 'f8000000-0000-0000-0000-000000000000', |
| 484 | + 'destination_type': 'volume', |
| 485 | + 'boot_index': 0, |
| 486 | + 'volume_id': 'de8836ac-d75e-11e2-8271-5254009297d6'})]) |
| 487 | + with mock.patch.object( |
| 488 | + notifications_objects_base.NotificationBase, 'emit', |
| 489 | + side_effect=Exception() |
| 490 | + ) as mock_emit: |
| 491 | + compute_utils.notify_about_instance_action( |
| 492 | + self.context, |
| 493 | + instance, |
| 494 | + host='fake-compute', |
| 495 | + action='delete', |
| 496 | + phase='start', |
| 497 | + bdms=bdms, |
| 498 | + best_effort=True) |
| 499 | + mock_emit.assert_called_once() |
| 500 | + |
475 | 501 | def test_notify_about_instance_action(self):
|
476 | 502 | instance = create_instance(self.context)
|
477 | 503 | bdms = block_device_obj.block_device_make_list(
|
@@ -873,6 +899,24 @@ def test_notify_about_volume_usage(self):
|
873 | 899 | self.assertEqual(200, payload['write_bytes'])
|
874 | 900 | self.assertEqual(200, payload['writes'])
|
875 | 901 |
|
| 902 | + def test_notify_about_instance_usage_best_effort(self): |
| 903 | + instance = create_instance(self.context) |
| 904 | + # Set some system metadata |
| 905 | + sys_metadata = {'image_md_key1': 'val1', |
| 906 | + 'image_md_key2': 'val2', |
| 907 | + 'other_data': 'meow'} |
| 908 | + instance.system_metadata.update(sys_metadata) |
| 909 | + instance.save() |
| 910 | + extra_usage_info = {'image_name': 'fake_name'} |
| 911 | + notifier = rpc.get_notifier('compute') |
| 912 | + with mock.patch.object( |
| 913 | + notifier, 'info', side_effect=Exception() |
| 914 | + ) as mock_info: |
| 915 | + compute_utils.notify_about_instance_usage( |
| 916 | + notifier, self.context, instance, 'create.start', |
| 917 | + extra_usage_info=extra_usage_info, best_effort=True) |
| 918 | + mock_info.assert_called_once() |
| 919 | + |
876 | 920 | def test_notify_about_instance_usage(self):
|
877 | 921 | instance = create_instance(self.context)
|
878 | 922 | # Set some system metadata
|
|
0 commit comments