Proper deprecation for HTTPClient tenant_id, tenant_name parameters

HTTPClient() tenant_id and tenant_name parameters weren't properly
deprecated since they were only mentioned in the docstring. Proper
deprecation requires use of warnings/debtcollector and documentation.

Also fixed a bunch of places in the tests where tenant_id and
tenant_name were still being used despite being deprecated.

bp deprecations

Change-Id: I9c4f596b8ff10aede6c417886638a942cb18044c
This commit is contained in:
Brant Knudson
2015-07-24 15:06:00 -05:00
parent a9ef92a43f
commit 1721e01743
9 changed files with 43 additions and 33 deletions

View File

@@ -22,6 +22,7 @@ OpenStack Client interface. Handles the REST calls and responses.
import logging
from debtcollector import removals
from debtcollector import renames
from oslo_serialization import jsonutils
import pkg_resources
import requests
@@ -190,10 +191,13 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
keyring is about to expire. default: 30
(optional)
:param string tenant_name: Tenant name. (optional) The tenant_name keyword
argument is deprecated, use project_name
instead.
argument is deprecated as of the 1.7.0 release
in favor of project_name and may be removed in
the 2.0.0 release.
:param string tenant_id: Tenant id. (optional) The tenant_id keyword
argument is deprecated, use project_id instead.
argument is deprecated as of the 1.7.0 release in
favor of project_id and may be removed in the
2.0.0 release.
:param string trust_id: Trust ID for trust scoping. (optional)
:param object session: A Session object to be used for
communicating with the identity service.
@@ -216,6 +220,10 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
version = None
@renames.renamed_kwarg('tenant_name', 'project_name', version='1.7.0',
removal_version='2.0.0')
@renames.renamed_kwarg('tenant_id', 'project_id', version='1.7.0',
removal_version='2.0.0')
@utils.positional(enforcement=utils.positional.WARN)
def __init__(self, username=None, tenant_id=None, tenant_name=None,
password=None, auth_url=None, region_name=None, endpoint=None,

View File

@@ -28,7 +28,7 @@ RESPONSE_BODY = '{"hi": "there"}'
def get_client():
cl = httpclient.HTTPClient(username="username", password="password",
tenant_id="tenant", auth_url="auth_test")
project_id="tenant", auth_url="auth_test")
return cl
@@ -118,7 +118,7 @@ class ClientTest(utils.TestCase):
def test_forwarded_for(self):
ORIGINAL_IP = "10.100.100.1"
cl = httpclient.HTTPClient(username="username", password="password",
tenant_id="tenant", auth_url="auth_test",
project_id="tenant", auth_url="auth_test",
original_ip=ORIGINAL_IP)
self.stub_url('GET')

View File

@@ -28,7 +28,7 @@ RESPONSE_BODY = '{"hi": "there"}'
def get_client():
cl = httpclient.HTTPClient(username="username", password="password",
tenant_id="tenant", auth_url="auth_test",
project_id="tenant", auth_url="auth_test",
cacert="ca.pem", key="key.pem", cert="cert.pem")
return cl
@@ -82,7 +82,7 @@ class ClientTest(utils.TestCase):
def test_post_auth(self, MOCK_REQUEST):
MOCK_REQUEST.return_value = FAKE_RESPONSE
cl = httpclient.HTTPClient(
username="username", password="password", tenant_id="tenant",
username="username", password="password", project_id="tenant",
auth_url="auth_test", cacert="ca.pem", key="key.pem",
cert="cert.pem")
cl.management_url = "https://127.0.0.1:5000"

View File

