Add missing headers to the inspection callback

Somehow, it has worked correctly for years, but now I've discovered that
the new inspection is (no longer?) tolerant to the missing header.

While here, copy all headers from the heartbeat code.

Change-Id: I9e5c609eb4435e520bc225dea08aedfdf169744b
This commit is contained in:
Dmitry Tantsur 2024-01-09 16:38:46 +01:00
parent a22d1fc411
commit 2bb74523ae
No known key found for this signature in database
GPG Key ID: 315B2AF9FD216C60
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.