Fix interactions with keystoneauth from newton
keystoneauth in newton did not have app_name or app_version as Session parameters. Although it isn't a super common combination, user agent strings aren't a reason to break something. Add a simple workaround. Change-Id: Ib5774389fefdbc190a4b78dd6784c8006afbb270
This commit is contained in:
@@ -215,14 +215,20 @@ class CloudConfig(object):
|
||||
requestsexceptions.squelch_warnings(insecure_requests=not verify)
|
||||
self._keystone_session = self._session_constructor(
|
||||
auth=self._auth,
|
||||
app_name=self._app_name,
|
||||
app_version=self._app_version,
|
||||
verify=verify,
|
||||
cert=cert,
|
||||
timeout=self.config['api_timeout'])
|
||||
if hasattr(self._keystone_session, 'additional_user_agent'):
|
||||
self._keystone_session.additional_user_agent.append(
|
||||
('os-client-config', os_client_config.__version__))
|
||||
# Using old keystoneauth with new os-client-config fails if
|
||||
# we pass in app_name and app_version. Those are not essential,
|
||||
# nor a reason to bump our minimum, so just test for the session
|
||||
# having the attribute post creation and set them then.
|
||||
if hasattr(self._keystone_session, 'app_name'):
|
||||
self._keystone_session.app_name = self._app_name
|
||||
if hasattr(self._keystone_session, 'app_version'):
|
||||
self._keystone_session.app_version = self._app_version
|
||||
return self._keystone_session
|
||||
|
||||
def get_session_client(self, service_key):
|
||||
|
@@ -187,8 +187,29 @@ class TestCloudConfig(base.TestCase):
|
||||
cc.get_session()
|
||||
mock_session.assert_called_with(
|
||||
auth=mock.ANY,
|
||||
verify=True, cert=None, timeout=None,
|
||||
app_name=None, app_version=None)
|
||||
verify=True, cert=None, timeout=None)
|
||||
self.assertEqual(
|
||||
fake_session.additional_user_agent,
|
||||
[('os-client-config', '1.2.3')])
|
||||
|
||||
@mock.patch.object(ksa_session, 'Session')
|
||||
def test_get_session_with_app_name(self, mock_session):
|
||||
config_dict = defaults.get_defaults()
|
||||
config_dict.update(fake_services_dict)
|
||||
fake_session = mock.Mock()
|
||||
fake_session.additional_user_agent = []
|
||||
fake_session.app_name = None
|
||||
fake_session.app_version = None
|
||||
mock_session.return_value = fake_session
|
||||
cc = cloud_config.CloudConfig(
|
||||
"test1", "region-al", config_dict, auth_plugin=mock.Mock(),
|
||||
app_name="test_app", app_version="test_version")
|
||||
cc.get_session()
|
||||
mock_session.assert_called_with(
|
||||
auth=mock.ANY,
|
||||
verify=True, cert=None, timeout=None)
|
||||
self.assertEqual(fake_session.app_name, "test_app")
|
||||
self.assertEqual(fake_session.app_version, "test_version")
|
||||
self.assertEqual(
|
||||
fake_session.additional_user_agent,
|
||||
[('os-client-config', '1.2.3')])
|
||||
@@ -206,8 +227,7 @@ class TestCloudConfig(base.TestCase):
|
||||
cc.get_session()
|
||||
mock_session.assert_called_with(
|
||||
auth=mock.ANY,
|
||||
verify=True, cert=None, timeout=9,
|
||||
app_name=None, app_version=None)
|
||||
verify=True, cert=None, timeout=9)
|
||||
self.assertEqual(
|
||||
fake_session.additional_user_agent,
|
||||
[('os-client-config', '1.2.3')])
|
||||
|
@@ -0,0 +1,7 @@
|
||||
---
|
||||
issues:
|
||||
- Fixed a regression when using latest os-client-config with
|
||||
the keystoneauth from stable/newton. Although this isn't a
|
||||
super common combination, the added feature that broke the
|
||||
interaction is really not worthy of the incompatibility, so
|
||||
a workaround was added.
|
Reference in New Issue
Block a user