Fixture

Fixture

Fixtures for writing tests for code using oslo.versionedobjects

Note

This module has several extra dependencies not needed at runtime for production code, and therefore not installed by default. To ensure those dependencies are present for your tests, add oslo.versionedobjects[fixtures] to your list of test dependencies.

class oslo_versionedobjects.fixture.FakeIndirectionAPI(serializer=None)
object_action(context, objinst, objmethod, args, kwargs)
object_backport(context, objinst, target_version)
object_class_action(context, objname, objmethod, objver, args, kwargs)
object_class_action_versions(context, objname, objmethod, object_versions, args, kwargs)
class oslo_versionedobjects.fixture.IndirectionFixture(indirection_api=None)
setUp()
exception oslo_versionedobjects.fixture.ObjectHashMismatch(expected, actual)
class oslo_versionedobjects.fixture.ObjectVersionChecker(obj_classes=defaultdict(<type 'list'>, {}))
get_dependency_tree()
get_hashes(extra_data_func=None)

Return a dict of computed object hashes.

Parameters:extra_data_func – a function that is given the object class which gathers more relevant data about the class that is needed in versioning. Returns a tuple containing the extra data bits.
test_compatibility_routines(use_manifest=False, init_args=None, init_kwargs=None)

Test obj_make_compatible() on all object classes.

Parameters:
  • use_manifest – a boolean that determines if the version manifest should be passed to obj_make_compatible
  • init_args – a dictionary of the format {obj_class: [arg1, arg2]} that will be used to pass arguments to init on the given obj_class. If no args are needed, the obj_class does not need to be added to the dict
  • init_kwargs – a dictionary of the format {obj_class: {‘kwarg1’: val1}} that will be used to pass kwargs to init on the given obj_class. If no kwargs are needed, the obj_class does not need to be added to the dict
test_hashes(expected_hashes, extra_data_func=None)
test_relationships(expected_tree)
test_relationships_in_order()
class oslo_versionedobjects.fixture.StableObjectJsonFixture

Fixture that makes sure we get stable JSON object representations.

Since objects contain things like set(), which can’t be converted to JSON, we have some situations where the representation isn’t fully deterministic. This doesn’t matter at all at runtime, but does to unit tests that try to assert things at a low level.

This fixture mocks the obj_to_primitive() call and makes sure to sort the list of changed fields (which came from a set) before returning it to the caller.

setUp()
class oslo_versionedobjects.fixture.VersionedObjectRegistryFixture

Use a VersionedObjectRegistry as a temp registry pattern fixture.

The pattern solution is to backup the object registry, register a class locally, and then restore the original registry. This could be used for test objects that do not need to be registered permanently but will have calls which lookup registration.

static register(cls_name)
setUp()
oslo_versionedobjects.fixture.compare_obj(test, obj, db_obj, subs=None, allow_missing=None, comparators=None)

Compare a VersionedObject and a dict-like database object.

This automatically converts TZ-aware datetimes and iterates over the fields of the object.

Parameters:
  • test – The TestCase doing the comparison
  • obj – The VersionedObject to examine
  • db_obj – The dict-like database object to use as reference
  • subs – A dict of objkey=dbkey field substitutions
  • allow_missing – A list of fields that may not be in db_obj
  • comparators – Map of comparator functions to use for certain fields

ObjectVersionChecker

Fingerprints

One function of the ObjectVersionChecker is to generate fingerprints of versioned objects. These fingerprints are a combination of the object’s version and a hash of the RPC-critical attributes of the object: fields and remotable methods.

The test_hashes() method is used to retrieve the expected and actual fingerprints of the objects. When using this method to assert the versions of objects in a local project, the expected fingerprints are the fingerprints of the previous state of the objects. These fingerprints are defined locally in the project and passed to test_hashes(). The actual fingerprints are the dynamically-generated fingerprints of the current state of the objects. If the expected and actual fingerprints do not match on an object, this means the RPC contract that was previously defined in the object is no longer the same. Because of this, the object’s version must be updated. When the version is updated and the tests are run again, a new fingerprint for the object is generated. This fingerprint should be written over the previous version of the fingerprint. This shows the newly generated fingerprint is now the most recent state of the object.

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.