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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mediaserver
envsetup
Commits
7c38eee3
Commit
7c38eee3
authored
6 years ago
by
Stéphane Diemer
Browse files
Options
Downloads
Patches
Plain Diff
Changed Nginx vhost test to handle ports (refs
#27163
).
parent
540e7454
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_nginx_vhosts.py
+158
-127
158 additions, 127 deletions
tests/test_nginx_vhosts.py
with
158 additions
and
127 deletions
tests/test_nginx_vhosts.py
+
158
−
127
View file @
7c38eee3
...
...
@@ -23,62 +23,18 @@ This script checks for all enabled vhosts in Nginx conf that:
* The Wowza response is correct on /streaming/ (only for mediaserver vhosts).
'''
# check that Nginx dir exists
nginx_dir
=
'
/etc/nginx/sites-enabled
'
if
not
os
.
path
.
exists
(
nginx_dir
):
print
(
'
Nginx 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: Wowza 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.
'
)
# get envsetup conf
conf
=
dict
()
os
.
chdir
(
os
.
path
.
dirname
(
__file__
))
if
os
.
path
.
isfile
(
'
../utils.py
'
):
es_utils
=
imp
.
load_source
(
'
es_utils
'
,
'
../utils.py
'
)
conf
=
es_utils
.
load_conf
()
# get celerity conf
celerity_conf
=
''
if
os
.
path
.
exists
(
'
/etc/celerity/config.py
'
):
with
open
(
'
/etc/celerity/config.py
'
,
'
r
'
)
as
fo
:
celerity_conf
=
fo
.
read
()
# get enabled vhosts
resolution_ignored
=
conf
.
get
(
'
TESTER_VHOST_RESOLUTION_IGNORED
'
,
''
).
split
(
'
,
'
)
found
=
False
def
test_vhost
(
ports_info
=
None
,
domains
=
None
,
resolution_ignored
=
None
,
celerity_conf
=
''
):
tested
=
0
errors
=
0
warnings
=
0
names
=
os
.
listdir
(
nginx_dir
)
names
.
sort
()
for
name
in
names
:
path
=
os
.
path
.
join
(
nginx_dir
,
name
)
with
open
(
path
,
'
r
'
)
as
fo
:
vhost
=
fo
.
read
()
vhost
=
vhost
.
replace
(
'
\t
'
,
'
'
)
matching
=
re
.
search
(
r
'
.*server_name\ +([0-9a-zA-Z\.\-\_\ ]+);.*
'
,
vhost
)
if
not
matching
:
print
(
'
The server_name was not found in:
"
%s
"
.
'
%
path
)
errors
+=
1
continue
domains
=
matching
.
groups
()[
0
].
strip
().
split
(
'
'
)
https
=
re
.
search
(
r
'
listen +\w* +ssl
'
,
vhost
)
is
not
None
\
or
re
.
search
(
r
'
ssl +on;
'
,
vhost
)
is
not
None
for
domain
in
domains
:
if
domain
==
'
localhost
'
:
continue
# status vhost
if
domain
==
'
default_server
'
:
continue
found
=
True
url
=
'
%s://%s
'
%
(
'
https
'
if
https
else
'
http
'
,
domain
)
for
port
,
https
in
(
ports_info
or
[(
80
,
False
)]):
for
domain
in
(
domains
or
[
'
localhost
'
]):
tested
+=
1
url
=
'
%s://%s:%s
'
%
(
'
https
'
if
https
else
'
http
'
,
domain
,
port
)
sys
.
stdout
.
write
(
'
Testing url
"
%s
"
:
\n
'
%
url
)
if
name
.
startswith
(
'
mediaserver
'
)
and
url
not
in
celerity_conf
:
if
name
.
startswith
(
'
mediaserver
'
):
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
)
warnings
+=
1
# test domain IP
...
...
@@ -93,13 +49,13 @@ for name in names:
ip_warning
=
'
domain is resolved with %s instead of 127.0.0.1
'
%
ip
sys
.
stdout
.
write
(
'
IP:
'
)
if
ip_error
:
if
domain
in
resolution_ignored
:
if
resolution_ignored
and
domain
in
resolution_ignored
:
sys
.
stdout
.
write
(
'
\033
[94mIgnored (%s)
\033
[0m
'
%
ip_error
)
ip_error
=
None
else
:
sys
.
stdout
.
write
(
'
\033
[91mKO (%s)
\033
[0m
'
%
ip_error
)
elif
ip_warning
:
if
domain
in
resolution_ignored
:
if
resolution_ignored
and
domain
in
resolution_ignored
:
sys
.
stdout
.
write
(
'
\033
[94mIgnored (%s)
\033
[0m
'
%
ip_warning
)
ip_warning
=
None
else
:
...
...
@@ -117,7 +73,7 @@ for name in names:
req_time
=
0
else
:
code
=
req
.
status_code
if
code
not
in
(
200
,
403
):
if
code
not
in
(
200
,
403
)
and
domain
!=
'
localhost
'
and
code
!=
404
:
sys
.
stdout
.
write
(
'
\033
[91mKO (%s, %sms)
\033
[0m
'
%
(
code
,
req_time
))
req_error
=
True
else
:
...
...
@@ -151,12 +107,87 @@ for name in names:
if
ip_error
or
req_error
:
errors
+=
1
return
tested
,
warnings
,
errors
if
__name__
==
'
__main__
'
:
# check that Nginx dir exists
nginx_dir
=
'
/etc/nginx/sites-enabled
'
if
not
os
.
path
.
exists
(
nginx_dir
):
print
(
'
Nginx 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: Wowza 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.
'
)
# get envsetup conf
conf
=
dict
()
os
.
chdir
(
os
.
path
.
dirname
(
__file__
))
if
os
.
path
.
isfile
(
'
../utils.py
'
):
es_utils
=
imp
.
load_source
(
'
es_utils
'
,
'
../utils.py
'
)
conf
=
es_utils
.
load_conf
()
# get celerity conf
celerity_conf
=
''
if
os
.
path
.
exists
(
'
/etc/celerity/config.py
'
):
with
open
(
'
/etc/celerity/config.py
'
,
'
r
'
)
as
fo
:
celerity_conf
=
fo
.
read
()
# get enabled vhosts
resolution_ignored
=
conf
.
get
(
'
TESTER_VHOST_RESOLUTION_IGNORED
'
,
''
).
split
(
'
,
'
)
tested
=
0
errors
=
0
warnings
=
0
names
=
os
.
listdir
(
nginx_dir
)
names
.
sort
()
for
name
in
names
:
path
=
os
.
path
.
join
(
nginx_dir
,
name
)
level
=
0
domains
=
list
()
ports_info
=
list
()
print
(
'
Parsing vhost
"
%s
"
...
'
%
path
)
with
open
(
path
,
'
r
'
)
as
fo
:
for
line
in
fo
:
line
=
line
.
strip
()
if
not
line
or
line
.
startswith
(
'
#
'
):
continue
words
=
re
.
sub
(
r
'
\s+
'
,
'
'
,
line
).
strip
(
'
;
'
).
split
(
'
'
)
if
'
{
'
in
words
or
'
}
'
in
words
:
level
+=
words
.
count
(
'
{
'
)
level
-=
words
.
count
(
'
}
'
)
if
level
==
0
:
# test
if
ports_info
or
domains
:
t
,
w
,
e
=
test_vhost
(
ports_info
,
domains
,
resolution_ignored
,
celerity_conf
)
tested
+=
t
warnings
+=
w
errors
+=
e
domains
=
list
()
ports_info
=
list
()
elif
level
==
1
:
# server section are level 1
if
words
[
0
]
==
'
listen
'
:
https
=
'
ssl
'
in
words
for
port
in
words
:
try
:
port
=
int
(
port
.
split
(
'
:
'
)[
-
1
])
except
ValueError
:
pass
else
:
ports_info
.
append
((
port
,
https
))
elif
words
[
0
]
==
'
server_name
'
:
domains
=
words
[
1
:]
if
errors
:
print
(
'
%s
vhost
(s) did not correctly respond.
'
%
errors
)
print
(
'
%s
url
(s) did not correctly respond.
'
%
errors
)
sys
.
exit
(
1
)
elif
warnings
:
sys
.
exit
(
3
)
if
not
foun
d
:
print
(
'
No
vhost
found in Nginx sites-enabled dir.
'
)
if
not
teste
d
:
print
(
'
No
url
found in Nginx 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