not mocking openstacksdk exception may cause random non detected errors in unit tests

Bug #1848147 reported by Riccardo Pittau
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Low
Riccardo Pittau

Bug Description

Recently added change to ironic notifier plugin migrated the client connection from ironicclient to openstacksdk. The change in the unit tests didn't take into consideration that the openstacksdk exceptions method raise_from_response evaluates the response code as int and this may cause random errors bypassed during tests.
An example can be seen here:
https://zuul.opendev.org/t/openstack/build/943c3f89519c44a58e0b5c86ad4efff8/log/job-output.txt#23782-23789

Important note:
this bug doesn't affect any operational part of the code but just the unit tests.

Tags: unittest
Revision history for this message
Riccardo Pittau (rpittau) wrote :

adding the text of the error to the bug to preserve it for posterity

2019-10-11 16:02:02.469156 | ubuntu-bionic | Disabling service 'placement': Encountered an exception attempting to process config for project 'placement' (service type 'placement'): module 'keystoneauth1.loading.adapter' has no attribute 'process_conf_options'

2019-10-11 16:02:02.471256 | ubuntu-bionic | Error encountered posting the event to ironic. '<' not supported between instances of 'MagicMock' and 'int'

2019-10-11 16:02:02.471319 | ubuntu-bionic | Traceback (most recent call last):

2019-10-11 16:02:02.471417 | ubuntu-bionic | File "/home/zuul/src/opendev.org/openstack/neutron/neutron/notifiers/ironic.py", line 77, in send_events

2019-10-11 16:02:02.471471 | ubuntu-bionic | os_exc.raise_from_response(response)

2019-10-11 16:02:02.471658 | ubuntu-bionic | File "/home/zuul/src/opendev.org/openstack/neutron/.tox/lower-constraints/lib/python3.6/site-packages/openstack/exceptions.py", line 186, in raise_from_response

2019-10-11 16:02:02.471709 | ubuntu-bionic | if response.status_code < 400:

2019-10-11 16:02:02.471799 | ubuntu-bionic | TypeError: '<' not supported between instances of 'MagicMock' and 'int'

2019-10-11 16:02:02.474934 | ubuntu-bionic | {6} neutron.tests.unit.notifiers.test_ironic.TestIronicNotifier.test_send_events [0.025151s] ... ok

2019-10-11 16:02:02.480138 | ubuntu-bionic | {5} neutron.tests.unit.objects.test_network.NetworkDhcpAgentBindingObjectIfaceTestCase.test_create [0.035683s] ... ok

Changed in neutron:
assignee: nobody → Riccardo Pittau (rpittau)
status: New → In Progress
Revision history for this message
Hongbin Lu (hongbin.lu) wrote :
Changed in neutron:
importance: Undecided → Low
tags: added: unittest
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.opendev.org/688439
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=dce7af902c4207dcaa062eef7a21da2017fb37c7
Submitter: Zuul
Branch: master

commit dce7af902c4207dcaa062eef7a21da2017fb37c7
Author: Riccardo Pittau <email address hidden>
Date: Mon Oct 14 17:12:33 2019 +0200

    Mock openstacksdk raise_from_response in ironic unit test

    Mocking the openstacksdk exception method raise_from_response
    to prevent random error messages even in succeded unit
    tests.
    An example:
    https://zuul.opendev.org/t/openstack/build/943c3f89519c44a58e0b5c86ad4efff8/log/job-output.txt#23782-23789

    Change-Id: I3d9128d6712b4094c0b2ad7e12db9e5a915e3d91
    Closes-Bug: #1848147

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
Riccardo Pittau (rpittau) wrote :

@Hongbin Lu hi!
I'm not sure what you mean by broken, it works fine for me.
Also the error is reported in comment #1 since the link will expire at some point (but it hasn't yet).

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 16.0.0.0b1

This issue was fixed in the openstack/neutron 16.0.0.0b1 development milestone.

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.