From 9ace679c1dae5e8f68946a46ce1dfb2926539b52 Mon Sep 17 00:00:00 2001 From: kairat_kushaev Date: Tue, 21 Nov 2017 12:14:27 +0400 Subject: [PATCH] Use cached auth_ref instead of gettin a new one each time The commit fixes an issue in renewing connections to Swift in case if a given token is about to expire soon. get_auth_ref() returned a new auth_ref each time it was called so the will_expire_soon() call was useless since it always returned False. Now the cached auth_ref property is used instead. Closes-Bug:#1733502 Change-Id: I6cb53aec6798f965cf2a120d4f676a43bca5046a --- glance_store/_drivers/swift/connection_manager.py | 3 +-- glance_store/tests/unit/test_connection_manager.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/glance_store/_drivers/swift/connection_manager.py b/glance_store/_drivers/swift/connection_manager.py index 8b16869f..883f8d56 100644 --- a/glance_store/_drivers/swift/connection_manager.py +++ b/glance_store/_drivers/swift/connection_manager.py @@ -80,8 +80,7 @@ class SwiftConnectionManager(object): # connection manager users. Also we disable re-authentication # if there is not way to execute it (cannot initialize trusts for # multi-tenant or auth_version is not 3) - auth_ref = self.client.session.auth.get_auth_ref( - self.client.session) + auth_ref = self.client.session.auth.auth_ref # if connection token is going to expire soon (keystone checks # is token is going to expire or expired already) if auth_ref.will_expire_soon( diff --git a/glance_store/tests/unit/test_connection_manager.py b/glance_store/tests/unit/test_connection_manager.py index be29a36d..5c444f48 100644 --- a/glance_store/tests/unit/test_connection_manager.py +++ b/glance_store/tests/unit/test_connection_manager.py @@ -107,7 +107,7 @@ class TestConnectionManager(base.StoreBaseTest): self.context) # return the same connection because it should not be expired auth_ref = mock.MagicMock() - self.client.session.auth.get_auth_ref.return_value = auth_ref + self.client.session.auth.auth_ref = auth_ref auth_ref.will_expire_soon.return_value = False manager.get_connection() # check that we don't update connection @@ -149,7 +149,7 @@ class TestConnectionManager(base.StoreBaseTest): ) # return the same connection because it should not be expired auth_ref = mock.MagicMock() - self.client.session.auth.get_auth_ref.return_value = auth_ref + self.client.session.auth.auth_ref = auth_ref auth_ref.will_expire_soon.return_value = False manager.get_connection() # check that we don't update connection