Merge lp:~lifeless/python-oops-datedir-repo/bug-891251 into lp:python-oops-datedir-repo

Proposed by Robert Collins
Status: Merged
Merged at revision: 28
Proposed branch: lp:~lifeless/python-oops-datedir-repo/bug-891251
Merge into: lp:python-oops-datedir-repo
Diff against target: 198 lines (+85/-23)
5 files modified
NEWS (+7/-0)
oops_datedir_repo/__init__.py (+1/-1)
oops_datedir_repo/repository.py (+10/-6)
oops_datedir_repo/tests/test_repository.py (+66/-15)
setup.py (+1/-1)
To merge this branch: bzr merge lp:~lifeless/python-oops-datedir-repo/bug-891251
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+82469@code.launchpad.net

Description of the change

Allow txlongpoll oopses to be analysed and viewed.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) wrote :

os.makedirs takes a mode argument, but apart from that this is good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2011-11-16 03:44:36 +0000
3+++ NEWS 2011-11-17 00:02:23 +0000
4@@ -6,6 +6,13 @@
5 NEXT
6 ----
7
8+0.0.13
9+------
10+
11+* The date directory created when writing an OOPS with hashed names has its
12+ permissions chmodded in the same way that the OOPS report file itself does.
13+ (Robert Collins, #891251)
14+
15 0.0.12
16 ------
17
18
19=== modified file 'oops_datedir_repo/__init__.py'
20--- oops_datedir_repo/__init__.py 2011-11-16 03:44:36 +0000
21+++ oops_datedir_repo/__init__.py 2011-11-17 00:02:23 +0000
22@@ -25,7 +25,7 @@
23 # established at this point, and setup.py will use a version of next-$(revno).
24 # If the releaselevel is 'final', then the tarball will be major.minor.micro.
25 # Otherwise it is major.minor.micro~$(revno).
26-__version__ = (0, 0, 12, 'beta', 0)
27+__version__ = (0, 0, 13, 'beta', 0)
28
29 __all__ = [
30 'DateDirRepo',
31
32=== modified file 'oops_datedir_repo/repository.py'
33--- oops_datedir_repo/repository.py 2011-11-14 03:20:31 +0000
34+++ oops_datedir_repo/repository.py 2011-11-17 00:02:23 +0000
35@@ -103,6 +103,11 @@
36 :param now: The datetime to use as the current time. Will be
37 determined if not supplied. Useful for testing.
38 """
39+ # We set file permission to: rw-r--r-- (so that reports from
40+ # umask-restricted services can be gathered by a tool running as
41+ # another user).
42+ wanted_file_permission = (
43+ stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
44 if now is not None:
45 now = now.astimezone(utc)
46 else:
47@@ -118,6 +123,10 @@
48 prefix = os.path.join(self.root, now.strftime('%Y-%m-%d'))
49 if not os.path.isdir(prefix):
50 os.makedirs(prefix)
51+ # For directories we need to set the x bits too.
52+ os.chmod(
53+ prefix, wanted_file_permission | stat.S_IXUSR | stat.S_IXGRP |
54+ stat.S_IXOTH)
55 filename = os.path.join(prefix, oopsid)
56 if self.inherit_id:
57 oopsid = report.get('id') or oopsid
58@@ -126,12 +135,7 @@
59 os.rename(filename + '.tmp', filename)
60 if self.stash_path:
61 original_report['datedir_repo_filepath'] = filename
62- # Set file permission to: rw-r--r-- (so that reports from
63- # umask-restricted services can be gathered by a tool running as
64- # another user).
65- wanted_permission = (
66- stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
67- os.chmod(filename, wanted_permission)
68+ os.chmod(filename, wanted_file_permission)
69 return report['id']
70
71 def republish(self, publisher):
72
73=== modified file 'oops_datedir_repo/tests/test_repository.py'
74--- oops_datedir_repo/tests/test_repository.py 2011-11-14 03:20:31 +0000
75+++ oops_datedir_repo/tests/test_repository.py 2011-11-17 00:02:23 +0000
76@@ -22,11 +22,17 @@
77 import os.path
78 import stat
79
80-from fixtures import TempDir
81+from fixtures import (
82+ Fixture,
83+ TempDir,
84+ )
85 import bson
86 from pytz import utc
87 import testtools
88-from testtools.matchers import raises
89+from testtools.matchers import (
90+ Equals,
91+ raises,
92+ )
93
94 from oops_datedir_repo import (
95 DateDirRepo,
96@@ -35,9 +41,39 @@
97 from oops_datedir_repo.uniquefileallocator import UniqueFileAllocator
98
99
100+class HasUnixPermissions:
101+
102+ def __init__(self, wanted_permission):
103+ self.wanted_permission = wanted_permission
104+
105+ def match(self, path):
106+ st = os.stat(path)
107+ # Get only the permission bits from this mode.
108+ file_permission = stat.S_IMODE(st.st_mode)
109+ return Equals(self.wanted_permission).match(file_permission)
110+
111+ def __str__(self):
112+ # TODO: might be nice to split out the bits in future, format nicely
113+ # etc. Should also move this into testtools.
114+ return "HasUnixPermissions(0%o)" % self.wanted_permission
115+
116+
117+class UMaskFixture(Fixture):
118+ """Set a umask temporarily."""
119+
120+ def __init__(self, mask):
121+ super(UMaskFixture, self).__init__()
122+ self.umask_permission = mask
123+
124+ def setUp(self):
125+ super(UMaskFixture, self).setUp()
126+ old_umask = os.umask(self.umask_permission)
127+ self.addCleanup(os.umask, old_umask)
128+
129+
130 class TestDateDirRepo(testtools.TestCase):
131
132- def test_publish_permissions(self):
133+ def test_publish_permissions_lognamer(self):
134 errordir = self.useFixture(TempDir()).path
135 repo = DateDirRepo(errordir, 'T')
136 report = {'id': 'OOPS-91T1'}
137@@ -45,21 +81,36 @@
138
139 # Set up default file creation mode to rwx------ as some restrictive
140 # servers do.
141- umask_permission = stat.S_IRWXG | stat.S_IRWXO
142- old_umask = os.umask(umask_permission)
143- self.addCleanup(os.umask, old_umask)
144+ self.useFixture(UMaskFixture(stat.S_IRWXG | stat.S_IRWXO))
145 repo.publish(report, now)
146
147 errorfile = os.path.join(repo.log_namer.output_dir(now), '01800.T1')
148- self.assertTrue(os.path.exists(errorfile))
149-
150- # Check errorfile is set with the correct permission: rw-r--r--
151- st = os.stat(errorfile)
152- wanted_permission = (
153- stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
154- # Get only the permission bits for this file.
155- file_permission = stat.S_IMODE(st.st_mode)
156- self.assertEqual(file_permission, wanted_permission)
157+ # Check errorfile and directory are set with the correct permission:
158+ # rw-r--r-- and rwxr-xr-x accordingly
159+ file_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH
160+ has_file_permission = HasUnixPermissions(file_perms)
161+ has_dir_permission = HasUnixPermissions(
162+ file_perms | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
163+ self.assertThat(errorfile, has_file_permission)
164+ self.assertThat(repo.log_namer.output_dir(now), has_dir_permission)
165+
166+ def test_publish_permissions_hashnames(self):
167+ repo = DateDirRepo(self.useFixture(TempDir()).path, stash_path=True)
168+ report = {'id': 'OOPS-91T1'}
169+ now = datetime.datetime(2006, 04, 01, 00, 30, 00, tzinfo=utc)
170+
171+ # Set up default file creation mode to rwx------ as some restrictive
172+ # servers do.
173+ self.useFixture(UMaskFixture(stat.S_IRWXG | stat.S_IRWXO))
174+ repo.publish(report, now)
175+ # Check errorfile and directory are set with the correct permission:
176+ # rw-r--r--
177+ file_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH
178+ has_file_permission = HasUnixPermissions(file_perms)
179+ has_dir_permission = HasUnixPermissions(
180+ file_perms | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
181+ self.assertThat(report['datedir_repo_filepath'], has_file_permission)
182+ self.assertThat(repo.root + '/2006-04-01', has_dir_permission)
183
184 def test_sets_log_namer_to_a_UniqueFileAllocator(self):
185 repo = DateDirRepo(self.useFixture(TempDir()).path, 'T')
186
187=== modified file 'setup.py'
188--- setup.py 2011-11-16 03:44:36 +0000
189+++ setup.py 2011-11-17 00:02:23 +0000
190@@ -22,7 +22,7 @@
191 description = file(os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()
192
193 setup(name="oops_datedir_repo",
194- version="0.0.12",
195+ version="0.0.13",
196 description="OOPS disk serialisation and repository management.",
197 long_description=description,
198 maintainer="Launchpad Developers",

Subscribers

People subscribed via source and target branches

to all changes: