From: Andreas Jaeger Date: Mon, 12 Aug 2013 09:29:11 +0000 (+0200) Subject: Merge from oslo-incubator for notifier X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=9d8ba3af477ebce0c159fecc1eb3dfceb066df23;p=openstack-build%2Fcinder-build.git Merge from oslo-incubator for notifier Goal: merge oslo-incubator change I282d4ae3311bc3fcda6be8e5a1fceecfc8ddb115 Done via: python update.py --nodeps --base cinder --dest-dir ../cinder \ --modules notifier Change-Id: I0cb982b3b45eb63941f9bfe5407c93af280c452a --- diff --git a/cinder/openstack/common/notifier/api.py b/cinder/openstack/common/notifier/api.py index f1115a743..b9b790895 100644 --- a/cinder/openstack/common/notifier/api.py +++ b/cinder/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 cinder.openstack.common import context -from cinder.openstack.common.gettextutils import _ +from cinder.openstack.common.gettextutils import _ # noqa from cinder.openstack.common import importutils from cinder.openstack.common import jsonutils from cinder.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'), ] @@ -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/cinder/openstack/common/notifier/log_notifier.py b/cinder/openstack/common/notifier/log_notifier.py index 8d81c24c3..11a453d9e 100644 --- a/cinder/openstack/common/notifier/log_notifier.py +++ b/cinder/openstack/common/notifier/log_notifier.py @@ -25,7 +25,7 @@ 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', diff --git a/cinder/openstack/common/notifier/rpc_notifier.py b/cinder/openstack/common/notifier/rpc_notifier.py index 32a8954a2..6c37cbdc2 100644 --- a/cinder/openstack/common/notifier/rpc_notifier.py +++ b/cinder/openstack/common/notifier/rpc_notifier.py @@ -16,7 +16,7 @@ from oslo.config import cfg from cinder.openstack.common import context as req_context -from cinder.openstack.common.gettextutils import _ +from cinder.openstack.common.gettextutils import _ # noqa from cinder.openstack.common import log as logging from cinder.openstack.common import rpc @@ -24,7 +24,7 @@ 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) diff --git a/cinder/openstack/common/notifier/rpc_notifier2.py b/cinder/openstack/common/notifier/rpc_notifier2.py index d624451de..9082cc5b7 100644 --- a/cinder/openstack/common/notifier/rpc_notifier2.py +++ b/cinder/openstack/common/notifier/rpc_notifier2.py @@ -18,7 +18,7 @@ from oslo.config import cfg from cinder.openstack.common import context as req_context -from cinder.openstack.common.gettextutils import _ +from cinder.openstack.common.gettextutils import _ # noqa from cinder.openstack.common import log as logging from cinder.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') diff --git a/etc/cinder/cinder.conf.sample b/etc/cinder/cinder.conf.sample index d91d7506b..435b3e764 100644 --- a/etc/cinder/cinder.conf.sample +++ b/etc/cinder/cinder.conf.sample @@ -541,7 +541,7 @@ # Options defined in cinder.openstack.common.notifier.rpc_notifier # -# AMQP topic used for openstack notifications (list value) +# AMQP topic used for OpenStack notifications (list value) #notification_topics=notifications @@ -549,7 +549,7 @@ # Options defined in cinder.openstack.common.notifier.rpc_notifier2 # -# AMQP topic(s) used for openstack notifications (list value) +# AMQP topic(s) used for OpenStack notifications (list value) #topics=notifications