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
This commit is contained in:
Gyorgy Szombathelyi 2017-02-21 15:04:13 +01:00
parent 384e02217d
commit a377fc5988
2 changed files with 10 additions and 8 deletions

View File

@ -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',

View File

@ -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'])