Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
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
RadioObservatory
LOFAR
Commits
eedb5f65
Commit
eedb5f65
authored
4 years ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
TMSS-000
: improved check for running server
parent
ace72c26
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/TMSS/test/test_utils.py
+24
-26
24 additions, 26 deletions
SAS/TMSS/test/test_utils.py
with
24 additions
and
26 deletions
SAS/TMSS/test/test_utils.py
+
24
−
26
View file @
eedb5f65
...
@@ -208,7 +208,7 @@ class TMSSDjangoServerInstance():
...
@@ -208,7 +208,7 @@ class TMSSDjangoServerInstance():
# wait for server to be up and running....
# wait for server to be up and running....
# or exit via TimeoutError
# or exit via TimeoutError
self
.
check_running_server
(
timeout
=
1
0
)
self
.
check_running_server
(
timeout
=
3
0
)
def
stop
(
self
):
def
stop
(
self
):
'''
'''
...
@@ -226,31 +226,29 @@ class TMSSDjangoServerInstance():
...
@@ -226,31 +226,29 @@ class TMSSDjangoServerInstance():
def
check_running_server
(
self
,
timeout
:
float
=
10
)
->
bool
:
def
check_running_server
(
self
,
timeout
:
float
=
10
)
->
bool
:
'''
Check the running django server for a valid response
'''
'''
Check the running django server for a valid response
'''
try
:
import
requests
import
requests
,
urllib3
from
_datetime
import
datetime
,
timedelta
from
_datetime
import
datetime
,
timedelta
start
=
datetime
.
utcnow
()
start
=
datetime
.
utcnow
()
while
True
:
while
True
:
try
:
try
:
logger
.
info
(
"
Checking if TMSS Django server is up and running at %s with database: %s and LDAP: %s ....
"
,
response
=
requests
.
get
(
self
.
url
,
auth
=
(
self
.
ldap_dbcreds
.
user
,
self
.
ldap_dbcreds
.
password
),
timeout
=
max
(
1
,
timeout
/
10
))
self
.
url
,
self
.
database_dbcreds
,
self
.
ldap_dbcreds
)
response
=
requests
.
get
(
self
.
url
,
auth
=
(
self
.
ldap_dbcreds
.
user
,
self
.
ldap_dbcreds
.
password
),
timeout
=
max
(
1
,
timeout
/
10
))
if
response
.
status_code
in
[
200
,
401
,
403
]:
logger
.
info
(
"
TMSS Django server is up and running at %s with database: %s and LDAP: %s
"
,
if
response
.
status_code
in
[
200
,
401
,
403
]:
self
.
url
,
self
.
database_dbcreds
,
self
.
ldap_dbcreds
)
logger
.
info
(
"
TMSS Django server is up and running at %s with database: %s and LDAP: %s
"
,
self
.
url
,
self
.
database_dbcreds
,
self
.
ldap_dbcreds
)
if
response
.
status_code
in
[
401
,
403
]:
logger
.
warning
(
"
TMSS Django server at %s could not autenticate with LDAP creds: %s
"
,
self
.
url
,
self
.
ldap_dbcreds
)
if
response
.
status_code
in
[
401
,
403
]:
logger
.
warning
(
"
TMSS Django server at %s could not autenticate with LDAP creds: %s
"
,
self
.
url
,
self
.
ldap_dbcreds
)
# TODO: logout, otherwise django remembers our login session.
return
True
# TODO: logout, otherwise django remembers our login session.
except
Exception
as
e
:
return
True
time
.
sleep
(
0.25
)
except
Exception
as
e
:
time
.
sleep
(
0.5
)
if
datetime
.
utcnow
()
-
start
>
timedelta
(
seconds
=
timeout
):
raise
TimeoutError
(
"
Could not get a valid response from the django server at %s
"
%
self
.
url
)
if
datetime
.
utcnow
()
-
start
>
timedelta
(
seconds
=
timeout
):
except
Exception
as
e
:
raise
TimeoutError
(
"
Could not get a valid response from the django server at %s within %s seconds
"
%
(
self
.
url
,
timeout
))
logger
.
error
(
e
)
return
False
def
__enter__
(
self
):
def
__enter__
(
self
):
try
:
try
:
...
...
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