Python >= 3.12 changes the string representation of an OrderedDict
which changes the md5 digest of an object; this causes a regression
on the test_get_hashes unit test on newer Pythons.
Subclass OrderedDict to revert the change in __repr__ in order provide
a represenation which is consistent across all supported Python versions.
Closes-Bug: #2046220
Change-Id: I9b0d9e7b501f3de425bc2c342f25b8ea2248da20
md5 is not an approved algorithm in FIPS mode, and trying to
instantiate a hashlib.md5() will fail when the system is running in
FIPS mode.
md5 is allowed when in a non-security context. There is a plan to
add a keyword parameter (usedforsecurity) to hashlib.md5() to annotate
whether or not the instance is being used in a security context.
In the case where it is not, the instantiation of md5 will be allowed.
See https://bugs.python.org/issue9216 for more details.
Some downstream python versions already support this parameter. To
support these versions, a new encapsulation of md5() has been added to
oslo_utils. See https://review.opendev.org/#/c/750031/
This patch is to replace the instances of hashlib.md5() with this new
encapsulation, adding an annotation indicating whether the usage is
a security context or not.
In this case, md5 is computed as one of the object hashes for the
purposes of object versioning.
Change-Id: Idf36897d690a20d23123950618643d0b9e085f6c
Depends-On: https://review.opendev.org/#/c/760160
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.
Change-Id: I26f2df6d4657133a5c7e6ed85298aa843c1bdd73
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
Python3 has deprecated inspect.getargspec(), which our fixture uses
to provide fingerprinting for remotable methods. Since the hashesh for
those methods are stored in the wild and are used to detect when objects
change in incompatible ways, it is desirable to avoid having to change
all stored hashes when a library adopts the newer method.
This change attempts to use the older spec format when possible to
avoid needless hash changes, and opts for the newer one when necessary
to represent some newer feature. Changing hashes when adding such a feature
to a remotable method is implied anyway, so getting the newer one based
on the newer method is expected.
Change-Id: I84b4ce9c95d6ab86c58f8d797dba28201c1f1668
We no longer need much of the functionality this was providing.
Change-Id: I0f625b714950a712249757906974715358f9e6c6
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
The ObjectVersionChecker fixture is logging object
comparison at INFO which in some tests can blow up
the subunit output stream capture parser (see nova
bug 1813147). This change drops the logging level
to DEBUG which can be enabled using the OS_DEBUG
environment variable found in oslotest.
Change-Id: If20663ecad19f18f22172ae489206b42489fd9f6
Closes-Bug: #1815223
1.As mentioned in [1], we should avoid using
six.iteritems to achieve iterators. We can use
dict.items instead, as it will return iterators
in PY3 as well. And dict.items/keys will more readable.
2.In py2, the performance about list should be negligible,
see the link [2].
[1] https://wiki.openstack.org/wiki/Python3
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html
Change-Id: I6bf760e6f3db50696dc87230c444f9ed493615f0
ObjectVersionChecker.get_hashes() already support extra data collection
for fingerprint generation via the extra_data_func parameter.
However this cannot be used from test_hashes().
Nova versioned notification work depends on this extra data gathering
support. See nova bug #1595575
Change-Id: I7f4d0f37e638de6fcef7211280cedd7d1f09ab74
Closes-Bug: #1595552
When comparing objects to dicts, if a field is unset on both, they
should still be counted as equal. If something is unset on one, but not
on the other, they should be counted as unequal. In any of these
situations, if the field is set in allow_missing, all of the equality
checks should just be skipped.
Change-Id: I3e5143bc872ab4cb645d09c7e969fd1cf9c7985c
Closes-Bug: #1566398
Because some subobjects of VersionedObject my require arguments to be
passed into __init__(), there needs to be a way for the
test_compatibility_routines() fixture to pass required args/kwargs to
init on certain objects. This change adds the ability to pass 2 mappings
to test_compatibility_routines, one for args and one for kwargs.
The key of each mapping is the object class that needs the special init
args. The value in the args dict will be a list of arguments to pass
(becomes *args), and the value in the kwargs dict is a list of kwargs
to pass (becomes **kwargs). If there is no key defined, the default
value of the args dict is [], and the default of kwargs is {}. *[] is
the equivalent of sending no arguments, and **{} is the equivalent of
not sending kwargs.
Change-Id: I62646b99adca47a9c9fe0f466f7a23ac8fa4553e
Related-Bug: #1537882
There is a temp registry pattern [1] where you can 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.
The FakeResource object in patch [2] is such a use case.
This change is to wrap the pattern rather than accessing
oslo.versionedobjects library internals.
[1] https://review.openstack.org/#/c/243826/4/cinder/test.py
[2] https://review.openstack.org/#/c/258026/
Change-Id: I02036becb32f8d3d11170c71e14e0a2db55d1f76
Nova has a copy of compare_obj and Cinder needs to start using the
same thing, so move compare_obj to the fixture module so other projects
that are already using oslo.versionedobjects fixtures can re-use this.
The if check at the beginning of the function was changed over because
one of the unit tests uncovered a case with undesirable failing.
Co-Authored-By: Ryan Rossiter <rlrossit@us.ibm.com>
Change-Id: I0bcfa7d4f501bd69b6343e4d719e98eb32a5a5cd
The original test_compatibility_routines() only called
obj_to_primitive() without the version manifest, which means the fixture
could not be used to test compatibility routines on manifest backports.
This adds a kwarg to test_compatibility_routines() that allows users to
specify if they want to use the version manifest in the calls to
obj_to_primitive().
Change-Id: I1ef6eed1c79a2f2fc8967518a8a3d09e89ab64e3
ObjectVersionChecker gathers a group of relevant data with which it then
generates a fingerprint. This change adds a callable to get_hashes() to
provide the object class, which the callable can then use to gather more
data upon which it wants the fingerprint to be generated. This allows
end users to version on more than just fields and methods.
Change-Id: Ibbaaf926d50693ed0ddd96132542830dba75a285
Rather than always installing dependencies for the test tools included
in the library, define an extras called "test" and include the
dependencies there.
Add API documentation for the fixture module, and include notes about
installing the extra dependencies in the module documentation and
installation instructions.
Closes-Bug: #1440350
Depends-On: I78838dcd4da43b3c1d2610ac87a3ec55b9535646
Depends-On: Ibd2410e0153053b5121155474e99752256c7e4b8
Change-Id: I4e45c1bb4f08c9da510939514c5358e1575d3e0a
We need to sort the version dictionary to ensure py27
and py34 generate the same fingerprint.
Depends-On: I0f07858e96ea3baf46f8a453e253b9ed29c7f7e2
Depends-On: I33bd2d9dff9cb7dc1a50177db7286b7317966784
Change-Id: I0adc3d696c90dfe20d35bdf06f033eb3a2491fd0
ObjectVersionChecker just needs a list of classes, we don't need
to check the base.VersionedObjectRegistry everytime, so just
initialize the list of classes in the constructor and default
it to the base.VersionedObjectRegistry to get the current
behavior. Will make it easy to run ObjectVersionChecker against
custom registries.
Change-Id: I700daa278473dff5285e0b21afffc03671e390f9
The fixture was just serializing and deserializing method arguments
with JSON, but this is not indicative of what actually happens in
a real project (like nova) where arguments can be objects.
Change-Id: I299983a2e345a2b8075038553c6a4dd77d3fd5e8
This makes it easier to ensure that you're using the same indirection
or serialization routines in tests as you are in production.
Change-Id: I4530ba5781ad81ad4a6b4af466af348551c3c3e4
This renamed the "checks" module to be in line with other oslo libraries,
and adds fixtures and mock to the list of requirements, since they are
required for actual library code.
Change-Id: I782762d5cd4166893593e172f49fda8ab35e478d