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
=== modified file 'src/mailman/config/mailman.cfg'
--- src/mailman/config/mailman.cfg 2013-01-01 14:05:42 +0000
+++ src/mailman/config/mailman.cfg 2013-01-17 07:44:42 +0000
@@ -60,6 +60,7 @@
6060
61[runner.lmtp]61[runner.lmtp]
62class: mailman.runners.lmtp.LMTPRunner62class: mailman.runners.lmtp.LMTPRunner
63path:
6364
64[runner.nntp]65[runner.nntp]
65class: mailman.runners.nntp.NNTPRunner66class: mailman.runners.nntp.NNTPRunner
@@ -72,6 +73,7 @@
7273
73[runner.rest]74[runner.rest]
74class: mailman.runners.rest.RESTRunner75class: mailman.runners.rest.RESTRunner
76path:
7577
76[runner.retry]78[runner.retry]
77class: mailman.runners.retry.RetryRunner79class: mailman.runners.retry.RetryRunner
7880
=== 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 @@
52@implementer(IRunner)52@implementer(IRunner)
53class Runner:53class Runner:
54 intercept_signals = True54 intercept_signals = True
55 is_non_queue_runner = False
5556
56 def __init__(self, name, slice=None):57 def __init__(self, name, slice=None):
57 """Create a runner.58 """Create a runner.
@@ -66,10 +67,15 @@
66 section = getattr(config, 'runner.' + name)67 section = getattr(config, 'runner.' + name)
67 substitutions = config.paths68 substitutions = config.paths
68 substitutions['name'] = name69 substitutions['name'] = name
69 self.queue_directory = expand(section.path, substitutions)
70 numslices = int(section.instances)70 numslices = int(section.instances)
71 self.switchboard = Switchboard(71 # Check whether the runner is queue runner or not; non queue runner should not have queue_directory or switchboard instance.
72 name, self.queue_directory, slice, numslices, True)72 if self.is_non_queue_runner:
73 self.queue_directory = None
74 self.switchboard= None
75 else:
76 self.queue_directory = expand(section.path, substitutions)
77 self.switchboard = Switchboard(
78 name, self.queue_directory, slice, numslices, True)
73 self.sleep_time = as_timedelta(section.sleep_time)79 self.sleep_time = as_timedelta(section.sleep_time)
74 # sleep_time is a timedelta; turn it into a float for time.sleep().80 # sleep_time is a timedelta; turn it into a float for time.sleep().
75 self.sleep_float = (86400 * self.sleep_time.days +81 self.sleep_float = (86400 * self.sleep_time.days +
7682
=== 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 @@
90 'Not a power of 2: {0}'.format(numslices))90 'Not a power of 2: {0}'.format(numslices))
91 self.name = name91 self.name = name
92 self.queue_directory = queue_directory92 self.queue_directory = queue_directory
93 self.non_queue_runner={'lmtp','rest'}
93 # If configured to, create the directory if it doesn't yet exist.94 # If configured to, create the directory if it doesn't yet exist.
94 if config.create_paths:95 if config.create_paths:
95 makedirs(self.queue_directory, 0770)96 makedirs(self.queue_directory,0770)
96 # Fast track for no slices97 # Fast track for no slices
97 self._lower = None98 self._lower = None
98 self._upper = None99 self._upper = None
@@ -143,11 +144,11 @@
143 data['_parsemsg'] = (protocol == 0)144 data['_parsemsg'] = (protocol == 0)
144 # Write to the pickle file the message object and metadata.145 # Write to the pickle file the message object and metadata.
145 with open(tmpfile, 'w') as fp:146 with open(tmpfile, 'w') as fp:
146 fp.write(msgsave)147 fp.write(msgsave)
147 cPickle.dump(data, fp, protocol)148 cPickle.dump(data, fp, protocol)
148 fp.flush()149 fp.flush()
149 os.fsync(fp.fileno())150 os.fsync(fp.fileno())
150 os.rename(tmpfile, filename)151 os.rename(tmpfile, filename)
151 return filebase152 return filebase
152153
153 def dequeue(self, filebase):154 def dequeue(self, filebase):
@@ -266,7 +267,9 @@
266 name = conf.name.split('.')[-1]267 name = conf.name.split('.')[-1]
267 assert name not in config.switchboards, (268 assert name not in config.switchboards, (
268 'Duplicate runner name: {0}'.format(name))269 'Duplicate runner name: {0}'.format(name))
269 substitutions = config.paths270 # Path is empty for non queue runners. hence check for path and create switchboard instance only for queue runner.
270 substitutions['name'] = name271 if conf.path:
271 path = expand(conf.path, substitutions)272 substitutions = config.paths
272 config.switchboards[name] = Switchboard(name, path)273 substitutions['name'] = name
274 path = expand(conf.path, substitutions)
275 config.switchboards[name] = Switchboard(name, path)
273276
=== modified file 'src/mailman/interfaces/runner.py'
--- src/mailman/interfaces/runner.py 2013-01-01 14:05:42 +0000
+++ src/mailman/interfaces/runner.py 2013-01-17 07:44:42 +0000
@@ -50,6 +50,10 @@
5050
51 def stop():51 def stop():
52 """Stop the runner on the next iteration through the loop."""52 """Stop the runner on the next iteration through the loop."""
53
54 is_non_queue_runner = Attribute("""\
55 A boolean variable to keep track of whether the runner is a queue runner or not.
56 """)
5357
54 queue_directory = Attribute(58 queue_directory = Attribute(
55 'The queue directory. Overridden in subclasses.')59 'The queue directory. Overridden in subclasses.')
5660
=== modified file 'src/mailman/rest/tests/test_root.py'
--- src/mailman/rest/tests/test_root.py 2013-01-01 14:05:42 +0000
+++ src/mailman/rest/tests/test_root.py 2013-01-17 07:44:42 +0000
@@ -25,9 +25,11 @@
2525
2626
27import unittest27import unittest
28import os
2829
29from urllib2 import HTTPError30from urllib2 import HTTPError
3031
32from mailman.config import config
31from mailman.testing.helpers import call_api33from mailman.testing.helpers import call_api
32from mailman.testing.layers import RESTLayer34from mailman.testing.layers import RESTLayer
3335
@@ -67,3 +69,8 @@
67 'receive_own_postings': True,69 'receive_own_postings': True,
68 }, method='PUT')70 }, method='PUT')
69 self.assertEqual(cm.exception.code, 405)71 self.assertEqual(cm.exception.code, 405)
72
73 def test_rest_queue_directory(self):
74 # Rest is a non queue runner, so it should not have a directory in var/queue
75 is_directory = os.path.isdir(os.path.join(config.paths['QUEUE_DIR'],'rest'))
76 self.assertEqual(is_directory,False)
7077
=== modified file 'src/mailman/runners/lmtp.py'
--- src/mailman/runners/lmtp.py 2013-01-01 14:05:42 +0000
+++ src/mailman/runners/lmtp.py 2013-01-17 07:44:42 +0000
@@ -49,6 +49,7 @@
4949
50from email.utils import parseaddr50from email.utils import parseaddr
51from zope.component import getUtility51from zope.component import getUtility
52from mailman.interfaces.messages import IMessageStore
5253
53from mailman.config import config54from mailman.config import config
54from mailman.core.runner import Runner55from mailman.core.runner import Runner
@@ -153,6 +154,9 @@
153 # Only __init__ is called on startup. Asyncore is responsible for later154 # Only __init__ is called on startup. Asyncore is responsible for later
154 # connections from the MTA. slice and numslices are ignored and are155 # connections from the MTA. slice and numslices are ignored and are
155 # necessary only to satisfy the API.156 # necessary only to satisfy the API.
157
158 is_non_queue_runner = True
159
156 def __init__(self, slice=None, numslices=1):160 def __init__(self, slice=None, numslices=1):
157 localaddr = config.mta.lmtp_host, int(config.mta.lmtp_port)161 localaddr = config.mta.lmtp_host, int(config.mta.lmtp_port)
158 # Do not call Runner's constructor because there's no QDIR to create162 # Do not call Runner's constructor because there's no QDIR to create
@@ -181,6 +185,7 @@
181 # Do basic post-processing of the message, checking it for defects or185 # Do basic post-processing of the message, checking it for defects or
182 # other missing information.186 # other missing information.
183 message_id = msg.get('message-id')187 message_id = msg.get('message-id')
188 message_store = getUtility(IMessageStore)
184 if message_id is None:189 if message_id is None:
185 return ERR_550_MID190 return ERR_550_MID
186 if msg.defects:191 if msg.defects:
187192
=== modified file 'src/mailman/runners/rest.py'
--- src/mailman/runners/rest.py 2013-01-01 14:05:42 +0000
+++ src/mailman/runners/rest.py 2013-01-17 07:44:42 +0000
@@ -41,6 +41,7 @@
4141
4242
43class RESTRunner(Runner):43class RESTRunner(Runner):
44 intercept_signals = False44 intercept_signals = False
45 is_non_queue_runner = True
4546
46 def run(self):47 def run(self):
47 log.info('Starting REST server')48 log.info('Starting REST server')
4849
=== modified file 'src/mailman/runners/tests/test_lmtp.py'
--- src/mailman/runners/tests/test_lmtp.py 2013-01-01 14:05:42 +0000
+++ src/mailman/runners/tests/test_lmtp.py 2013-01-17 07:44:42 +0000
@@ -27,9 +27,11 @@
2727
28import smtplib28import smtplib
29import unittest29import unittest
30import os
3031
31from datetime import datetime32from datetime import datetime
3233
34from mailman.config import config
33from mailman.app.lifecycle import create_list35from mailman.app.lifecycle import create_list
34from mailman.database.transaction import transaction36from mailman.database.transaction import transaction
35from mailman.testing.helpers import get_lmtp_client, get_queue_messages37from mailman.testing.helpers import get_lmtp_client, get_queue_messages
@@ -109,3 +111,8 @@
109 self.assertEqual(len(messages), 1)111 self.assertEqual(len(messages), 1)
110 self.assertEqual(messages[0].msgdata['received_time'],112 self.assertEqual(messages[0].msgdata['received_time'],
111 datetime(2005, 8, 1, 7, 49, 23))113 datetime(2005, 8, 1, 7, 49, 23))
114
115 def test_lmtp_queue_directory(self):
116 # Lmtp is a non queue runner, so it should not have a directory in var/queue
117 is_directory = os.path.isdir(os.path.join(config.paths['QUEUE_DIR'],'lmtp'))
118 self.assertEqual(is_directory,False)