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
78aa14fd
Commit
78aa14fd
authored
3 years ago
by
Stéphane Diemer
Browse files
Options
Downloads
Plain Diff
Merge branch 't34153-detect-status-vhost-port' into 'master'
See merge request mediaserver/envsetup!68
parents
fb15c4b8
9564a384
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/scripts/test_nginx_status.py
+27
-16
27 additions, 16 deletions
tests/scripts/test_nginx_status.py
with
27 additions
and
16 deletions
tests/scripts/test_nginx_status.py
+
27
−
16
View file @
78aa14fd
#!/usr/bin/env python3
"""
'''
Criticality: Normal
Checks that the webserver is running.
"""
'''
from
pathlib
import
Path
import
re
import
requests
import
sys
...
...
@@ -16,29 +17,39 @@ from utilities import logging as lg # noqa: E402
def
main
():
lg
.
log
(
"
Checking nginx status:
"
)
lg
.
log
(
'
Checking nginx status:
'
)
if
not
Path
(
"
/etc/nginx
"
).
exists
():
lg
.
info
(
"
nginx dir does not exists, skip test
"
)
exit
(
2
)
stats_file
=
Path
(
'
/etc/nginx/sites-enabled/stats.conf
'
)
if
not
stats_file
.
exists
():
lg
.
info
(
'
The Nginx status vhost does not exist, skipping test.
'
)
return
2
with
open
(
stats_file
,
'
r
'
)
as
fo
:
content
=
fo
.
read
()
listen_s
=
re
.
search
(
r
'
listen (\d+);
'
,
content
)
if
not
listen_s
:
lg
.
info
(
'
The Nginx status vhost has no listen directive, skipping test.
'
)
return
2
port
=
int
(
listen_s
.
group
(
1
))
try
:
req
=
requests
.
get
(
"
http://127.0.0.1:
1080
/nginx_status
"
,
proxies
=
{
"
http
"
:
""
,
"
https
"
:
""
},
'
http://127.0.0.1:
%s
/nginx_status
'
%
port
,
proxies
=
{
'
http
'
:
''
,
'
https
'
:
''
},
timeout
=
5
,
)
if
req
.
status_code
!=
200
:
raise
Exception
(
"
s
tatus code:
{}
"
.
format
(
req
.
status_code
)
)
if
"
Active connections
"
not
in
req
.
text
:
raise
Exception
(
"
invalid response from nginx status url
"
)
raise
Exception
(
'
S
tatus code:
%s.
'
%
req
.
status_code
)
if
'
Active connections
'
not
in
req
.
text
:
raise
Exception
(
'
invalid response from nginx status url
.
'
)
except
Exception
as
e
:
lg
.
error
(
str
(
e
))
exit
(
1
)
return
1
lg
.
success
(
"
s
tatus code:
{}
"
.
format
(
req
.
status_code
)
)
exit
(
0
)
lg
.
success
(
'
S
tatus code:
%s.
'
%
req
.
status_code
)
return
0
if
__name__
==
"
__main__
"
:
main
()
if
__name__
==
'
__main__
'
:
rc
=
main
()
sys
.
exit
(
rc
)
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