Limit get_sdk_adapter to requested service type

Previously openstacksdk would process the config for *every* known
service type, even though get_sdk_adapter only cares about one at a
time. Aside from just being wasteful, this also resulted in weird log
messages complaining about other conf sections that weren't set up
properly for sdk consumption (which we don't care about). And that would
happen every time we requested an sdk adapter.

openstacksdk added support for restricting a Connection to a single
service type via [1]. So this commit takes advantage of it.

[1] https://review.opendev.org/674675

Change-Id: Ib0e43f6c9e28ce4f1ac1831a3e3558c825a372ca
This commit is contained in:
Eric Fried 2019-08-05 14:11:47 -05:00
parent eb5f137292
commit 4412a90cf1
2 changed files with 5 additions and 3 deletions

View File

@ -1579,8 +1579,9 @@ class TestGetSDKAdapter(test.NoDBTestCase):
self.assertEqual(actual, mock_proxy)
mock_get_confgrp.assert_called_once_with(service_type)
mock_get_auth_sess.assert_called_once_with(mock_confgrp)
mock_connection.assert_called_once_with(session=mock_session,
oslo_conf=mock_conf)
mock_connection.assert_called_once_with(
session=mock_session, oslo_conf=mock_conf,
service_types={'test_service'})
@mock.patch('nova.utils._get_conf_group')
@mock.patch('nova.utils._get_auth_and_session')

View File

@ -1249,7 +1249,8 @@ def get_sdk_adapter(service_type):
"""
confgrp = _get_conf_group(service_type)
_, sess = _get_auth_and_session(confgrp)
conn = connection.Connection(session=sess, oslo_conf=CONF)
conn = connection.Connection(
session=sess, oslo_conf=CONF, service_types={service_type})
return getattr(conn, service_type)