Merge "Proper deprecation for UserManager project argument"

This commit is contained in:
Jenkins
2015-08-26 06:35:23 +00:00
committed by Gerrit Code Review
2 changed files with 22 additions and 13 deletions

View File

@@ -111,6 +111,7 @@ class UserTests(utils.TestCase, utils.CrudTests):
def test_create_with_project(self): def test_create_with_project(self):
# Can create a user with the deprecated project option rather than # Can create a user with the deprecated project option rather than
# default_project_id. # default_project_id.
self.deprecations.expect_deprecations()
ref = self.new_ref() ref = self.new_ref()
self.stub_entity('POST', [self.collection_key], self.stub_entity('POST', [self.collection_key],
@@ -135,6 +136,8 @@ class UserTests(utils.TestCase, utils.CrudTests):
def test_create_with_project_and_default_project(self): def test_create_with_project_and_default_project(self):
# Can create a user with the deprecated project and default_project_id. # Can create a user with the deprecated project and default_project_id.
# The backend call should only pass the default_project_id. # The backend call should only pass the default_project_id.
self.deprecations.expect_deprecations()
ref = self.new_ref() ref = self.new_ref()
self.stub_entity('POST', self.stub_entity('POST',
@@ -180,6 +183,8 @@ class UserTests(utils.TestCase, utils.CrudTests):
def test_update_with_project(self): def test_update_with_project(self):
# Can update a user with the deprecated project option rather than # Can update a user with the deprecated project option rather than
# default_project_id. # default_project_id.
self.deprecations.expect_deprecations()
ref = self.new_ref() ref = self.new_ref()
req_ref = ref.copy() req_ref = ref.copy()
req_ref.pop('id') req_ref.pop('id')
@@ -203,6 +208,8 @@ class UserTests(utils.TestCase, utils.CrudTests):
self.assertEntityRequestBodyIs(req_ref) self.assertEntityRequestBodyIs(req_ref)
def test_update_with_project_and_default_project(self, ref=None): def test_update_with_project_and_default_project(self, ref=None):
self.deprecations.expect_deprecations()
ref = self.new_ref() ref = self.new_ref()
req_ref = ref.copy() req_ref = ref.copy()
req_ref.pop('id') req_ref.pop('id')

View File

@@ -16,9 +16,11 @@
import logging import logging
from debtcollector import renames
from keystoneclient import base from keystoneclient import base
from keystoneclient import exceptions from keystoneclient import exceptions
from keystoneclient.i18n import _, _LW from keystoneclient.i18n import _
from keystoneclient import utils from keystoneclient import utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@@ -45,6 +47,8 @@ class UserManager(base.CrudManager):
msg = _('Specify both a user and a group') msg = _('Specify both a user and a group')
raise exceptions.ValidationError(msg) raise exceptions.ValidationError(msg)
@renames.renamed_kwarg('project', 'default_project', version='1.7.0',
removal_version='2.0.0')
@utils.positional(1, enforcement=utils.positional.WARN) @utils.positional(1, enforcement=utils.positional.WARN)
def create(self, name, domain=None, project=None, password=None, def create(self, name, domain=None, project=None, password=None,
email=None, description=None, enabled=True, email=None, description=None, enabled=True,
@@ -53,14 +57,12 @@ class UserManager(base.CrudManager):
.. warning:: .. warning::
The project argument is deprecated, use default_project instead. The project argument is deprecated as of the 1.7.0 release in favor
of default_project and may be removed in the 2.0.0 release.
If both default_project and project is provided, the default_project If both default_project and project is provided, the default_project
will be used. will be used.
""" """
if project:
LOG.warning(_LW("The project argument is deprecated, "
"use default_project instead."))
default_project_id = base.getid(default_project) or base.getid(project) default_project_id = base.getid(default_project) or base.getid(project)
user_data = base.filter_none(name=name, user_data = base.filter_none(name=name,
domain_id=base.getid(domain), domain_id=base.getid(domain),
@@ -74,6 +76,8 @@ class UserManager(base.CrudManager):
return self._create('/users', {'user': user_data}, 'user', return self._create('/users', {'user': user_data}, 'user',
log=not bool(password)) log=not bool(password))
@renames.renamed_kwarg('project', 'default_project', version='1.7.0',
removal_version='2.0.0')
@utils.positional(enforcement=utils.positional.WARN) @utils.positional(enforcement=utils.positional.WARN)
def list(self, project=None, domain=None, group=None, default_project=None, def list(self, project=None, domain=None, group=None, default_project=None,
**kwargs): **kwargs):
@@ -87,14 +91,12 @@ class UserManager(base.CrudManager):
.. warning:: .. warning::
The project argument is deprecated, use default_project instead. The project argument is deprecated as of the 1.7.0 release in favor
of default_project and may be removed in the 2.0.0 release.
If both default_project and project is provided, the default_project If both default_project and project is provided, the default_project
will be used. will be used.
""" """
if project:
LOG.warning(_LW("The project argument is deprecated, "
"use default_project instead."))
default_project_id = base.getid(default_project) or base.getid(project) default_project_id = base.getid(default_project) or base.getid(project)
if group: if group:
base_url = '/groups/%s' % base.getid(group) base_url = '/groups/%s' % base.getid(group)
@@ -111,6 +113,8 @@ class UserManager(base.CrudManager):
return super(UserManager, self).get( return super(UserManager, self).get(
user_id=base.getid(user)) user_id=base.getid(user))
@renames.renamed_kwarg('project', 'default_project', version='1.7.0',
removal_version='2.0.0')
@utils.positional(enforcement=utils.positional.WARN) @utils.positional(enforcement=utils.positional.WARN)
def update(self, user, name=None, domain=None, project=None, password=None, def update(self, user, name=None, domain=None, project=None, password=None,
email=None, description=None, enabled=None, email=None, description=None, enabled=None,
@@ -119,14 +123,12 @@ class UserManager(base.CrudManager):
.. warning:: .. warning::
The project argument is deprecated, use default_project instead. The project argument is deprecated as of the 1.7.0 release in favor
of default_project and may be removed in the 2.0.0 release.
If both default_project and project is provided, the default_project If both default_project and project is provided, the default_project
will be used. will be used.
""" """
if project:
LOG.warning(_LW("The project argument is deprecated, "
"use default_project instead."))
default_project_id = base.getid(default_project) or base.getid(project) default_project_id = base.getid(default_project) or base.getid(project)
user_data = base.filter_none(name=name, user_data = base.filter_none(name=name,
domain_id=base.getid(domain), domain_id=base.getid(domain),