diff --git a/ironic/api/controllers/v1/portgroup.py b/ironic/api/controllers/v1/portgroup.py index 732d55600c..916ddee96a 100644 --- a/ironic/api/controllers/v1/portgroup.py +++ b/ironic/api/controllers/v1/portgroup.py @@ -188,6 +188,7 @@ class Portgroup(base.APIBase): class PortgroupPatchType(types.JsonPatchType): _api_base = Portgroup + _extra_non_removable_attrs = {'/mode'} @staticmethod def internal_attrs(): diff --git a/ironic/tests/unit/api/v1/test_portgroups.py b/ironic/tests/unit/api/v1/test_portgroups.py index 1e4b1dc2f3..b80a002297 100644 --- a/ironic/tests/unit/api/v1/test_portgroups.py +++ b/ironic/tests/unit/api/v1/test_portgroups.py @@ -852,10 +852,21 @@ class TestPatch(test_api_base.BaseApiTest): def test_update_portgroup_mode_properties_bad_api_version(self, mock_upd): self._test_update_portgroup_mode_properties_bad_api_version( - [{'path': '/mode', 'op': 'remove'}], mock_upd) + [{'path': '/mode', 'op': 'add', 'value': '802.3ad'}], mock_upd) self._test_update_portgroup_mode_properties_bad_api_version( [{'path': '/properties/abc', 'op': 'add', 'value': 123}], mock_upd) + def test_remove_mode_not_allowed(self, mock_upd): + response = self.patch_json('/portgroups/%s' % self.portgroup.uuid, + [{'path': '/mode', + 'op': 'remove'}], + expect_errors=True, + headers=self.headers) + self.assertEqual(http_client.BAD_REQUEST, response.status_int) + self.assertEqual('application/json', response.content_type) + self.assertTrue(response.json['error_message']) + self.assertFalse(mock_upd.called) + class TestPost(test_api_base.BaseApiTest): headers = {api_base.Version.string: str(api_v1.MAX_VER)} diff --git a/releasenotes/notes/add-portgroup-config-fields-cd21e35e9c210733.yaml b/releasenotes/notes/add-portgroup-config-fields-cd21e35e9c210733.yaml index 48815f92d1..578b114d99 100644 --- a/releasenotes/notes/add-portgroup-config-fields-cd21e35e9c210733.yaml +++ b/releasenotes/notes/add-portgroup-config-fields-cd21e35e9c210733.yaml @@ -1,8 +1,9 @@ --- features: - Adds ``mode`` and ``properties`` fields in the portgroup object. Both of - them are optional and can be set from the API. They are available starting - with API microversion 1.26. If the ``mode`` field of a portgroup is not + them are optional and can be set from the API, though it is forbidden to + remove the ``mode`` from the portgroup. They are available starting with + API microversion 1.26. If the ``mode`` field of a portgroup is not specified in a POST request, its value will be set to the value of the configuration option ``[DEFAULT]default_portgroup_mode``. The configuration option ``[DEFAULT]default_portgroup_mode`` has a value of ``active-backup``