diff --git a/novaclient/shell.py b/novaclient/shell.py index 1dbc08584..ec415bb6e 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 a8826deb5..4958023d7 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):