Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.core
Commits
00459999
Commit
00459999
authored
Apr 25, 2018
by
André Anjos
💬
Browse files
Get an actual free random port instead of a random port number
parent
16d368b5
Pipeline
#19448
failed with stages
in 32 minutes and 6 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
beat/core/execution/docker.py
View file @
00459999
...
...
@@ -32,7 +32,6 @@ import os
import
requests
import
simplejson
import
zmq
import
random
import
logging
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -254,7 +253,7 @@ class DockerExecutor(RemoteExecutor):
# Creation of the container
# Note: we only support one databases image loaded at the same time
database_port
=
random
.
randint
(
51000
,
60000
)
database_port
=
utils
.
find_free_port
(
)
cmd
=
[
'databases_provider'
,
...
...
@@ -293,7 +292,7 @@ class DockerExecutor(RemoteExecutor):
break
databases_container
.
reset_ports
()
database_port
=
random
.
randint
(
51000
,
60000
)
database_port
=
utils
.
find_free_port
(
)
cmd
=
[
x
if
not
x
.
startswith
(
'0.0.0.0:'
)
else
'0.0.0.0:%d'
%
database_port
for
x
in
cmd
]
databases_container
.
command
=
cmd
...
...
beat/core/execution/subprocess.py
View file @
00459999
...
...
@@ -33,7 +33,6 @@ from __future__ import absolute_import
import
os
import
requests
import
zmq
import
random
import
sys
import
subprocess
as
sp
import
tempfile
...
...
@@ -240,7 +239,7 @@ class SubprocessExecutor(RemoteExecutor):
#----- (If necessary) Instantiate the subprocess that provide the databases
databases_process
=
None
database_port
=
random
.
randint
(
51000
,
60000
)
database_port
=
utils
.
find_free_port
(
)
if
len
(
self
.
databases
)
>
0
:
...
...
beat/core/utils.py
View file @
00459999
...
...
@@ -29,6 +29,8 @@
import
os
import
sys
import
tempfile
import
socket
import
contextlib
import
numpy
import
simplejson
...
...
@@ -66,6 +68,9 @@ def uniq(seq):
return
result
#----------------------------------------------------------
def
send_multipart
(
socket
,
parts
):
"""
Send the parts through the socket after having encoded them if
...
...
@@ -77,3 +82,15 @@ def send_multipart(socket, parts):
parts
[
index
]
=
item
.
encode
(
'utf-8'
)
socket
.
send_multipart
(
parts
)
#----------------------------------------------------------
def
find_free_port
():
'''Returns the value of a free random port'''
with
contextlib
.
closing
(
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
))
as
s
:
s
.
bind
((
''
,
0
))
return
s
.
getsockname
()[
1
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment