]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Sync latest notifier changes from openstack-common
authorDan Prince <dprince@redhat.com>
Mon, 5 Nov 2012 21:41:41 +0000 (16:41 -0500)
committerDan Prince <dprince@redhat.com>
Mon, 5 Nov 2012 21:48:52 +0000 (16:48 -0500)
Updates Quantum with the latest changes from openstack-commons
notifier package:

    Rename rabbit_notifier to rpc_notifier.

    The previous rabbit_notifier module is generic and can be used
    for all RPC notifications.

    This commit moves the rabbit_notifier module to rpc_notifier and
    adds a new deprecated rabbit_notifier module which can be used for
    Grizzly so that users can have a chance to easily upgrade this
    config setting.

Also updates the agent code and config file to reflect this change
(and get unit tests to pass)

Fixes LP Bug #1075330.

Change-Id: If9a4f5fa27638b25a29b66dbfed757554358ff7c

etc/quantum.conf
quantum/agent/rpc.py
quantum/openstack/common/cfg.py
quantum/openstack/common/log.py
quantum/openstack/common/notifier/rabbit_notifier.py
quantum/openstack/common/notifier/rpc_notifier.py [new file with mode: 0644]

index e767102ef21f4fdbef4d24060e0510a402d671dd..8733590492b720bc85c3ed5e7e6b831863f9ba0c 100644 (file)
@@ -164,7 +164,7 @@ control_exchange = quantum
 # Logging driver
 # notification_driver = quantum.openstack.common.notifier.log_notifier
 # RPC driver. DHCP agents needs it.
-notification_driver = quantum.openstack.common.notifier.rabbit_notifier
+notification_driver = quantum.openstack.common.notifier.rpc_notifier
 
 # default_notification_level is used to form actual topic name(s) or to set logging level
 default_notification_level = INFO
@@ -173,7 +173,7 @@ default_notification_level = INFO
 # host = myhost.com
 # default_publisher_id = $host
 
-# Defined in rabbit_notifier for rpc way, can be comma separated values.
+# Defined in rpc_notifier, can be comma separated values.
 # The actual topic names will be %s.%(default_notification_level)s
 notification_topics = notifications
 
index 81b3e291d8a65a9dc02ca1c794148cb05c4856b5..cab2c2ae2bb6599c7f7a133d0b70d3bfb8604074 100644 (file)
@@ -19,7 +19,7 @@ from quantum.common import topics
 
 from quantum.openstack.common import log as logging
 from quantum.openstack.common.notifier import api
-from quantum.openstack.common.notifier import rabbit_notifier
+from quantum.openstack.common.notifier import rpc_notifier
 from quantum.openstack.common import rpc
 from quantum.openstack.common.rpc import proxy
 
@@ -84,7 +84,7 @@ class NotificationDispatcher(object):
         # being buffered in the process.
         self.queue = eventlet.queue.Queue(1)
         self.connection = rpc.create_connection(new=True)
