27 Commits

Author SHA1 Message Date
James Page
fe10f4559b fixture: Drop use of OrderedDict for Python compat
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
2024-10-02 19:07:49 +09:00
Ade Lee
9f0f31eb8b Replace md5 with oslo version
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
2020-10-29 13:30:07 -04:00
Sean McGinnis
4d2310b2a9
Use unittest.mock instead of third party mock
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>
2020-03-31 15:56:19 -05:00
Dan Smith
c1933306dd Provide stable getargspec() behavior for method fingerprinting
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
2020-02-07 10:37:24 -08:00
Stephen Finucane
da7cd17a2b Drop use of six
We no longer need much of the functionality this was providing.

Change-Id: I0f625b714950a712249757906974715358f9e6c6
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2020-02-07 10:35:08 -08:00
ZhijunWei
e2f25b563e Update hacking version
Use latest release 1.1.0 and compatible changes w.r.t pep8

Change-Id: Ie245c376f126b885dcf8e9bb250355f98613a6a4
2019-02-17 11:24:12 +08:00
Matt Riedemann
1fbd1b557a Lower ObjectVersionChecker logging to DEBUG level
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
2019-02-08 12:32:53 -05:00
ChangBo Guo(gcb)
16a6db4e9e Add bandit to pep8 job
Add the bandit security scanner to the pep8 job.
* convert assert statement to raise AssertionError
* skip B303

Change-Id: I0eb83dd6de80090562dd43bca4e5eb4e88e27bf9
2017-12-26 18:56:35 +08:00
gecong1973
49f5a9b00a Replace six.iteritems() with .items()
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
2016-12-12 13:30:37 +08:00
Balazs Gibizer
cf28125447 Extend test_hashes to allow extra info gathering
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
2016-06-23 16:37:16 +02:00
Jenkins
4af33ee76a Merge "Fix compare_obj() to obey missing/unset fields" 2016-05-19 19:02:10 +00:00
Ihar Hrachyshka
85dcf71f22 Introduce fixture to enforce sorted order for object changes
In unit tests, sometimes you want to compare that JSON representation of
an object is identical to a JSON blob. Sadly, it may not work for
objects with changes made, since those changes are represented in the
object as a set, and hence end up in unstable order in JSON blobs.

To facilitate smooth object representation comparison for objects using
__eq__, this fixture enforces sorting for object changes.

Note: this code is directly ripped from Nova tree, with tiny
modifications:

https://git.openstack.org/cgit/openstack/nova/tree/nova/tests/fixtures.py?id=dd36b6474ee9d70636fd4bc5f30237de2151fc45#n571
https://git.openstack.org/cgit/openstack/nova/tree/nova/tests/unit/test_fixtures.py?id=dd36b6474ee9d70636fd4bc5f30237de2151fc45#n425

Co-Authored-By: Dan Smith <dansmith@redhat.com>
Change-Id: Ib24eea4af863078d39f8969a7890b5d9d2e11405
Closes-Bug: #1552676
2016-04-15 08:50:12 +02:00
Ryan Rossiter
52545273d9 Fix compare_obj() to obey missing/unset fields
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
2016-04-11 14:11:20 +00:00
Ryan Rossiter
905799e580 Add ability to pass args/kwargs to obj_class init
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
2016-01-26 16:49:06 +00:00
Martin Hickey
37005c310e Add temporary registry pattern to VersionedObjectRegistry
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
2016-01-22 11:07:32 +00:00
Matt Riedemann
bca1f6059b Move compare_obj to the fixture module for external consumption
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
2016-01-15 22:28:24 +00:00
Ryan Rossiter
442ddcaeab Added checking compat using manifest backports
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
2015-12-16 15:24:31 +00:00
Jenkins
af5954e479 Merge "Use version convert methods from oslo_utils.versionutils" 2015-12-09 10:48:51 +00:00
Ryan Rossiter
b881872086 Add a callable to gather extra data for fps
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
2015-12-02 20:05:23 +00:00
ChangBo Guo(gcb)
a9752e281a Use version convert methods from oslo_utils.versionutils
oslo_utils provide version convert methods in versionutis[1],
these methods work well on Python 2.7 and Python 3.4,
so don't need maintain them.

[1]https://github.com/openstack/oslo.utils/blob/master/oslo_utils/versionutils.py

Change-Id: Ifc4b7f5c7e42bce9f5bbf8a961fd32506cca98eb
2015-12-01 00:26:55 +08:00
Dan Smith
c85f3bb785 Make tests properly use object_class_action_versions()
This also includes a new test to validate that the fallback behavior
still works.

Change-Id: Id85cbd837774a8fe8ec4f0631f57c3421cef54e4
2015-10-20 11:18:56 -07:00
Doug Hellmann
3f9f2e1199 Move fixture dependencies to extras
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
2015-07-12 18:08:01 +00:00
Davanum Srinivas
adb66403bd Sort child versions before generating fingerprint
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
2015-07-06 18:01:25 +00:00
Davanum Srinivas
4f1007a661 Decouple ObjectVersionChecker and VersionedObjectRegistry
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
2015-06-11 07:07:42 -04:00
Dan Smith
4201a4f980 Properly serialize/deserialize arguments in fake indirection api
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
2015-02-26 15:26:49 -08:00
Dan Smith
0b4668f90c Allow passing serializer and indirection API objects to Fixture
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
2015-02-26 14:37:42 -08:00
Dan Smith
1ac8ac9f9f Rename checks to fixture and update requirements
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
2015-02-19 07:24:07 -08:00