From 5905eb7f48a86dcac5a810d318f1d4dae9138286 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Tue, 1 Aug 2017 23:35:56 +0100 Subject: [PATCH] Always use application/json accept header in report client Always send 'accept: application/json' header when the scheduler report client talks to placement. Setting accept ensures that if there are error responses, they will be formatted as JSON, not HTML. Without the accept header, webob will choose to send what it thinks is a reasonable default. Change-Id: I7464e085c8c688d85cdce5aaddcf3bf2e04498ab Closes-Bug: #1708037 --- nova/scheduler/client/report.py | 7 ++++++- nova/tests/unit/scheduler/client/test_report.py | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/nova/scheduler/client/report.py b/nova/scheduler/client/report.py index e92fde93f310..e3022989bdb7 100644 --- a/nova/scheduler/client/report.py +++ b/nova/scheduler/client/report.py @@ -236,8 +236,13 @@ class SchedulerReportClient(object): self._provider_aggregate_map = {} auth_plugin = keystone.load_auth_from_conf_options( CONF, 'placement') + # Set content-type and accept on every request to ensure we notify + # placement service of our request and response body media type + # preferences. self._client = keystone.load_session_from_conf_options( - CONF, 'placement', auth=auth_plugin) + CONF, 'placement', auth=auth_plugin, + additional_headers={'accept': 'application/json'}) + # NOTE(danms): Keep track of how naggy we've been self._warn_count = 0 self.ks_filter = {'service_type': 'placement', diff --git a/nova/tests/unit/scheduler/client/test_report.py b/nova/tests/unit/scheduler/client/test_report.py index 211dd93c5703..95b6149ce3ef 100644 --- a/nova/tests/unit/scheduler/client/test_report.py +++ b/nova/tests/unit/scheduler/client/test_report.py @@ -141,7 +141,8 @@ class TestConstructor(test.NoDBTestCase): load_auth_mock.assert_called_once_with(CONF, 'placement') load_sess_mock.assert_called_once_with(CONF, 'placement', - auth=load_auth_mock.return_value) + additional_headers={'accept': 'application/json'}, + auth=load_auth_mock.return_value) self.assertIsNone(client.ks_filter['interface']) @mock.patch('keystoneauth1.loading.load_session_from_conf_options') @@ -152,7 +153,8 @@ class TestConstructor(test.NoDBTestCase): load_auth_mock.assert_called_once_with(CONF, 'placement') load_sess_mock.assert_called_once_with(CONF, 'placement', - auth=load_auth_mock.return_value) + additional_headers={'accept': 'application/json'}, + auth=load_auth_mock.return_value) self.assertEqual('admin', client.ks_filter['interface'])