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
a59ad160
Verified
Commit
a59ad160
authored
5 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
update output format
parent
fa7723d1
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_nginx_vhosts.py
+28
-39
28 additions, 39 deletions
tests/test_nginx_vhosts.py
with
28 additions
and
39 deletions
tests/test_nginx_vhosts.py
+
28
−
39
View file @
a59ad160
...
...
@@ -20,6 +20,11 @@ try:
except
ImportError
:
requests
.
packages
.
urllib3
.
disable_warnings
()
sys
.
path
.
append
(
str
(
Path
(
__file__
).
parents
[
1
].
resolve
()))
# pylint: disable=wrong-import-position
from
envsetup
import
utils
as
u
# noqa: E402
"""
This script checks for all enabled vhosts in Nginx conf that:
* The response status code is 200, 401 or 403.
...
...
@@ -85,19 +90,14 @@ def test_vhost(
):
errors
=
0
warnings
=
0
name
=
nginx_file
.
stem
name
=
nginx_file
.
name
for
port
,
proto
in
ports_info
or
[(
80
,
False
)]:
for
domain
in
domains
or
[
"
localhost
"
]:
url
=
"
%s://%s:%s
"
%
(
proto
,
domain
,
port
)
sys
.
stdout
.
write
(
'
T
esting url
"
%s
"
from %s
:
\n
'
%
(
url
,
name
))
u
.
info
(
"
t
esting url
'
%s
'
from %s
"
%
(
url
,
name
))
if
name
.
startswith
(
"
mediaserver
"
)
and
not
tested
:
if
not
celerity_conf
or
not
re
.
search
(
r
"
http[s]{0,1}://%s
"
%
domain
,
celerity_conf
):
sys
.
stdout
.
write
(
'
\033
[93mWarning:
\033
[0m Url
"
%s
"
not found in celerity conf; it should also be set in the MediaWorker.
\n
'
%
url
)
if
not
re
.
search
(
r
"
https?://%s
"
%
domain
,
celerity_conf
):
u
.
warning
(
"
url
'
%s
'
not found in celerity conf
"
%
url
)
warnings
+=
1
# test domain IP
ip_error
=
None
...
...
@@ -105,27 +105,25 @@ def test_vhost(
try
:
ip
=
socket
.
gethostbyname
(
domain
)
except
Exception
as
e
:
ip_error
=
"
domain
is
not resolved
:
%s
"
%
e
ip_error
=
"
domain
:
not resolved %s
"
%
e
else
:
if
ip
!=
"
127.0.0.1
"
:
ip_warning
=
"
domain is resolved with %s instead of 127.0.0.1
"
%
ip
sys
.
stdout
.
write
(
"
IP:
"
)
ip_warning
=
"
domain: resolve to %s instead of 127.0.0.1
"
%
ip
if
ip_error
:
if
resolution_ignored
and
domain
in
resolution_ignored
:
sys
.
stdout
.
write
(
"
\033
[94mIgnored (%s)
\033
[0m
"
%
ip_error
)
u
.
info
(
"
%s (ignored)
"
%
ip_error
)
ip_error
=
None
else
:
sys
.
stdout
.
write
(
"
\033
[91mKO (%s)
\033
[0m
"
%
ip_error
)
u
.
error
(
ip_error
)
elif
ip_warning
:
if
resolution_ignored
and
domain
in
resolution_ignored
:
sys
.
stdout
.
write
(
"
\033
[94mIgnored (%s)
\033
[0m
"
%
ip_warning
)
u
.
info
(
"
%s (ignored)
"
%
ip_warning
)
ip_warning
=
None
else
:
sys
.
stdout
.
write
(
"
\033
[93mWarning (%s)
\033
[0m
"
%
ip_warning
)
u
.
warning
(
ip_warning
)
else
:
sys
.
stdout
.
write
(
"
\033
[92mOK (
127.0.0.1
)
\033
[0m
"
)
u
.
success
(
"
domain: resolve to
127.0.0.1
"
)
# test url
sys
.
stdout
.
write
(
"
, status:
"
)
req_error
=
False
try
:
req
=
requests
.
get
(
...
...
@@ -143,17 +141,16 @@ def test_vhost(
or
domain
==
"
localhost
"
and
code
not
in
(
200
,
401
,
403
,
404
)
):
sys
.
stdout
.
write
(
"
\033
[91mKO (%s, %sms)
\033
[0m
"
%
(
code
,
req_time
))
u
.
error
(
"
status: %s, %sms
"
%
(
code
,
req_time
))
req_error
=
True
else
:
if
req_time
>
10000
:
sys
.
stdout
.
write
(
"
\033
[93mOK (%s, %sms)
\033
[0m
"
%
(
code
,
req_time
))
u
.
warning
(
"
status: %s, %sms
"
%
(
code
,
req_time
))
warnings
+=
1
else
:
sys
.
stdout
.
write
(
"
\033
[92mOK (%s, %sms)
\033
[0m
"
%
(
code
,
req_time
))
u
.
success
(
"
status: %s, %sms
"
%
(
code
,
req_time
))
if
"
mediaserver
"
in
name
and
wowza_dir
:
# test /streaming url
sys
.
stdout
.
write
(
"
, streaming:
"
)
try
:
req
=
requests
.
get
(
url
+
"
/streaming/
"
,
...
...
@@ -168,19 +165,13 @@ def test_vhost(
else
:
code
=
req
.
status_code
if
code
!=
200
:
sys
.
stdout
.
write
(
"
\033
[91mKO (%s, %sms)
\033
[0m
"
%
(
code
,
req_time
)
)
u
.
error
(
"
streaming: %s, %sms
"
%
(
code
,
req_time
))
req_error
=
True
elif
req_time
>
10000
:
sys
.
stdout
.
write
(
"
\033
[93mOK (%s, %sms)
\033
[0m
"
%
(
code
,
req_time
)
)
u
.
warning
(
"
streaming: %s, %sms
"
%
(
code
,
req_time
))
warnings
+=
1
else
:
sys
.
stdout
.
write
(
"
\033
[92mOK (%s, %sms)
\033
[0m
"
%
(
code
,
req_time
)
)
sys
.
stdout
.
write
(
"
.
\n
"
)
u
.
success
(
"
streaming: %s, %sms
"
%
(
code
,
req_time
))
tested
+=
1
if
ip_warning
:
...
...
@@ -192,21 +183,20 @@ def test_vhost(
def
main
():
print
(
"
Check that nginx vhosts are well configured:
"
)
# check that Nginx dir exists
nginx_dir
=
"
/etc/nginx/sites-enabled
"
if
not
os
.
path
.
exists
(
nginx_dir
):
print
(
'
N
ginx dir does not exists (
"
%s
"
).
'
%
nginx_dir
)
u
.
error
(
"
n
ginx dir does not exists (
'
%s
'
).
"
%
nginx_dir
)
sys
.
exit
(
2
)
# check that Wowza is installed
wowza_dir
=
"
/usr/local/WowzaStreamingEngine
"
if
not
os
.
path
.
exists
(
wowza_dir
):
print
(
'
Info: W
owza is not installed (
"
%s
"
does not exist).
'
%
wowza_dir
)
u
.
info
(
"
w
owza is not installed (
'
%s
'
does not exist).
"
%
wowza_dir
)
wowza_dir
=
None
else
:
print
(
"
Info: Wowza is installed, /streaming/ will be tested on mediaserver vhosts.
"
)
u
.
info
(
"
wowza is installed, /streaming/ will be tested on mediaserver vhosts.
"
)
# get envsetup conf
conf
=
dict
()
...
...
@@ -246,12 +236,11 @@ def main():
errors
+=
e
if
errors
:
print
(
"
%s url(s) did not correctly respond.
"
%
errors
)
sys
.
exit
(
1
)
elif
warnings
:
sys
.
exit
(
3
)
if
not
tested
:
print
(
"
N
o url found in
N
ginx sites-enabled dir
.
"
)
u
.
error
(
"
n
o url found in
n
ginx sites-enabled dir
"
)
sys
.
exit
(
1
)
...
...
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