ironic/ironic/tests/unit/objects
Mark Goddard be94e64b91 Support nested objects and object lists in as_dict
The value returned by ironic.objects.IronicObject.as_dict() should be a
plain object, in order for it to be serialised to JSON. Currently,
nested object fields and object list fields are not converted to dict
format. This caused problems during cleaning, when the node object's
as_dict representation is JSON encoded and sent to IPA.

This change adds support for calling as_dict() on nested objects and
list objects, to ensure these are also returned in dict form.

We also change the method used in as_dict() for checking whether an
object has an attribute. The hasattr() function used previously has
problems when used with properties in python 2 [1], in that any
exceptions raised in the property getter result in hasattr() returning
False. Instead we use obj_attr_is_set() to determine whether the object
has a particular attribute.

[1] https://hynek.me/articles/hasattr/

Change-Id: Ib2166040508827db28d6f6e2d9a3e655c16f2993
Closes-Bug: #1750027
(cherry picked from commit c66679f14b)
2018-02-22 09:41:51 +00:00
..
__init__.py Prepare for functional testing 2015-09-28 21:27:01 +00:00
test_chassis.py Unit test consistency: DB base and utils prefix 2017-06-20 09:36:21 +01:00
test_conductor.py Add missing 'autospec' to unit tests - /unit/objects/ 2017-11-09 09:28:10 -08:00
test_fields.py Add power state change notifications 2016-10-17 15:39:18 +00:00
test_node.py Support nested objects and object lists in as_dict 2018-02-22 09:41:51 +00:00
test_notification.py Add missing 'autospec' to unit tests - /unit/objects/ 2017-11-09 09:28:10 -08:00
test_objects.py Support nested objects and object lists in as_dict 2018-02-22 09:41:51 +00:00
test_port.py Add missing 'autospec' to unit tests - /unit/objects/ 2017-11-09 09:28:10 -08:00
test_portgroup.py Unit test consistency: DB base and utils prefix 2017-06-20 09:36:21 +01:00
test_trait.py Support nested objects and object lists in as_dict 2018-02-22 09:41:51 +00:00
test_volume_connector.py Add missing 'autospec' to unit tests - /unit/objects/ 2017-11-09 09:28:10 -08:00
test_volume_target.py Add missing 'autospec' to unit tests - /unit/objects/ 2017-11-09 09:28:10 -08:00
utils.py Add RPC object for traits 2018-01-23 22:58:59 +00:00