Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
BioHPC
clair-singularity
Commits
2fe74ff0
Commit
2fe74ff0
authored
Aug 24, 2017
by
David Trudgian
Browse files
Nicer wait for inbuilt httpd
parent
1ab56554
Changes
3
Hide whitespace changes
Inline
Side-by-side
clair_singularity/cli.py
View file @
2fe74ff0
...
...
@@ -6,7 +6,7 @@ from multiprocessing import Process
from
.
import
VERSION
from
.clair
import
check_clair
,
post_layer
,
get_report
,
format_report_text
from
.util
import
sha256
,
wait_net_service
from
.util
import
sha256
,
wait_net_service
,
err_and_exit
from
.image
import
check_image
,
image_to_tgz
,
http_server
...
...
@@ -43,7 +43,10 @@ def cli(image, clair_uri, text_output, json_output, bind_ip, bind_port, quiet):
httpd
=
Process
(
target
=
http_server
,
args
=
(
tar_dir
,
bind_ip
,
bind_port
,
quiet
))
httpd
.
start
()
# Allow up to 30 seconds for the httpd to start and be answering requests
wait_net_service
(
bind_ip
,
bind_port
,
30
)
httpd_ready
=
wait_net_service
(
bind_ip
,
bind_port
,
30
)
if
not
httpd_ready
:
httpd
.
terminate
()
err_and_exit
(
"HTTP server did not become ready
\n
"
,
1
)
image_uri
=
'http://%s:%d/%s'
%
(
bind_ip
,
bind_port
,
path
.
basename
(
tar_file
))
...
...
clair_singularity/util.py
View file @
2fe74ff0
...
...
@@ -48,7 +48,6 @@ def wait_net_service(server, port, timeout=None):
throw unhandled network exception
"""
import
socket
import
errno
s
=
socket
.
socket
()
if
timeout
:
...
...
@@ -67,16 +66,9 @@ def wait_net_service(server, port, timeout=None):
s
.
connect
((
server
,
port
))
except
socket
.
timeout
,
err
:
# this exception occurs only if timeout is set
if
timeout
:
return
False
except
(
socket
.
timeout
,
socket
.
error
):
pass
except
socket
.
error
,
err
:
# catch timeout exception from underlying network library
# this one is different from socket.timeout
if
type
(
err
.
args
)
!=
tuple
or
err
[
0
]
!=
errno
.
ETIMEDOUT
:
raise
else
:
s
.
close
()
return
True
\ No newline at end of file
tests/test_image.py
View file @
2fe74ff0
...
...
@@ -7,7 +7,7 @@ import pytest
import
requests
from
clair_singularity.image
import
image_to_tgz
,
check_image
,
http_server
from
clair_singularity.util
import
sha256
from
clair_singularity.util
import
sha256
,
err_and_exit
@
pytest
.
fixture
...
...
@@ -48,7 +48,11 @@ def test_http_server(testimage, tmpdir):
args
=
(
os
.
path
.
dirname
(
testimage
),
'127.0.0.1'
,
8088
,
False
))
httpd
.
start
()
# Allow up to 30 seconds for the httpd to start and be answering requests
wait_net_service
(
'127.0.0.1'
,
8088
,
30
)
httpd_ready
=
wait_net_service
(
'127.0.0.1'
,
8088
,
30
)
if
not
httpd_ready
:
httpd
.
terminate
()
err_and_exit
(
"HTTP server did not become ready"
,
1
)
r
=
requests
.
get
(
'http://127.0.0.1:8088/vsoch-singularity-hello-world-master.img'
,
proxies
=
{
'http://127.0.0.1'
:
''
},
stream
=
True
)
...
...
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