From 720ab5a157c1d741f59d52811d92458516234368 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Mon, 27 Jun 2011 20:21:45 -0700 Subject: [PATCH 1/4] getting started --- nova/rpc.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/nova/rpc.py b/nova/rpc.py index 2e78a31e..d4ac19c2 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -45,6 +45,8 @@ from nova import flags from nova import log as logging from nova import utils +from nova.notifier import api as notifier + LOG = logging.getLogger('nova.rpc') @@ -312,6 +314,7 @@ class ConsumerSet(object): if not it: break while True: + ex = None try: it.next() except StopIteration: @@ -319,7 +322,17 @@ class ConsumerSet(object): except greenlet.GreenletExit: running = False break + except exception.NovaException, e: + if not e.notification_level: + ex = e + # We have an exception we can + # tell the Notification system about. + # Pass it on. + except Exception as e: + ex = e + + if ex: LOG.exception(_("Exception while processing consumer")) self.reconnect() # Break to outer loop From cd3a40bc0b23a4e52e82eaec8b3fa47271ef7e08 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Tue, 28 Jun 2011 05:51:40 -0700 Subject: [PATCH 2/4] refactoring to compute from scheduler --- nova/notifier/api.py | 39 +++++++++++++++++++++++++++++++++++++++ nova/rpc.py | 9 ++------- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/nova/notifier/api.py b/nova/notifier/api.py index d49517c8..027aa7cc 100644 --- a/nova/notifier/api.py +++ b/nova/notifier/api.py @@ -37,6 +37,45 @@ class BadPriorityException(Exception): pass +def publisher_id(service, host=None): + if not host: + host = FLAGS.host + return "%s.%s" % (service, host) + + +def msgkeys(event_type, instance_id, level, publisher_id): + return dict(event_type=event_type, instance_id=instance_id, + notification_level=level, publisher_id=publisher_id) + + +def safe_notify(publisher_id, event_type, priority, payload): + try: + notify(publisher_id, event_type, notification_level, payload) + exception Exception, e: + LOG.exception(_("Problem '%(e)' attempting to " + "send to notification system." % locals())) + + +def instance_safe_notify(publisher_id, event_type, priority, instance_id, + extra_payload=None): + payload = dict(instance_id = instance_id) + if extra_payload: + payload.extend(extra_payload) + safe_notify(publisher_id, event_type, priority, payload) + + +def exception_to_notification(self, ex): + required = ['instance_id', 'publisher_id', 'notification_level', + 'event_type'] + for key in required: + if not (hasattr(ex, key) and ex.key): + return # Doesn't have everything we need. Skip it. + instance_id = ex.instance_id + publisher_id = ex.publisher_id + notification_level = ex.notification_level + event_type = ex.event_type + instance_safe_notify(publisher_id, event_type, priority, instance_id) + def notify(publisher_id, event_type, priority, payload): """ Sends a notification using the specified driver diff --git a/nova/rpc.py b/nova/rpc.py index d4ac19c2..47d63769 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -44,7 +44,6 @@ from nova import fakerabbit from nova import flags from nova import log as logging from nova import utils - from nova.notifier import api as notifier @@ -323,12 +322,8 @@ class ConsumerSet(object): running = False break except exception.NovaException, e: - if not e.notification_level: - ex = e - # We have an exception we can - # tell the Notification system about. - # Pass it on. - + ex = e + notifier.exception_to_notification(e) except Exception as e: ex = e From f0f8da9fdd303a7305f5cd79bd8db8d2e1ca23ac Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Tue, 28 Jun 2011 21:04:50 -0700 Subject: [PATCH 3/4] moved to wrap_exception decorator --- nova/notifier/api.py | 26 -------------------------- nova/rpc.py | 8 -------- 2 files changed, 34 deletions(-) diff --git a/nova/notifier/api.py b/nova/notifier/api.py index 027aa7cc..89527be1 100644 --- a/nova/notifier/api.py +++ b/nova/notifier/api.py @@ -43,11 +43,6 @@ def publisher_id(service, host=None): return "%s.%s" % (service, host) -def msgkeys(event_type, instance_id, level, publisher_id): - return dict(event_type=event_type, instance_id=instance_id, - notification_level=level, publisher_id=publisher_id) - - def safe_notify(publisher_id, event_type, priority, payload): try: notify(publisher_id, event_type, notification_level, payload) @@ -55,27 +50,6 @@ def safe_notify(publisher_id, event_type, priority, payload): LOG.exception(_("Problem '%(e)' attempting to " "send to notification system." % locals())) - -def instance_safe_notify(publisher_id, event_type, priority, instance_id, - extra_payload=None): - payload = dict(instance_id = instance_id) - if extra_payload: - payload.extend(extra_payload) - safe_notify(publisher_id, event_type, priority, payload) - - -def exception_to_notification(self, ex): - required = ['instance_id', 'publisher_id', 'notification_level', - 'event_type'] - for key in required: - if not (hasattr(ex, key) and ex.key): - return # Doesn't have everything we need. Skip it. - instance_id = ex.instance_id - publisher_id = ex.publisher_id - notification_level = ex.notification_level - event_type = ex.event_type - instance_safe_notify(publisher_id, event_type, priority, instance_id) - def notify(publisher_id, event_type, priority, payload): """ Sends a notification using the specified driver diff --git a/nova/rpc.py b/nova/rpc.py index 47d63769..2e78a31e 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -44,7 +44,6 @@ from nova import fakerabbit from nova import flags from nova import log as logging from nova import utils -from nova.notifier import api as notifier LOG = logging.getLogger('nova.rpc') @@ -313,7 +312,6 @@ class ConsumerSet(object): if not it: break while True: - ex = None try: it.next() except StopIteration: @@ -321,13 +319,7 @@ class ConsumerSet(object): except greenlet.GreenletExit: running = False break - except exception.NovaException, e: - ex = e - notifier.exception_to_notification(e) except Exception as e: - ex = e - - if ex: LOG.exception(_("Exception while processing consumer")) self.reconnect() # Break to outer loop From 7d74fd08b329fd7e4189b1c4ce9135bfff700800 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Fri, 1 Jul 2011 07:31:17 -0700 Subject: [PATCH 4/4] review fixes --- nova/notifier/api.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/nova/notifier/api.py b/nova/notifier/api.py index d388eda9..98969fd3 100644 --- a/nova/notifier/api.py +++ b/nova/notifier/api.py @@ -45,14 +45,6 @@ def publisher_id(service, host=None): return "%s.%s" % (service, host) -def safe_notify(publisher_id, event_type, priority, payload): - try: - notify(publisher_id, event_type, notification_level, payload) - except Exception, e: - LOG.exception(_("Problem '%(e)s' attempting to " - "send to notification system." % locals())) - - def notify(publisher_id, event_type, priority, payload): """ Sends a notification using the specified driver @@ -95,4 +87,8 @@ def notify(publisher_id, event_type, priority, payload): priority=priority, payload=payload, timestamp=str(utils.utcnow())) - driver.notify(msg) + try: + driver.notify(msg) + except Exception, e: + LOG.exception(_("Problem '%(e)s' attempting to " + "send to notification system." % locals()))