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

Proposed by Steve Kowalik on 2012-07-02
Status: Merged
Approved by: Steve Kowalik on 2012-07-03
Approved revision: no longer in the source branch.
Merged at revision: 15540
Proposed branch: lp:~stevenk/launchpad/auditor-layer
Merge into: lp:launchpad
Diff against target: 219 lines (+119/-2)
6 files modified
buildout.cfg (+8/-0)
lib/lp/services/auditor/server.py (+35/-0)
lib/lp/services/auditor/tests/test_server.py (+28/-0)
lib/lp/testing/layers.py (+43/-2)
setup.py (+1/-0)
versions.cfg (+4/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/auditor-layer
Reviewer Review Type Date Requested Status
Benji York (community) code 2012-07-02 Approve on 2012-07-02
Review via email: mp+112962@code.launchpad.net

Commit Message

Add AuditorLayer and a server that the layer brings up, which allows us to start making use of auditor in code and tests.

Description of the Change

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.

To post a comment you must log in.
Benji York (benji) wrote :

Why do you use setattr in the AuditorServer class's setUp method?

    setattr(
        self, 'service_config',
        dedent("""\
            [auditor]
            port: %d
            """ % (self.config.port)))

I would think this would work:

    self.service_config = ...

Under most conditions distribution names are case-insensitive so I am
curious why there are two Djangos in versions.cfg:

+django = 1.4
+Django = 1.4

Steve Kowalik (stevenk) wrote :

The two Django's are there so that buildout actually works. The tarball is 'Django-1.4.tar.gz', and refers to itself as 'Django', but every import is 'from django.something import else' so buildout looks for django, but it's Django, and so buildout goes bang.

Benji York (benji) wrote :

> The two Django's are there so that buildout actually works. The tarball is
> 'Django-1.4.tar.gz', and refers to itself as 'Django', but every import is
> 'from django.something import else' so buildout looks for django, but it's
> Django, and so buildout goes bang.

Hmm, that's funny. In that case the branch looks good to me.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'buildout.cfg'
2--- buildout.cfg 2012-05-14 20:33:32 +0000
3+++ buildout.cfg 2012-07-02 23:31:04 +0000
4@@ -10,6 +10,7 @@
5 iharness
6 i18n
7 txlongpoll
8+ auditor
9 unzip = true
10 eggs-directory = eggs
11 download-cache = download-cache
12@@ -121,3 +122,10 @@
13 initialization = ${scripts:initialization}
14 entry-points = twistd-for-txlongpoll=twisted.scripts.twistd:run
15 scripts = twistd-for-txlongpoll
16+
17+[auditor]
18+recipe = z3c.recipe.scripts
19+eggs = auditor
20+include-site-packages = false
21+entry-points = auditor-manage=auditor.manage:run
22+scripts = auditor-manage
23
24=== added directory 'lib/lp/services/auditor'
25=== added file 'lib/lp/services/auditor/__init__.py'
26=== added file 'lib/lp/services/auditor/server.py'
27--- lib/lp/services/auditor/server.py 1970-01-01 00:00:00 +0000
28+++ lib/lp/services/auditor/server.py 2012-07-02 23:31:04 +0000
29@@ -0,0 +1,35 @@
30+# Copyright 2012 Canonical Ltd. This software is licensed under the
31+# GNU Affero General Public License version 3 (see the file LICENSE).
32+
33+"""Auditor server fixture."""
34+
35+__metaclass__ = type
36+__all__ = [
37+ 'AuditorServer',
38+ ]
39+
40+import os
41+from textwrap import dedent
42+
43+from auditorfixture.server import AuditorFixture
44+
45+import lp
46+
47+
48+class AuditorServer(AuditorFixture):
49+ """An Auditor server fixture with Launchpad-specific config.
50+
51+ :ivar service_config: A snippet of .ini that describes the `auditor`
52+ configuration.
53+ """
54+
55+ def __init__(self, port=None, logfile=None, manage_bin=None):
56+ manage_bin = os.path.join(
57+ os.path.dirname(lp.__file__), '../../bin/auditor-manage')
58+ super(AuditorServer, self).__init__(port, logfile, manage_bin)
59+
60+ def setUp(self):
61+ super(AuditorServer, self).setUp()
62+ self.service_config = dedent("""\
63+ [auditor]
64+ port: %d""" % (self.config.port))
65
66=== added directory 'lib/lp/services/auditor/tests'
67=== added file 'lib/lp/services/auditor/tests/__init__.py'
68=== added file 'lib/lp/services/auditor/tests/test_server.py'
69--- lib/lp/services/auditor/tests/test_server.py 1970-01-01 00:00:00 +0000
70+++ lib/lp/services/auditor/tests/test_server.py 2012-07-02 23:31:04 +0000
71@@ -0,0 +1,28 @@
72+# Copyright 2012 Canonical Ltd. This software is licensed under the
73+# GNU Affero General Public License version 3 (see the file LICENSE).
74+
75+"""Tests for lp.services.auditor.AuditorServer."""
76+
77+__metaclass__ = type
78+
79+from ConfigParser import SafeConfigParser
80+from StringIO import StringIO
81+
82+from lp.services.auditor.server import AuditorServer
83+from lp.testing import TestCase
84+from lp.testing.layers import BaseLayer
85+
86+
87+class TestAuditorServer(TestCase):
88+
89+ layer = BaseLayer
90+
91+ def test_service_config(self):
92+ # AuditorServer pokes some .ini configuration into its config.
93+ fixture = self.useFixture(AuditorServer())
94+ service_config = SafeConfigParser()
95+ service_config.readfp(StringIO(fixture.service_config))
96+ self.assertEqual(["auditor"], service_config.sections())
97+ expected = {"port": "%d" % fixture.config.port}
98+ observed = dict(service_config.items("auditor"))
99+ self.assertEqual(expected, observed)
100
101=== modified file 'lib/lp/testing/layers.py'
102--- lib/lp/testing/layers.py 2012-06-14 05:18:22 +0000
103+++ lib/lp/testing/layers.py 2012-07-02 23:31:04 +0000
104@@ -1,10 +1,10 @@
105-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
106+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
107 # GNU Affero General Public License version 3 (see the file LICENSE).
108
109 # We like global!
110 # pylint: disable-msg=W0603,W0702
111
112-"""Layers used by Canonical tests.
113+"""Layers used by Launchpad tests.
114
115 Layers are the mechanism used by the Zope3 test runner to efficiently
116 provide environments for tests and are documented in the lib/zope/testing.
117@@ -24,6 +24,7 @@
118 __metaclass__ = type
119 __all__ = [
120 'AppServerLayer',
121+ 'AuditorLayer',
122 'BaseLayer',
123 'DatabaseFunctionalLayer',
124 'DatabaseLayer',
125@@ -39,6 +40,7 @@
126 'LayerIsolationError',
127 'LibrarianLayer',
128 'PageTestLayer',
129+ 'RabbitMQLayer',
130 'TwistedAppServerLayer',
131 'TwistedLaunchpadZopelessLayer',
132 'TwistedLayer',
133@@ -101,6 +103,7 @@
134 from zope.server.logger.pythonlogger import PythonLogger
135
136 from lp.services import pidfile
137+from lp.services.auditor.server import AuditorServer
138 from lp.services.config import (
139 config,
140 dbconfig,
141@@ -704,6 +707,44 @@
142 pass
143
144
145+class AuditorLayer(BaseLayer):
146+
147+ auditor = AuditorServer()
148+
149+ _is_setup = False
150+
151+ @classmethod
152+ @profiled
153+ def setUp(cls):
154+ cls.auditor.setUp()
155+ cls.config_fixture.add_section(
156+ cls.auditor.config.service_config)
157+ cls.appserver_config_fixture.add_section(
158+ cls.auditor.config.service_config)
159+ cls._is_setup = True
160+
161+ @classmethod
162+ @profiled
163+ def tearDown(cls):
164+ if not cls._is_setup:
165+ return
166+ cls.auditor.cleanUp()
167+ cls._is_setup = False
168+ # Can't pop the config above, so bail here and let the test runner
169+ # start a sub-process.
170+ raise NotImplementedError
171+
172+ @classmethod
173+ @profiled
174+ def testSetUp(cls):
175+ pass
176+
177+ @classmethod
178+ @profiled
179+ def testTearDown(cls):
180+ pass
181+
182+
183 # We store a reference to the DB-API connect method here when we
184 # put a proxy in its place.
185 _org_connect = None
186
187=== modified file 'setup.py'
188--- setup.py 2012-04-24 04:23:52 +0000
189+++ setup.py 2012-07-02 23:31:04 +0000
190@@ -27,6 +27,7 @@
191 # used in zcml.
192 install_requires=[
193 'ampoule',
194+ 'auditorfixture',
195 'BeautifulSoup',
196 'bzr',
197 'Chameleon',
198
199=== modified file 'versions.cfg'
200--- versions.cfg 2012-06-22 14:56:27 +0000
201+++ versions.cfg 2012-07-02 23:31:04 +0000
202@@ -8,6 +8,8 @@
203 amqplib = 1.0.2
204 anyjson = 0.3.1
205 argparse = 1.2.1
206+auditor = 0.0.1
207+auditorfixture = 0.0.1
208 BeautifulSoup = 3.1.0.1
209 bson = 0.3.2
210 # The source for this version of bzr is at lp:~benji/bzr/bug-998040
211@@ -19,6 +21,8 @@
212 ClientForm = 0.2.10
213 cssutils = 0.9.7
214 docutils = 0.5
215+django = 1.4
216+Django = 1.4
217 # Required by pydkim
218 dnspython = 1.7.1
219 elementtree = 1.2.6-20050316