some tests call "called_once_with_args" with no assert, those lines are ignored

Bug #1297875 reported by Miguel Angel Ajo
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Medium
Miguel Angel Ajo

Bug Description

A few tests use "called_once_with_args" instead of mock's "assert_called_once_with_args"
without checking the result.

That means that we're not asserting for that to happen.

Those tests need to be fixed.

[majopela@f20-devstack neutron]$ grep ".called_once_with" * -R | grep -v assert
neutron/tests/unit/test_dhcp_agent.py: disable.called_once_with_args(network.id)

neutron/tests/unit/test_dhcp_agent.py: uuid5.called_once_with(uuid.NAMESPACE_DNS, 'localhost')

neutron/tests/unit/test_post_mortem_debug.py: mock_print_exception.called_once_with(*exc_info)

neutron/tests/unit/test_db_migration.py: mock_open.write.called_once_with('a')

neutron/tests/unit/test_agent_netns_cleanup.py: ovs_br_cls.called_once_with('br-int', conf.AGENT.root_helper)

neutron/tests/unit/test_metadata_agent.py: self.eventlet.wsgi.server.called_once_with(

Tags: unittest
Changed in neutron:
assignee: nobody → Miguel Angel Ajo (mangelajo)
status: New → In Progress
Revision history for this message
Miguel Angel Ajo (mangelajo) wrote :

There are a few ".called_once()" too.

[majopela@f20-devstack neutron]$ grep ".called_once" * -R | grep -v assert
Binary file neutron/tests/unit/test_agent_netns_cleanup.pyc matches
neutron/tests/unit/agent/linux/test_async_process.py: mock_kill.called_once()
neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py: mock_loop.called_once()

Revision history for this message
Miguel Angel Ajo (mangelajo) wrote :

After setting the right asserts, a few tests are failing, so we will fix them/the code with this bug:

FAIL: neutron.tests.unit.test_post_mortem_debug.TestTesttoolsExceptionHandler.test_exception_handler
----------------------------------------------------------------------
Empty attachments:
  pythonlogging:''

Traceback (most recent call last):
  File "neutron/tests/unit/test_post_mortem_debug.py", line 41, in test_exception_handler
    mock_print_exception.assert_called_once_with(*exc_info)
  File "/opt/stack/neutron/.venv/lib/python2.7/site-packages/mock.py", line 846, in assert_called_once_with
    return self.assert_called_with(*args, **kwargs)
  File "/opt/stack/neutron/.venv/lib/python2.7/site-packages/mock.py", line 835, in assert_called_with
    raise AssertionError(msg)
AssertionError: Expected call: print_exception(<type 'exceptions.AssertionError'>, AssertionError('False is not true',), <traceback object at 0x17b8200>)
Actual call: print_exception(<type 'exceptions.AssertionError'>, AssertionError('False is not true',), <neutron.tests.post_mortem_debug.FilteredTraceback object at 0x17cb290>)

Ran 7 tests in 0.010s
FAILED (failures=1)

======================================================================
FAIL: neutron.tests.unit.test_dhcp_agent.TestDeviceManager.test_get_device_id
----------------------------------------------------------------------
Empty attachments:
  pythonlogging:''

Traceback (most recent call last):
  File "neutron/tests/unit/test_dhcp_agent.py", line 1308, in test_get_device_id
    uuid5.assert_called_once_with(uuid.NAMESPACE_DNS, 'localhost')
  File "/opt/stack/neutron/.venv/lib/python2.7/site-packages/mock.py", line 845, in assert_called_once_with
    raise AssertionError(msg)
AssertionError: Expected to be called once. Called 0 times.

Ran 99 tests in 1.325s
FAILED (failures=1)

======================================================================
FAIL: neutron.tests.unit.test_db_migration.TestCli.test_update_head_file_success
----------------------------------------------------------------------
Empty attachments:
  pythonlogging:''

Traceback (most recent call last):
  File "neutron/tests/unit/test_db_migration.py", line 184, in test_update_head_file_success
    mock_open.write.assert_called_once_with('a')
  File "/opt/stack/neutron/.venv/lib/python2.7/site-packages/mock.py", line 845, in assert_called_once_with
    raise AssertionError(msg)
AssertionError: Expected to be called once. Called 0 times.

Ran 15 tests in 0.112s
FAILED (failures=1)

Kyle Mestery (mestery)
Changed in neutron:
importance: Undecided → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (master)

Fix proposed to branch: master
Review: https://review.openstack.org/84139

tags: added: icehouse-backport-potential unittest
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.openstack.org/84139
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=c6c4a20777921dc1b21e80edb96ccd957a054c68
Submitter: Jenkins
Branch: master

commit c6c4a20777921dc1b21e80edb96ccd957a054c68
Author: Miguel Angel Ajo <email address hidden>
Date: Mon Mar 31 15:50:55 2014 +0200

    fixes tests using called_once_ without assert

    A few tests were using mock's called_once, or called_once_with_args
    instead of assert_called_once or assert_called_once_with_args. Those
    methods return a bool that needs to be actively checked.

    The tests are fixed to avoid them from passing if the call condition
    is not met.

    Change-Id: I21e5257b26b2a08cc8f0b108233d1d5cc0b97b89
    Closes-bug: #1297875

Changed in neutron:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Reviewed: https://review.openstack.org/80261
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=907bf41afbdb9f565c45a535f637c8928d0be52a
Submitter: Jenkins
Branch: master

commit 907bf41afbdb9f565c45a535f637c8928d0be52a
Author: Miguel Angel Ajo <email address hidden>
Date: Tue Mar 18 13:33:19 2014 +0100

    fixes broken neutron-netns-cleanup

    Some configuration parameters used in neutron.agent.linux.utils
    were missing. The namespace attribute in the FakeNetwork object
    was missing, and used in neutron.agent.linux.dhcp. Also, the
    plugin object was missing for release_dhcp_port operation.

    We provide a fake plugin object to accept current and any future
    plugin calls as this is meant to be an standalone tool that
    should work without any RPC connectivity.

    FakeNetwork was switched for neutron.agent.linux.dhcp.NetModel
    to follow any future changes in NetModel.

    Two wrong called_once_with_args calls without assert were fixed.

    Change-Id: Ia51ea9bd4c8eea6b250858964ad5286c933702e0
    Closes-Bug: #1291915
    Partial-Bug: #1297875

Changed in neutron:
milestone: none → juno-1
tags: removed: icehouse-backport-potential
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (milestone-proposed)

Fix proposed to branch: milestone-proposed
Review: https://review.openstack.org/85503

no longer affects: neutron/icehouse
Changed in neutron:
milestone: juno-1 → icehouse-rc2
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: milestone-proposed
Review: https://review.openstack.org/85521

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (milestone-proposed)

Reviewed: https://review.openstack.org/85503
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=5417220fc50fb31218ed1ed2aba6b926591c5f81
Submitter: Jenkins
Branch: milestone-proposed

commit 5417220fc50fb31218ed1ed2aba6b926591c5f81
Author: Miguel Angel Ajo <email address hidden>
Date: Tue Mar 18 13:33:19 2014 +0100

    fixes broken neutron-netns-cleanup

    Some configuration parameters used in neutron.agent.linux.utils
    were missing. The namespace attribute in the FakeNetwork object
    was missing, and used in neutron.agent.linux.dhcp. Also, the
    plugin object was missing for release_dhcp_port operation.

    We provide a fake plugin object to accept current and any future
    plugin calls as this is meant to be an standalone tool that
    should work without any RPC connectivity.

    FakeNetwork was switched for neutron.agent.linux.dhcp.NetModel
    to follow any future changes in NetModel.

    Two wrong called_once_with_args calls without assert were fixed.

    Change-Id: Ia51ea9bd4c8eea6b250858964ad5286c933702e0
    Closes-Bug: #1291915
    Partial-Bug: #1297875
    (cherry picked from commit 907bf41afbdb9f565c45a535f637c8928d0be52a)

Changed in neutron:
status: Fix Committed → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Reviewed: https://review.openstack.org/85521
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=5efc0163490d02b6015286f2d25a186624be95c5
Submitter: Jenkins
Branch: milestone-proposed

commit 5efc0163490d02b6015286f2d25a186624be95c5
Author: Miguel Angel Ajo <email address hidden>
Date: Mon Mar 31 15:50:55 2014 +0200

    fixes tests using called_once_ without assert

    A few tests were using mock's called_once, or called_once_with_args
    instead of assert_called_once or assert_called_once_with_args. Those
    methods return a bool that needs to be actively checked.

    The tests are fixed to avoid them from passing if the call condition
    is not met.

    Change-Id: I21e5257b26b2a08cc8f0b108233d1d5cc0b97b89
    Closes-bug: #1297875
    (cherry picked from commit c6c4a20777921dc1b21e80edb96ccd957a054c68)

Thierry Carrez (ttx)
Changed in neutron:
milestone: icehouse-rc2 → 2014.1
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.