summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy McCrory <jimmy.mccrory@gmail.com>2015-06-07 11:16:11 -0500
committerJimmy McCrory <jimmy.mccrory@gmail.com>2015-06-10 23:54:28 -0700
commit784a8b4a9113e919b6514cdb57da6b0b27ee2c63 (patch)
tree82a07e3cf278aff04eca6013afc774918a7fc88a
parent773eea811df7be3dcb73dc2ae16354b172f442c6 (diff)
downloadpython-novaclient-784a8b4a9113e919b6514cdb57da6b0b27ee2c63.tar.gz
Cache a new token when the existing token expires
The client.keyring_saver attribute was not being reliably set so the client._save_keys function was not storing any new tokens in the keyring. Add a unit test to ensure keyring_saver is being property set. Closes-Bug: #1397732 Change-Id: If0df24c819d71b4df302309d049079a867a11c76
-rw-r--r--novaclient/shell.py2
-rw-r--r--novaclient/tests/unit/test_shell.py20
2 files changed, 21 insertions, 1 deletions
diff --git a/novaclient/shell.py b/novaclient/shell.py
index 1dbc0858..ec415bb6 100644
--- a/novaclient/shell.py
+++ b/novaclient/shell.py
@@ -703,6 +703,7 @@ class OpenStackComputeShell(object):
# identifying keyring key can come from the underlying client
if must_auth:
helper = SecretsHelper(args, self.cs.client)
+ self.cs.client.keyring_saver = helper
if (auth_plugin and auth_plugin.opts and
"os_password" not in auth_plugin.opts):
use_pw = False
@@ -724,7 +725,6 @@ class OpenStackComputeShell(object):
# We're missing something, so auth with user/pass and save
# the result in our helper.
self.cs.client.password = helper.password
- self.cs.client.keyring_saver = helper
try:
# This does a couple of bits which are useful even if we've
diff --git a/novaclient/tests/unit/test_shell.py b/novaclient/tests/unit/test_shell.py
index a8826deb..4958023d 100644
--- a/novaclient/tests/unit/test_shell.py
+++ b/novaclient/tests/unit/test_shell.py
@@ -379,6 +379,26 @@ class ShellTest(utils.TestCase):
exc = self.assertRaises(RuntimeError, self.shell, '--timings list')
self.assertEqual('Boom!', str(exc))
+ @mock.patch('novaclient.shell.SecretsHelper.tenant_id',
+ return_value=True)
+ @mock.patch('novaclient.shell.SecretsHelper.auth_token',
+ return_value=True)
+ @mock.patch('novaclient.shell.SecretsHelper.management_url',
+ return_value=True)
+ @mock.patch('novaclient.client.Client')
+ @requests_mock.Mocker()
+ def test_keyring_saver_helper(self, mock_client,
+ sh_management_url_function,
+ sh_auth_token_function,
+ sh_tenant_id_function,
+ m_requests):
+ self.make_env(fake_env=FAKE_ENV)
+ self.register_keystone_discovery_fixture(m_requests)
+ self.shell('list')
+ mock_client_instance = mock_client.return_value
+ keyring_saver = mock_client_instance.client.keyring_saver
+ self.assertIsInstance(keyring_saver, novaclient.shell.SecretsHelper)
+
class ShellTestKeystoneV3(ShellTest):
def make_env(self, exclude=None, fake_env=FAKE_ENV):