From c803488af21e638bd83f522949608f27a5f1b85a Mon Sep 17 00:00:00 2001 From: Jim Rollenhagen Date: Tue, 5 Feb 2019 16:16:57 -0500 Subject: [PATCH] Allow case-insensitivity when setting conductor_group via API Since we use the new conductor group to calculate which conductor an update_node message should go to, we need to lowercase the new conductor_group value at the API level, rather than just before saving the node object. Change-Id: I5530f8e1c2fdff9008e008cfa0c63edaa04e81d9 Story: 2004947 Task: 29362 --- ironic/api/controllers/v1/node.py | 5 +++++ ironic/tests/unit/api/controllers/v1/test_node.py | 13 +++++++++++++ .../notes/bug-2004947-e5f27e11b8f9c96d.yaml | 6 ++++++ 3 files changed, 24 insertions(+) create mode 100644 releasenotes/notes/bug-2004947-e5f27e11b8f9c96d.yaml diff --git a/ironic/api/controllers/v1/node.py b/ironic/api/controllers/v1/node.py index ef98ac988d..5e3495e74f 100644 --- a/ironic/api/controllers/v1/node.py +++ b/ironic/api/controllers/v1/node.py @@ -1738,6 +1738,11 @@ class NodesController(rest.RestController): continue if patch_val == wtypes.Unset: patch_val = None + # conductor_group is case-insensitive, and we use it to calculate + # the conductor to send an update too. lowercase it here instead + # of just before saving so we calculate correctly. + if field == 'conductor_group': + patch_val = patch_val.lower() if rpc_node[field] != patch_val: rpc_node[field] = patch_val diff --git a/ironic/tests/unit/api/controllers/v1/test_node.py b/ironic/tests/unit/api/controllers/v1/test_node.py index f5b717710c..a090bd6ea8 100644 --- a/ironic/tests/unit/api/controllers/v1/test_node.py +++ b/ironic/tests/unit/api/controllers/v1/test_node.py @@ -2267,6 +2267,19 @@ class TestPatch(test_api_base.BaseApiTest): self.assertEqual(http_client.NOT_ACCEPTABLE, response.status_code) self.assertTrue(response.json['error_message']) + @mock.patch('pecan.request') + def test__update_changed_fields_lowers_conductor_group(self, + mock_pecan_req): + mock_pecan_req.version.minor = versions.MINOR_MAX_VERSION + controller = api_node.NodesController() + + node_dict = self.node.as_dict() + node_dict['conductor_group'] = 'NEW-GROUP' + node_obj = api_node.Node(**node_dict) + + controller._update_changed_fields(node_obj, self.node) + self.assertEqual('new-group', self.node.conductor_group) + @mock.patch("pecan.request") def test__update_changed_fields_remove_chassis_uuid(self, mock_pecan_req): mock_pecan_req.version.minor = versions.MINOR_MAX_VERSION diff --git a/releasenotes/notes/bug-2004947-e5f27e11b8f9c96d.yaml b/releasenotes/notes/bug-2004947-e5f27e11b8f9c96d.yaml new file mode 100644 index 0000000000..4af981224d --- /dev/null +++ b/releasenotes/notes/bug-2004947-e5f27e11b8f9c96d.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes an issue where setting the ``conductor_group`` for a node was not + entirely case-sensitive, in that this could fail if case-sensitivity did + not match between the conductor configuration and the API request.