Merge lp:~stub/launchpad/librarian-gc into lp:launchpad

Proposed by Stuart Bishop
Status: Merged
Approved by: Stuart Bishop
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~stub/launchpad/librarian-gc
Merge into: lp:launchpad
Diff against target: 93 lines
2 files modified
lib/canonical/librarian/ftests/test_gc.py (+11/-6)
lib/canonical/librarian/librariangc.py (+6/-4)
To merge this branch: bzr merge lp:~stub/launchpad/librarian-gc
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Approve
Review via email: mp+13048@code.launchpad.net

Commit message

Ignore well known 'lost+found' directory silently and lower the threat level of some errors from ERROR to WARNING.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

The Librarian garbage collection job currently reports an ERROR as it doesn't know how to handle the directory 'lost+found' that exists in the storage area. This directory isn't going away, so this branch makes the job just ignore it - we know it is benign.

This branch also reduces the severity of some errors to warnings.

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

Looks fine, but I cringe at the sight of yet another MockLogger in the diff :(

review: Approve
Revision history for this message
Stuart Bishop (stub) wrote :

> Looks fine, but I cringe at the sight of yet another MockLogger in the diff :(

This was probably the original MockLogger. All the others are poor imitations :-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/librarian/ftests/test_gc.py'
2--- lib/canonical/librarian/ftests/test_gc.py 2009-10-01 08:02:29 +0000
3+++ lib/canonical/librarian/ftests/test_gc.py 2009-10-09 05:06:13 +0000
4@@ -31,13 +31,18 @@
5
6
7 class MockLogger:
8- def __init__(self, fail_on_error=True):
9+ def __init__(self, fail_on_error=True, fail_on_warning=True):
10 self.fail_on_error = fail_on_error
11+ self.fail_on_warning = fail_on_warning
12
13 def error(self, *args, **kw):
14 if self.fail_on_error:
15 raise RuntimeError("An error was indicated: %r %r" % (args, kw))
16
17+ def warning(self, *args, **kw):
18+ if self.fail_on_warning:
19+ raise RuntimeError("A warning was indicated: %r %r" % (args, kw))
20+
21 def debug(self, *args, **kw):
22 #print '%r %r' % (args, kw)
23 pass
24@@ -517,10 +522,10 @@
25 self.failUnless(os.path.exists(path))
26
27 def test_deleteUnwantedFilesIgnoresNoise(self):
28- # Directories with invalid names in the storage area are ignored.
29- # They are reported as errors though, so don't let errors fail
30- # this test.
31- librariangc.log = MockLogger(fail_on_error=False)
32+ # Directories with invalid names in the storage area are
33+ # ignored. They are reported as warnings though, so don't let
34+ # warnings fail this test.
35+ librariangc.log = MockLogger(fail_on_warning=False)
36
37 # Not a hexidecimal number.
38 noisedir1_path = os.path.join(config.librarian_server.root, 'zz')
39@@ -574,7 +579,7 @@
40 # There was a bug where delete_unwanted_files() would die
41 # if the last file found on disk was unwanted.
42 self.layer.switchDbUser(dbuser='testadmin')
43- content='foo'
44+ content = 'foo'
45 self.client.addFile(
46 'foo.txt', len(content), StringIO(content), 'text/plain')
47 # Roll back the database changes, leaving the file on disk.
48
49=== modified file 'lib/canonical/librarian/librariangc.py'
50--- lib/canonical/librarian/librariangc.py 2009-09-30 10:46:38 +0000
51+++ lib/canonical/librarian/librariangc.py 2009-10-09 05:06:13 +0000
52@@ -534,20 +534,22 @@
53 # Ignore known and harmless noise in the Librarian storage area.
54 if 'incoming' in dirnames:
55 dirnames.remove('incoming')
56+ if 'lost+found' in dirnames:
57+ dirnames.remove('lost+found')
58 if 'librarian.pid' in filenames:
59 filenames.remove('librarian.pid')
60
61 for dirname in dirnames[:]:
62 if len(dirname) != 2:
63 dirnames.remove(dirname)
64- log.error(
65+ log.warning(
66 "Ignoring directory %s that shouldn't be here" % dirname)
67 continue
68 try:
69 int(dirname, 16)
70 except ValueError:
71 dirnames.remove(dirname)
72- log.error("Ignoring invalid directory %s" % dirname)
73+ log.warning("Ignoring invalid directory %s" % dirname)
74
75 # We need everything in order to ensure we visit files in the
76 # same order we retrieve wanted files from the database.
77@@ -557,7 +559,7 @@
78 # Noise in the storage area, or maybe we are looking at the wrong
79 # path?
80 if dirnames and filenames:
81- log.error(
82+ log.warning(
83 "%s contains both files %r and subdirectories %r. Skipping."
84 % (dirpath, filenames, dirnames))
85 continue
86@@ -566,7 +568,7 @@
87 path = os.path.join(dirpath, filename)
88 hex_content_id = ''.join(path.split(os.sep)[-4:])
89 if hex_content_id_re.search(hex_content_id) is None:
90- log.error(
91+ log.warning(
92 "Ignoring invalid path %s" % path)
93 continue
94