Merge "Fix authentication issue"

This commit is contained in:
Jenkins
2016-07-15 20:58:36 +00:00
committed by Gerrit Code Review
2 changed files with 13 additions and 1 deletions

View File

@@ -580,6 +580,9 @@ class OpenStackCinderShell(object):
# Check for Ctl-D
try:
os_password = getpass.getpass('OS Password: ')
# Initialize options.os_password with password
# input from tty. It is used in _get_keystone_session.
options.os_password = os_password
except EOFError:
pass
# No password because we didn't have a tty or the

View File

@@ -142,6 +142,7 @@ class ShellTest(utils.TestCase):
for count in range(1, 4):
self.list_volumes_on_service(count)
@mock.patch('keystoneclient.auth.identity.v2.Password')
@mock.patch('keystoneclient.adapter.Adapter.get_token',
side_effect=ks_exc.ConnectionRefused())
@mock.patch('keystoneclient.discover.Discover',
@@ -149,11 +150,19 @@ class ShellTest(utils.TestCase):
@mock.patch('sys.stdin', side_effect=mock.MagicMock)
@mock.patch('getpass.getpass', return_value='password')
def test_password_prompted(self, mock_getpass, mock_stdin, mock_discover,
mock_token):
mock_token, mock_password):
self.make_env(exclude='OS_PASSWORD')
_shell = shell.OpenStackCinderShell()
self.assertRaises(ks_exc.ConnectionRefused, _shell.main, ['list'])
mock_getpass.assert_called_with('OS Password: ')
# Verify that Password() is called with value of param 'password'
# equal to mock_getpass.return_value.
mock_password.assert_called_with(
self.FAKE_ENV['OS_AUTH_URL'],
password=mock_getpass.return_value,
tenant_id='',
tenant_name=self.FAKE_ENV['OS_TENANT_NAME'],
username=self.FAKE_ENV['OS_USERNAME'])
@mock.patch.object(requests, "request")
@mock.patch.object(pkg_resources, "iter_entry_points")