← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~stevenk/launchpad/auditor-layer into lp:launchpad

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/auditor-layer into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/auditor-layer/+merge/112962

Add auditor and auditorfixture as depends (and Django, but let's not mention that fun fact at all), a layer and a server that the layer brings up. This allows us to start making use of auditor in code and tests.
-- 
https://code.launchpad.net/~stevenk/launchpad/auditor-layer/+merge/112962
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/auditor-layer into lp:launchpad.
=== modified file 'buildout.cfg'
--- buildout.cfg	2012-05-14 20:33:32 +0000
+++ buildout.cfg	2012-07-02 04:42:47 +0000
@@ -10,6 +10,7 @@
     iharness
     i18n
     txlongpoll
+    auditor
 unzip = true
 eggs-directory = eggs
 download-cache = download-cache
@@ -121,3 +122,10 @@
 initialization = ${scripts:initialization}
 entry-points = twistd-for-txlongpoll=twisted.scripts.twistd:run
 scripts = twistd-for-txlongpoll
+
+[auditor]
+recipe = z3c.recipe.scripts
+eggs = auditor
+include-site-packages = false
+entry-points = auditor-manage=auditor.manage:run
+scripts = auditor-manage

=== added directory 'lib/lp/services/auditor'
=== added file 'lib/lp/services/auditor/__init__.py'
=== added file 'lib/lp/services/auditor/server.py'
--- lib/lp/services/auditor/server.py	1970-01-01 00:00:00 +0000
+++ lib/lp/services/auditor/server.py	2012-07-02 04:42:47 +0000
@@ -0,0 +1,38 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Auditor server fixture."""
+
+__metaclass__ = type
+__all__ = [
+    'AuditorServer',
+    ]
+
+import os
+from textwrap import dedent
+
+from auditorfixture.server import AuditorFixture
+
+import lp
+
+
+class AuditorServer(AuditorFixture):
+    """An Auditor server fixture with Launchpad-specific config.
+
+    :ivar service_config: A snippet of .ini that describes the `auditor`
+        configuration.
+    """
+
+    def __init__(self, port=None, logfile=None, manage_bin=None):
+        manage_bin = os.path.join(
+            os.path.dirname(lp.__file__), '../../bin/auditor-manage')
+        super(AuditorServer, self).__init__(port, logfile, manage_bin)
+
+    def setUp(self):
+        super(AuditorServer, self).setUp()
+        setattr(
+            self, 'service_config',
+            dedent("""\
+                [auditor]
+                port: %d
+                """ % (self.config.port)))

=== added directory 'lib/lp/services/auditor/tests'
=== added file 'lib/lp/services/auditor/tests/__init__.py'
=== added file 'lib/lp/services/auditor/tests/test_server.py'
--- lib/lp/services/auditor/tests/test_server.py	1970-01-01 00:00:00 +0000
+++ lib/lp/services/auditor/tests/test_server.py	2012-07-02 04:42:47 +0000
@@ -0,0 +1,28 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for lp.services.auditor.AuditorServer."""
+
+__metaclass__ = type
+
+from ConfigParser import SafeConfigParser
+from StringIO import StringIO
+
+from lp.services.auditor.server import AuditorServer
+from lp.testing import TestCase
+from lp.testing.layers import BaseLayer
+
+
+class TestAuditorServer(TestCase):
+
+    layer = BaseLayer
+
+    def test_service_config(self):
+        # AuditorServer pokes some .ini configuration into its config.
+        fixture = self.useFixture(AuditorServer())
+        service_config = SafeConfigParser()
+        service_config.readfp(StringIO(fixture.service_config))
+        self.assertEqual(["auditor"], service_config.sections())
+        expected = {"port": "%d" % fixture.config.port}
+        observed = dict(service_config.items("auditor"))
+        self.assertEqual(expected, observed)

=== modified file 'lib/lp/testing/layers.py'
--- lib/lp/testing/layers.py	2012-06-14 05:18:22 +0000
+++ lib/lp/testing/layers.py	2012-07-02 04:42:47 +0000
@@ -1,10 +1,10 @@
-# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 # We like global!
 # pylint: disable-msg=W0603,W0702
 
-"""Layers used by Canonical tests.
+"""Layers used by Launchpad tests.
 
 Layers are the mechanism used by the Zope3 test runner to efficiently
 provide environments for tests and are documented in the lib/zope/testing.
@@ -24,6 +24,7 @@
 __metaclass__ = type
 __all__ = [
     'AppServerLayer',
+    'AuditorLayer',
     'BaseLayer',
     'DatabaseFunctionalLayer',
     'DatabaseLayer',
@@ -39,6 +40,7 @@
     'LayerIsolationError',
     'LibrarianLayer',
     'PageTestLayer',
+    'RabbitMQLayer',
     'TwistedAppServerLayer',
     'TwistedLaunchpadZopelessLayer',
     'TwistedLayer',
@@ -101,6 +103,7 @@
 from zope.server.logger.pythonlogger import PythonLogger
 
 from lp.services import pidfile
+from lp.services.auditor.server import AuditorServer
 from lp.services.config import (
     config,
     dbconfig,
@@ -704,6 +707,44 @@
         pass
 
 
+class AuditorLayer(BaseLayer):
+
+    auditor = AuditorServer()
+
+    _is_setup = False
+
+    @classmethod
+    @profiled
+    def setUp(cls):
+        cls.auditor.setUp()
+        cls.config_fixture.add_section(
+            cls.auditor.config.service_config)
+        cls.appserver_config_fixture.add_section(
+            cls.auditor.config.service_config)
+        cls._is_setup = True
+
+    @classmethod
+    @profiled
+    def tearDown(cls):
+        if not cls._is_setup:
+            return
+        cls.auditor.cleanUp()
+        cls._is_setup = False
+        # Can't pop the config above, so bail here and let the test runner
+        # start a sub-process.
+        raise NotImplementedError
+
+    @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

=== modified file 'setup.py'
--- setup.py	2012-04-24 04:23:52 +0000
+++ setup.py	2012-07-02 04:42:47 +0000
@@ -27,6 +27,7 @@
     # used in zcml.
     install_requires=[
         'ampoule',
+        'auditorfixture',
         'BeautifulSoup',
         'bzr',
         'Chameleon',

=== modified file 'versions.cfg'
--- versions.cfg	2012-06-22 14:56:27 +0000
+++ versions.cfg	2012-07-02 04:42:47 +0000
@@ -8,6 +8,8 @@
 amqplib = 1.0.2
 anyjson = 0.3.1
 argparse = 1.2.1
+auditor = 0.0.1
+auditorfixture = 0.0.1
 BeautifulSoup = 3.1.0.1
 bson = 0.3.2
 # The source for this version of bzr is at lp:~benji/bzr/bug-998040
@@ -19,6 +21,8 @@
 ClientForm = 0.2.10
 cssutils = 0.9.7
 docutils = 0.5
+django = 1.4
+Django = 1.4
 # Required by pydkim
 dnspython = 1.7.1
 elementtree = 1.2.6-20050316


Follow ups