Follow up patch for 8c3e102fc5

This patch is a follow up patch fixing some nits left by the review
8c3e102fc5.

This patch:

1) Removes the duplicated conditional testing if the variable properties
is set

2) Uses a valid regex to test the error message raised by one of the
tests

Change-Id: I52efa7643057ece4329f21d3bd214075a4dd8f16
This commit is contained in:
Lucas Alvares Gomes 2015-11-10 10:26:57 +00:00
parent 8c3e102fc5
commit 8a16f2ad6e
2 changed files with 3 additions and 12 deletions

View File

@ -298,9 +298,7 @@ class Node(base.IronicObject, object_base.VersionedObjectDictCompat):
:raises: InvalidParameterValue if some property values are invalid.
"""
values = self.obj_get_changes()
properties = values.get('properties')
if properties:
self._validate_property_values(properties)
self._validate_property_values(values.get('properties'))
db_node = self.dbapi.create_node(values)
self._from_db_object(self, db_node)
@ -342,9 +340,7 @@ class Node(base.IronicObject, object_base.VersionedObjectDictCompat):
:raises: InvalidParameterValue if some property values are invalid.
"""
updates = self.obj_get_changes()
properties = updates.get('properties')
if properties:
self._validate_property_values(properties)
self._validate_property_values(updates.get('properties'))
if 'driver' in updates and 'driver_internal_info' not in updates:
# Clean driver_internal_info when changes driver
self.driver_internal_info = {}

View File

@ -163,13 +163,8 @@ class TestNodeObject(base.DbTestCase):
node = objects.Node.get(self.context, uuid)
node.properties = {"local_gb": "5G", "memory_mb": "5",
'cpus': '-1', 'cpu_arch': 'x86_64'}
expected_error_message = (
('The following properties for node %(node_uuid)s '
'should be non-negative integers, but provided values '
'are: local_gb=5G, cpus=-1') %
{'node_uuid': uuid})
self.assertRaisesRegexp(exception.InvalidParameterValue,
expected_error_message, node.save)
".*local_gb=5G, cpus=-1$", node.save)
mock_get_node.assert_called_once_with(uuid)
def test__validate_property_values_success(self):