nova.test.SubclassSignatureTestCase no longer works

Bug #2019772 reported by melanie witt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Undecided
melanie witt

Bug Description

I found this the hard way while working on a patch that added a keyword argument to the signature of nova.virt.libvirt.volume.LibvirtBaseVolumeDriver.disconnect_volume.

I had missed updating some of the volume drivers and LibvirtBaseVolumeDriverSubclassSignatureTestCase.test_signatures should have caught it ... but it didn't because it was not actually checking any signatures.

After some digging, I found that SubclassSignatureTestCase has not worked properly since we dropped support for python 2.7. The reason is the use of the inspect.ismethod() function; in python 2.7
it returned true if the object was a bound or an unbound method [2] but as of python 3, it only returns true if the object is a bound method [2].

So in this code [3]:

        # the base class. It's redundant for us to test these, but as
        # they'll always pass it's not worth the complexity to filter them out.
        for (name, method) in inspect.getmembers(cls, inspect.ismethod):

inspect.getmembers(cls, inspect.ismethod) never returns any methods because none of them are bound.

As of python 3, we need to use inspect.isfunction() instead.

[1] https://docs.python.org/2.7/library/inspect.html#inspect.ismethod
[2] https://docs.python.org/3.5/library/inspect.html#inspect.ismethod
[3] https://github.com/openstack/nova/blob/b3fdd7c/nova/test.py#L718

Tags: testing
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/nova/+/883217

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.opendev.org/c/openstack/nova/+/883217
Committed: https://opendev.org/openstack/nova/commit/091e3ea8fd3541e0edb98e31f9484cc08b0e5413
Submitter: "Zuul (22348)"
Branch: master

commit 091e3ea8fd3541e0edb98e31f9484cc08b0e5413
Author: melanie witt <email address hidden>
Date: Tue May 16 01:34:00 2023 +0000

    testing: Use inspect.isfunction() to check signatures

    We recently discovered that nova.test.SubclassSignatureTestCase has not
    worked properly since support for python 2.7 was dropped.

    The reason is the use of the inspect.ismethod() function; in python 2.7
    it returned true if the object was a bound or an unbound method [2] but
    as of python 3, it only returns true if the object is a bound method
    [2].

    Because of this, LibvirtBaseVolumeDriverSubclassSignatureTestCase was
    not actually checking any signatures.

    This replaces the use of inspect.ismethod() with inspect.isfunction()
    to fix the issue.

    It also adds a skip for subclass private functions as these are
    expected to be different among subclasses.

    One subclass method signature caught by the test is also updated to
    match the base class.

    [1] https://docs.python.org/2.7/library/inspect.html#inspect.ismethod
    [2] https://docs.python.org/3.5/library/inspect.html#inspect.ismethod

    Closes-Bug: #2019772

    Change-Id: I5644effac7206035de77e0d1cd450a9fb96c3a0d

Changed in nova:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 29.0.0.0rc1

This issue was fixed in the openstack/nova 29.0.0.0rc1 release candidate.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.