Merge ~pappacena/launchpad:remove-auditor into launchpad:master

Proposed by Thiago F. Pappacena
Status: Merged
Approved by: Thiago F. Pappacena
Approved revision: 8670afbd8aa078dcda07368a684bcf60b86215ad
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pappacena/launchpad:remove-auditor
Merge into: launchpad:master
Diff against target: 385 lines (+0/-90)
7 files modified
constraints.txt (+0/-4)
dev/null (+0/-28)
lib/lp/services/config/schema-lazr.conf (+0/-5)
lib/lp/services/features/flags.py (+0/-6)
lib/lp/soyuz/model/queue.py (+0/-7)
lib/lp/testing/layers.py (+0/-38)
setup.py (+0/-2)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+379021@code.launchpad.net

Commit message

Removing auditor

Auditor client (and mock test server) are not in use, and we solved the audit problem on package upload with a database table keeping track of the history of the package upload.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Mostly LGTM, thanks!

review: Approve
~pappacena/launchpad:remove-auditor updated
8670afb... by Thiago F. Pappacena

removing django

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/constraints.txt b/constraints.txt
2index a47ebfd..efb6db9 100644
3--- a/constraints.txt
4+++ b/constraints.txt
5@@ -162,9 +162,6 @@ anyjson==0.3.3
6 appdirs==1.4.3
7 asn1crypto==0.23.0
8 attrs==19.1.0
9-auditor==0.0.3
10-auditorclient==0.0.4
11-auditorfixture==0.0.7
12 Automat==0.6.0
13 Babel==2.5.1
14 backports.functools-lru-cache==1.5
15@@ -188,7 +185,6 @@ cssutils==1.0.2
16 d2to1==0.2.12
17 defusedxml==0.6.0
18 distro==1.4.0
19-Django==1.4
20 dkimpy==0.5.4
21 # Required by dkimpy
22 dnspython==1.10.0
23diff --git a/lib/lp/services/auditor/__init__.py b/lib/lp/services/auditor/__init__.py
24deleted file mode 100644
25index e69de29..0000000
26--- a/lib/lp/services/auditor/__init__.py
27+++ /dev/null
28diff --git a/lib/lp/services/auditor/client.py b/lib/lp/services/auditor/client.py
29deleted file mode 100644
30index 3e2189f..0000000
31--- a/lib/lp/services/auditor/client.py
32+++ /dev/null
33@@ -1,70 +0,0 @@
34-# Copyright 2012-2013 Canonical Ltd. This software is licensed under the
35-# GNU Affero General Public License version 3 (see the file LICENSE).
36-
37-"""Client that will send and receive audit logs to an auditor instance."""
38-
39-__metaclass__ = type
40-__all__ = [
41- 'AuditorClient',
42- ]
43-
44-from auditorclient.client import Client
45-from lazr.restful.utils import get_current_browser_request
46-
47-from lp.services.config import config
48-from lp.services.enterpriseid import (
49- enterpriseids_to_objects,
50- object_to_enterpriseid,
51- )
52-from lp.services.timeline.requesttimeline import get_request_timeline
53-
54-
55-class AuditorClient(Client):
56-
57- def __init__(self):
58- super(AuditorClient, self).__init__(
59- config.auditor.host, config.auditor.port)
60-
61- def __get_timeline_action(self, suffix, obj, operation, actorobj):
62- data = "Object: %s; Operation: %s, Actor: %s" % (
63- obj, operation, actorobj)
64- timeline = get_request_timeline(get_current_browser_request())
65- return timeline.start("auditor-%s" % suffix, data)
66-
67- def send(self, obj, operation, actorobj, comment=None, details=None):
68- obj = object_to_enterpriseid(obj)
69- actorobj = object_to_enterpriseid(actorobj)
70- action = self.__get_timeline_action("send", obj, operation, actorobj)
71- try:
72- return super(AuditorClient, self).send(
73- obj, operation, actorobj, comment, details)
74- finally:
75- action.finish()
76-
77- def _convert_to_enterpriseid(self, obj):
78- if isinstance(obj, (list, tuple)):
79- return [object_to_enterpriseid(o) for o in obj]
80- else:
81- return object_to_enterpriseid(obj)
82-
83- def receive(self, obj=None, operation=None, actorobj=None, limit=None):
84- if obj:
85- obj = self._convert_to_enterpriseid(obj)
86- if actorobj:
87- actorobj = self._convert_to_enterpriseid(actorobj)
88- action = self.__get_timeline_action(
89- "receive", obj, operation, actorobj)
90- try:
91- logs = super(AuditorClient, self).receive(
92- obj, operation, actorobj, limit)
93- finally:
94- action.finish()
95- # Process the actors and objects back from enterprise ids.
96- eids = set()
97- for entry in logs['log-entries']:
98- eids |= set([entry['actor'], entry['object']])
99- map_eids_to_obj = enterpriseids_to_objects(eids)
100- for entry in logs['log-entries']:
101- entry['actor'] = map_eids_to_obj.get(entry['actor'], None)
102- entry['object'] = map_eids_to_obj.get(entry['object'], None)
103- return logs['log-entries']
104diff --git a/lib/lp/services/auditor/server.py b/lib/lp/services/auditor/server.py
105deleted file mode 100644
106index 205c68b..0000000
107--- a/lib/lp/services/auditor/server.py
108+++ /dev/null
109@@ -1,27 +0,0 @@
110-# Copyright 2012 Canonical Ltd. This software is licensed under the
111-# GNU Affero General Public License version 3 (see the file LICENSE).
112-
113-"""Auditor server fixture."""
114-
115-__metaclass__ = type
116-__all__ = [
117- 'AuditorServer',
118- ]
119-
120-from textwrap import dedent
121-
122-from auditorfixture.server import AuditorFixture
123-
124-
125-class AuditorServer(AuditorFixture):
126- """An Auditor server fixture with Launchpad-specific config.
127-
128- :ivar service_config: A snippet of .ini that describes the `auditor`
129- configuration.
130- """
131-
132- def setUp(self):
133- super(AuditorServer, self).setUp()
134- self.service_config = dedent("""\
135- [auditor]
136- port: %d""" % (self.config.port))
137diff --git a/lib/lp/services/auditor/tests/__init__.py b/lib/lp/services/auditor/tests/__init__.py
138deleted file mode 100644
139index e69de29..0000000
140--- a/lib/lp/services/auditor/tests/__init__.py
141+++ /dev/null
142diff --git a/lib/lp/services/auditor/tests/test_client.py b/lib/lp/services/auditor/tests/test_client.py
143deleted file mode 100644
144index 0248fa5..0000000
145--- a/lib/lp/services/auditor/tests/test_client.py
146+++ /dev/null
147@@ -1,63 +0,0 @@
148-# Copyright 2012-2013 Canonical Ltd. This software is licensed under the
149-# GNU Affero General Public License version 3 (see the file LICENSE).
150-
151-__metaclass__ = type
152-
153-from lazr.restful.utils import get_current_browser_request
154-
155-from lp.services.auditor.client import AuditorClient
156-from lp.services.enterpriseid import object_to_enterpriseid
157-from lp.services.timeline.requesttimeline import get_request_timeline
158-from lp.testing import TestCaseWithFactory
159-from lp.testing.layers import AuditorLayer
160-
161-
162-class TestAuditorClient(TestCaseWithFactory):
163-
164- layer = AuditorLayer
165-
166- def assertAction(self, category, data):
167- timeline = get_request_timeline(get_current_browser_request())
168- action = timeline.actions[-1]
169- self.assertEqual(category, action.category)
170- self.assertEqual(data, action.detail)
171-
172- def test_send_and_receive(self):
173- # We can use .send() and .receive() on AuditorClient to log.
174- actor = self.factory.makePerson()
175- pu = self.factory.makePackageUpload()
176- client = AuditorClient()
177- result = client.send(pu, 'packageupload-accepted', actor)
178- self.assertEqual('Operation recorded.', result)
179- data = "Object: %s; Operation: packageupload-accepted, Actor: %s" % (
180- object_to_enterpriseid(pu), object_to_enterpriseid(actor))
181- self.assertAction('auditor-send', data)
182- result = client.receive(obj=pu)
183- del result[0]['date'] # Ignore the date.
184- expected = [{
185- u'comment': u'', u'details': u'', u'actor': actor,
186- u'operation': u'packageupload-accepted', u'object': pu}]
187- self.assertContentEqual(expected, result)
188- self.assertAction(
189- 'auditor-receive', "Object: %s; Operation: None, Actor: None" % (
190- object_to_enterpriseid(pu)))
191-
192- def test_multiple_receive(self):
193- # We can ask AuditorClient for a number of operations.
194- actor = self.factory.makePerson()
195- actor2 = self.factory.makePerson()
196- client = AuditorClient()
197- client.send(actor, 'person-deleted', actor)
198- client.send(actor2, 'person-undeleted', actor)
199- result = client.receive(
200- obj=(actor, actor2),
201- operation=('person-deleted', 'person-undeleted'))
202- self.assertEqual(2, len(result))
203- for r in result:
204- del r['date'] # Ignore the date.
205- expected = [
206- {u'comment': u'', u'details': u'', u'actor': actor,
207- u'operation': u'person-deleted', u'object': actor},
208- {u'comment': u'', u'details': u'', u'actor': actor,
209- u'operation': u'person-undeleted', u'object': actor2}]
210- self.assertContentEqual(expected, result)
211diff --git a/lib/lp/services/auditor/tests/test_server.py b/lib/lp/services/auditor/tests/test_server.py
212deleted file mode 100644
213index 217b41a..0000000
214--- a/lib/lp/services/auditor/tests/test_server.py
215+++ /dev/null
216@@ -1,28 +0,0 @@
217-# Copyright 2012 Canonical Ltd. This software is licensed under the
218-# GNU Affero General Public License version 3 (see the file LICENSE).
219-
220-"""Tests for lp.services.auditor.AuditorServer."""
221-
222-__metaclass__ = type
223-
224-from ConfigParser import SafeConfigParser
225-from StringIO import StringIO
226-
227-from lp.services.auditor.server import AuditorServer
228-from lp.testing import TestCase
229-from lp.testing.layers import BaseLayer
230-
231-
232-class TestAuditorServer(TestCase):
233-
234- layer = BaseLayer
235-
236- def test_service_config(self):
237- # AuditorServer pokes some .ini configuration into its config.
238- fixture = self.useFixture(AuditorServer())
239- service_config = SafeConfigParser()
240- service_config.readfp(StringIO(fixture.service_config))
241- self.assertEqual(["auditor"], service_config.sections())
242- expected = {"port": "%d" % fixture.config.port}
243- observed = dict(service_config.items("auditor"))
244- self.assertEqual(expected, observed)
245diff --git a/lib/lp/services/config/schema-lazr.conf b/lib/lp/services/config/schema-lazr.conf
246index d8c1204..ada0c9d 100644
247--- a/lib/lp/services/config/schema-lazr.conf
248+++ b/lib/lp/services/config/schema-lazr.conf
249@@ -33,11 +33,6 @@ dbuser: archivepublisher
250 run_parts_location: none
251
252
253-[auditor]
254-host: localhost
255-port: none
256-
257-
258 [binaryfile_expire]
259 dbuser: binaryfile-expire
260
261diff --git a/lib/lp/services/features/flags.py b/lib/lp/services/features/flags.py
262index e366a94..9fdb4a0 100644
263--- a/lib/lp/services/features/flags.py
264+++ b/lib/lp/services/features/flags.py
265@@ -191,12 +191,6 @@ flag_info = sorted([
266 '',
267 '',
268 ''),
269- ('auditor.enabled',
270- 'boolean',
271- 'If true, send audit data to an auditor instance.',
272- '',
273- '',
274- ''),
275 ('app.root_blog.enabled',
276 'boolean',
277 'If true, load posts from the Launchpad blog to show on the root page.',
278diff --git a/lib/lp/soyuz/model/queue.py b/lib/lp/soyuz/model/queue.py
279index 91e92cd..82e02a9 100644
280--- a/lib/lp/soyuz/model/queue.py
281+++ b/lib/lp/soyuz/model/queue.py
282@@ -47,7 +47,6 @@ from lp.registry.interfaces.gpg import IGPGKeySet
283 from lp.registry.interfaces.person import IPersonSet
284 from lp.registry.interfaces.pocket import PackagePublishingPocket
285 from lp.registry.model.sourcepackagename import SourcePackageName
286-from lp.services.auditor.client import AuditorClient
287 from lp.services.database.bulk import (
288 load_referencing,
289 load_related,
290@@ -610,9 +609,6 @@ class PackageUpload(SQLBase):
291 self._acceptNonSyncFromQueue()
292 else:
293 self._acceptSyncFromQueue()
294- if bool(getFeatureFlag('auditor.enabled')):
295- client = AuditorClient()
296- client.send(self, 'packageupload-accepted', user)
297
298 def rejectFromQueue(self, user, comment=None):
299 """See `IPackageUpload`."""
300@@ -637,9 +633,6 @@ class PackageUpload(SQLBase):
301 getUtility(IPackageUploadNotificationJobSource).create(
302 self, summary_text=summary_text)
303 self.syncUpdate()
304- if bool(getFeatureFlag('auditor.enabled')):
305- client = AuditorClient()
306- client.send(self, 'packageupload-rejected', user)
307
308 def _isSingleSourceUpload(self):
309 """Return True if this upload contains only a single source."""
310diff --git a/lib/lp/testing/layers.py b/lib/lp/testing/layers.py
311index 65fb63e..8a1afd3 100644
312--- a/lib/lp/testing/layers.py
313+++ b/lib/lp/testing/layers.py
314@@ -23,7 +23,6 @@ from __future__ import absolute_import, print_function
315 __metaclass__ = type
316 __all__ = [
317 'AppServerLayer',
318- 'AuditorLayer',
319 'BaseLayer',
320 'BingLaunchpadFunctionalLayer',
321 'BingServiceLayer',
322@@ -109,7 +108,6 @@ import zope.testbrowser.wsgi
323 from zope.testbrowser.wsgi import AuthorizationMiddleware
324
325 from lp.services import pidfile
326-from lp.services.auditor.server import AuditorServer
327 from lp.services.config import (
328 config,
329 dbconfig,
330@@ -1423,42 +1421,6 @@ class LaunchpadFunctionalLayer(LaunchpadLayer, FunctionalLayer):
331 disconnect_stores()
332
333
334-class AuditorLayer(LaunchpadFunctionalLayer):
335-
336- auditor = AuditorServer()
337-
338- _is_setup = False
339-
340- @classmethod
341- @profiled
342- def setUp(cls):
343- cls.auditor.setUp()
344- cls.config_fixture.add_section(cls.auditor.service_config)
345- cls.appserver_config_fixture.add_section(cls.auditor.service_config)
346- cls._is_setup = True
347-
348- @classmethod
349- @profiled
350- def tearDown(cls):
351- if not cls._is_setup:
352- return
353- cls.auditor.cleanUp()
354- cls._is_setup = False
355- # Can't pop the config above, so bail here and let the test runner
356- # start a sub-process.
357- raise NotImplementedError
358-
359- @classmethod
360- @profiled
361- def testSetUp(cls):
362- pass
363-
364- @classmethod
365- @profiled
366- def testTearDown(cls):
367- pass
368-
369-
370 class BingLaunchpadFunctionalLayer(LaunchpadFunctionalLayer,
371 BingServiceLayer):
372 """Provides Bing service in addition to LaunchpadFunctionalLayer."""
373diff --git a/setup.py b/setup.py
374index e149110..ef792da 100644
375--- a/setup.py
376+++ b/setup.py
377@@ -144,8 +144,6 @@ setup(
378 # used in zcml.
379 install_requires=[
380 'ampoule',
381- 'auditorclient',
382- 'auditorfixture',
383 'backports.lzma; python_version < "3.3"',
384 'beautifulsoup4[lxml]',
385 'breezy',