launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #03623
[Merge] lp:~lifeless/launchpad/rabbit into lp:launchpad
Robert Collins has proposed merging lp:~lifeless/launchpad/rabbit into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~lifeless/launchpad/rabbit/+merge/61057
Add a testing layer for rabbitmq. I had a small bug in the ConfigFixture to make this expose more sanely.
--
https://code.launchpad.net/~lifeless/launchpad/rabbit/+merge/61057
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~lifeless/launchpad/rabbit into lp:launchpad.
=== modified file 'lib/canonical/config/fixture.py'
--- lib/canonical/config/fixture.py 2010-12-21 13:59:56 +0000
+++ lib/canonical/config/fixture.py 2011-05-16 02:48:32 +0000
@@ -43,6 +43,9 @@
"""Add sectioncontent to the lazy config."""
with open(self.absroot + '/launchpad-lazr.conf', 'ab') as out:
out.write(sectioncontent)
+ # Trigger a refresh IFF the config is in use at the moment.
+ if config.instance_name == self.instance_name:
+ config._invalidateConfig()
def setUp(self):
super(ConfigFixture, self).setUp()
=== modified file 'lib/canonical/config/schema-lazr.conf'
--- lib/canonical/config/schema-lazr.conf 2011-05-06 13:55:19 +0000
+++ lib/canonical/config/schema-lazr.conf 2011-05-16 02:48:32 +0000
@@ -1771,6 +1771,17 @@
# datatype: filename
memory_profile_log:
+[rabbitmq]
+# hostname to connect to.
+# datatype: string
+host: none
+# username
+# datatype: string
+userid: guest
+# datatype: string
+password: guest
+# datatype: string
+virtual_host: /
[reclaimbranchspace]
# The database user which will be used by this process.
=== modified file 'lib/canonical/testing/ftests/test_layers.py'
--- lib/canonical/testing/ftests/test_layers.py 2010-12-21 13:59:56 +0000
+++ lib/canonical/testing/ftests/test_layers.py 2011-05-16 02:48:32 +0000
@@ -19,6 +19,7 @@
from cStringIO import StringIO
from urllib import urlopen
+from amqplib import client_0_8 as amqp
from fixtures import (
Fixture,
EnvironmentVariableFixture,
@@ -48,6 +49,7 @@
LayerProcessController,
LibrarianLayer,
MemcachedLayer,
+ RabbitMQLayer,
ZopelessLayer,
)
from lp.services.memcache.client import memcache_client_factory
@@ -162,6 +164,7 @@
want_functional_flag = False
want_zopeless_flag = False
want_memcached = False
+ want_rabbitmq = False
def testBaseIsSetUpFlag(self):
self.failUnlessEqual(BaseLayer.isSetUp, True)
@@ -259,6 +262,17 @@
self.assertEqual(
is_live, False, "memcached is live but should not be.")
+ def testRabbitWorking(self):
+ rabbitmq = config.rabbitmq
+ if not self.want_rabbitmq:
+ self.assertEqual(None, rabbitmq.host)
+ else:
+ self.assertNotEqual(None, rabbitmq.host)
+ conn = amqp.Connection(host=rabbitmq.host, userid=rabbitmq.userid,
+ password=rabbitmq.password, virtual_host=rabbitmq.virtual_host,
+ insist=False)
+ conn.close()
+
class MemcachedTestCase(BaseTestCase):
layer = MemcachedLayer
@@ -380,6 +394,11 @@
'foo', len(data), StringIO(data), 'text/plain')
+class RabbitMQTestCase(BaseTestCase):
+ layer = RabbitMQLayer
+ want_rabbitmq = True
+
+
class DatabaseTestCase(BaseTestCase):
layer = DatabaseLayer
@@ -432,6 +451,7 @@
want_launchpad_database = True
want_librarian_running = True
want_memcached = True
+ want_rabbitmq = True
class FunctionalTestCase(BaseTestCase):
@@ -458,6 +478,7 @@
want_librarian_running = True
want_functional_flag = True
want_memcached = True
+ want_rabbitmq = True
class LaunchpadZopelessTestCase(BaseTestCase):
@@ -468,6 +489,7 @@
want_librarian_running = True
want_zopeless_flag = True
want_memcached = True
+ want_rabbitmq = True
class LaunchpadScriptTestCase(BaseTestCase):
@@ -478,6 +500,7 @@
want_librarian_running = True
want_zopeless_flag = True
want_memcached = True
+ want_rabbitmq = True
def testSwitchDbConfig(self):
# Test that we can switch database configurations, and that we
@@ -503,6 +526,7 @@
want_functional_flag = True
want_zopeless_flag = False
want_memcached = True
+ want_rabbitmq = True
def testAppServerIsAvailable(self):
# Test that the app server is up and running.
=== modified file 'lib/canonical/testing/layers.py'
--- lib/canonical/testing/layers.py 2011-04-14 02:06:27 +0000
+++ lib/canonical/testing/layers.py 2011-05-16 02:48:32 +0000
@@ -115,6 +115,7 @@
from lp.testing import ANONYMOUS, login, logout, is_logged_in
import lp.services.mail.stub
from lp.services.mail.mailbox import TestMailBox
+from lp.services.rabbit.testing.server import RabbitServer
from canonical.launchpad.scripts import execute_zcml_for_scripts
from lp.services.googlesearch.tests.googleserviceharness import (
GoogleServiceTestSetup)
@@ -639,6 +640,43 @@
MemcachedLayer.client.flush_all() # Only do this in tests!
+class RabbitMQLayer(BaseLayer):
+ """Provides tests access to a rabbitMQ instance."""
+ _reset_between_tests = True
+
+ rabbit = RabbitServer()
+
+ _is_setup = False
+
+ @classmethod
+ @profiled
+ def setUp(cls):
+ cls.rabbit.setUp()
+ cls.config_fixture.add_section(
+ cls.rabbit.config.service_config)
+ cls.appserver_config_fixture.add_section(
+ cls.rabbit.config.service_config)
+ cls._is_setup = True
+
+ @classmethod
+ @profiled
+ def tearDown(cls):
+ if not cls._is_setup:
+ return
+ cls.rabbit.cleanUp()
+ cls._is_setup = False
+
+ @classmethod
+ @profiled
+ def testSetUp(cls):
+ pass
+
+ @classmethod
+ @profiled
+ def testTearDown(cls):
+ pass
+
+
# We store a reference to the DB-API connect method here when we
# put a proxy in its place.
_org_connect = None
@@ -934,7 +972,7 @@
return None
-class LaunchpadLayer(LibrarianLayer, MemcachedLayer):
+class LaunchpadLayer(LibrarianLayer, MemcachedLayer, RabbitMQLayer):
"""Provides access to the Launchpad database and daemons.
We need to ensure that the database setup runs before the daemon
=== modified file 'lib/lp/services/rabbit/testing/server.py'
--- lib/lp/services/rabbit/testing/server.py 2011-05-11 00:49:23 +0000
+++ lib/lp/services/rabbit/testing/server.py 2011-05-16 02:48:32 +0000
@@ -10,6 +10,7 @@
import socket
import optparse
import subprocess
+from textwrap import dedent
import time
import bzrlib.branch
@@ -177,6 +178,13 @@
self.logfile = os.path.join(self.rabbitdir, 'rabbit.log')
self.pidfile = os.path.join(self.rabbitdir, 'rabbit.pid')
self.nodename = os.path.basename(self.useFixture(TempDir()).path)
+ self.service_config = dedent("""\
+ [rabbitmq]
+ host: localhost:%d
+ userid: guest
+ password: guest
+ virtual_host: /
+ """ % self.port)
def fq_nodename(self):
"""Get the node of the rabbit that is being exported."""
@@ -381,7 +389,7 @@
self.config = self.useFixture(AllocateRabbitServer())
self.server = RunRabbitServer(self.config)
self.useFixture(self.server)
+ self.host = 'localhost:%s' % self.config.port
def getDetails(self):
return self.server.getDetails()
-
=== modified file 'lib/lp/services/rabbit/tests/test_fixture.py'
--- lib/lp/services/rabbit/tests/test_fixture.py 2011-05-11 00:49:23 +0000
+++ lib/lp/services/rabbit/tests/test_fixture.py 2011-05-16 02:48:32 +0000
@@ -6,6 +6,7 @@
__metaclass__ = type
import socket
+from textwrap import dedent
from amqplib import client_0_8 as amqp
from fixtures import EnvironmentVariableFixture
@@ -28,14 +29,25 @@
self.addCleanup(self._gather_details, fixture.getDetails)
fixture.setUp()
# We can connect.
- host = 'localhost:%s' % fixture.config.port
+ host = fixture.host
conn = amqp.Connection(host=host, userid="guest",
- password="guest", virtual_host="/", insist=False)
+ password="guest", virtual_host="/", insist=False)
conn.close()
# And get a log file
log = fixture.getDetails()['rabbit log file']
# Which shouldn't blow up on iteration.
list(log.iter_text())
+ # There is a (launchpad specific) config fixture. (This could be a
+ # separate class if we make the fixture external in the future).
+ expected = dedent("""\
+ [rabbitmq]
+ host: %s
+ userid: guest
+ password: guest
+ virtual_host: /
+ """ % host)
+ self.assertEqual(expected, fixture.config.service_config)
+
finally:
fixture.cleanUp()
# The daemon should be closed now.