launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #07211
[Merge] lp:~matsubara/maas/oops-over-amqp into lp:maas
Diogo Matsubara has proposed merging lp:~matsubara/maas/oops-over-amqp into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~matsubara/maas/oops-over-amqp/+merge/103184
This branch implements publishing of oops reports to a rabbit queue, if RABBITMQ_PUBLISH is set to True. It's mostly cargo culted from Launchpad.
--
https://code.launchpad.net/~matsubara/maas/oops-over-amqp/+merge/103184
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~matsubara/maas/oops-over-amqp into lp:maas.
=== modified file 'buildout.cfg'
--- buildout.cfg 2012-04-18 15:14:17 +0000
+++ buildout.cfg 2012-04-23 22:21:18 +0000
@@ -35,6 +35,7 @@
oops-twisted
oops-wsgi
psycopg2
+ oops-amqp
PyYAML
Twisted
txAMQP
@@ -87,6 +88,7 @@
oops-wsgi
psycopg2
pyasn1
+ oops-amqp
rabbitfixture
South
twisted
=== modified file 'setup.py'
--- setup.py 2012-04-16 10:00:51 +0000
+++ setup.py 2012-04-23 22:21:18 +0000
@@ -65,6 +65,7 @@
'psycopg2',
'avahi',
'amqplib',
+ 'bson',
'convoy',
'dbus',
'django-piston',
@@ -72,6 +73,7 @@
'oauth',
'oops',
'oops-datedir-repo',
+ 'oops-amqp',
'oops-twisted',
'PyYAML',
'South',
=== modified file 'src/maas/demo.py'
--- src/maas/demo.py 2012-04-18 10:51:03 +0000
+++ src/maas/demo.py 2012-04-23 22:21:18 +0000
@@ -36,11 +36,21 @@
# Enable longpoll. Set LONGPOLL_PATH to None to disable it.
LONGPOLL_PATH = '/longpoll/'
+DEBUG = False
+
# For demo purposes, use a real provisioning server.
USE_REAL_PSERV = True
MAAS_CLI = os.path.join(os.getcwd(), 'bin', 'maas')
+# Rabbit MQ Configuration.
+RABBITMQ_HOST = 'localhost'
+RABBITMQ_USERID = 'guest'
+RABBITMQ_PASSWORD = 'guest'
+RABBITMQ_VIRTUAL_HOST = '/'
+OOPS_RABBITMQ_EXCHANGE = 'oopses'
+OOPS_RABBITMQ_ROUTING_KEY = ''
+
RABBITMQ_PUBLISH = True
LOGGING = {
=== modified file 'src/maas/settings.py'
--- src/maas/settings.py 2012-04-18 10:51:03 +0000
+++ src/maas/settings.py 2012-04-23 22:21:18 +0000
@@ -93,6 +93,8 @@
RABBITMQ_USERID = 'guest'
RABBITMQ_PASSWORD = 'guest'
RABBITMQ_VIRTUAL_HOST = '/'
+OOPS_RABBITMQ_EXCHANGE = 'oopses'
+OOPS_RABBITMQ_ROUTING_KEY = ''
RABBITMQ_PUBLISH = True
=== modified file 'src/maasserver/management/commands/runserver.py'
--- src/maasserver/management/commands/runserver.py 2012-04-16 10:00:51 +0000
+++ src/maasserver/management/commands/runserver.py 2012-04-23 22:21:18 +0000
@@ -19,7 +19,9 @@
from django.core.management.commands.runserver import BaseRunserverCommand
from django.core.servers import basehttp
from django.core.servers.basehttp import WSGIServer
+from maasserver import rabbit
import oops
+import oops_amqp
from oops_datedir_repo import DateDirRepo
from oops_wsgi import (
install_hooks,
@@ -74,13 +76,27 @@
wsgi_handler = super(Command, self).get_handler(self, *args, **kwargs)
# Wrap the WSGI handler in an oops handler. This catches (most)
- # exceptions bubbling up out of the app, and stores them as
- # oopses in the directory specified by the OOPS_REPOSITORY
- # configuration setting.
+ # exceptions bubbling up out of the app.
# Django's debug mode causes it to handle exceptions itself, so
# don't expect oopses when DEBUG is set to True.
+ oops_config = self.setup_oops_publishers()
+ install_hooks(oops_config)
+ return make_app(wsgi_handler, oops_config, error_render=render_error)
+
+ def setup_oops_publishers(self):
+ """Setup publishers for OOPS reports and return the oops_config.
+
+ Publishes OOPS reports to the amqp queue, if RABBITMQ_PUBLISH is True
+ Always add the on disk publisher, which stores oops in the directory
+ specified by OOPS_REPOSITORY configuration setting.
+ """
oops_config = oops.Config()
+ if settings.RABBITMQ_PUBLISH:
+ exchange = settings.OOPS_RABBITMQ_EXCHANGE
+ routing_key = settings.OOPS_RABBITMQ_ROUTING_KEY
+ amqp_publisher = oops_amqp.Publisher(
+ rabbit.connect, exchange, routing_key)
+ oops_config.publishers.append(amqp_publisher)
oops_repository = DateDirRepo(settings.OOPS_REPOSITORY)
oops_config.publishers.append(oops_repository.publish)
- install_hooks(oops_config)
- return make_app(wsgi_handler, oops_config, error_render=render_error)
+ return oops_config
=== modified file 'src/maasserver/tests/test_runserver.py'
--- src/maasserver/tests/test_runserver.py 2012-04-16 10:00:51 +0000
+++ src/maasserver/tests/test_runserver.py 2012-04-23 22:21:18 +0000
@@ -12,8 +12,11 @@
__metaclass__ = type
__all__ = []
-from maasserver.management.commands.runserver import render_error
+from django.conf import settings
+from maasserver.management.commands.runserver import Command, render_error
from maasserver.testing.testcase import TestCase
+import oops_amqp
+import oops_datedir_repo
class TestRunServer(TestCase):
@@ -34,3 +37,22 @@
# the oops page.
fake_oops = {'id': '\u2322'}
self.assertRaises(Exception, render_error, fake_oops)
+
+ def test_setup_oops_publishers(self):
+ # When RABBITMQ_PUBLISH is False, we only have the on disk publisher
+ self.assertFalse(settings.RABBITMQ_PUBLISH)
+ oops_config = Command().setup_oops_publishers()
+ self.assertEqual(1, len(oops_config.publishers))
+ publisher = oops_config.publishers[0].__self__
+ self.assertIsInstance(publisher, oops_datedir_repo.DateDirRepo)
+
+ def test_setup_oops_publishers_with_rabbit(self):
+ # when RABBITMQ_PUBLISH is True, we should have two publishers setup.
+ self.patch(settings, 'RABBITMQ_PUBLISH', True)
+ oops_config = Command().setup_oops_publishers()
+ self.assertEqual(2, len(oops_config.publishers))
+ # - a rabbit publisher
+ self.assertIsInstance(oops_config.publishers[0], oops_amqp.Publisher)
+ # - a datedir publisher
+ publisher = oops_config.publishers[1].__self__
+ self.assertIsInstance(publisher, oops_datedir_repo.DateDirRepo)
=== modified file 'src/metadataserver/models/__init__.py' (properties changed: +x to -x)