Merge lp:~sakuag333/mailman/BUG_non_queue_runner into lp:mailman

Proposed by Sandesh Kumar Agrawal
Status: Merged
Approved by: Barry Warsaw
Approved revision: 7207
Merge reported by: Barry Warsaw
Merged at revision: not available
Proposed branch: lp:~sakuag333/mailman/BUG_non_queue_runner
Merge into: lp:mailman
Diff against target: 204 lines (+48/-13)
8 files modified
src/mailman/config/mailman.cfg (+2/-0)
src/mailman/core/runner.py (+9/-3)
src/mailman/core/switchboard.py (+13/-10)
src/mailman/interfaces/runner.py (+4/-0)
src/mailman/rest/tests/test_root.py (+7/-0)
src/mailman/runners/lmtp.py (+5/-0)
src/mailman/runners/rest.py (+1/-0)
src/mailman/runners/tests/test_lmtp.py (+7/-0)
To merge this branch: bzr merge lp:~sakuag333/mailman/BUG_non_queue_runner
Reviewer Review Type Date Requested Status
Barry Warsaw Pending
Review via email: mp+143640@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :
Download full text (8.9 KiB)

Hi Sandesh,

Thanks for taking another run at this bug. In general, I think you've
addressed the bug nicely, although there are a few things that still need
fixing. Since the branch is close enough, I'll just fix those when I merge
your branch, but I'll comment on the issues below for future reference.

These are all minor issues. Thanks for your contribution to Mailman!

I'll omit the diff blocks that look fine.

On Jan 17, 2013, at 07:45 AM, Sandesh Kumar Agrawal wrote:

=== modified file 'src/mailman/core/runner.py'
--- src/mailman/core/runner.py 2013-01-01 14:05:42 +0000
+++ src/mailman/core/runner.py 2013-01-17 07:44:42 +0000
> @@ -52,6 +52,7 @@
> @implementer(IRunner)
> class Runner:
> intercept_signals = True
> + is_non_queue_runner = False

In general, I prefer positive flags rather than negative flags. This is
because it's usually more difficult to reason about double negatives. I'll
change the sense of this to "is_queue_runner = True" and then override the
flag to False in the lmtp and rest runners.

