From a377fc5988e9a6057bd14617879a7cbcc3c8bb81 Mon Sep 17 00:00:00 2001 From: Gyorgy Szombathelyi Date: Tue, 21 Feb 2017 15:04:13 +0100 Subject: [PATCH] Use the keystone session loader in the placement reporting Using load_session_from_conf_options has the advantage that it honors session settings like cafile and insecure, to make use of non-system TLS certificates (or disable certificate checks at all). Also client certificates and timeout values can be specified, too. Closes-Bug: #1666936 Change-Id: I510a2683958fc8c3aaca9293b4280f325b9551fc --- nova/scheduler/client/report.py | 4 ++-- nova/tests/unit/scheduler/client/test_report.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/nova/scheduler/client/report.py b/nova/scheduler/client/report.py index 88764445de4d..94b621dcea18 100644 --- a/nova/scheduler/client/report.py +++ b/nova/scheduler/client/report.py @@ -21,7 +21,6 @@ import time from keystoneauth1 import exceptions as ks_exc from keystoneauth1 import loading as keystone -from keystoneauth1 import session from oslo_log import log as logging from nova.compute import utils as compute_utils @@ -195,7 +194,8 @@ class SchedulerReportClient(object): self._provider_aggregate_map = {} auth_plugin = keystone.load_auth_from_conf_options( CONF, 'placement') - self._client = session.Session(auth=auth_plugin) + self._client = keystone.load_session_from_conf_options( + CONF, 'placement', auth=auth_plugin) # 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 d2cc1966775a..bca1dda88f68 100644 --- a/nova/tests/unit/scheduler/client/test_report.py +++ b/nova/tests/unit/scheduler/client/test_report.py @@ -132,23 +132,25 @@ class SafeConnectedTestCase(test.NoDBTestCase): class TestConstructor(test.NoDBTestCase): - @mock.patch('keystoneauth1.session.Session') + @mock.patch('keystoneauth1.loading.load_session_from_conf_options') @mock.patch('keystoneauth1.loading.load_auth_from_conf_options') - def test_constructor(self, load_auth_mock, ks_sess_mock): + def test_constructor(self, load_auth_mock, load_sess_mock): client = report.SchedulerReportClient() load_auth_mock.assert_called_once_with(CONF, 'placement') - ks_sess_mock.assert_called_once_with(auth=load_auth_mock.return_value) + load_sess_mock.assert_called_once_with(CONF, 'placement', + auth=load_auth_mock.return_value) self.assertIsNone(client.ks_filter['interface']) - @mock.patch('keystoneauth1.session.Session') + @mock.patch('keystoneauth1.loading.load_session_from_conf_options') @mock.patch('keystoneauth1.loading.load_auth_from_conf_options') - def test_constructor_admin_interface(self, load_auth_mock, ks_sess_mock): + def test_constructor_admin_interface(self, load_auth_mock, load_sess_mock): self.flags(os_interface='admin', group='placement') client = report.SchedulerReportClient() load_auth_mock.assert_called_once_with(CONF, 'placement') - ks_sess_mock.assert_called_once_with(auth=load_auth_mock.return_value) + load_sess_mock.assert_called_once_with(CONF, 'placement', + auth=load_auth_mock.return_value) self.assertEqual('admin', client.ks_filter['interface'])