Skip to content

Commit

Permalink
GH Actions: Tidy mocked mail stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Aug 27, 2020
1 parent 14f96b7 commit 4cfd006
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
19 changes: 14 additions & 5 deletions .github/bin/mail
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
#!/usr/bin/env python3

"""Mock the mailx / mailutils `mail` command"""

import argparse
import smtplib
import sys
import os

parser = argparse.ArgumentParser(description='Cylc functional tests mail command.')
parser.add_argument('-s', metavar='subject', dest='subject', type=str, help='e-mail subject')
parser.add_argument('-r', metavar='reply_to', dest='sender', type=str, help='e-mail reply-to address')
parser.add_argument('to', metavar='to', type=str, help='e-mail destination address')
parser.add_argument('body', metavar='body', nargs='?', type=argparse.FileType('r'), default=sys.stdin, help='e-mail body')
parser = argparse.ArgumentParser(
description='Cylc functional tests mail command.')
parser.add_argument(
'-s', metavar='subject', dest='subject', type=str, help='e-mail subject')
parser.add_argument(
'-r', metavar='reply_to', dest='sender', type=str,
help='e-mail reply-to address')
parser.add_argument(
'to', metavar='to', type=str, help='e-mail destination address')
parser.add_argument(
'body', metavar='body', nargs='?', type=argparse.FileType('r'),
default=sys.stdin, help='e-mail body')

smtp_server = os.getenv('smtp')
try:
Expand Down
10 changes: 6 additions & 4 deletions tests/functional/lib/bash/test_header
Original file line number Diff line number Diff line change
Expand Up @@ -658,17 +658,19 @@ __PYTHON__

mock_smtpd_init() { # Logic borrowed from Rose
local SMTPD_PORT=
# Try several ports in case any are in use:
for SMTPD_PORT in 8025 8125 8225 8325 8425 8525 8625 8725 8825 8925; do
local SMTPD_HOST="localhost:${SMTPD_PORT}"
local SMTPD_LOG="${TEST_DIR}/smtpd.log"
local SMTPD_HOST="localhost:${SMTPD_PORT}"
# Set up fake SMTP server to catch outgoing mail & redirect to log:
python3 -u -m 'smtpd' -c 'DebuggingServer' -d -n "${SMTPD_HOST}" \
1>"${SMTPD_LOG}" 2>&1 &
1>"${SMTPD_LOG}" 2>&1 & # Runs in background
local SMTPD_PID="$!"
while ! grep -q 'DebuggingServer started' "${SMTPD_LOG}" 2>'/dev/null'
do
if ps "${SMTPD_PID}" 1>/dev/null 2>&1; then
sleep 1
else
sleep 1 # Still waiting for fake server to start
else # Server process failed
rm -f "${SMTPD_LOG}"
unset SMTPD_HOST SMTPD_LOG SMTPD_PID
break
Expand Down

0 comments on commit 4cfd006

Please sign in to comment.