From 4f3bdcc9907a2533c85ecaee053725f262eb2e2e Mon Sep 17 00:00:00 2001 From: rabi Date: Wed, 1 Jun 2016 12:29:09 +0530 Subject: [PATCH] Use get_auth_ref() rather than auth_ref property Some plugins like Token does not have this property. It's better to use get_auth_ref method. Change-Id: Ib1de63d692b29179503b65f4b38461e2b82b7be8 --- heat/engine/clients/client_plugin.py | 4 +++- heat/tests/clients/test_clients.py | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/heat/engine/clients/client_plugin.py b/heat/engine/clients/client_plugin.py index 17347b710..8d1eb89db 100644 --- a/heat/engine/clients/client_plugin.py +++ b/heat/engine/clients/client_plugin.py @@ -142,8 +142,10 @@ class ClientPlugin(object): version = self.default_version if version in self._client_instances: + auth_ref = self.context.auth_plugin.get_auth_ref( + self._keystone_session) if (cfg.CONF.reauthentication_auth_method == 'trusts' - and self.context.auth_plugin.auth_ref.will_expire_soon( + and auth_ref.will_expire_soon( cfg.CONF.stale_token_duration)): # If the token is near expiry, force creating a new client, # which will get a new token via another call to auth_token diff --git a/heat/tests/clients/test_clients.py b/heat/tests/clients/test_clients.py index c4febd8e6..f29ac3902 100644 --- a/heat/tests/clients/test_clients.py +++ b/heat/tests/clients/test_clients.py @@ -363,15 +363,18 @@ class ClientPluginTest(common.HeatTestCase): def test_create_client_on_token_expiration(self): cfg.CONF.set_override('reauthentication_auth_method', 'trusts', enforce_type=True) - con = mock.Mock() - con.auth_plugin.auth_ref.will_expire_soon.return_value = False + con = utils.dummy_context() + auth_ref = mock.Mock() + self.patchobject(con.auth_plugin, 'get_auth_ref', + return_value=auth_ref) + auth_ref.will_expire_soon.return_value = False plugin = FooClientsPlugin(con) plugin._create = mock.Mock() plugin.client() self.assertEqual(1, plugin._create.call_count) plugin.client() self.assertEqual(1, plugin._create.call_count) - con.auth_plugin.auth_ref.will_expire_soon.return_value = True + auth_ref.will_expire_soon.return_value = True plugin.client() self.assertEqual(2, plugin._create.call_count)