>
> def __init__(self, name, slice=None):
> """Create a runner.
> @@ -66,10 +67,15 @@
> section = getattr(config, 'runner.' + name)
> substitutions = config.paths
> substitutions['name'] = name
> - self.queue_directory = expand(section.path, substitutions)
> numslices = int(section.instances)
> - self.switchboard = Switchboard(
> - name, self.queue_directory, slice, numslices, True)
> + # Check whether the runner is queue runner or not; non queue runner should not have queue_directory or switchboard instance.

PEP 8 has a line length limit of 79 characters, so this line needs to be
wrapped.

> + if self.is_non_queue_runner:
> + self.queue_directory = None
> + self.switchboard= None

PEP 8 requires a single space both before and after the = sign.

> + else:
> + self.queue_directory = expand(section.path, substitutions)
> + self.switchboard = Switchboard(
> + name, self.queue_directory, slice, numslices, True)
> self.sleep_time = as_timedelta(section.sleep_time)
> # sleep_time is a timedelta; turn it into a float for time.sleep().
> self.sleep_float = (86400 * self.sleep_time.days +

=== modified file 'src/mailman/core/switchboard.py'
--- src/mailman/core/switchboard.py 2013-01-01 14:05:42 +0000
+++ src/mailman/core/switchboard.py 2013-01-17 07:44:42 +0000
> @@ -90,9 +90,10 @@
> 'Not a power of 2: {0}'.format(numslices))
> self.name = name
> self.queue_directory = queue_directory
> + self.non_queue_runner={'lmtp','rest'}

This should no longer be necessary, right? (I hope it's not! :)

> # If configured to, create the directory if it doesn't yet exist.
> if config.create_paths:
> - makedirs(self.queue_directory, 0770)
> + makedirs(self.queue_directory,0770)

This line should not be changed, and besides, PEP 8 requires a space after the
comma.

> # Fast track for no slices
> self._lower = None
> self._upper = None
> @@ -143,11 +144,11 @@
> ...

Read more...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/mailman/config/mailman.cfg'
2--- src/mailman/config/mailman.cfg 2013-01-01 14:05:42 +0000
3+++ src/mailman/config/mailman.cfg 2013-01-17 07:44:42 +0000
4@@ -60,6 +60,7 @@
5
6 [runner.lmtp]
7 class: mailman.runners.lmtp.LMTPRunner
8+path:
9
10 [runner.nntp]
11 class: mailman.runners.nntp.NNTPRunner
12@@ -72,6 +73,7 @@
13
14 [runner.rest]
15 class: mailman.runners.rest.RESTRunner
16+path:
17
18 [runner.retry]
19 class: mailman.runners.retry.RetryRunner
20
21=== modified file 'src/mailman/core/runner.py'
22--- src/mailman/core/runner.py 2013-01-01 14:05:42 +0000
23+++ src/mailman/core/runner.py 2013-01-17 07:44:42 +0000
24@@ -52,6 +52,7 @@
25 @implementer(IRunner)
26 class Runner:
27 intercept_signals = True
28+ is_non_queue_runner = False
29
30 def __init__(self, name, slice=None):
31 """Create a runner.
32@@ -66,10 +67,15 @@
33 section = getattr(config, 'runner.' + name)
34 substitutions = config.paths
35 substitutions['name'] = name
36- self.queue_directory = expand(section.path, substitutions)
37 numslices = int(section.instances)
38- self.switchboard = Switchboard(
39- name, self.queue_directory, slice, numslices, True)
40+ # Check whether the runner is queue runner or not; non queue runner should not have queue_directory or switchboard instance.
41+ if self.is_non_queue_runner:
42+ self.queue_directory = None
43+ self.switchboard= None
44+ else:
45+ self.queue_directory = expand(section.path, substitutions)
46+ self.switchboard = Switchboard(
47+ name, self.queue_directory, slice, numslices, True)
48 self.sleep_time = as_timedelta(section.sleep_time)
49 # sleep_time is a timedelta; turn it into a float for time.sleep().
50 self.sleep_float = (86400 * self.sleep_time.days +
51
52=== modified file 'src/mailman/core/switchboard.py'
53--- src/mailman/core/switchboard.py 2013-01-01 14:05:42 +0000
54+++ src/mailman/core/switchboard.py 2013-01-17 07:44:42 +0000
55@@ -90,9 +90,10 @@
56 'Not a power of 2: {0}'.format(numslices))
57 self.name = name
58 self.queue_directory = queue_directory
59+ self.non_queue_runner={'lmtp','rest'}
60 # If configured to, create the directory if it doesn't yet exist.
61 if config.create_paths:
62- makedirs(self.queue_directory, 0770)
63+ makedirs(self.queue_directory,0770)
64 # Fast track for no slices
65 self._lower = None
66 self._upper = None
67@@ -143,11 +144,11 @@
68 data['_parsemsg'] = (protocol == 0)
69 # Write to the pickle file the message object and metadata.
70 with open(tmpfile, 'w') as fp:
71- fp.write(msgsave)
72- cPickle.dump(data, fp, protocol)
73- fp.flush()
74- os.fsync(fp.fileno())
75- os.rename(tmpfile, filename)
76+ fp.write(msgsave)
77+ cPickle.dump(data, fp, protocol)
78+ fp.flush()
79+ os.fsync(fp.fileno())
80+ os.rename(tmpfile, filename)
81 return filebase
82
83 def dequeue(self, filebase):
84@@ -266,7 +267,9 @@
85 name = conf.name.split('.')[-1]
86 assert name not in config.switchboards, (
87 'Duplicate runner name: {0}'.format(name))
88- substitutions = config.paths
89- substitutions['name'] = name
90- path = expand(conf.path, substitutions)
91- config.switchboards[name] = Switchboard(name, path)
92+ # Path is empty for non queue runners. hence check for path and create switchboard instance only for queue runner.
93+ if conf.path:
94+ substitutions = config.paths
95+ substitutions['name'] = name
96+ path = expand(conf.path, substitutions)
97+ config.switchboards[name] = Switchboard(name, path)
98
99=== modified file 'src/mailman/interfaces/runner.py'
100--- src/mailman/interfaces/runner.py 2013-01-01 14:05:42 +0000
101+++ src/mailman/interfaces/runner.py 2013-01-17 07:44:42 +0000
102@@ -50,6 +50,10 @@
103
104 def stop():
105 """Stop the runner on the next iteration through the loop."""
106+
107+ is_non_queue_runner = Attribute("""\
108+ A boolean variable to keep track of whether the runner is a queue runner or not.
109+ """)
110
111 queue_directory = Attribute(
112 'The queue directory. Overridden in subclasses.')
113
114=== modified file 'src/mailman/rest/tests/test_root.py'
115--- src/mailman/rest/tests/test_root.py 2013-01-01 14:05:42 +0000
116+++ src/mailman/rest/tests/test_root.py 2013-01-17 07:44:42 +0000
117@@ -25,9 +25,11 @@
118
119
120 import unittest
121+import os
122
123 from urllib2 import HTTPError
124
125+from mailman.config import config
126 from mailman.testing.helpers import call_api
127 from mailman.testing.layers import RESTLayer
128
129@@ -67,3 +69,8 @@
130 'receive_own_postings': True,
131 }, method='PUT')
132 self.assertEqual(cm.exception.code, 405)
133+
134+ def test_rest_queue_directory(self):
135+ # Rest is a non queue runner, so it should not have a directory in var/queue
136+ is_directory = os.path.isdir(os.path.join(config.paths['QUEUE_DIR'],'rest'))
137+ self.assertEqual(is_directory,False)
138
139=== modified file 'src/mailman/runners/lmtp.py'
140--- src/mailman/runners/lmtp.py 2013-01-01 14:05:42 +0000
141+++ src/mailman/runners/lmtp.py 2013-01-17 07:44:42 +0000
142@@ -49,6 +49,7 @@
143
144 from email.utils import parseaddr
145 from zope.component import getUtility
146+from mailman.interfaces.messages import IMessageStore
147
148 from mailman.config import config
149 from mailman.core.runner import Runner
150@@ -153,6 +154,9 @@
151 # Only __init__ is called on startup. Asyncore is responsible for later
152 # connections from the MTA. slice and numslices are ignored and are
153 # necessary only to satisfy the API.
154+
155+ is_non_queue_runner = True
156+
157 def __init__(self, slice=None, numslices=1):
158 localaddr = config.mta.lmtp_host, int(config.mta.lmtp_port)
159 # Do not call Runner's constructor because there's no QDIR to create
160@@ -181,6 +185,7 @@
161 # Do basic post-processing of the message, checking it for defects or
162 # other missing information.
163 message_id = msg.get('message-id')
164+ message_store = getUtility(IMessageStore)
165 if message_id is None:
166 return ERR_550_MID
167 if msg.defects:
168
169=== modified file 'src/mailman/runners/rest.py'
170--- src/mailman/runners/rest.py 2013-01-01 14:05:42 +0000
171+++ src/mailman/runners/rest.py 2013-01-17 07:44:42 +0000
172@@ -41,6 +41,7 @@
173
174
175 class RESTRunner(Runner):
176 intercept_signals = False
177+ is_non_queue_runner = True
178
179 def run(self):
180 log.info('Starting REST server')
181
182=== modified file 'src/mailman/runners/tests/test_lmtp.py'
183--- src/mailman/runners/tests/test_lmtp.py 2013-01-01 14:05:42 +0000
184+++ src/mailman/runners/tests/test_lmtp.py 2013-01-17 07:44:42 +0000
185@@ -27,9 +27,11 @@
186
187 import smtplib
188 import unittest
189+import os
190
191 from datetime import datetime
192
193+from mailman.config import config
194 from mailman.app.lifecycle import create_list
195 from mailman.database.transaction import transaction
196 from mailman.testing.helpers import get_lmtp_client, get_queue_messages
197@@ -109,3 +111,8 @@
198 self.assertEqual(len(messages), 1)
199 self.assertEqual(messages[0].msgdata['received_time'],
200 datetime(2005, 8, 1, 7, 49, 23))
201+
202+ def test_lmtp_queue_directory(self):
203+ # Lmtp is a non queue runner, so it should not have a directory in var/queue
204+ is_directory = os.path.isdir(os.path.join(config.paths['QUEUE_DIR'],'lmtp'))
205+ self.assertEqual(is_directory,False)