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
This commit is contained in:
Matt Riedemann 2019-10-24 18:32:13 -04:00 committed by Dan Smith
parent ba48c2369f
commit d50efc337c
6 changed files with 72 additions and 1 deletions

View File

@ -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 = {}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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,

View File

@ -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

View File

@ -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])