Project update to change enabled only when provided

The project update call considers enabled=True as the default, causing
the project to always become enabled unless enabled=False is passed
explicitly.

This patch removes that default and only touches the enable field when
it is explicitly provided as enabled=False or enabled=True.

Closes-Bug: #2001080

Change-Id: I0a3b926b42be0321d06ebc370e4f51eba4150a50
This commit is contained in:
Samuel de Medeiros Queiroz 2017-06-23 10:48:51 -04:00
parent baaf415567
commit f4668b7c6f
3 changed files with 29 additions and 7 deletions

View File

@ -0,0 +1,10 @@
---
prelude: >
Fixed a bug where a project was always enabled upon update, unless
``enabled=False`` is passed explicitly.
fixes:
- |
[`bug 2001080 <https://storyboard.openstack.org/#!/story/2001080>`_]
Project update will only update the enabled field of projects when
``enabled=True`` or ``enabled=False`` is passed explicitly. The previous
behavior had ``enabled=True`` as the default.

View File

@ -893,7 +893,7 @@ class OpenStackCloud(
domain_id=domain_id) domain_id=domain_id)
@_utils.valid_kwargs('description') @_utils.valid_kwargs('description')
def update_project(self, name_or_id, enabled=True, domain_id=None, def update_project(self, name_or_id, enabled=None, domain_id=None,
**kwargs): **kwargs):
with _utils.shade_exceptions( with _utils.shade_exceptions(
"Error in updating project {project}".format( "Error in updating project {project}".format(
@ -902,12 +902,10 @@ class OpenStackCloud(
if not proj: if not proj:
raise OpenStackCloudException( raise OpenStackCloudException(
"Project %s not found." % name_or_id) "Project %s not found." % name_or_id)
if enabled is not None:
kwargs.update({'enabled': enabled}) kwargs.update({'enabled': enabled})
# NOTE(samueldmq): Current code only allow updates of description # NOTE(samueldmq): Current code only allow updates of description
# or enabled fields. # or enabled fields.
# FIXME(samueldmq): enable=True is the default, meaning it will
# enable a disabled project if you simply update other fields
if self.cloud_config.get_api_version('identity') == '3': if self.cloud_config.get_api_version('identity') == '3':
data = self._identity_client.patch( data = self._identity_client.patch(
'/projects/' + proj['id'], json={'project': kwargs}) '/projects/' + proj['id'], json={'project': kwargs})

View File

@ -67,18 +67,32 @@ class TestProject(base.KeystoneBaseFunctionalTestCase):
params = { params = {
'name': project_name, 'name': project_name,
'description': 'test_update_project', 'description': 'test_update_project',
'enabled': True
} }
if self.identity_version == '3': if self.identity_version == '3':
params['domain_id'] = \ params['domain_id'] = \
self.operator_cloud.get_domain('default')['id'] self.operator_cloud.get_domain('default')['id']
project = self.operator_cloud.create_project(**params) project = self.operator_cloud.create_project(**params)
updated_project = self.operator_cloud.update_project(project_name, updated_project = self.operator_cloud.update_project(
description='new') project_name, enabled=False, description='new')
self.assertIsNotNone(updated_project) self.assertIsNotNone(updated_project)
self.assertEqual(project['id'], updated_project['id']) self.assertEqual(project['id'], updated_project['id'])
self.assertEqual(project['name'], updated_project['name']) self.assertEqual(project['name'], updated_project['name'])
self.assertEqual(updated_project['description'], 'new') self.assertEqual(updated_project['description'], 'new')
self.assertTrue(project['enabled'])
self.assertFalse(updated_project['enabled'])
# Revert the description and verify the project is still disabled
updated_project = self.operator_cloud.update_project(
project_name, description=params['description'])
self.assertIsNotNone(updated_project)
self.assertEqual(project['id'], updated_project['id'])
self.assertEqual(project['name'], updated_project['name'])
self.assertEqual(project['description'],
updated_project['description'])
self.assertTrue(project['enabled'])
self.assertFalse(updated_project['enabled'])
def test_delete_project(self): def test_delete_project(self):
project_name = self.new_project_name + '_delete' project_name = self.new_project_name + '_delete'