← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 2019772] Re: nova.test.SubclassSignatureTestCase no longer works

 

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 <melwittt@xxxxxxxxx>
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

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Compute (nova).
https://bugs.launchpad.net/bugs/2019772

Title:
  nova.test.SubclassSignatureTestCase no longer works

Status in OpenStack Compute (nova):
  Fix Released

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

To manage notifications about this bug go to:
https://bugs.launchpad.net/nova/+bug/2019772/+subscriptions



References