Skip to content

Commit 713bf0a

Browse files
committed
test: dump debug information if http request to firecracker fails
Sometimes, we intermittently see `ConnectionRefused` errors when doing http requests to the firecracker API in integration tests. Have the test framework dump relevant logs in these cases. Signed-off-by: Patrick Roy <[email protected]>
1 parent 0324791 commit 713bf0a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

tests/framework/http_api.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,25 @@ def __init__(self, api, resource, id_field=None):
5858
def get(self):
5959
"""Make a GET request"""
6060
url = self._api.endpoint + self.resource
61-
res = self._api.session.get(url)
61+
try:
62+
res = self._api.session.get(url)
63+
except Exception as e:
64+
if self._api.error_callback:
65+
self._api.error_callback("GET", self.resource, str(e))
66+
raise
6267
assert res.status_code == HTTPStatus.OK, res.json()
6368
return res
6469

6570
def request(self, method, path, **kwargs):
6671
"""Make an HTTP request"""
6772
kwargs = {key: val for key, val in kwargs.items() if val is not None}
6873
url = self._api.endpoint + path
69-
res = self._api.session.request(method, url, json=kwargs)
74+
try:
75+
res = self._api.session.request(method, url, json=kwargs)
76+
except Exception as e:
77+
if self._api.error_callback:
78+
self._api.error_callback(method, path, str(e))
79+
raise
7080
if res.status_code != HTTPStatus.NO_CONTENT:
7181
json = res.json()
7282
msg = res.content
@@ -95,7 +105,8 @@ def patch(self, **kwargs):
95105
class Api:
96106
"""A simple HTTP client for the Firecracker API"""
97107

98-
def __init__(self, api_usocket_full_name):
108+
def __init__(self, api_usocket_full_name, *, on_error=None):
109+
self.error_callback = on_error
99110
self.socket = api_usocket_full_name
100111
url_encoded_path = urllib.parse.quote_plus(api_usocket_full_name)
101112
self.endpoint = DEFAULT_SCHEME + url_encoded_path

tests/framework/microvm.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,12 @@ def spawn(
615615
# pylint: disable=subprocess-run-check
616616
# pylint: disable=too-many-branches
617617
self.jailer.setup()
618-
self.api = Api(self.jailer.api_socket_path())
618+
self.api = Api(
619+
self.jailer.api_socket_path(),
620+
on_error=lambda verb, uri, err_msg: self._dump_debug_information(
621+
f"Error during {verb} {uri}: {err_msg}"
622+
),
623+
)
619624

620625
if log_file is not None:
621626
self.log_file = Path(self.path) / log_file

0 commit comments

Comments
 (0)