Skip to content
Snippets Groups Projects
Commit 8fa34c36 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Changed email test to handle deferred sendings (refs #21068).

parent d1986508
No related branches found
No related tags found
No related merge requests found
...@@ -88,16 +88,23 @@ def send_test_email(): ...@@ -88,16 +88,23 @@ def send_test_email():
print('Sending test email to "%s".' % email) print('Sending test email to "%s".' % email)
cmd = 'echo "This is a test email" | mail -s "Test email from `cat /etc/hostname`" %s' % email cmd = 'echo "This is a test email" | mail -s "Test email from `cat /etc/hostname`" %s' % email
subprocess.getstatusoutput(cmd) subprocess.getstatusoutput(cmd)
time.sleep(3) timeout = 120
waited = 2
out = ''
cmd = 'grep "%s" /var/log/mail.log' % email cmd = 'grep "%s" /var/log/mail.log' % email
status, out = subprocess.getstatusoutput(cmd) while True:
if status != 0:
time.sleep(7)
status, out = subprocess.getstatusoutput(cmd) status, out = subprocess.getstatusoutput(cmd)
if status != 0: if status == 0:
out = out.strip().split('\n')[-1]
if 'status=deferred' not in out:
break
if waited >= timeout:
print_red('Failed to send email.') print_red('Failed to send email.')
print('No log entry found using command: %s' % cmd) print('No log entry found after %s seconds using command: %s' % (waited, cmd))
return 1 return 1
print('Waiting %s seconds for email sending status.' % waited)
time.sleep(waited)
waited *= 2
if 'bounced' not in out or 'The email account that you tried to reach does not exist.' in out: if 'bounced' not in out or 'The email account that you tried to reach does not exist.' in out:
print_green('Email sent.') print_green('Email sent.')
return 0 return 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment