diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-11-19 11:25:07 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-11-19 11:25:07 +0000 |
commit | dd4e355141bfadab484b30e2bd84b59299932066 (patch) | |
tree | 6eba74b6cc6457b441618ef4a924f2494621cbf4 /ironic | |
parent | 0aa0f6fd1e10593b84bc2201a3692accde854da6 (diff) | |
parent | bea0d484257b346fb8b0617dcbd6c66b18e746e2 (diff) | |
download | ironic-dd4e355141bfadab484b30e2bd84b59299932066.tar.gz |
Merge "sync common.notifier.* from oslo"
Diffstat (limited to 'ironic')
-rw-r--r-- | ironic/openstack/common/notifier/api.py | 41 | ||||
-rw-r--r-- | ironic/openstack/common/notifier/log_notifier.py | 4 | ||||
-rw-r--r-- | ironic/openstack/common/notifier/no_op_notifier.py | 2 | ||||
-rw-r--r-- | ironic/openstack/common/notifier/rpc_notifier.py | 9 | ||||
-rw-r--r-- | ironic/openstack/common/notifier/rpc_notifier2.py | 9 |
5 files changed, 30 insertions, 35 deletions
diff --git a/ironic/openstack/common/notifier/api.py b/ironic/openstack/common/notifier/api.py index 068da4d28..2962306b1 100644 --- a/ironic/openstack/common/notifier/api.py +++ b/ironic/openstack/common/notifier/api.py @@ -13,12 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +import socket import uuid from oslo.config import cfg from ironic.openstack.common import context -from ironic.openstack.common.gettextutils import _ +from ironic.openstack.common.gettextutils import _ # noqa from ironic.openstack.common import importutils from ironic.openstack.common import jsonutils from ironic.openstack.common import log as logging @@ -35,7 +36,7 @@ notifier_opts = [ default='INFO', help='Default notification level for outgoing notifications'), cfg.StrOpt('default_publisher_id', - default='$host', + default=None, help='Default publisher_id for outgoing notifications'), ] @@ -56,7 +57,7 @@ class BadPriorityException(Exception): def notify_decorator(name, fn): - """ decorator for notify which is used from utils.monkey_patch() + """Decorator for notify which is used from utils.monkey_patch(). :param name: name of the function :param function: - object of the function @@ -74,7 +75,7 @@ def notify_decorator(name, fn): ctxt = context.get_context_from_function_and_args(fn, args, kwarg) notify(ctxt, - CONF.default_publisher_id, + CONF.default_publisher_id or socket.gethostname(), name, CONF.default_notification_level, body) @@ -84,7 +85,10 @@ def notify_decorator(name, fn): def publisher_id(service, host=None): if not host: - host = CONF.host + try: + host = CONF.host + except AttributeError: + host = CONF.default_publisher_id or socket.gethostname() return "%s.%s" % (service, host) @@ -153,29 +157,16 @@ def _get_drivers(): if _drivers is None: _drivers = {} for notification_driver in CONF.notification_driver: - add_driver(notification_driver) - + try: + driver = importutils.import_module(notification_driver) + _drivers[notification_driver] = driver + except ImportError: + LOG.exception(_("Failed to load notifier %s. " + "These notifications will not be sent.") % + notification_driver) return _drivers.values() -def add_driver(notification_driver): - """Add a notification driver at runtime.""" - # Make sure the driver list is initialized. - _get_drivers() - if isinstance(notification_driver, basestring): - # Load and add - try: - driver = importutils.import_module(notification_driver) - _drivers[notification_driver] = driver - except ImportError: - LOG.exception(_("Failed to load notifier %s. " - "These notifications will not be sent.") % - notification_driver) - else: - # Driver is already loaded; just add the object. - _drivers[notification_driver] = notification_driver - - def _reset_drivers(): """Used by unit tests to reset the drivers.""" global _drivers diff --git a/ironic/openstack/common/notifier/log_notifier.py b/ironic/openstack/common/notifier/log_notifier.py index 71a6717e1..04b1a3afa 100644 --- a/ironic/openstack/common/notifier/log_notifier.py +++ b/ironic/openstack/common/notifier/log_notifier.py @@ -24,7 +24,9 @@ CONF = cfg.CONF def notify(_context, message): """Notifies the recipient of the desired event given the model. - Log notifications using openstack's default logging system""" + + Log notifications using OpenStack's default logging system. + """ priority = message.get('priority', CONF.default_notification_level) diff --git a/ironic/openstack/common/notifier/no_op_notifier.py b/ironic/openstack/common/notifier/no_op_notifier.py index bc7a56ca7..13d946e36 100644 --- a/ironic/openstack/common/notifier/no_op_notifier.py +++ b/ironic/openstack/common/notifier/no_op_notifier.py @@ -15,5 +15,5 @@ def notify(_context, message): - """Notifies the recipient of the desired event given the model""" + """Notifies the recipient of the desired event given the model.""" pass diff --git a/ironic/openstack/common/notifier/rpc_notifier.py b/ironic/openstack/common/notifier/rpc_notifier.py index 845dec8b6..f87e40bb2 100644 --- a/ironic/openstack/common/notifier/rpc_notifier.py +++ b/ironic/openstack/common/notifier/rpc_notifier.py @@ -16,7 +16,7 @@ from oslo.config import cfg from ironic.openstack.common import context as req_context -from ironic.openstack.common.gettextutils import _ +from ironic.openstack.common.gettextutils import _ # noqa from ironic.openstack.common import log as logging from ironic.openstack.common import rpc @@ -24,14 +24,14 @@ LOG = logging.getLogger(__name__) notification_topic_opt = cfg.ListOpt( 'notification_topics', default=['notifications', ], - help='AMQP topic used for openstack notifications') + help='AMQP topic used for OpenStack notifications') CONF = cfg.CONF CONF.register_opt(notification_topic_opt) def notify(context, message): - """Sends a notification via RPC""" + """Sends a notification via RPC.""" if not context: context = req_context.get_admin_context() priority = message.get('priority', @@ -43,4 +43,5 @@ def notify(context, message): rpc.notify(context, topic, message) except Exception: LOG.exception(_("Could not send notification to %(topic)s. " - "Payload=%(message)s"), locals()) + "Payload=%(message)s"), + {"topic": topic, "message": message}) diff --git a/ironic/openstack/common/notifier/rpc_notifier2.py b/ironic/openstack/common/notifier/rpc_notifier2.py index 6bcc8ea8c..deb96ab77 100644 --- a/ironic/openstack/common/notifier/rpc_notifier2.py +++ b/ironic/openstack/common/notifier/rpc_notifier2.py @@ -18,7 +18,7 @@ from oslo.config import cfg from ironic.openstack.common import context as req_context -from ironic.openstack.common.gettextutils import _ +from ironic.openstack.common.gettextutils import _ # noqa from ironic.openstack.common import log as logging from ironic.openstack.common import rpc @@ -26,7 +26,7 @@ LOG = logging.getLogger(__name__) notification_topic_opt = cfg.ListOpt( 'topics', default=['notifications', ], - help='AMQP topic(s) used for openstack notifications') + help='AMQP topic(s) used for OpenStack notifications') opt_group = cfg.OptGroup(name='rpc_notifier2', title='Options for rpc_notifier2') @@ -37,7 +37,7 @@ CONF.register_opt(notification_topic_opt, opt_group) def notify(context, message): - """Sends a notification via RPC""" + """Sends a notification via RPC.""" if not context: context = req_context.get_admin_context() priority = message.get('priority', @@ -49,4 +49,5 @@ def notify(context, message): rpc.notify(context, topic, message, envelope=True) except Exception: LOG.exception(_("Could not send notification to %(topic)s. " - "Payload=%(message)s"), locals()) + "Payload=%(message)s"), + {"topic": topic, "message": message}) |