Segment unit tests are not mocking properly

Bug #2038373 reported by Brian Haley
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
New
Low
Unassigned

Bug Description

Running the segment unit tests - neutron/tests/unit/extensions/test_segment.py generates a lot of extra noise, like:

{0} neutron.tests.unit.extensions.test_segment.TestNovaSegmentNotifier.test_delete_network_and_owned_segments [1.185650s] ... ok

Captured stderr:
~~~~~~~~~~~~~~~~
    /home/bhaley/git/neutron.dev/.tox/py311/lib/python3.11/site-packages/kombu/utils/compat.py:82: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
  for ep in importlib_metadata.entry_points().get(namespace, [])
Traceback (most recent call last):
  File "/home/bhaley/git/neutron.dev/.tox/py311/lib/python3.11/site-packages/eventlet/hubs/hub.py", line 476, in fire_timers
    timer()
  File "/home/bhaley/git/neutron.dev/.tox/py311/lib/python3.11/site-packages/eventlet/hubs/timer.py", line 59, in __call__
    cb(*args, **kw)
  File "/home/bhaley/git/neutron.dev/neutron/common/utils.py", line 956, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/bhaley/git/neutron.dev/neutron/notifiers/batch_notifier.py", line 58, in synced_send
    self._notify()
  File "/home/bhaley/git/neutron.dev/neutron/notifiers/batch_notifier.py", line 70, in _notify
    self.callback(batched_events)
  File "/home/bhaley/git/neutron.dev/neutron/services/segments/plugin.py", line 212, in _send_notifications
    event.method(event)
  File "/home/bhaley/git/neutron.dev/neutron/services/segments/plugin.py", line 384, in _delete_nova_inventory
    aggregate_id = self._get_aggregate_id(event.segment_id)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bhaley/git/neutron.dev/neutron/services/segments/plugin.py", line 378, in _get_aggregate_id
    for aggregate in self.n_client.aggregates.list():
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bhaley/git/neutron.dev/.tox/py311/lib/python3.11/site-packages/novaclient/v2/aggregates.py", line 59, in list
    return self._list('/os-aggregates', 'aggregates')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bhaley/git/neutron.dev/.tox/py311/lib/python3.11/site-packages/novaclient/base.py", line 253, in _list
    resp, body = self.api.client.get(url)
                 ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bhaley/git/neutron.dev/.tox/py311/lib/python3.11/site-packages/keystoneauth1/adapter.py", line 395, in get
    return self.request(url, 'GET', **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bhaley/git/neutron.dev/.tox/py311/lib/python3.11/site-packages/novaclient/client.py", line 77, in request
    if raise_exc and resp.status_code >= 400:
                     ^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>=' not supported between instances of 'MagicMock' and 'int'

From looking at the code it's not mocking things properly, for example it does this in TestNovaSegmentNotifier.setUp():

    self.batch_notifier._waiting_to_send = True

That code was removed in 2016 in 255e8a839db0be10c98b5d9f480ce476e2f2e171 :-/

The noise doesn't seem to cause the test to fail, but it should be fixed.

There are also keystone auth exceptions in other tests, and again, nothing seems to fail because of it:

   raise exceptions.MissingAuthPlugin(msg_fmt % msg)
keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin: An auth plugin is required to determine endpoint URL

tags: added: low-hanging-fruit
Revision history for this message
Brian Haley (brian-haley) wrote :

neutron.tests.unit.plugins.ml2.test_plugin.TestMultiSegmentNetworks.test_release_network_segments fails in a similar way, and since it's also segment-related I'll add it here.

As with the above the test still passes.

{1} neutron.tests.unit.plugins.ml2.test_plugin.TestMultiSegmentNetworks.test_release_network_segments [0.805345s] ... ok

Captured stderr:
~~~~~~~~~~~~~~~~
    Traceback (most recent call last):
  File "/home/bhaley/git/neutron.work/.tox/py310/lib/python3.10/site-packages/eventlet/hubs/hub.py", line 476, in fire_timers
    timer()
  File "/home/bhaley/git/neutron.work/.tox/py310/lib/python3.10/site-packages/eventlet/hubs/timer.py", line 59, in __call__
    cb(*args, **kw)
  File "/home/bhaley/git/neutron.work/neutron/common/utils.py", line 956, in wrapper
    return func(*args, **kwargs)
  File "/home/bhaley/git/neutron.work/neutron/notifiers/batch_notifier.py", line 58, in synced_send
    self._notify()
  File "/home/bhaley/git/neutron.work/neutron/notifiers/batch_notifier.py", line 69, in _notify
    self.callback(batched_events)
  File "/home/bhaley/git/neutron.work/neutron/services/segments/plugin.py", line 211, in _send_notifications
    event.method(event)
  File "/home/bhaley/git/neutron.work/neutron/services/segments/plugin.py", line 383, in _delete_nova_inventory
    aggregate_id = self._get_aggregate_id(event.segment_id)
  File "/home/bhaley/git/neutron.work/neutron/services/segments/plugin.py", line 370, in _get_aggregate_id
    aggregate_uuid = self.p_client.list_aggregates(
  File "/home/bhaley/git/neutron.work/.tox/py310/lib/python3.10/site-packages/neutron_lib/placement/client.py", line 58, in wrapper
    return f(self, *a, **k)
  File "/home/bhaley/git/neutron.work/.tox/py310/lib/python3.10/site-packages/neutron_lib/placement/client.py", line 554, in list_aggregates
    return self._get(url).json()
  File "/home/bhaley/git/neutron.work/.tox/py310/lib/python3.10/site-packages/neutron_lib/placement/client.py", line 190, in _get
    return self._client.get(url, endpoint_filter=self._ks_filter,
  File "/home/bhaley/git/neutron.work/.tox/py310/lib/python3.10/site-packages/keystoneauth1/session.py", line 1144, in get
    return self.request(url, 'GET', **kwargs)
  File "/home/bhaley/git/neutron.work/.tox/py310/lib/python3.10/site-packages/keystoneauth1/session.py", line 803, in request
    base_url = self.get_endpoint(auth, allow=allow,
  File "/home/bhaley/git/neutron.work/.tox/py310/lib/python3.10/site-packages/keystoneauth1/session.py", line 1244, in get_endpoint
    auth = self._auth_required(auth, 'determine endpoint URL')
  File "/home/bhaley/git/neutron.work/.tox/py310/lib/python3.10/site-packages/keystoneauth1/session.py", line 1184, in _auth_required
    raise exceptions.MissingAuthPlugin(msg_fmt % msg)
keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin: An auth plugin is required to determine endpoint URL

Jang YeHoon (yhjang)
Changed in neutron:
assignee: nobody → Jang YeHoon (yhjang)
Jang YeHoon (yhjang)
Changed in neutron:
assignee: Jang YeHoon (yhjang) → nobody
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.