Do not use asserts with business logic

a piece of code in node object was relying on result of 'assert'
to block negative values of properties.

When running Python in optimized mode (-OO) this assert will be
swallowed and negative values may slip through.

Replace this line with proper if-block.

Change-Id: Iec1edc55219cfd6c54afa52c1ecd0cf76340bddf
This commit is contained in:
Pavlo Shchelokovskyy 2018-01-29 19:44:11 +02:00
parent 180234b445
commit a61ee9429a
1 changed files with 3 additions and 2 deletions

View File

@ -148,8 +148,9 @@ class Node(base.IronicObject, object_base.VersionedObjectDictCompat):
continue
try:
int_value = int(value)
assert int_value >= 0
except (ValueError, AssertionError):
if int_value < 0:
raise ValueError("Value must be non-negative")
except (ValueError, TypeError):
msg = (('%(param)s=%(value)s') %
{'param': param, 'value': value})
invalid_msgs_list.append(msg)