diff --git a/releasenotes/notes/bug-2001080-de52ead3c5466792.yaml b/releasenotes/notes/bug-2001080-de52ead3c5466792.yaml new file mode 100644 index 000000000..2b8b3c319 --- /dev/null +++ b/releasenotes/notes/bug-2001080-de52ead3c5466792.yaml @@ -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 `_] + 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. diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index 06879089f..084dc3ffc 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -893,7 +893,7 @@ class OpenStackCloud( domain_id=domain_id) @_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): with _utils.shade_exceptions( "Error in updating project {project}".format( @@ -902,12 +902,10 @@ class OpenStackCloud( if not proj: raise OpenStackCloudException( "Project %s not found." % name_or_id) - - kwargs.update({'enabled': enabled}) + if enabled is not None: + kwargs.update({'enabled': enabled}) # NOTE(samueldmq): Current code only allow updates of description # 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': data = self._identity_client.patch( '/projects/' + proj['id'], json={'project': kwargs}) diff --git a/shade/tests/functional/test_project.py b/shade/tests/functional/test_project.py index 9ffd4150f..25d59e6db 100644 --- a/shade/tests/functional/test_project.py +++ b/shade/tests/functional/test_project.py @@ -67,18 +67,32 @@ class TestProject(base.KeystoneBaseFunctionalTestCase): params = { 'name': project_name, 'description': 'test_update_project', + 'enabled': True } if self.identity_version == '3': params['domain_id'] = \ self.operator_cloud.get_domain('default')['id'] project = self.operator_cloud.create_project(**params) - updated_project = self.operator_cloud.update_project(project_name, - description='new') + updated_project = self.operator_cloud.update_project( + project_name, enabled=False, description='new') self.assertIsNotNone(updated_project) self.assertEqual(project['id'], updated_project['id']) self.assertEqual(project['name'], updated_project['name']) 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): project_name = self.new_project_name + '_delete'