From f98b8470de2e0225befc5a39ef20ed5e4f7880c1 Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Fri, 2 Dec 2016 19:51:57 +0200 Subject: [PATCH] Rename api_key to password "password" term is more clear. Resolves FIXME from the code: FIXME(comstud): Rename the api_key argument above when we know it's not being used as keyword argument Change-Id: I39f810a181b119591cf017eded71356a437a8c0a --- novaclient/client.py | 19 ++++++++++++------- novaclient/tests/unit/fixture_data/client.py | 2 +- novaclient/tests/unit/test_client.py | 6 ------ novaclient/v2/client.py | 9 +++------ ...e-apikey-to-password-735588d841efa49e.yaml | 5 +++++ 5 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 releasenotes/notes/rename-apikey-to-password-735588d841efa49e.yaml diff --git a/novaclient/client.py b/novaclient/client.py index 6897fe334..c7dbd2189 100644 --- a/novaclient/client.py +++ b/novaclient/client.py @@ -850,7 +850,7 @@ def _check_arguments(kwargs, release, deprecated_name, right_name=None): warnings.warn(msg) -def Client(version, username=None, api_key=None, project_id=None, +def Client(version, username=None, password=None, project_id=None, auth_url=None, **kwargs): """Initialize client object based on given version. @@ -872,19 +872,24 @@ def Client(version, username=None, api_key=None, project_id=None, session API. See "The novaclient Python API" page at python-novaclient's doc. """ - + if password: + kwargs["password"] = password _check_arguments(kwargs, "Ocata", "auth_plugin") _check_arguments(kwargs, "Ocata", "auth_system") if "no_cache" in kwargs: - _check_arguments(kwargs, "Ocata", "no_cache", "os_cache") + _check_arguments(kwargs, "Ocata", "no_cache", right_name="os_cache") # os_cache is not a fully compatible with no_cache, so we need to # apply this custom processing kwargs["os_cache"] = not kwargs["os_cache"] - _check_arguments(kwargs, "Ocata", "bypass_url", "endpoint_override") + _check_arguments(kwargs, "Ocata", "bypass_url", + right_name="endpoint_override") + _check_arguments(kwargs, "Ocata", "api_key", right_name="password") api_version, client_class = _get_client_class_and_version(version) kwargs.pop("direct_use", None) - return client_class(username=username, api_key=api_key, - project_id=project_id, auth_url=auth_url, - api_version=api_version, direct_use=False, + return client_class(api_version=api_version, + auth_url=auth_url, + direct_use=False, + project_id=project_id, + username=username, **kwargs) diff --git a/novaclient/tests/unit/fixture_data/client.py b/novaclient/tests/unit/fixture_data/client.py index 7bfaf4cc3..c37141095 100644 --- a/novaclient/tests/unit/fixture_data/client.py +++ b/novaclient/tests/unit/fixture_data/client.py @@ -56,7 +56,7 @@ class V1(fixtures.Fixture): def new_client(self): return client.Client("2", username='xx', - api_key='xx', + password='xx', project_id='xx', auth_url=self.identity_url) diff --git a/novaclient/tests/unit/test_client.py b/novaclient/tests/unit/test_client.py index 945749d54..ab25fe0b4 100644 --- a/novaclient/tests/unit/test_client.py +++ b/novaclient/tests/unit/test_client.py @@ -211,12 +211,6 @@ class ClientTest(utils.TestCase): 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() diff --git a/novaclient/v2/client.py b/novaclient/v2/client.py index 1cb72570d..e903c1a69 100644 --- a/novaclient/v2/client.py +++ b/novaclient/v2/client.py @@ -68,7 +68,7 @@ class Client(object): directly. It should be done via `novaclient.client.Client` interface. """ - def __init__(self, api_key=None, + def __init__(self, api_version=None, auth=None, auth_token=None, @@ -83,6 +83,7 @@ class Client(object): insecure=False, logger=None, os_cache=False, + password=None, project_id=None, proxy_tenant_id=None, proxy_token=None, @@ -99,7 +100,6 @@ class Client(object): **kwargs): """Initialization of Client object. - :param str api_key: API Key :param api_version: Compute API version :type api_version: novaclient.api_versions.APIVersion :param str auth: Auth @@ -115,6 +115,7 @@ class Client(object): :param bool insecure: Allow insecure :param logging.Logger logger: Logger instance to be used for all logging stuff + :param str password: User password :param bool os_cache: OS cache :param str project_id: Project ID :param str proxy_tenant_id: Tenant ID @@ -138,16 +139,12 @@ class Client(object): "'novaclient.client.Client' instead. Related lp " "bug-report: 1493576")) - # FIXME(comstud): Rename the api_key argument above when we - # know it's not being used as keyword argument - # NOTE(cyeoh): In the novaclient context (unlike Nova) the # project_id is not the same as the tenant_id. Here project_id # is a name (what the Nova API often refers to as a project or # tenant name) and tenant_id is a UUID (what the Nova API # often refers to as a project_id or tenant_id). - password = kwargs.pop('password', api_key) self.projectid = project_id self.tenant_id = tenant_id self.user_id = user_id diff --git a/releasenotes/notes/rename-apikey-to-password-735588d841efa49e.yaml b/releasenotes/notes/rename-apikey-to-password-735588d841efa49e.yaml new file mode 100644 index 000000000..36578342a --- /dev/null +++ b/releasenotes/notes/rename-apikey-to-password-735588d841efa49e.yaml @@ -0,0 +1,5 @@ +--- +deprecations: + - The **api_key** variable of novaclient.client.Client entry-point was + deprecated in favor of **password**. Nothing has changed in the case + of positional argument usage.