From d50efc337cb1dea0011a26887e2b9db4f8bc30d3 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Thu, 24 Oct 2019 18:32:13 -0400 Subject: [PATCH] Add notification sample test for aggregate.cache_images.start|end This adds the functional notification sample test for the aggregate.cache_images.start and aggregate.cache_images.end versioned notifications. I also added a comment to the docs builder code since it took me a bit to figure out how to get the notification sample linked into the docs, and for whatever reason figured that out by looking through code rather than our nicely detailed docs that already explain it. Part of blueprint image-precache-support Change-Id: I0869979a1b8a0966f0e7b49e5a5984f76d7d67cd --- doc/ext/versioned_notifications.py | 4 ++ .../aggregate-cache_images-end.json | 11 +++++ .../aggregate-cache_images-start.json | 11 +++++ nova/conductor/manager.py | 3 +- nova/notifications/objects/aggregate.py | 2 + .../test_aggregate.py | 42 +++++++++++++++++++ 6 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 doc/notification_samples/aggregate-cache_images-end.json create mode 100644 doc/notification_samples/aggregate-cache_images-start.json diff --git a/doc/ext/versioned_notifications.py b/doc/ext/versioned_notifications.py index 7972b87277..09a7621c8a 100644 --- a/doc/ext/versioned_notifications.py +++ b/doc/ext/versioned_notifications.py @@ -61,6 +61,10 @@ jQuery(document).ready(function(){ pkgutil.iter_modules(nova.notifications.objects.__path__)))) def _collect_notifications(self): + # If you do not see your notification sample showing up in the docs + # be sure that the sample filename matches what is registered on the + # versioned notification object class using the + # @base.notification_sample decorator. self._import_all_notification_packages() base.NovaObjectRegistry.register_notification_objects() notifications = {} diff --git a/doc/notification_samples/aggregate-cache_images-end.json b/doc/notification_samples/aggregate-cache_images-end.json new file mode 100644 index 0000000000..4c41e0add2 --- /dev/null +++ b/doc/notification_samples/aggregate-cache_images-end.json @@ -0,0 +1,11 @@ +{ + "priority": "INFO", + "payload": { + "$ref": "common_payloads/AggregatePayload.json#", + "nova_object.data": { + "hosts": ["compute"] + } + }, + "event_type": "aggregate.cache_images.end", + "publisher_id": "nova-api:fake-mini" +} diff --git a/doc/notification_samples/aggregate-cache_images-start.json b/doc/notification_samples/aggregate-cache_images-start.json new file mode 100644 index 0000000000..98f38c9766 --- /dev/null +++ b/doc/notification_samples/aggregate-cache_images-start.json @@ -0,0 +1,11 @@ +{ + "priority": "INFO", + "payload": { + "$ref": "common_payloads/AggregatePayload.json#", + "nova_object.data": { + "hosts": ["compute"] + } + }, + "event_type": "aggregate.cache_images.start", + "publisher_id": "nova-api:fake-mini" +} diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py index 7531a2eacd..6ff940419e 100644 --- a/nova/conductor/manager.py +++ b/nova/conductor/manager.py @@ -1640,7 +1640,8 @@ class ComputeTaskManager(base.Base): :param image_id: The IDs of the image to cache """ - # TODO(danms): Fix notification sample for IMAGE_CACHE action + # TODO(mriedem): Consider including the list of images in the + # notification payload. compute_utils.notify_about_aggregate_action( context, aggregate, fields.NotificationAction.IMAGE_CACHE, diff --git a/nova/notifications/objects/aggregate.py b/nova/notifications/objects/aggregate.py index 38871dd680..fed8a20357 100644 --- a/nova/notifications/objects/aggregate.py +++ b/nova/notifications/objects/aggregate.py @@ -54,6 +54,8 @@ class AggregatePayload(base.NotificationPayloadBase): @base.notification_sample('aggregate-update_metadata-end.json') @base.notification_sample('aggregate-update_prop-start.json') @base.notification_sample('aggregate-update_prop-end.json') +@base.notification_sample('aggregate-cache_images-start.json') +@base.notification_sample('aggregate-cache_images-end.json') @nova_base.NovaObjectRegistry.register_notification class AggregateNotification(base.NotificationBase): # Version 1.0: Initial version diff --git a/nova/tests/functional/notification_sample_tests/test_aggregate.py b/nova/tests/functional/notification_sample_tests/test_aggregate.py index ca6a701b29..5682331662 100644 --- a/nova/tests/functional/notification_sample_tests/test_aggregate.py +++ b/nova/tests/functional/notification_sample_tests/test_aggregate.py @@ -166,3 +166,45 @@ class TestAggregateNotificationSample( 'uuid': aggregate['uuid'], 'id': aggregate['id']}, actual=fake_notifier.VERSIONED_NOTIFICATIONS[3]) + + def test_aggregate_cache_images(self): + aggregate_req = { + "aggregate": { + "name": "my-aggregate", + "availability_zone": "nova"}} + aggregate = self.admin_api.post_aggregate(aggregate_req) + add_host_req = { + "add_host": { + "host": "compute" + } + } + self.admin_api.post_aggregate_action(aggregate['id'], add_host_req) + + fake_notifier.reset() + + cache_images_req = { + 'cache': [ + {'id': '155d900f-4e14-4e4c-a73d-069cbf4541e6'} + ] + } + self.admin_api.api_post('/os-aggregates/%s/images' % aggregate['id'], + cache_images_req) + # Since the operation is asynchronous we have to wait for the end + # notification. + fake_notifier.wait_for_versioned_notifications( + 'aggregate.cache_images.end') + + self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS), + fake_notifier.VERSIONED_NOTIFICATIONS) + self._verify_notification( + 'aggregate-cache_images-start', + replacements={ + 'uuid': aggregate['uuid'], + 'id': aggregate['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[0]) + self._verify_notification( + 'aggregate-cache_images-end', + replacements={ + 'uuid': aggregate['uuid'], + 'id': aggregate['id']}, + actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])