Merge lp:~hloeung/bzr/mailname-first-line into lp:bzr

Proposed by Haw Loeung
Status: Superseded
Proposed branch: lp:~hloeung/bzr/mailname-first-line
Merge into: lp:bzr
Diff against target: 114 lines (+44/-8)
3 files modified
bzrlib/config.py (+3/-3)
bzrlib/tests/test_config.py (+35/-4)
doc/en/release-notes/bzr-2.6.txt (+6/-1)
To merge this branch: bzr merge lp:~hloeung/bzr/mailname-first-line
Reviewer Review Type Date Requested Status
Haw Loeung Needs Information
Jelmer Vernooij (community) Approve
Review via email: mp+115882@code.launchpad.net

This proposal has been superseded by a proposal from 2012-07-22.

Description of the change

Read only the first line from /etc/mailname. This makes it consistent with postfix and allows us to append our puppet warning headers.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Thanks for the fix; the change looks reasonable. It would be good to have a test for it so we can be sure this won't regress in the future.

Revision history for this message
Haw Loeung (hloeung) wrote :

Hi Jelmer,

I have added a couple of test cases. This is my first so all feedback appreciated.

Regards,

Haw

review: Needs Resubmitting
Revision history for this message
Haw Loeung (hloeung) wrote :

Err, discard the "resubmit".

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Thanks, looks great!

One really minor nitpick: we should use try/finally to make sure the tests don't leak any file descriptors if they fail. It would also be nice to have a news entry about this in doc/en/release-notes/bzr-2.6.txt

review: Approve
Revision history for this message
Haw Loeung (hloeung) wrote :

Jelmer,

I've updated the release notes for 2.6 and made the tests use try/finally to make sure we don't leak any file descriptors if/when they fail. How does it look now?

Thanks for your feedback.

Revision history for this message
Haw Loeung (hloeung) :
review: Needs Information
Revision history for this message
Haw Loeung (hloeung) wrote :

[hloeung@darkon mailname-first-line]$ ./bzr selftest -v TestDefaultMailDomain
running 3 tests...
bzr selftest: /home/hloeung/tmp/mailname-first-line/bzr
   /home/hloeung/tmp/mailname-first-line/bzrlib
   bzr-2.6.0dev3 python-2.7.3 Linux-3.5.0-5-generic-x86_64-with-Ubuntu-12.10-quantal

...stDefaultMailDomain.test_default_mail_domain_multiple_lines OK 21ms
...onfig.TestDefaultMailDomain.test_default_mail_domain_no_eol OK 2ms
...onfig.TestDefaultMailDomain.test_default_mail_domain_simple OK 2ms
----------------------------------------------------------------------
Ran 3 tests in 0.046s

