summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openstack/common/notifier/api.py10
-rw-r--r--tests/unit/test_notifier.py8
2 files changed, 15 insertions, 3 deletions
diff --git a/openstack/common/notifier/api.py b/openstack/common/notifier/api.py
index 7c4dbd1..dc4f578 100644
--- a/openstack/common/notifier/api.py
+++ b/openstack/common/notifier/api.py
@@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import socket
import uuid
from oslo.config import cfg
@@ -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)
diff --git a/tests/unit/test_notifier.py b/tests/unit/test_notifier.py
index 6c3b886..891b0ec 100644
--- a/tests/unit/test_notifier.py
+++ b/tests/unit/test_notifier.py
@@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import socket
+
from oslo.config import cfg
from openstack.common import context
@@ -308,3 +310,9 @@ class MultiNotifierTestCase(test_utils.BaseTestCase):
notifier_api.WARN,
dict(a=3))
self.assertEqual(self.notify_count, 1)
+
+ def test_publisher_id(self):
+ self.assertEqual(notifier_api.publisher_id('foobar'),
+ 'foobar.' + socket.gethostname())
+ self.assertEqual(notifier_api.publisher_id('foobar', 'baz'),
+ 'foobar.baz')