summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2017-04-28 12:46:44 -0500
committerMonty Taylor <mordred@inaugust.com>2017-04-28 15:06:27 -0500
commit17debbb09907b83d5781ad683f4b72c9eb1ce221 (patch)
treea85cf8ae551dcc6f76e7a8e8f91210724486ff82
parentf6804f6b0dec9b1322ee996972489c1118f19f90 (diff)
downloados-client-config-17debbb09907b83d5781ad683f4b72c9eb1ce221.tar.gz
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
-rw-r--r--os_client_config/cloud_config.py10
-rw-r--r--os_client_config/tests/test_cloud_config.py28
-rw-r--r--releasenotes/notes/fix-compat-with-old-keystoneauth-66e11ee9d008b962.yaml7
3 files changed, 39 insertions, 6 deletions
diff --git a/os_client_config/cloud_config.py b/os_client_config/cloud_config.py
index 0860924..fec3500 100644
--- a/os_client_config/cloud_config.py
+++ b/os_client_config/cloud_config.py
@@ -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):
diff --git a/os_client_config/tests/test_cloud_config.py b/os_client_config/tests/test_cloud_config.py
index 0671fcc..5df1faf 100644
--- a/os_client_config/tests/test_cloud_config.py
+++ b/os_client_config/tests/test_cloud_config.py
@@ -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')])
diff --git a/releasenotes/notes/fix-compat-with-old-keystoneauth-66e11ee9d008b962.yaml b/releasenotes/notes/fix-compat-with-old-keystoneauth-66e11ee9d008b962.yaml
new file mode 100644
index 0000000..80d09fb
--- /dev/null
+++ b/releasenotes/notes/fix-compat-with-old-keystoneauth-66e11ee9d008b962.yaml
@@ -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.