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
This commit is contained in:
Steve Baker 2020-09-29 16:13:37 +13:00 committed by Dmitry Tantsur
parent fb90ed41fe
commit a1c5559fae
2 changed files with 8 additions and 0 deletions

View File

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

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Fixes HTTP 500 when trying to unset the ``protected`` attribute via
the CLI.