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
d8cf24df
Commit
d8cf24df
authored
8 years ago
by
Stéphane Diemer
Browse files
Options
Downloads
Patches
Plain Diff
Fixed mail test (refs
#20807
).
parent
568789c7
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_mail.py
+47
-36
47 additions, 36 deletions
tests/test_mail.py
with
47 additions
and
36 deletions
tests/test_mail.py
+
47
−
36
View file @
d8cf24df
...
@@ -17,8 +17,11 @@ DEF = '\033[0m'
...
@@ -17,8 +17,11 @@ DEF = '\033[0m'
os
.
chdir
(
os
.
path
.
dirname
(
__file__
))
os
.
chdir
(
os
.
path
.
dirname
(
__file__
))
if
not
os
.
path
.
isfile
(
'
../utils.py
'
):
if
not
os
.
path
.
isfile
(
'
../utils.py
'
):
print
(
'
conf.sh
not found
'
)
print
(
'
The envsetup configuration was
not found
.
'
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
else
:
es_utils
=
imp
.
load_source
(
'
es_utils
'
,
'
../utils.py
'
)
conf
=
es_utils
.
load_conf
()
def
print_color
(
txt
,
col
):
def
print_color
(
txt
,
col
):
...
@@ -33,57 +36,65 @@ def print_green(txt):
...
@@ -33,57 +36,65 @@ def print_green(txt):
print_color
(
txt
,
GREEN
)
print_color
(
txt
,
GREEN
)
all_ok
=
True
def
check_listening_port
():
# check that postfix listens the port 25 correctly
status
,
out
=
subprocess
.
getstatusoutput
(
'
netstat -pant | grep master | grep 127.0.0.1:25
'
)
if
status
!=
0
:
print_red
(
'
The port 25 is not listened by postfix
"
master
"
process.
'
)
return
False
else
:
print_green
(
'
Postfix is listening port 25 correctly.
'
)
return
True
def
get_configured_relay
():
def
check_relay
():
print
(
'
Checking if SMTP relay conforms to conf.
'
)
status
,
out
=
subprocess
.
getstatusoutput
(
'
grep relayhost /etc/postfix/main.cf
'
)
status
,
out
=
subprocess
.
getstatusoutput
(
'
grep relayhost /etc/postfix/main.cf
'
)
if
status
==
0
:
if
status
==
0
:
return
out
.
split
(
'
relayhost =
'
)[
1
]
configured_relay
=
out
[
len
(
'
relayhost
'
):].
strip
(
'
\t
=
'
)
else
:
print_red
(
'
Configured relay not found.
'
)
def
check_relay
():
return
False
global
all_ok
global
conf
configured_relay
=
get_configured_relay
()
print
(
'
Checking if SMTP relay conforms to conf
'
)
es_utils
=
imp
.
load_source
(
'
es_utils
'
,
'
../utils.py
'
)
conf
=
es_utils
.
load_conf
()
conf_relay
=
conf
.
get
(
'
EMAIL_SMTP_SERVER
'
)
conf_relay
=
conf
.
get
(
'
EMAIL_SMTP_SERVER
'
)
if
conf_relay
!=
configured_relay
:
if
conf_relay
!=
configured_relay
:
print_red
(
'
Configured STMP relay (%s) does not match the expected value (%s)
'
%
(
configured_relay
,
conf_relay
))
print_red
(
'
Configured STMP relay (%s) does not match the expected value (%s)
.
'
%
(
configured_relay
,
conf_relay
))
all_ok
=
False
return
False
else
:
else
:
print_green
(
'
STMP relay is properly set
'
)
print_green
(
'
STMP relay is properly set.
'
)
return
True
def
send_test_email
():
def
send_test_email
():
print
(
'
Sending test email
'
)
email
=
'
noreply+%s-%s@ubicast.eu
'
%
(
time
.
time
(),
random
.
randint
(
0
,
1000
))
global
all_ok
print
(
'
Sending test email to
"
%s
"
.
'
%
email
)
email
=
"
noreply+%s@ubicast.eu
"
%
random
.
randint
(
0
,
1000
)
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
)
time
.
sleep
(
3
)
cmd
=
'
grep
"
%s
"
/var/log/mail.log
'
%
email
status
,
out
=
subprocess
.
getstatusoutput
(
cmd
)
status
,
out
=
subprocess
.
getstatusoutput
(
cmd
)
time
.
sleep
(
5
)
if
status
!=
0
:
status
,
out
=
subprocess
.
getstatusoutput
(
'
grep %s /var/log/mail.log | grep bounced
'
%
email
)
time
.
sleep
(
7
)
if
status
==
0
:
status
,
out
=
subprocess
.
getstatusoutput
(
cmd
)
print_red
(
'
Sending mail failed
'
)
if
status
!=
0
:
all_ok
=
False
print_red
(
'
Failed to send email.
'
)
print
(
'
No log entry found using command: %s
'
%
cmd
)
return
False
if
'
bounced
'
not
in
out
or
'
The email account that you tried to reach does not exist.
'
in
out
:
print_green
(
'
Email sent.
'
)
return
True
else
:
else
:
print_green
(
'
Email sent
'
)
print_red
(
'
Failed to send email.
'
)
print
(
'
Sending log line:
\n
%s
'
%
out
)
return
False
if
not
os
.
path
.
exists
(
'
/etc/postfix
'
):
if
not
os
.
path
.
exists
(
'
/etc/postfix
'
):
print_red
(
'
Postfix dir does not exists, please install postfix.
'
)
print_red
(
'
Postfix dir does not exists, please install postfix.
'
)
all_ok
=
False
sys
.
exit
(
1
)
else
:
# check that postfix listens the port 25 correctly
all_ok
=
check_listening_port
()
status
,
out
=
subprocess
.
getstatusoutput
(
'
netstat -pant | grep master | grep 127.0.0.1:25
'
)
if
all_ok
:
if
status
!=
0
:
all_ok
=
all_ok
and
check_relay
()
print_red
(
'
The port 25 is not listened by any process.
'
)
all_ok
=
all_ok
and
send_test_email
()
all_ok
=
False
else
:
print_green
(
'
Postfix listening port: OK.
'
)
check_relay
()
send_test_email
()
sys
.
exit
(
int
(
not
all_ok
))
sys
.
exit
(
int
(
not
all_ok
))
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