@@ -88,7 +88,7 @@ class KeyringTest(utils.TestCase):
the keyring is never accessed.
"""
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
tenant_id=TENANT_ID, auth_url=AUTH_URL)
project_id=TENANT_ID, auth_url=AUTH_URL)
# stub and check that a new token is received
method = 'get_raw_token_from_identity_service'
@@ -105,7 +105,7 @@ class KeyringTest(utils.TestCase):
def test_build_keyring_key(self):
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
tenant_id=TENANT_ID, auth_url=AUTH_URL)
project_id=TENANT_ID, auth_url=AUTH_URL)
keyring_key = cl._build_keyring_key(auth_url=AUTH_URL,
username=USERNAME,
@@ -119,7 +119,7 @@ class KeyringTest(utils.TestCase):
def test_set_and_get_keyring_expired(self):
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
tenant_id=TENANT_ID, auth_url=AUTH_URL,
project_id=TENANT_ID, auth_url=AUTH_URL,
use_keyring=True)
# set an expired token into the keyring
@@ -147,7 +147,7 @@ class KeyringTest(utils.TestCase):
def test_get_keyring(self):
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
tenant_id=TENANT_ID, auth_url=AUTH_URL,
project_id=TENANT_ID, auth_url=AUTH_URL,
use_keyring=True)
# set an token into the keyring
@@ -163,7 +163,7 @@ class KeyringTest(utils.TestCase):
def test_set_keyring(self):
cl = httpclient.HTTPClient(username=USERNAME, password=PASSWORD,
tenant_id=TENANT_ID, auth_url=AUTH_URL,
project_id=TENANT_ID, auth_url=AUTH_URL,
use_keyring=True)
# stub and check that a new token is received

View File

@@ -67,7 +67,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
self.stub_auth(response_list=[{'json': resp_a, 'headers': headers},
{'json': resp_b, 'headers': headers}])
cs = client.Client(tenant_id=self.TEST_TENANT_ID,
cs = client.Client(project_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL,
username=self.TEST_USER,
password=self.TEST_TOKEN)
@@ -95,7 +95,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
def client_create_wrapper():
client.Client(username=self.TEST_USER,
password="bad_key",
tenant_id=self.TEST_TENANT_ID,
project_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL)
self.assertRaises(exceptions.Unauthorized, client_create_wrapper)
@@ -110,7 +110,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
cs = client.Client(username=self.TEST_USER,
password=self.TEST_TOKEN,
tenant_id=self.TEST_TENANT_ID,
project_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL)
self.assertEqual(cs.management_url,
@@ -125,7 +125,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
cs = client.Client(username=self.TEST_USER,
password=self.TEST_TOKEN,
tenant_id=self.TEST_TENANT_ID,
project_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL)
self.assertEqual(cs.management_url,
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
@@ -174,7 +174,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
self.stub_auth(json=self.TEST_RESPONSE_DICT)
cs = client.Client(token=self.TEST_TOKEN,
tenant_id=self.TEST_TENANT_ID,
project_id=self.TEST_TENANT_ID,
auth_url=self.TEST_URL)
self.assertEqual(cs.management_url,
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
@@ -193,7 +193,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
self.stub_auth(json=response)
cs = client.Client(token=self.TEST_TOKEN,
tenant_id=self.TEST_TENANT_ID,
project_id=self.TEST_TENANT_ID,
trust_id=self.TEST_TRUST_ID,
auth_url=self.TEST_URL)
self.assertTrue(cs.auth_ref.trust_scoped)
@@ -227,7 +227,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
cl = client.Client(username='exampleuser',
password='password',
tenant_name='exampleproject',
project_name='exampleproject',
auth_url=self.TEST_URL)
self.assertEqual(cl.auth_token, self.TEST_TOKEN)

View File

@@ -49,7 +49,7 @@ class KeystoneClientTest(utils.TestCase):
c = client.Client(username='exampleuser',
password='password',
tenant_name='exampleproject',
project_name='exampleproject',
auth_url=self.TEST_URL)
self.assertIsNotNone(c.auth_ref)
with self.deprecations.expect_deprecations_here():
@@ -67,7 +67,7 @@ class KeystoneClientTest(utils.TestCase):
cl = client.Client(username='exampleuser',
password='password',
tenant_name='exampleproject',
project_name='exampleproject',
auth_url=self.TEST_URL)
cache = json.dumps(cl.auth_ref)
new_client = client.Client(auth_ref=json.loads(cache))
@@ -88,7 +88,7 @@ class KeystoneClientTest(utils.TestCase):
cl = client.Client(username='exampleuser',
password='password',
tenant_name='exampleproject',
project_name='exampleproject',
auth_url=self.TEST_URL)
cache = json.dumps(cl.auth_ref)
new_auth_url = "http://new-public:5000/v2.0"
@@ -133,7 +133,7 @@ class KeystoneClientTest(utils.TestCase):
cl = client.Client(username='exampleuser',
password='password',
tenant_name='exampleproject',
project_name='exampleproject',
auth_url=self.TEST_URL)
self.assertEqual(cl.management_url, admin_url)
@@ -147,7 +147,7 @@ class KeystoneClientTest(utils.TestCase):
cl = client.Client(username='exampleuser',
password='password',
tenant_name='exampleproject',
project_name='exampleproject',
auth_url=self.TEST_URL,
region_name='North')
self.assertEqual(cl.service_catalog.url_for(service_type='image'),
@@ -155,7 +155,7 @@ class KeystoneClientTest(utils.TestCase):
cl = client.Client(username='exampleuser',
password='password',
tenant_name='exampleproject',
project_name='exampleproject',
auth_url=self.TEST_URL,
region_name='South')
self.assertEqual(cl.service_catalog.url_for(service_type='image'),
@@ -164,7 +164,7 @@ class KeystoneClientTest(utils.TestCase):
def test_client_without_auth_params(self):
self.assertRaises(exceptions.AuthorizationFailure,
client.Client,
tenant_name='exampleproject',
project_name='exampleproject',
auth_url=self.TEST_URL)
def test_client_params(self):

View File

@@ -321,7 +321,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
cl = client.Client(username='exampleuser',
password='password',
tenant_name='exampleproject',
project_name='exampleproject',
auth_url=self.TEST_URL)
self.assertEqual(cl.auth_token, self.TEST_TOKEN)

View File

@@ -190,7 +190,7 @@ class KeystoneClientTest(utils.TestCase):
cl = client.Client(username='exampleuser',
password='password',
tenant_name='exampleproject',
project_name='exampleproject',
auth_url=self.TEST_URL,
region_name='North')
self.assertEqual(cl.service_catalog.url_for(service_type='image'),
@@ -198,7 +198,7 @@ class KeystoneClientTest(utils.TestCase):
cl = client.Client(username='exampleuser',
password='password',
tenant_name='exampleproject',
project_name='exampleproject',
auth_url=self.TEST_URL,
region_name='South')
self.assertEqual(cl.service_catalog.url_for(service_type='image'),

View File

@@ -66,11 +66,13 @@ class Client(httpclient.HTTPClient):
:param string project_domain_name: Project's domain name for project
scoping. (optional)
:param string tenant_name: Tenant name. (optional)
The tenant_name keyword argument is deprecated,
use project_name instead.
The tenant_name keyword argument is deprecated
as of the 1.7.0 release in favor of project_name
and may be removed in the 2.0.0 release.
:param string tenant_id: Tenant id. (optional)
The tenant_id keyword argument is deprecated,
use project_id instead.
The tenant_id keyword argument is deprecated as of
the 1.7.0 release in favor of project_id and may
be removed in the 2.0.0 release.
:param string auth_url: Identity service endpoint for authorization.
:param string region_name: Name of a region to select when choosing an
endpoint from the service catalog.