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

Improved log of email test | refs #30015

parent 114fc1e3
No related branches found
No related tags found
No related merge requests found
......@@ -119,12 +119,6 @@ def check_send(sender: str) -> tuple:
)
subprocess.getoutput(cmd)
# init vars
timeout = 120
waited = 1
delay = 2
out = ""
# find logs
if Path("/var/log/maillog").is_file():
cmd = "grep '{}' /var/log/maillog".format(email)
......@@ -133,29 +127,49 @@ def check_send(sender: str) -> tuple:
else:
u.info("/var/log/mail.log not found, trying journalctl")
cmd = "journalctl -t postfix/smtp | grep {}".format(email)
u.log("Using following command to search for sending log:\n{}".format(cmd))
# init vars
timeout = 120
waited = 0
delay = 1
timed_out = False
out = ""
u.log("Email sending timeout is {} seconds.".format(timeout))
# logs polling
time.sleep(1)
while True:
sys.stdout.write("Waiting for sending log")
sys.stdout.flush()
while not timed_out:
# wait
time.sleep(delay)
waited += delay
delay *= 2
# run command
status, out = subprocess.getstatusoutput(cmd)
# log loop
sys.stdout.write(".")
sys.stdout.flush()
# found
if status == 0:
out = out.strip().split("\n")[-1]
if "status=deferred" not in out:
break
# timeout
if waited >= timeout:
u.error("Failed to send email.")
u.info("> no log entry found using command: {}".format(cmd))
errors += 1
break
# wait before next iteration
time.sleep(delay)
waited += delay
delay *= 2
timed_out = waited >= timeout
sys.stdout.write("\n")
# check if the sending has timed out
if timed_out:
u.error("Failed to send email (timed out).")
if out:
u.info("> sending log line:\n{}".format(out))
else:
u.info("> no log entry found.")
errors += 1
# check output for errors
if "bounced" in out or "you tried to reach does not exist" in out:
elif "bounced" in out or "you tried to reach does not exist" in out:
u.error("Failed to send email")
u.info("> sending log line:\n{}".format(out))
errors += 1
......
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