← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 2038373] [NEW] Segment unit tests are not mocking properly

 

Public bug reported:

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

** Affects: neutron
     Importance: Low
         Status: New


** Tags: unittest

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to neutron.
https://bugs.launchpad.net/bugs/2038373

Title:
  Segment unit tests are not mocking properly

Status in neutron:
  New

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

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