← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~gz/lp-dev-utils/smtp_authentication_prompt into lp:lp-dev-utils

 

Martin Packman has proposed merging lp:~gz/lp-dev-utils/smtp_authentication_prompt into lp:lp-dev-utils.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~gz/lp-dev-utils/smtp_authentication_prompt/+merge/112291

At the moment ec2 land sends your local smtp configuration bazaar.conf to the instance and there is some logic for checking it looks sane, only the server is required. Technically smtp doesn't demand a username and password, but bzrlib.smtp_connection does, and running an open relay accessible to EC2 would be daft. So, in practice not having either set works fine with bzrlib, which prompts for them, but with ec2 you just get no feedback from your test run and the proposal doesn't land.

This branch makes ec2test use the same logic locally as bzr uses, falling back to AuthenticationConfig which will prompt, when gathering the config to forward to ec2. As it doesn't connect and send email right then, a problem will still manifest only as a lack of email, but this should at least be a better hint that email configuration is at issue.

No tests, but I have run this locally and it prompted me for my password as expected.
-- 
https://code.launchpad.net/~gz/lp-dev-utils/smtp_authentication_prompt/+merge/112291
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~gz/lp-dev-utils/smtp_authentication_prompt into lp:lp-dev-utils.
=== modified file 'ec2test/testrunner.py'
--- ec2test/testrunner.py	2012-05-04 10:15:01 +0000
+++ ec2test/testrunner.py	2012-06-27 08:38:22 +0000
@@ -16,7 +16,7 @@
 
 from bzrlib.branch import Branch
 from bzrlib.bzrdir import BzrDir
-from bzrlib.config import GlobalConfig
+from bzrlib.config import AuthenticationConfig, GlobalConfig
 from bzrlib.errors import UncommittedChanges
 from bzrlib.plugins.pqm.pqm_submit import (
     NoPQMSubmissionAddress,
@@ -299,8 +299,16 @@
                     'configured in bzr.  See the SMTP server information '
                     'here: https://wiki.canonical.com/EmailSetup .'
                     'This server must be reachable from the EC2 instance.')
+            auth = AuthenticationConfig()
             self._smtp_username = config.get_user_option('smtp_username')
+            if self._smtp_username is None:
+                self._smtp_username = auth.get_user("smtp", self._smtp_server)
             self._smtp_password = config.get_user_option('smtp_password')
+            if self._smtp_password is None:
+                self.log("Careful, only connects from instance and a typo"
+                    " means no feedback from tests.\n")
+                self._smtp_password = auth.get_password("smtp",
+                    self._smtp_server, self._smtp_username)
             self._from_email = config.username()
             if not self._from_email:
                 raise ValueError(
@@ -351,12 +359,10 @@
                 'email = %s\n' % (self._from_email.encode('utf-8'),))
             bazaar_conf_file.write(
                 'smtp_server = %s\n' % (self._smtp_server,))
-            if self._smtp_username:
-                bazaar_conf_file.write(
-                    'smtp_username = %s\n' % (self._smtp_username,))
-            if self._smtp_password:
-                bazaar_conf_file.write(
-                    'smtp_password = %s\n' % (self._smtp_password,))
+            bazaar_conf_file.write(
+                'smtp_username = %s\n' % (self._smtp_username,))
+            bazaar_conf_file.write(
+                'smtp_password = %s\n' % (self._smtp_password,))
             bazaar_conf_file.close()
         # Copy remote ec2-remote over
         self.log('Copying remote.py to remote machine.\n')