Short circuit notifications when not enabled

Wasting time on generating the payload of the notifications is
unnecessary if the notification will not be emitted due to
configuration.

This patch depends on an oslo messaging improvement that adds
a way to check if a Notifier will emit the notification or not.

Depends-On: Ib992f5c20fef85224fb00823e1d8d9c6cff19bec
Depends-On: I979fb3385671aba6f4162ef991da8f0febe0068a

Change-Id: I3e6741d59df49e1e58409314008c2ed609fdedc1
This commit is contained in:
Balazs Gibizer
2017-02-02 17:49:58 +01:00
committed by melanie witt
parent 1e0e4080fb
commit 29cb8f1c45
9 changed files with 184 additions and 15 deletions

View File

@@ -215,6 +215,19 @@ def get_versioned_notifier(publisher_id):
return NOTIFIER.prepare(publisher_id=publisher_id)
def if_notifications_enabled(f):
"""Calls decorated method only if versioned notifications are enabled."""
@functools.wraps(f)
def wrapped(*args, **kwargs):
if (NOTIFIER.is_enabled() and
CONF.notifications.notification_format in ('both',
'versioned')):
return f(*args, **kwargs)
else:
return None
return wrapped
def create_transport(url):
exmods = get_allowed_exmods()
return messaging.get_transport(CONF,