Commit 2fe74ff0 authored by David Trudgian's avatar David Trudgian
Browse files

Nicer wait for inbuilt httpd

parent 1ab56554
...@@ -6,7 +6,7 @@ from multiprocessing import Process ...@@ -6,7 +6,7 @@ from multiprocessing import Process
from . import VERSION from . import VERSION
from .clair import check_clair, post_layer, get_report, format_report_text 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 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): ...@@ -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 = Process(target=http_server, args=(tar_dir, bind_ip, bind_port, quiet))
httpd.start() httpd.start()
# Allow up to 30 seconds for the httpd to start and be answering requests # 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)) image_uri = 'http://%s:%d/%s' % (bind_ip, bind_port, path.basename(tar_file))
......
...@@ -48,7 +48,6 @@ def wait_net_service(server, port, timeout=None): ...@@ -48,7 +48,6 @@ def wait_net_service(server, port, timeout=None):
throw unhandled network exception throw unhandled network exception
""" """
import socket import socket
import errno
s = socket.socket() s = socket.socket()
if timeout: if timeout:
...@@ -67,16 +66,9 @@ def wait_net_service(server, port, timeout=None): ...@@ -67,16 +66,9 @@ def wait_net_service(server, port, timeout=None):
s.connect((server, port)) s.connect((server, port))
except socket.timeout, err: except (socket.timeout, socket.error):
# this exception occurs only if timeout is set pass
if timeout:
return False
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: else:
s.close() s.close()
return True return True
\ No newline at end of file
...@@ -7,7 +7,7 @@ import pytest ...@@ -7,7 +7,7 @@ import pytest
import requests import requests
from clair_singularity.image import image_to_tgz, check_image, http_server 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 @pytest.fixture
...@@ -48,7 +48,11 @@ def test_http_server(testimage, tmpdir): ...@@ -48,7 +48,11 @@ def test_http_server(testimage, tmpdir):
args=(os.path.dirname(testimage), '127.0.0.1', 8088, False)) args=(os.path.dirname(testimage), '127.0.0.1', 8088, False))
httpd.start() httpd.start()
# Allow up to 30 seconds for the httpd to start and be answering requests # 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', r = requests.get('http://127.0.0.1:8088/vsoch-singularity-hello-world-master.img',
proxies={'http://127.0.0.1': ''}, stream=True) proxies={'http://127.0.0.1': ''}, stream=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment