Skip to content
GitLab
Explore
Sign in
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
b8751307
Commit
b8751307
authored
5 years ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
TMSS-139
: use a preferred port if available, otherwise a random free port
parent
44bf1a0b
No related branches found
No related tags found
1 merge request
!96
Resolve TMSS-139
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
LCS/PyCommon/util.py
+10
-3
10 additions, 3 deletions
LCS/PyCommon/util.py
SAS/TMSS/test/test_utils.py
+1
-1
1 addition, 1 deletion
SAS/TMSS/test/test_utils.py
with
11 additions
and
4 deletions
LCS/PyCommon/util.py
+
10
−
3
View file @
b8751307
...
...
@@ -194,12 +194,19 @@ def single_line_with_single_spaces(lines: str) -> str:
return
line
length
=
new_length
def
find_free_port
():
'''
find and return a random free network port
'''
def
find_free_port
(
preferred_port
:
int
=
0
):
'''
find and return a random free network port
, preferably the given <preferred_port>
'''
import
socket
from
contextlib
import
closing
with
closing
(
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
))
as
s
:
try
:
s
.
bind
((
''
,
preferred_port
))
except
OSError
as
e
:
if
e
.
errno
==
98
:
# OSError: [Errno 98] Address already in use
s
.
bind
((
''
,
0
))
else
:
raise
s
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
return
s
.
getsockname
()[
1
]
This diff is collapsed.
Click to expand it.
SAS/TMSS/test/test_utils.py
+
1
−
1
View file @
b8751307
...
...
@@ -233,7 +233,7 @@ class TMSSTestEnvironment:
self
.
database
=
TMSSTestDatabaseInstance
()
self
.
django_server
=
TMSSDjangoServerInstance
(
db_dbcreds_id
=
self
.
database
.
dbcreds_id
,
ldap_dbcreds_id
=
self
.
ldap_server
.
dbcreds_id
,
port
=
find_free_port
())
port
=
find_free_port
(
8000
))
def
start
(
self
):
self
.
ldap_server
.
start
()
...
...
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