OK

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/config.py'
--- bzrlib/config.py 2012-06-19 16:36:07 +0000
+++ bzrlib/config.py 2012-07-21 02:03:18 +0000
@@ -1562,7 +1562,7 @@
1562 return os.path.expanduser('~/.cache')1562 return os.path.expanduser('~/.cache')
15631563
15641564
1565def _get_default_mail_domain():1565def _get_default_mail_domain(mailname_file='/etc/mailname'):
1566 """If possible, return the assumed default email domain.1566 """If possible, return the assumed default email domain.
15671567
1568 :returns: string mail domain, or None.1568 :returns: string mail domain, or None.
@@ -1571,11 +1571,11 @@
1571 # No implementation yet; patches welcome1571 # No implementation yet; patches welcome
1572 return None1572 return None
1573 try:1573 try:
1574 f = open('/etc/mailname')1574 f = open(mailname_file)
1575 except (IOError, OSError), e:1575 except (IOError, OSError), e:
1576 return None1576 return None
1577 try:1577 try:
1578 domain = f.read().strip()1578 domain = f.readline().strip()
1579 return domain1579 return domain
1580 finally:1580 finally:
1581 f.close()1581 f.close()
15821582
=== modified file 'bzrlib/tests/test_config.py'
--- bzrlib/tests/test_config.py 2012-06-20 14:35:26 +0000
+++ bzrlib/tests/test_config.py 2012-07-21 02:03:18 +0000
@@ -4568,8 +4568,8 @@
4568 port=99, path='/foo',4568 port=99, path='/foo',
4569 realm='realm')4569 realm='realm')
4570 CREDENTIALS = {'name': 'name', 'user': 'user', 'password': 'password',4570 CREDENTIALS = {'name': 'name', 'user': 'user', 'password': 'password',
4571 'verify_certificates': False, 'scheme': 'scheme', 4571 'verify_certificates': False, 'scheme': 'scheme',
4572 'host': 'host', 'port': 99, 'path': '/foo', 4572 'host': 'host', 'port': 99, 'path': '/foo',
4573 'realm': 'realm'}4573 'realm': 'realm'}
4574 self.assertEqual(CREDENTIALS, credentials)4574 self.assertEqual(CREDENTIALS, credentials)
4575 credentials_from_disk = config.AuthenticationConfig().get_credentials(4575 credentials_from_disk = config.AuthenticationConfig().get_credentials(
@@ -4583,8 +4583,8 @@
4583 self.assertIs(None, conf._get_config().get('name'))4583 self.assertIs(None, conf._get_config().get('name'))
4584 credentials = conf.get_credentials(host='host', scheme='scheme')4584 credentials = conf.get_credentials(host='host', scheme='scheme')
4585 CREDENTIALS = {'name': 'name2', 'user': 'user2', 'password':4585 CREDENTIALS = {'name': 'name2', 'user': 'user2', 'password':
4586 'password', 'verify_certificates': True, 4586 'password', 'verify_certificates': True,
4587 'scheme': 'scheme', 'host': 'host', 'port': None, 4587 'scheme': 'scheme', 'host': 'host', 'port': None,
4588 'path': None, 'realm': None}4588 'path': None, 'realm': None}
4589 self.assertEqual(CREDENTIALS, credentials)4589 self.assertEqual(CREDENTIALS, credentials)
45904590
@@ -4876,6 +4876,37 @@
4876 self.assertEquals((None, None), (realname, address))4876 self.assertEquals((None, None), (realname, address))
48774877
48784878
4879class TestDefaultMailDomain(tests.TestCaseInTempDir):
4880 """Test retrieving default domain from mailname file"""
4881
4882 def test_default_mail_domain_simple(self):
4883 f = file('simple', 'w')
4884 try:
4885 f.write("domainname.com\n")
4886 finally:
4887 f.close()
4888 r = config._get_default_mail_domain('simple')
4889 self.assertEquals('domainname.com', r)
4890
4891 def test_default_mail_domain_no_eol(self):
4892 f = file('no_eol', 'w')
4893 try:
4894 f.write("domainname.com")
4895 finally:
4896 f.close()
4897 r = config._get_default_mail_domain('no_eol')
4898 self.assertEquals('domainname.com', r)
4899
4900 def test_default_mail_domain_multiple_lines(self):
4901 f = file('multiple_lines', 'w')
4902 try:
4903 f.write("domainname.com\nsome other text\n")
4904 finally:
4905 f.close()
4906 r = config._get_default_mail_domain('multiple_lines')
4907 self.assertEquals('domainname.com', r)
4908
4909
4879class EmailOptionTests(tests.TestCase):4910class EmailOptionTests(tests.TestCase):
48804911
4881 def test_default_email_uses_BZR_EMAIL(self):4912 def test_default_email_uses_BZR_EMAIL(self):
48824913
=== modified file 'doc/en/release-notes/bzr-2.6.txt'
--- doc/en/release-notes/bzr-2.6.txt 2012-07-10 12:19:23 +0000
+++ doc/en/release-notes/bzr-2.6.txt 2012-07-21 02:03:18 +0000
@@ -23,7 +23,7 @@
23Improvements23Improvements
24************24************
2525
26.. Improvements to existing commands, especially improved performance 26.. Improvements to existing commands, especially improved performance
27 or memory usage, or better results.27 or memory usage, or better results.
2828
29Bug Fixes29Bug Fixes
@@ -32,6 +32,11 @@
32.. Fixes for situations where bzr would previously crash or give incorrect32.. Fixes for situations where bzr would previously crash or give incorrect
33 or undesirable results.33 or undesirable results.
3434
35* Fixed a bug where the entire contents of ``/etc/mailname`` is read in.
36 We only want to read in the first line so that comments could be added
37 and would be ignored.
38 (Haw Loeung, #932515)
39
35Documentation40Documentation
36*************41*************
3742