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
db8d9a89
Commit
db8d9a89
authored
6 years ago
by
Stéphane Diemer
Browse files
Options
Downloads
Patches
Plain Diff
Use email sender config in email test (refs
#26619
).
parent
7a1a8785
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
+18
-5
18 additions, 5 deletions
tests/test_email.py
with
18 additions
and
5 deletions
tests/test_email.py
+
18
−
5
View file @
db8d9a89
...
...
@@ -20,7 +20,7 @@ except ImportError:
import
spf
# install netstat if not present
if
subprocess
.
call
([
"
which
"
,
"
netstat
"
])
!=
0
:
if
subprocess
.
call
([
"
which
"
,
"
netstat
"
]
,
stdout
=
subprocess
.
DEVNULL
)
!=
0
:
subprocess
.
check_call
([
"
apt-get
"
,
"
-qq
"
,
"
-y
"
,
"
install
"
,
"
net-tools
"
])
sys
.
path
.
append
(
str
(
Path
(
__file__
).
parents
[
1
].
resolve
()))
...
...
@@ -66,7 +66,7 @@ def check_relay(conf: dict) -> int:
if
status
==
0
:
configured_relay
=
(
out
[
len
(
"
relayhost
"
)
:].
strip
(
"
\t
=
"
).
replace
(
"
[
"
,
""
).
replace
(
"
]
"
,
""
)
out
[
len
(
"
relayhost
"
):].
strip
(
"
\t
=
"
).
replace
(
"
[
"
,
""
).
replace
(
"
]
"
,
""
)
)
else
:
configured_relay
=
""
...
...
@@ -102,7 +102,7 @@ def check_relay(conf: dict) -> int:
return
0
def
check_send_test_email
()
->
int
:
def
check_send_test_email
(
conf
:
dict
)
->
int
:
"""
Check that Postfix can send email.
:return: Exit return code
...
...
@@ -111,10 +111,23 @@ def check_send_test_email() -> int:
print
(
"
Checking Postfix can send email:
"
)
# check if s-nail is installed, if not set from address
sender
=
""
status
,
out
=
subprocess
.
getstatusoutput
(
"
dpkg -l s-nail | grep -E
'
^ii
'"
)
if
status
==
0
:
u
.
warning
(
"
The package
'
s-nail
'
is installed, the email sender address will be ignored.
"
)
else
:
sender
=
conf
.
get
(
"
EMAIL_SENDER
"
)
or
""
# send email
email
=
"
noreply+{}-{}@ubicast.eu
"
.
format
(
time
.
time
(),
random
.
randint
(
0
,
1000
))
u
.
info
(
"
Sending test email to
'
{}
'"
.
format
(
email
))
cmd
=
"
echo
'
test email
'
| mail -s
'
test email
'
{}
"
.
format
(
email
)
if
sender
:
u
.
info
(
"
Sender address is
'
{}
'"
.
format
(
sender
))
sender
=
"
-a
'
From: {}
'
"
.
format
(
sender
)
else
:
u
.
info
(
"
Sender address is not set
"
)
cmd
=
"
echo
'
test email
'
| mail -s
'
Email used to test configuration.
'
{}{}
"
.
format
(
sender
,
email
)
subprocess
.
getstatusoutput
(
cmd
)
# init vars
...
...
@@ -182,7 +195,7 @@ def main():
rcode
=
check_listen
()
if
rcode
==
0
:
rcode
=
check_relay
(
conf
)
if
check_send_test_email
()
==
1
:
if
check_send_test_email
(
conf
)
==
1
:
rcode
=
1
sys
.
exit
(
rcode
)
...
...
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