diff --git a/tests/test_postfix.py b/tests/test_postfix.py index de99cc15eb8d16eb30f17e0f91405e6180f59c1d..15afa1e2f1f24f25c81ae576a00f1e47e7ed7ff4 100755 --- a/tests/test_postfix.py +++ b/tests/test_postfix.py @@ -4,34 +4,17 @@ Check that emails can be sent. ''' import os -import re import subprocess import sys if not os.path.exists('/etc/postfix'): print('Postfix dir does not exists, test skipped.') + sys.exit(1) else: # check that postfix listens the port 25 correctly - out = subprocess.check_output('netstat -pant | grep \':25\'', shell=True) - out = out.decode('utf-8') if out else '' - - # netstat -pant output columns are: - # Proto | Recv-Q | Send-Q | Local address | Foreign address | State | PID/Program name - - expected = r'tcp +\d +\d +127\.0\.0\.1:25 +0\.0\.0\.0:\* +LISTEN +[\d]+/master' - found = False - if out: - for line in out.split('\n'): - line = re.sub(r' +', ' ', line) - if line: - if not re.match(expected, line): - print('Unexpected result for postfix listening ports:\n%s' % line) - sys.exit(1) - else: - found = True - - if not found: + status, out = subprocess.getstatusoutput('netstat -pant | grep master | grep 127.0.0.1:25', shell=True) + if status != 0: print('The port 25 is not listened by any process.') sys.exit(1) print('Postfix listening port: OK.')