Forbid new legacy notification event_type
As we agreed on the Mitaka midcycle no new legacy notification event_type are allowed in Nova and every new notification shall use the versioned notification framework. This patch adds a validation step into the legacy notification sending call chain. It checks the event_type against a whitelist. During unit and functional testing an exception is raised if the event_type is not known and therefore forbiden. This check is not 100% foolproof as it only detects the new event_type if there is a test that triggers the sending of it and this check is not capable of detecting such event_types if the test directly mocks nova.rpc.get_notifier. During normal operation a WARNING is logged so that a logstash query can be set up to detect the rest of the cases. Change-Id: Ia6600868aa7b3a22cb8c020503f49dce6a4c2c2b
This commit is contained in:
@@ -244,6 +244,8 @@ class TestCase(testtools.TestCase):
|
||||
|
||||
openstack_driver.DRIVER_CACHE = {}
|
||||
|
||||
self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture())
|
||||
|
||||
def _restore_obj_registry(self):
|
||||
objects_base.NovaObjectRegistry._registry._obj_classes = \
|
||||
self._base_test_obj_backup
|
||||
|
||||
@@ -524,3 +524,26 @@ class EngineFacadeFixture(fixtures.Fixture):
|
||||
|
||||
def cleanup(self):
|
||||
self._ctx_manager._root_factory = self._existing_factory
|
||||
|
||||
|
||||
class ForbidNewLegacyNotificationFixture(fixtures.Fixture):
|
||||
"""Make sure the test fails if new legacy notification is added"""
|
||||
def __init__(self):
|
||||
super(ForbidNewLegacyNotificationFixture, self).__init__()
|
||||
self.notifier = rpc.LegacyValidatingNotifier
|
||||
|
||||
def setUp(self):
|
||||
super(ForbidNewLegacyNotificationFixture, self).setUp()
|
||||
self.notifier.fatal = True
|
||||
|
||||
# allow the special test value used in
|
||||
# nova.tests.unit.test_notifications.NotificationsTestCase
|
||||
self.notifier.allowed_legacy_notification_event_types.append(
|
||||
'_decorated_function')
|
||||
|
||||
self.addCleanup(self.cleanup)
|
||||
|
||||
def cleanup(self):
|
||||
self.notifier.fatal = False
|
||||
self.notifier.allowed_legacy_notification_event_types.remove(
|
||||
'_decorated_function')
|
||||
|
||||
Reference in New Issue
Block a user