Skip to content

Commit

Permalink
Fixes TypeError on Client instantiation
Browse files Browse the repository at this point in the history
When instantiating novaclient with kwargs or named attributes, the 'password'
field is duplicated due to an overwrite on the __init__ method of Client v2.
This patch pops out the password field when it's passed and no api_key is
provided.

Co-Authored-By: Pavel Kholkin <pkholkin@mirantis.com>

Closes-bug: #1511417

Change-Id: Id8310eccef5f0f9a2983e25dd35541d1eb0efe86
  • Loading branch information
Thiago Paiva authored and pkholkin committed Aug 26, 2016
1 parent ef5dc32 commit f7dc91d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions novaclient/tests/unit/test_client.py
Expand Up @@ -229,6 +229,12 @@ def test_contextmanager_v1_1(self, mock_http_client):
self.assertTrue(fake_client.open_session.called)
self.assertTrue(fake_client.close_session.called)

def test_client_with_password_in_args_and_kwargs(self):
# check that TypeError is not raised during instantiation of Client
cs = novaclient.client.Client("2", "user", "password", "project_id",
password='pass')
self.assertEqual('pass', cs.client.password)

def test_get_password_simple(self):
cs = novaclient.client.HTTPClient("user", "password", "", "")
cs.password_func = mock.Mock()
Expand Down
2 changes: 1 addition & 1 deletion novaclient/v2/client.py
Expand Up @@ -125,7 +125,7 @@ def __init__(self, username=None, api_key=None, project_id=None,
# tenant name) and tenant_id is a UUID (what the Nova API
# often refers to as a project_id or tenant_id).

password = api_key
password = kwargs.pop('password', api_key)
self.projectid = project_id
self.tenant_id = tenant_id
self.user_id = user_id
Expand Down

0 comments on commit f7dc91d

Please sign in to comment.