From 1e2274aef011c143ef0ae421b45755babaff3652 Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Tue, 1 Sep 2015 18:03:41 +0200 Subject: [PATCH] Password should be prompted once There's a corner case where password may be requested twice. In a fresh environment, when schemas have not be downloaded for v2, the client will ask for a password to download the schemas and then it'll ask for the password again to run the actual command. This happens because we parse the CLI arguments twice to make sure we're parsing them for the right client version. This patch checks if the password is unset in the newly parsed arguments and if it's been set in the previously parsed ones. In this case it keeps the set password. I believe this approach is safer than re-using the already parsed arguements which may have been parsed for a different API version (might happen because we fallback to v1 if v2 is not available). Change-Id: I080253170e3e84a90363e5bb494cf137895fe2e7 Closes-bug: #1488892 --- glanceclient/shell.py | 7 +++++++ glanceclient/tests/unit/test_shell.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/glanceclient/shell.py b/glanceclient/shell.py index e613139..cba0010 100755 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -659,6 +659,13 @@ class OpenStackImagesShell(object): # Parse args again and call whatever callback was selected args = subcommand_parser.parse_args(argv) + # NOTE(flaper87): Make sure we re-use the password input if we + # have one. This may happen if the schemas were downloaded in + # this same command. Password will be asked to download the + # schemas and then for the operations below. + if not args.os_password and options.os_password: + args.os_password = options.os_password + # Short-circuit and deal with help command right away. if args.func == self.do_help: self.do_help(args) diff --git a/glanceclient/tests/unit/test_shell.py b/glanceclient/tests/unit/test_shell.py index f0dfb67..8f0ab42 100644 --- a/glanceclient/tests/unit/test_shell.py +++ b/glanceclient/tests/unit/test_shell.py @@ -291,7 +291,7 @@ class ShellTest(testutils.TestCase): self.assertRaises(ks_exc.ConnectionRefused, glance_shell.main, ['image-list']) # Make sure we are actually prompted. - mock_getpass.assert_called_with('OS Password: ') + mock_getpass.assert_called_once_with('OS Password: ') @mock.patch('sys.stdin', side_effect=mock.MagicMock) @mock.patch('getpass.getpass', side_effect=EOFError)