Browse Source

Forbid removing portgroup mode

Mode can be left empty on creation, the value will be populated by
the dbapi, but in case of updates, we should not allow removing it.

Partial-Bug: #1618754
Change-Id: I917b23bc155972b777b143d16545a49039604910
tags/7.0.0
Vladyslav Drok 3 years ago
parent
commit
ef818b7a31
3 changed files with 16 additions and 3 deletions
  1. +1
    -0
      ironic/api/controllers/v1/portgroup.py
  2. +12
    -1
      ironic/tests/unit/api/v1/test_portgroups.py
  3. +3
    -2
      releasenotes/notes/add-portgroup-config-fields-cd21e35e9c210733.yaml

+ 1
- 0
ironic/api/controllers/v1/portgroup.py View File

@@ -188,6 +188,7 @@ class Portgroup(base.APIBase):
class PortgroupPatchType(types.JsonPatchType):

_api_base = Portgroup
_extra_non_removable_attrs = {'/mode'}

@staticmethod
def internal_attrs():


+ 12
- 1
ironic/tests/unit/api/v1/test_portgroups.py View File

@@ -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)}


+ 3
- 2
releasenotes/notes/add-portgroup-config-fields-cd21e35e9c210733.yaml View File

@@ -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``


Loading…
Cancel
Save