Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions tests/framework/http_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,25 @@ def __init__(self, api, resource, id_field=None):
def get(self):
"""Make a GET request"""
url = self._api.endpoint + self.resource
res = self._api.session.get(url)
try:
res = self._api.session.get(url)
except Exception as e:
if self._api.error_callback:
self._api.error_callback("GET", self.resource, str(e))
raise
assert res.status_code == HTTPStatus.OK, res.json()
return res

def request(self, method, path, **kwargs):
"""Make an HTTP request"""
kwargs = {key: val for key, val in kwargs.items() if val is not None}
url = self._api.endpoint + path
res = self._api.session.request(method, url, json=kwargs)
try:
res = self._api.session.request(method, url, json=kwargs)
except Exception as e:
if self._api.error_callback:
self._api.error_callback(method, path, str(e))
raise
if res.status_code != HTTPStatus.NO_CONTENT:
json = res.json()
msg = res.content
Expand Down Expand Up @@ -95,7 +105,8 @@ def patch(self, **kwargs):
class Api:
"""A simple HTTP client for the Firecracker API"""

def __init__(self, api_usocket_full_name):
def __init__(self, api_usocket_full_name, *, on_error=None):
self.error_callback = on_error
self.socket = api_usocket_full_name
url_encoded_path = urllib.parse.quote_plus(api_usocket_full_name)
self.endpoint = DEFAULT_SCHEME + url_encoded_path
Expand Down
7 changes: 6 additions & 1 deletion tests/framework/microvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,12 @@ def spawn(
# pylint: disable=subprocess-run-check
# pylint: disable=too-many-branches
self.jailer.setup()
self.api = Api(self.jailer.api_socket_path())
self.api = Api(
self.jailer.api_socket_path(),
on_error=lambda verb, uri, err_msg: self._dump_debug_information(
f"Error during {verb} {uri}: {err_msg}"
),
)

if log_file is not None:
self.log_file = Path(self.path) / log_file
Expand Down