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.