Merge ~ahasenack/qa-regression-testing:postfix-py3-fixes into qa-regression-testing:master

Proposed by Andreas Hasenack
Status: Merged
Merged at revision: 96c5e011c102a82e302de80566bf306f184be75b
Proposed branch: ~ahasenack/qa-regression-testing:postfix-py3-fixes
Merge into: qa-regression-testing:master
Diff against target: 113 lines (+21/-17)
1 file modified
scripts/test-postfix.py (+21/-17)
Reviewer Review Type Date Requested Status
Steve Beattie Approve
Review via email: mp+373276@code.launchpad.net

Description of the change

Remaining py3 fixes. I didn't change any defaults or package dependencies, i.e., if just following the README instructions, py2 will still be used.

I was also getting a lot of warnings about files left open, so I took a stab at that too.

In eoan:
$ sudo python3 ./test-postfix.py
...............
----------------------------------------------------------------------
Ran 15 tests in 62.400s

OK

$ sudo python2 ./test-postfix.py
...............
----------------------------------------------------------------------
Ran 15 tests in 63.094s

OK

I also checked xenial:
$ sudo python3 ./test-postfix.py
...............
----------------------------------------------------------------------
Ran 15 tests in 62.069s

OK
$ apt-cache policy python3
python3:
  Installed: 3.5.1-3
  Candidate: 3.5.1-3
  Version table:
 *** 3.5.1-3 500
        500 http://br.archive.ubuntu.com/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status

To post a comment you must log in.
Revision history for this message
Steve Beattie (sbeattie) wrote :

Looks good to me. Thanks for fixing the open file descriptor issues (ugh).

With your fixes, I verified that the tests continue to succeed on trusty and precise (ESM releases). Both worked under python2 and trusty did for python3; precise is missing a python3-pexpect package. That's not a blocker for merging this PR, but it complicates our plan to move to python3 by default for qrt scripts.

Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/scripts/test-postfix.py b/scripts/test-postfix.py
2index b294791..a616ba9 100755
3--- a/scripts/test-postfix.py
4+++ b/scripts/test-postfix.py
5@@ -49,13 +49,13 @@ class PostfixTest(testlib.TestlibCase):
6
7 # Move listener to localhost:2525
8 conf_file = '/etc/postfix/master.cf'
9- lines = open(conf_file)
10 contents = ''
11- for cfline in lines:
12- if cfline.startswith('smtp') and 'smtpd' in cfline and 'inet' in cfline:
13- contents += '127.0.0.1:2525 inet n - - - - smtpd\n'
14- else:
15- contents += "%s\n" % cfline
16+ with open(conf_file) as fh:
17+ for cfline in fh:
18+ if cfline.startswith('smtp') and 'smtpd' in cfline and 'inet' in cfline:
19+ contents += '127.0.0.1:2525 inet n - - - - smtpd\n'
20+ else:
21+ contents += "%s\n" % cfline
22 testlib.config_replace(conf_file, contents, append=False)
23
24 conf_file = '/etc/postfix/main.cf'
25@@ -205,7 +205,7 @@ mech_list: %s %s
26 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
27 s.settimeout(5)
28 s.connect(('localhost', 2525))
29- greeting = s.recv(1024)
30+ greeting = s.recv(1024).decode('utf-8')
31 # 220 gorgon.outflux.net ESMTP Postfix (Ubuntu)
32 self.assertTrue(greeting.startswith('220 '), greeting)
33 self.assertTrue('ESMTP' in greeting, greeting)
34@@ -226,11 +226,11 @@ mech_list: %s %s
35 reply = '%d %s' % (code, msg)
36 if valid:
37 self.assertEqual(code, 252, reply)
38- self.assertTrue(address in msg, reply)
39+ self.assertTrue(address.encode('utf-8') in msg, reply)
40 else:
41 self.assertEqual(code, 550, reply)
42- self.assertTrue('Recipient address rejected' in msg, reply)
43- self.assertTrue('<%s>' % (address) in msg, reply)
44+ self.assertTrue(b'Recipient address rejected' in msg, reply)
45+ self.assertTrue(('<%s>' % (address)).encode('utf-8') in msg, reply)
46
47 def test_10_commands(self):
48 '''Basic SMTP commands'''
49@@ -241,13 +241,13 @@ mech_list: %s %s
50 reply = '%d %s' % (code, msg)
51 self.assertEqual(code, 250, reply)
52 self.assertEqual(self.s.does_esmtp, 1, reply)
53- self.assertTrue('8BITMIME' in self.s.ehlo_resp, reply)
54+ self.assertTrue(b'8BITMIME' in self.s.ehlo_resp, reply)
55 # No help available
56 self.s.putcmd("help")
57 code, msg = self.s.getreply()
58 reply = '%d %s' % (code, msg)
59 self.assertEqual(code, 502, reply)
60- self.assertTrue('Error' in msg, reply)
61+ self.assertTrue(b'Error' in msg, reply)
62 # VRFY addresses
63 self._vrfy('address@example.com', valid=True)
64 self._vrfy('does-not-exist', valid=False)
65@@ -286,7 +286,8 @@ Hello, nice to meet you.
66 if spool_file == None:
67 spool_file = '/var/mail/%s' % (target_spool_user.login)
68 time.sleep(1)
69- contents = open(spool_file).read()
70+ with open(spool_file) as fh:
71+ contents = fh.read()
72 #print contents
73 # Server-side added headers...
74 self.assertTrue('\nReceived: ' in contents, contents)
75@@ -336,7 +337,8 @@ Hello, nice to meet you.
76
77 def _write_forward(self, user, contents):
78 forward_filename = '/home/%s/.forward' % (user.login)
79- open(forward_filename, 'w').write(contents)
80+ with open(forward_filename, 'w') as fh:
81+ fh.write(contents)
82 os.chown(forward_filename, user.uid, user.gid)
83
84 def test_10_sending_mail_forward_normal(self):
85@@ -372,7 +374,8 @@ Hello, nice to meet you.
86
87 # First, create our "target" file
88 secret = '/root/secret.txt'
89- open(secret, 'w').write('Secret information\n')
90+ with open(secret, 'w') as fh:
91+ fh.write('Secret information\n')
92 os.chmod(secret, 0o700)
93
94 # Now, create a symlink to the target (we're going to use /var/tmp
95@@ -398,7 +401,8 @@ Hello, nice to pwn you.
96 # Pause for delivery
97 time.sleep(2)
98
99- contents = open(secret).read()
100+ with open(secret) as fh:
101+ contents = fh.read()
102 # Clean up before possible failures
103 os.unlink('/var/mail/%s' % (self.user.login))
104 os.unlink('/var/tmp/secret.link')
105@@ -422,7 +426,7 @@ Hello, nice to pwn you.
106 reply = '%d %s' % (code, msg)
107 self.assertEqual(code, 250, reply)
108 self.assertEqual(self.s.does_esmtp, 1, reply)
109- self.assertTrue('%s' % mech in self.s.ehlo_resp, reply)
110+ self.assertTrue(mech.encode('utf-8') in self.s.ehlo_resp, reply)
111 return reply
112
113 def test_20_sasldb_cram_md5(self):

Subscribers

People subscribed via source and target branches