-        topic = '%s.%s' % (rabbit_notifier.CONF.notification_topics[0],
+        topic = '%s.%s' % (rpc_notifier.CONF.notification_topics[0],
                            api.CONF.default_notification_level.lower())
         self.connection.declare_topic_consumer(topic=topic,
                                                callback=self._add_to_queue)
index bcd1f05fdf52817c3411f18a3710552d43a67b4e..4fcd242517c91965ab15bce4551fa08193e458b0 100644 (file)
@@ -239,7 +239,7 @@ in order to support a common usage pattern in OpenStack:
   from openstack.common import cfg
 
   opts = [
-    cfg.StrOpt('bind_host' default='0.0.0.0'),
+    cfg.StrOpt('bind_host', default='0.0.0.0'),
     cfg.IntOpt('bind_port', default=9292),
   ]
 
@@ -1507,7 +1507,7 @@ class ConfigOpts(collections.Mapping):
                 if ('default' in info or 'override' in info):
                     continue
 
-                if self._get(opt.name, group) is None:
+                if self._get(opt.dest, group) is None:
                     raise RequiredOptError(opt.name, group)
 
     def _parse_cli_opts(self, args):
index be29bf8ad9eca36a150f5c36fa5edf18ce15b904..acdf96def0eba786355d59b12723460506e1d07e 100644 (file)
@@ -76,6 +76,9 @@ log_opts = [
     cfg.BoolOpt('publish_errors',
                 default=False,
                 help='publish error events'),
+    cfg.BoolOpt('fatal_deprecations',
+                default=False,
+                help='make deprecations fatal'),
 
     # NOTE(mikal): there are two options here because sometimes we are handed
     # a full instance (and could include more information), and other times we
@@ -170,6 +173,14 @@ class ContextAdapter(logging.LoggerAdapter):
     def audit(self, msg, *args, **kwargs):
         self.log(logging.AUDIT, msg, *args, **kwargs)
 
+    def deprecated(self, msg, *args, **kwargs):
+        stdmsg = _("Deprecated Config: %s") % msg
+        if CONF.fatal_deprecations:
+            self.critical(stdmsg, *args, **kwargs)
+            raise DeprecatedConfig(msg=stdmsg)
+        else:
+            self.warn(stdmsg, *args, **kwargs)
+
     def process(self, msg, kwargs):
         if 'extra' not in kwargs:
             kwargs['extra'] = {}
@@ -246,7 +257,7 @@ class JSONFormatter(logging.Formatter):
 
 class PublishErrorsHandler(logging.Handler):
     def emit(self, record):
-        if ('quantum.openstack.common.notifier.log_notifier' in
+        if ('openstack.common.notifier.log_notifier' in
             CONF.notification_driver):
             return
         notifier.api.notify(None, 'error.publisher',
@@ -450,3 +461,10 @@ class ColorHandler(logging.StreamHandler):
     def format(self, record):
         record.color = self.LEVEL_COLORS[record.levelno]
         return logging.StreamHandler.format(self, record)
+
+
+class DeprecatedConfig(Exception):
+    message = _("Fatal call to deprecated config: %(msg)s")
+
+    def __init__(self, msg):
+        super(Exception, self).__init__(self.message % dict(msg=msg))
index e11c418fead1abb12dcdb990827e2d3eeddf67b3..428ec7b7f5e26670bfb4c28559859c357efdb21f 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2011 OpenStack LLC.
+# Copyright 2012 Red Hat, Inc.
 # All Rights Reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
 #    under the License.
 
 
-from quantum.openstack.common import cfg
-from quantum.openstack.common import context as req_context
 from quantum.openstack.common.gettextutils import _
 from quantum.openstack.common import log as logging
-from quantum.openstack.common import rpc
+from quantum.openstack.common.notifier import rpc_notifier
 
 LOG = logging.getLogger(__name__)
 
-notification_topic_opt = cfg.ListOpt(
-    'notification_topics', default=['notifications', ],
-    help='AMQP topic used for openstack notifications')
-
-CONF = cfg.CONF
-CONF.register_opt(notification_topic_opt)
-
 
 def notify(context, message):
-    """Sends a notification to the RabbitMQ"""
-    if not context:
-        context = req_context.get_admin_context()
-    priority = message.get('priority',
-                           CONF.default_notification_level)
-    priority = priority.lower()
-    for topic in CONF.notification_topics:
-        topic = '%s.%s' % (topic, priority)
-        try:
-            rpc.notify(context, topic, message)
-        except Exception, e:
-            LOG.exception(_("Could not send notification to %(topic)s. "
-                            "Payload=%(message)s"), locals())
+    """Deprecated in Grizzly. Please use rpc_notifier instead."""
+
+    LOG.deprecated(_("The rabbit_notifier is now deprecated."
+                     " Please use rpc_notifier instead."))
+    rpc_notifier.notify(context, message)
diff --git a/quantum/openstack/common/notifier/rpc_notifier.py b/quantum/openstack/common/notifier/rpc_notifier.py
new file mode 100644 (file)
index 0000000..c165053
--- /dev/null
@@ -0,0 +1,46 @@
+# Copyright 2011 OpenStack LLC.
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+
+from quantum.openstack.common import cfg
+from quantum.openstack.common import context as req_context
+from quantum.openstack.common.gettextutils import _
+from quantum.openstack.common import log as logging
+from quantum.openstack.common import rpc
+
+LOG = logging.getLogger(__name__)
+
+notification_topic_opt = cfg.ListOpt(
+    'notification_topics', default=['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"""
+    if not context:
+        context = req_context.get_admin_context()
+    priority = message.get('priority',
+                           CONF.default_notification_level)
+    priority = priority.lower()
+    for topic in CONF.notification_topics:
+        topic = '%s.%s' % (topic, priority)
+        try:
+            rpc.notify(context, topic, message)
+        except Exception, e:
+            LOG.exception(_("Could not send notification to %(topic)s. "
+                            "Payload=%(message)s"), locals())