Merge "Add missing headers to the inspection callback"

This commit is contained in:
Zuul 2024-01-16 19:17:35 +00:00 committed by Gerrit Code Review
commit 3e066e3f3e
3 changed files with 23 additions and 5 deletions

View File

@ -133,6 +133,13 @@ def call_inspector(data, failures):
data = encoder.encode(data)
verify, cert = utils.get_ssl_client_options(CONF)
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
if CONF.global_request_id:
headers["X-OpenStack-Request-ID"] = CONF.global_request_id
@tenacity.retry(
retry=tenacity.retry_if_exception_type(
(requests.exceptions.ConnectionError,
@ -143,7 +150,7 @@ def call_inspector(data, failures):
reraise=True)
def _post_to_inspector():
inspector_resp = requests.post(
CONF.inspection_callback_url, data=data,
CONF.inspection_callback_url, data=data, headers=headers,
verify=verify, cert=cert, timeout=CONF.http_request_timeout)
if inspector_resp.status_code >= 500:
raise requests.exceptions.HTTPError(response=inspector_resp)

View File

@ -161,10 +161,12 @@ class TestCallInspector(base.IronicAgentTest):
res = inspector.call_inspector(data, failures)
mock_post.assert_called_once_with('url',
cert=None, verify=True,
data='{"data": 42, "error": null}',
timeout=30)
mock_post.assert_called_once_with(
'url', data='{"data": 42, "error": null}',
cert=None, verify=True,
headers={'Content-Type': 'application/json',
'Accept': 'application/json'},
timeout=30)
self.assertEqual(mock_post.return_value.json.return_value, res)
def test_send_failure(self, mock_post):
@ -178,6 +180,7 @@ class TestCallInspector(base.IronicAgentTest):
mock_post.assert_called_once_with('url',
cert=None, verify=True,
data='{"data": 42, "error": "boom"}',
headers=mock.ANY,
timeout=30)
self.assertEqual(mock_post.return_value.json.return_value, res)
@ -191,6 +194,7 @@ class TestCallInspector(base.IronicAgentTest):
mock_post.assert_called_once_with('url',
cert=None, verify=True,
data='{"data": 42, "error": null}',
headers=mock.ANY,
timeout=30)
self.assertIsNone(res)
@ -233,6 +237,7 @@ class TestCallInspector(base.IronicAgentTest):
mock_post.assert_called_with('url',
cert=None, verify=True,
data='{"data": 42, "error": null}',
headers=mock.ANY,
timeout=30)

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixes missing ``Content-Type`` header when sending inspection data back
to ironic-inspector or ironic. While ironic-inspector tolerates the
missing header, it may cause issues with the new inspection implementation.