Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits:
9fbc107f by Abhilash Raj at 2019-12-14T22:54:25+00:00
Add a generate-alias-file argument to mailman command
Closes #469
- - - - -
c239a993 by Abhilash Raj at 2019-12-14T22:54:25+00:00
Merge branch 'peb/mailman-fix_469' into 'master'
Add a generate-alias-file argument to mailman command
Closes #469
See merge request mailman/mailman!415
- - - - -
5 changed files:
- src/mailman/commands/cli_control.py
- src/mailman/commands/docs/control.rst
- src/mailman/commands/tests/test_cli_control.py
- src/mailman/docs/NEWS.rst
- src/mailman/testing/mta.py
Changes:
=====================================
src/mailman/commands/cli_control.py
=====================================
@@ -28,6 +28,7 @@ from mailman.bin.master import WatcherState, master_state
from mailman.config import config
from mailman.core.i18n import _
from mailman.interfaces.command import ICLISubCommand
+from mailman.utilities.modules import call_name
from mailman.utilities.options import I18nCommand
from public import public
from zope.interface import implementer
@@ -50,6 +51,15 @@ qlog = logging.getLogger('mailman.runner')
clean up the lock. But if no matching process is found, the master will
remove the apparently stale lock and make another attempt to claim the
master lock."""))
[email protected](
+ '--generate-alias-file', '-g',
+ is_flag=True, default=True,
+ help=_("""\
+ Generate the MTA alias files upon startup. Some MTA, like postfix, can't
+ deliver email if alias files mentioned in its configuration are not
+ present. In some situations, this could lead to a deadlock at the first
+ start of mailman3 server. Setting this option to true will make this
+ script create the files and thus allow the MTA to operate smoothly."""))
@click.option(
'--run-as-user', '-u',
is_flag=True, default=True,
@@ -74,7 +84,7 @@ qlog = logging.getLogger('mailman.runner')
Don't print status messages. Error messages are still printed to standard
error."""))
@click.pass_context
-def start(ctx, force, run_as_user, quiet):
+def start(ctx, force, generate_alias_file, run_as_user, quiet):
# Although there's a potential race condition here, it's a better user
# experience for the parent process to refuse to start twice, rather than
# having it try to start the master, which will error exit.
@@ -93,6 +103,10 @@ def start(ctx, force, run_as_user, quiet):
# parent
if not quiet:
print(_("Starting Mailman's master runner"))
+ if generate_alias_file:
+ if not quiet:
+ print(_("Generating MTA alias maps"))
+ call_name(config.mta.incoming).regenerate()
return
# child: Create a new session and become the session leader, but since we
# won't be opening any terminal devices, don't do the ultra-paranoid
=====================================
src/mailman/commands/docs/control.rst
=====================================
@@ -27,6 +27,7 @@ process in the background.
>>> command('mailman start')
Starting Mailman's master runner
+ Generating MTA alias maps
>>> from mailman.commands.tests.test_cli_control import find_master
=====================================
src/mailman/commands/tests/test_cli_control.py
=====================================
@@ -270,6 +270,24 @@ class TestControl(unittest.TestCase):
posargs, kws = self._execl.call_args_list[0]
self.assertIn('--force', posargs)
+ def test_generate_aliases_file_on_start(self):
+ # Test that 'aliases' command is called when 'start' is called.
+ with ExitStack() as resources:
+ # To be able to get the output from aliases command, we need to
+ # capture the output from parent command, which invokes the aliases
+ # command.
+ resources.enter_context(patch(
+ 'mailman.commands.cli_control.os.fork',
+ # Pretend to be the parent.
+ return_value=1))
+ mock_regenerate = resources.enter_context(
+ patch('{}.regenerate'.format(config.mta.incoming)))
+ result = self._command.invoke(start)
+ self.assertTrue('Generating MTA alias maps' in result.output)
+ # At some point, this should be moved to assert_called_once() when
+ # we drop support for Python 3.5.
+ self.assertTrue(mock_regenerate.called)
+
class TestControlSimple(unittest.TestCase):
layer = ConfigLayer
=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -27,7 +27,8 @@ Bugs
domain names. (Closes #651)
* Fix failing test cases due to changed API in a new version of dkimpy. (Closes
#655)
-
+* Mailman now auto-geneartes alias maps when it starts for the first
+ time. (Closes #469)
REST
----
=====================================
src/mailman/testing/mta.py
=====================================
@@ -41,7 +41,7 @@ class FakeMTA:
def delete(self, mlist):
pass
- def regenerate(self, output=None):
+ def regenerate(self, directory=None):
pass
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/ac0879a2a4e233633820cad8c8efa3f2bf29dbac...c239a9937d6076aa9ce1e0045ac7e6bdc0f39c37
--
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/ac0879a2a4e233633820cad8c8efa3f2bf29dbac...c239a9937d6076aa9ce1e0045ac7e6bdc0f39c37
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org