Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mediaserver
envsetup
Commits
a66a7d52
Commit
a66a7d52
authored
7 years ago
by
Stéphane Diemer
Browse files
Options
Downloads
Patches
Plain Diff
Changed timeout handling for email test.
parent
f849ac57
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_email.py
+9
-4
9 additions, 4 deletions
tests/test_email.py
with
9 additions
and
4 deletions
tests/test_email.py
+
9
−
4
View file @
a66a7d52
...
@@ -89,26 +89,31 @@ def send_test_email():
...
@@ -89,26 +89,31 @@ def send_test_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
)
timeout
=
120
timeout
=
120
waited
=
2
waited
=
1
delay
=
2
print
(
'
Timeout to find email sending log is set to %s seconds.
'
%
timeout
)
out
=
''
out
=
''
if
os
.
path
.
isfile
(
'
/var/log/mail.log
'
):
if
os
.
path
.
isfile
(
'
/var/log/mail.log
'
):
cmd
=
'
grep
"
%s
"
/var/log/mail.log
'
%
email
cmd
=
'
grep
"
%s
"
/var/log/mail.log
'
%
email
else
:
else
:
print
(
'
/var/log/mail.log not found, trying journalctl
'
)
print
(
'
/var/log/mail.log not found, trying journalctl
'
)
cmd
=
'
journalctl -u postfix | grep %s
'
%
email
cmd
=
'
journalctl -u postfix | grep %s
'
%
email
time
.
sleep
(
1
)
while
True
:
while
True
:
status
,
out
=
subprocess
.
getstatusoutput
(
cmd
)
status
,
out
=
subprocess
.
getstatusoutput
(
cmd
)
if
status
==
0
:
if
status
==
0
:
out
=
out
.
strip
().
split
(
'
\n
'
)[
-
1
]
out
=
out
.
strip
().
split
(
'
\n
'
)[
-
1
]
if
'
status=deferred
'
not
in
out
:
if
'
status=deferred
'
not
in
out
:
print
(
'
Log entry found after %s seconds.
'
%
waited
)
break
break
if
waited
>=
timeout
:
if
waited
>=
timeout
:
print_red
(
'
Failed to send email.
'
)
print_red
(
'
Failed to send email.
'
)
print
(
'
No log entry found after %s seconds using command: %s
'
%
(
waited
,
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.
'
%
(
timeout
-
waited
))
print
(
'
No log entry found after %s seconds, waiting %s more seconds...
'
%
(
waited
,
delay
))
time
.
sleep
(
waited
)
time
.
sleep
(
delay
)
waited
*=
2
waited
+=
delay
delay
*=
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment