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
1=== modified file 'bzrlib/config.py'
2--- bzrlib/config.py 2012-06-19 16:36:07 +0000
3+++ bzrlib/config.py 2012-07-21 02:03:18 +0000
4@@ -1562,7 +1562,7 @@
5 return os.path.expanduser('~/.cache')
6
7
8-def _get_default_mail_domain():
9+def _get_default_mail_domain(mailname_file='/etc/mailname'):
10 """If possible, return the assumed default email domain.
11
12 :returns: string mail domain, or None.
13@@ -1571,11 +1571,11 @@
14 # No implementation yet; patches welcome
15 return None
16 try:
17- f = open('/etc/mailname')
18+ f = open(mailname_file)
19 except (IOError, OSError), e:
20 return None
21 try:
22- domain = f.read().strip()
23+ domain = f.readline().strip()
24 return domain
25 finally:
26 f.close()
27
28=== modified file 'bzrlib/tests/test_config.py'
29--- bzrlib/tests/test_config.py 2012-06-20 14:35:26 +0000
30+++ bzrlib/tests/test_config.py 2012-07-21 02:03:18 +0000
31@@ -4568,8 +4568,8 @@
32 port=99, path='/foo',
33 realm='realm')
34 CREDENTIALS = {'name': 'name', 'user': 'user', 'password': 'password',
35- 'verify_certificates': False, 'scheme': 'scheme',
36- 'host': 'host', 'port': 99, 'path': '/foo',
37+ 'verify_certificates': False, 'scheme': 'scheme',
38+ 'host': 'host', 'port': 99, 'path': '/foo',
39 'realm': 'realm'}
40 self.assertEqual(CREDENTIALS, credentials)
41 credentials_from_disk = config.AuthenticationConfig().get_credentials(
42@@ -4583,8 +4583,8 @@
43 self.assertIs(None, conf._get_config().get('name'))
44 credentials = conf.get_credentials(host='host', scheme='scheme')
45 CREDENTIALS = {'name': 'name2', 'user': 'user2', 'password':
46- 'password', 'verify_certificates': True,
47- 'scheme': 'scheme', 'host': 'host', 'port': None,
48+ 'password', 'verify_certificates': True,
49+ 'scheme': 'scheme', 'host': 'host', 'port': None,
50 'path': None, 'realm': None}
51 self.assertEqual(CREDENTIALS, credentials)
52
53@@ -4876,6 +4876,37 @@
54 self.assertEquals((None, None), (realname, address))
55
56
57+class TestDefaultMailDomain(tests.TestCaseInTempDir):
58+ """Test retrieving default domain from mailname file"""
59+
60+ def test_default_mail_domain_simple(self):
61+ f = file('simple', 'w')
62+ try:
63+ f.write("domainname.com\n")
64+ finally:
65+ f.close()
66+ r = config._get_default_mail_domain('simple')
67+ self.assertEquals('domainname.com', r)
68+
69+ def test_default_mail_domain_no_eol(self):
70+ f = file('no_eol', 'w')
71+ try:
72+ f.write("domainname.com")
73+ finally:
74+ f.close()
75+ r = config._get_default_mail_domain('no_eol')
76+ self.assertEquals('domainname.com', r)
77+
78+ def test_default_mail_domain_multiple_lines(self):
79+ f = file('multiple_lines', 'w')
80+ try:
81+ f.write("domainname.com\nsome other text\n")
82+ finally:
83+ f.close()
84+ r = config._get_default_mail_domain('multiple_lines')
85+ self.assertEquals('domainname.com', r)
86+
87+
88 class EmailOptionTests(tests.TestCase):
89
90 def test_default_email_uses_BZR_EMAIL(self):
91
92=== modified file 'doc/en/release-notes/bzr-2.6.txt'
93--- doc/en/release-notes/bzr-2.6.txt 2012-07-10 12:19:23 +0000
94+++ doc/en/release-notes/bzr-2.6.txt 2012-07-21 02:03:18 +0000
95@@ -23,7 +23,7 @@
96 Improvements
97 ************
98
99-.. Improvements to existing commands, especially improved performance
100+.. Improvements to existing commands, especially improved performance
101 or memory usage, or better results.
102
103 Bug Fixes
104@@ -32,6 +32,11 @@
105 .. Fixes for situations where bzr would previously crash or give incorrect
106 or undesirable results.
107
108+* Fixed a bug where the entire contents of ``/etc/mailname`` is read in.
109+ We only want to read in the first line so that comments could be added
110+ and would be ignored.
111+ (Haw Loeung, #932515)
112+
113 Documentation
114 *************
115