From a1c5559fae6b7b0cddfe7c34e9a831d34464a189 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Tue, 29 Sep 2020 16:13:37 +1300 Subject: [PATCH] Handle patching node /protected value with None Calling baremetal node unset --protected will attempt to set the protected attribute to None, which raises a 500 error because the object attribute is not nullable[1]. This change checks for this case in the patch call and sets protected to False. This appears to be the only boolean attribute affected by this issue (node, port, and portgroup boolean attributes were checked). [1] https://opendev.org/openstack/ironic/src/branch/master/ironic/objects/node.py#L146 Change-Id: I561e059218a99154e77df075aeadd68f56b86267 Story: 2008205 Task: 40989 --- ironic/api/controllers/v1/node.py | 3 +++ releasenotes/notes/protected-unset-0620b844afbb635e.yaml | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 releasenotes/notes/protected-unset-0620b844afbb635e.yaml diff --git a/ironic/api/controllers/v1/node.py b/ironic/api/controllers/v1/node.py index cba7a4e5cc..46c02521d4 100644 --- a/ironic/api/controllers/v1/node.py +++ b/ironic/api/controllers/v1/node.py @@ -1988,6 +1988,9 @@ class NodesController(rest.RestController): # of just before saving so we calculate correctly. if field == 'conductor_group': patch_val = patch_val.lower() + # Node object protected field is not nullable + if field == 'protected' and patch_val is None: + patch_val = False if rpc_node[field] != patch_val: rpc_node[field] = patch_val diff --git a/releasenotes/notes/protected-unset-0620b844afbb635e.yaml b/releasenotes/notes/protected-unset-0620b844afbb635e.yaml new file mode 100644 index 0000000000..f516a5c0e2 --- /dev/null +++ b/releasenotes/notes/protected-unset-0620b844afbb635e.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixes HTTP 500 when trying to unset the ``protected`` attribute via + the CLI.