Merge lp:~thumper/launchpad/permission-fail into lp:launchpad/db-devel

Proposed by Tim Penhey
Status: Merged
Merged at revision: not available
Proposed branch: lp:~thumper/launchpad/permission-fail
Merge into: lp:launchpad/db-devel
Diff against target: 178 lines
4 files modified
database/schema/security.cfg (+1/-0)
lib/canonical/librarian/ftests/test_gc.py (+53/-29)
lib/canonical/librarian/librariangc.py (+1/-0)
lib/lp/code/mail/tests/test_codehandler.py (+21/-0)
To merge this branch: bzr merge lp:~thumper/launchpad/permission-fail
Reviewer Review Type Date Requested Status
Francis J. Lacoste (community) release-critical Disapprove
Michael Hudson-Doyle Approve
Brad Crittenden release-critical Pending
Review via email: mp+12329@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Fix a permission bug.

Revision history for this message
Tim Penhey (thumper) wrote :

Added the test now too.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Looks fine.

review: Approve
Revision history for this message
Francis J. Lacoste (flacoste) wrote :

Since this is actually a DB change and the re-roll won't update the DB, and the permission has been manually granted, I don't think we should land this change "release-critical".

review: Disapprove (release-critical)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/schema/security.cfg'
2--- database/schema/security.cfg 2009-10-01 01:18:55 +0000
3+++ database/schema/security.cfg 2009-10-01 11:45:25 +0000
4@@ -1482,6 +1482,7 @@
5 public.distroseries = SELECT
6 public.job = SELECT, INSERT, UPDATE
7 public.mergedirectivejob = SELECT, INSERT
8+public.previewdiff = SELECT
9 public.staticdiff = SELECT, INSERT, UPDATE
10 public.sourcepackagename = SELECT
11 public.seriessourcepackagebranch = SELECT
12
13=== modified file 'lib/canonical/librarian/ftests/test_gc.py'
14--- lib/canonical/librarian/ftests/test_gc.py 2009-09-26 09:06:13 +0000
15+++ lib/canonical/librarian/ftests/test_gc.py 2009-10-01 11:45:25 +0000
16@@ -5,6 +5,7 @@
17
18 __metaclass__ = type
19
20+import shutil
21 import sys
22 import os
23 from subprocess import Popen, PIPE, STDOUT
24@@ -15,6 +16,7 @@
25 from pytz import utc
26 from sqlobject import SQLObjectNotFound
27 from storm.locals import SQL, AutoReload
28+import transaction
29 from zope.component import getUtility
30
31 from canonical.config import config
32@@ -529,37 +531,59 @@
33 # Long non-hexadecimal number
34 noisedir3_path = os.path.join(config.librarian_server.root, '11.bak')
35
36- os.mkdir(noisedir1_path)
37- os.mkdir(noisedir2_path)
38- os.mkdir(noisedir3_path)
39-
40- # Files in the noise directories.
41- noisefile1_path = os.path.join(noisedir1_path, 'abc')
42- noisefile2_path = os.path.join(noisedir2_path, 'def')
43- noisefile3_path = os.path.join(noisedir2_path, 'ghi')
44- open(noisefile1_path, 'w').write('hello')
45- open(noisefile2_path, 'w').write('there')
46- open(noisefile3_path, 'w').write('testsuite')
47-
48- # Pretend it is tomorrow to ensure the files don't count as
49- # recently created, and run the delete_unwanted_files process.
50- org_time = librariangc.time
51- def tomorrow_time():
52- return org_time() + 24 * 60 * 60 + 1
53 try:
54- librariangc.time = tomorrow_time
55- librariangc.delete_unwanted_files(self.con)
56+ os.mkdir(noisedir1_path)
57+ os.mkdir(noisedir2_path)
58+ os.mkdir(noisedir3_path)
59+
60+ # Files in the noise directories.
61+ noisefile1_path = os.path.join(noisedir1_path, 'abc')
62+ noisefile2_path = os.path.join(noisedir2_path, 'def')
63+ noisefile3_path = os.path.join(noisedir2_path, 'ghi')
64+ open(noisefile1_path, 'w').write('hello')
65+ open(noisefile2_path, 'w').write('there')
66+ open(noisefile3_path, 'w').write('testsuite')
67+
68+ # Pretend it is tomorrow to ensure the files don't count as
69+ # recently created, and run the delete_unwanted_files process.
70+ org_time = librariangc.time
71+ def tomorrow_time():
72+ return org_time() + 24 * 60 * 60 + 1
73+ try:
74+ librariangc.time = tomorrow_time
75+ librariangc.delete_unwanted_files(self.con)
76+ finally:
77+ librariangc.time = org_time
78+
79+ # None of the rubbish we created has been touched.
80+ self.assert_(os.path.isdir(noisedir1_path))
81+ self.assert_(os.path.isdir(noisedir2_path))
82+ self.assert_(os.path.isdir(noisedir3_path))
83+ self.assert_(os.path.exists(noisefile1_path))
84+ self.assert_(os.path.exists(noisefile2_path))
85+ self.assert_(os.path.exists(noisefile3_path))
86 finally:
87- librariangc.time = org_time
88-
89- # None of the rubbish we created has been touched.
90- self.assert_(os.path.isdir(noisedir1_path))
91- self.assert_(os.path.isdir(noisedir2_path))
92- self.assert_(os.path.isdir(noisedir3_path))
93- self.assert_(os.path.exists(noisefile1_path))
94- self.assert_(os.path.exists(noisefile2_path))
95- self.assert_(os.path.exists(noisefile3_path))
96-
97+ # We need to clean this up ourselves, as the standard librarian
98+ # cleanup only removes files it knows where valid to avoid
99+ # accidents.
100+ shutil.rmtree(noisedir1_path)
101+ shutil.rmtree(noisedir2_path)
102+ shutil.rmtree(noisedir3_path)
103+
104+ def test_delete_unwanted_files_bug437084(self):
105+ # There was a bug where delete_unwanted_files() would die
106+ # if the last file found on disk was unwanted.
107+ self.layer.switchDbUser(dbuser='testadmin')
108+ content='foo'
109+ self.client.addFile(
110+ 'foo.txt', len(content), StringIO(content), 'text/plain')
111+ # Roll back the database changes, leaving the file on disk.
112+ transaction.abort()
113+
114+ self.layer.switchDbUser(config.librarian_gc.dbuser)
115+
116+ # This should cope.
117+ librariangc.delete_unwanted_files(self.con)
118
119 def test_cronscript(self):
120 script_path = os.path.join(
121
122=== modified file 'lib/canonical/librarian/librariangc.py'
123--- lib/canonical/librarian/librariangc.py 2009-09-26 08:43:07 +0000
124+++ lib/canonical/librarian/librariangc.py 2009-10-01 11:45:25 +0000
125@@ -578,6 +578,7 @@
126 next_wanted_content_id = get_next_wanted_content_id()
127
128 if (config.librarian_server.upstream_host is None
129+ and next_wanted_content_id is not None
130 and next_wanted_content_id < content_id):
131 log.error(
132 "LibraryFileContent %d exists in the database but "
133
134=== modified file 'lib/lp/code/mail/tests/test_codehandler.py'
135--- lib/lp/code/mail/tests/test_codehandler.py 2009-09-15 14:32:47 +0000
136+++ lib/lp/code/mail/tests/test_codehandler.py 2009-10-01 11:45:24 +0000
137@@ -5,6 +5,7 @@
138
139 __metaclass__ = type
140
141+from difflib import unified_diff
142 from textwrap import dedent
143 import transaction
144 import unittest
145@@ -30,6 +31,7 @@
146 from canonical.launchpad.database import MessageSet
147 from lp.code.model.branchmergeproposaljob import (
148 CreateMergeProposalJob, MergeProposalCreatedJob)
149+from lp.code.model.diff import PreviewDiff
150 from canonical.launchpad.interfaces.mail import (
151 EmailProcessingError, IWeaklyAuthenticatedPrincipal)
152 from lp.code.mail.codehandler import (
153@@ -590,6 +592,25 @@
154 # Ensure the DB operations violate no constraints.
155 transaction.commit()
156
157+ def test_reviewer_with_diff(self):
158+ """Requesting a review with a diff works."""
159+ diff_text = ''.join(unified_diff('', 'Fake diff'))
160+ preview_diff = PreviewDiff.create(
161+ diff_text,
162+ unicode(self.factory.getUniqueString('revid')),
163+ unicode(self.factory.getUniqueString('revid')),
164+ None, None)
165+ # To record the diff in the librarian.
166+ transaction.commit()
167+ bmp = self.factory.makeBranchMergeProposal(preview_diff=preview_diff)
168+ eric = self.factory.makePerson(name="eric", email="eric@example.com")
169+ mail = self.factory.makeSignedMessage(body=' reviewer eric')
170+ email_addr = bmp.address
171+ self.switchDbUser(config.processmail.dbuser)
172+ self.code_handler.process(mail, email_addr, None)
173+ [vote] = bmp.votes
174+ self.assertEqual(eric, vote.reviewer)
175+
176 def test_processMergeProposalDefaultReviewer(self):
177 # If no reviewer was requested in the comment body, then the default
178 # reviewer of the target branch is used.

Subscribers

People subscribed via source and target branches

to status/vote changes: