nova.tests.unit.console.test_websocketproxy. NovaProxyRequestHandlerTestCase.test_tcp_rst_no_compute_rpcapi fails with mock==4.0.2

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

Bug Description

Seen in a proposed patch to update upper-constraints in openstack/requirements [1]:

nova.tests.unit.console.test_websocketproxy.NovaProxyRequestHandlerTestCase.test_tcp_rst_no_compute_rpcapitesttools.testresult.real._StringException: pythonlogging:'': {{{
2020-07-15 21:09:49,927 INFO [nova.console.websocketproxy] WebSocket server settings:
2020-07-15 21:09:49,928 INFO [nova.console.websocketproxy] - Listen on :None
2020-07-15 21:09:49,928 INFO [nova.console.websocketproxy] - SSL/TLS support
2020-07-15 21:09:49,932 INFO [nova.console.websocketproxy] handler exception: Expected int or long, got <class 'mock.mock.MagicMock'>
}}}

Traceback (most recent call last):
  File "/home/zuul/src/opendev.org/openstack/nova/nova/tests/unit/console/test_websocketproxy.py", line 627, in test_tcp_rst_no_compute_rpcapi
    self.assertIsNone(self.wh._compute_rpcapi)
  File "/home/zuul/src/opendev.org/openstack/nova/.tox/py36/lib/python3.6/site-packages/testtools/testcase.py", line 430, in assertIsNone
    self.assertThat(observed, matcher, message)
  File "/home/zuul/src/opendev.org/openstack/nova/.tox/py36/lib/python3.6/site-packages/testtools/testcase.py", line 502, in assertThat
    raise mismatch_error
testtools.matchers._impl.MismatchError: <nova.compute.rpcapi.ComputeAPI object at 0x7ff4113810f0> is not None

I did some print()ing locally and found that what's happening here is that the mock library's own process for create_autospec is calling the NovaProxyRequestHandler class's compute_rpcapi @property directly and causing us to create the nova.compute.rpcapi.ComputeAPI object even though none of the nova code is touching it.

This bug has actually been brought up before as an issue in the mock library repo [2] and is likely a bug in mock.

The mock library is minimally maintained AFAIK and the community has desired to move away from it. Based on this, I think instead of working around the bug in nova or potentially blacklisting mock==4.0.2 (since nova is the only project failing with its use at this point), it might best to fix the issue by using unittest.mock from the python standard library instead, in test_websocketproxy.py.

[1] https://review.opendev.org/741091
[2] https://github.com/testing-cabal/mock/issues/487

Tags: testing
melanie witt (melwitt)
summary: - nova.tests.unit.console.test_websocketproxy.NovaProxyRequestHandlerTestCase.test_tcp_rst_no_compute_rpcapi
- fails with mock==4.0.2
+ nova.tests.unit.console.test_websocketproxy.
+ NovaProxyRequestHandlerTestCase.test_tcp_rst_no_compute_rpcapi fails
+ with mock==4.0.2
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/741351

Changed in nova:
status: New → In Progress
Revision history for this message
melanie witt (melwitt) wrote :

> This bug has actually been brought up before as an issue in the mock library repo [2] and is likely a bug in mock.

Correction: this does not seem to be a bug in mock -- same thing is happening in the python3.8 version of unittest.mock.

Back to the drawing board.

Revision history for this message
melanie witt (melwitt) wrote :

This is the format_stack() output when the @property is called by the mock itself in python3.8. It does not happen with python3.6:

File "/home/vagrant/nova/nova/tests/unit/console/test_websocketproxy.py", line 138, in setUp
    self.wh = websocketproxy.NovaProxyRequestHandler()
File "/home/vagrant/nova/nova/console/websocketproxy.py", line 100, in __init__
    websockify.ProxyRequestHandler.__init__(self, *args, **kwargs)
File "/home/vagrant/nova/.tox/py38/lib/python3.8/site-packages/oslotest/mock_fixture.py", line 46, in __init__
    super(_AutospecMockMixin, self).__init__(*args, **kwargs)
File "/usr/lib/python3.8/unittest/mock.py", line 2018, in __init__
    _safe_super(MagicMixin, self).__init__(*args, **kw)
File "/usr/lib/python3.8/unittest/mock.py", line 1057, in __init__
    _safe_super(CallableMixin, self).__init__(
File "/usr/lib/python3.8/unittest/mock.py", line 442, in __init__
    self._mock_add_spec(spec, spec_set, _spec_as_instance, _eat_self)
File "/usr/lib/python3.8/unittest/mock.py", line 497, in _mock_add_spec
    if asyncio.iscoroutinefunction(getattr(spec, attr, None)):
File "/home/vagrant/nova/nova/console/websocketproxy.py", line 106, in compute_rpcapi
    for line in traceback.format_stack():

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on nova (master)

Change abandoned by melanie witt (<email address hidden>) on branch: master
Review: https://review.opendev.org/741351
Reason: This unit test is prevented from working properly because of a bug in python 3.8 where mock speccing is calling class properties:

https://bugs.python.org/issue41768

Abandoning this in favor of the following change which [temporarily] removes the test:

https://review.opendev.org/714676

The only other way to potentially make the test work is if there's a way we could disable use of the MockAutoSpecFixture [1] only for the one test until if/when the python 3.8 bug is fixed.

[1] https://github.com/openstack/nova/blob/3dbb6c18a58ce42ea515b8ca71e69b0b438ef268/nova/test.py#L273

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 23.0.0.0rc1

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

Revision history for this message
melanie witt (melwitt) wrote :
Changed in nova:
status: In Progress → Fix Released
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.