Don't use Mock.called_once_with that does not exist

Bug #1544522 reported by javeme
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Low
javeme
OpenStack Compute (nova)
Fix Released
Undecided
Takashi Natsume
OpenStack DBaaS (Trove)
Fix Released
Undecided
STEW TY
Rally
Fix Released
Low
Chaozhe Chen
Sahara
Fix Released
Low
javeme
neutron
Fix Released
Low
Wang Bo
octavia
Fix Released
Undecided
Wang Bo
python-designateclient
Fix Released
Undecided
Chaozhe Chen
python-openstackclient
Fix Released
Undecided
Tang Chen

Bug Description

class mock.Mock does not exist method "called_once_with", it just exists method "assert_called_once_with". Currently there are still some places where we use called_once_with method, we should correct it.

NOTE: called_once_with() does nothing because it's a mock object.

javeme (javaloveme)
Changed in sahara:
assignee: nobody → javeme (javaloveme)
Changed in cinder:
assignee: nobody → javeme (javaloveme)
Revision history for this message
Eric Harney (eharney) wrote :

Cinder seems to have a number of instances of:
asert_called_once_with()
ssert_called_once_with()
asset_called_once_with()

as well.

All of these tests need to be fixed.

Changed in cinder:
status: New → Confirmed
tags: added: tests
Revision history for this message
Assaf Muller (amuller) wrote :

Neutron has two occurrences of .called_once_with(), despite a hacking rule to prevent this: https://github.com/openstack/neutron/blob/master/neutron/hacking/checks.py#L113. It needs to be a bit more robust :)

Please add me as a reviewer if you send a Neutron patch.

Changed in neutron:
status: New → Confirmed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to sahara (master)

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

Changed in sahara:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (master)

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

Changed in cinder:
status: Confirmed → In Progress
Eric Harney (eharney)
Changed in cinder:
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to cinder (master)

Related fix proposed to branch: master
Review: https://review.openstack.org/279153

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to cinder (master)

Reviewed: https://review.openstack.org/279153
Committed: https://git.openstack.org/cgit/openstack/cinder/commit/?id=1c94c6ab40f5320f74d992281ea7ebed3b55c730
Submitter: Jenkins
Branch: master

commit 1c94c6ab40f5320f74d992281ea7ebed3b55c730
Author: Eric Harney <email address hidden>
Date: Thu Feb 11 10:51:46 2016 -0500

    Tests: Fix calls to non-existent assert methods

    These tests currently aren't asserting anything.

    Related-Bug: #1544522

    Change-Id: Ic051ca411abcb8bb62b7897292c89c5c9e552599

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to sahara (master)

Reviewed: https://review.openstack.org/279126
Committed: https://git.openstack.org/cgit/openstack/sahara/commit/?id=7d01fabc5e16de0363afeb55c07fde889eb38a32
Submitter: Jenkins
Branch: master

commit 7d01fabc5e16de0363afeb55c07fde889eb38a32
Author: Javeme <email address hidden>
Date: Thu Feb 11 19:19:12 2016 +0800

    Don't use Mock.called_once_with that does not exist

    class mock.Mock does not exist method called_once_with, it just exists
    method assert_called_once_with. Currently there are still ome places
    where we use called_once_with method, this patch let's correct it.

    NOTE: called_once_with() does nothing because it's a mock object.

    Closes-Bug: #1544522
    Change-Id: I5698a724bc030b838faa06330a0d3dc77cc0d07a

Changed in sahara:
status: In Progress → Fix Released
Changed in sahara:
milestone: none → mitaka-3
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cinder (master)

Reviewed: https://review.openstack.org/279134
Committed: https://git.openstack.org/cgit/openstack/cinder/commit/?id=22cb2e81a6d5dfad022fae5fca7601e2ae9aab88
Submitter: Jenkins
Branch: master

commit 22cb2e81a6d5dfad022fae5fca7601e2ae9aab88
Author: Javeme <email address hidden>
Date: Thu Feb 11 20:09:41 2016 +0800

    Don't use Mock.called_once_with that does not exist

    class mock.Mock does not exist method called_once_with, it just exists
    method assert_called_once_with. Currently there are still ome places
    where we use called_once_with method, this patch let's correct it.

    NOTE: called_once_with() does nothing because it's a mock object.

    Closes-Bug: #1544522
    Change-Id: Iac7c029a1cc66439f43d441bc6d0832686536961

Changed in cinder:
status: In Progress → Fix Released
Wang Bo (chestack)
Changed in neutron:
assignee: nobody → Wang Bo (chestack)
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/280279

Changed in neutron:
status: Confirmed → In Progress
Revision history for this message
Wang Bo (chestack) wrote :

@amuller. has added you as the reviewer for the patch: https://review.openstack.org/280279

Wang Bo (chestack)
Changed in octavia:
assignee: nobody → Wang Bo (chestack)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to octavia (master)

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

Changed in octavia:
status: New → In Progress
Changed in neutron:
importance: Undecided → Low
Changed in trove:
assignee: nobody → Chaozhe Chen (chaozhe-chen)
no longer affects: designate
Changed in python-designateclient:
assignee: nobody → Chaozhe Chen (chaozhe-chen)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-designateclient (master)

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

Changed in python-designateclient:
status: New → In Progress
Changed in trove:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to trove (master)

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

Changed in rally:
status: New → In Progress
importance: Undecided → Low
Piyush (pirsriva)
Changed in rally:
assignee: nobody → Piyush Raman Srivastava (pirsriva)
Changed in rally:
assignee: Piyush Raman Srivastava (pirsriva) → Chaozhe Chen (chaozhe-chen)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to rally (master)

Reviewed: https://review.openstack.org/281252
Committed: https://git.openstack.org/cgit/openstack/rally/commit/?id=a924151906eab93d7455688337cf08415c56058e
Submitter: Jenkins
Branch: master

commit a924151906eab93d7455688337cf08415c56058e
Author: Chaozhe.Chen <email address hidden>
Date: Wed Feb 17 20:54:46 2016 +0800

    Test: Stop using non-existent method of Mock

    There is no method called_once_with() in Mock object.
    Use assert_called_once_with() instead.
    And called_once_with() does nothing because it's a mock object.

    In case 'test_setup_with_no_lbaas', method iterate_per_tenants() will
    not be called when setup with no lbass, so use assert_not_called()
    instead.

    Change-Id: Ib25b325b8764e6f0e0928f46f4789fce0f04b9e1
    Closes-Bug: #1544522

Changed in rally:
status: In Progress → Fix Released
Tang Chen (tangchen)
Changed in python-openstackclient:
assignee: nobody → Tang Chen (tangchen)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-openstackclient (master)

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

Changed in python-openstackclient:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

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

commit fd0ed209d214c2a4f825eda9dd0b97234f75875a
Author: Bo Wang <email address hidden>
Date: Mon Feb 15 23:05:20 2016 +0800

    Stop using non-existent method of Mock

    There is no method called_once_with() in Mock object.
    Use assert_called_once_with() instead.

    Change-Id: I263c407ba2a82f53aace5f71cb27ad8974335e24
    Closes-Bug: #1544522

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-openstackclient (master)

Reviewed: https://review.openstack.org/282188
Committed: https://git.openstack.org/cgit/openstack/python-openstackclient/commit/?id=48681af86a1dfd50a8e90a9d7cd9068417cc52a9
Submitter: Jenkins
Branch: master

commit 48681af86a1dfd50a8e90a9d7cd9068417cc52a9
Author: Tang Chen <email address hidden>
Date: Fri Feb 19 13:44:54 2016 +0800

    Don't use Mock.called_once_with that does not exist

    Class mock.Mock does not exist method "called_once_with()", it just
    exists method "assert_called_once_with()". "called_once_with()" does
    nothing because it's a mock object.

    In OSC, only one place is still using "called_once_with()". Fix it.

    Change-Id: Ib890e95d775c3fc43df80fa05c82d726e78cdac8
    Partial Bug: 1544522

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-designateclient (master)

Reviewed: https://review.openstack.org/281230
Committed: https://git.openstack.org/cgit/openstack/python-designateclient/commit/?id=607bef280c19a8842ff97629d65bbf8ddf288845
Submitter: Jenkins
Branch: master

commit 607bef280c19a8842ff97629d65bbf8ddf288845
Author: Chaozhe.Chen <email address hidden>
Date: Wed Feb 17 11:49:22 2016 +0800

    Stop using non-existent method of Mock

    There is no method called_once_with() in Mock object.
    Use assert_called_once_with() instead.

    I tested it in my tox environment. The revised assertion will work.

    Change-Id: I530b58a434b4c031d236b0b04e8c7091854c992f
    Closes-Bug: #1544522

Changed in python-designateclient:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to octavia (master)

Reviewed: https://review.openstack.org/280766
Committed: https://git.openstack.org/cgit/openstack/octavia/commit/?id=c31781b122ad5bfd3f6ad5b6036aed3dfc2a4869
Submitter: Jenkins
Branch: master

commit c31781b122ad5bfd3f6ad5b6036aed3dfc2a4869
Author: Bo Wang <email address hidden>
Date: Tue Feb 16 23:23:17 2016 +0800

    Stop using non-existent method of Mock

    There is no method called_once_with() in Mock object.
    Use assert_called_once_with() instead.

    Change-Id: Ib41a3fb4d7b4333cb56f69244fed0bf13366453d
    Closes-Bug: #1544522

Changed in octavia:
status: In Progress → Fix Released
Revision history for this message
Thierry Carrez (ttx) wrote : Fix included in openstack/neutron 8.0.0.0b3

This issue was fixed in the openstack/neutron 8.0.0.0b3 development milestone.

Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/cinder 8.0.0.0b3

This issue was fixed in the openstack/cinder 8.0.0.0b3 development milestone.

Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/sahara 4.0.0.0b3

This issue was fixed in the openstack/sahara 4.0.0.0b3 development milestone.

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

Change abandoned by amrith (<email address hidden>) on branch: master
Review: https://review.openstack.org/281232
Reason: inactivity

Amrith Kumar (amrith)
Changed in trove:
assignee: Chaozhe Chen (chaozhe-chen) → nobody
status: In Progress → Confirmed
milestone: none → newton-1
Revision history for this message
Richard Theis (rtheis) wrote :

This was fixed in openstackclient release 2.2.0.

Changed in python-openstackclient:
status: In Progress → Fix Released
Amrith Kumar (amrith)
tags: added: low-hanging-fruit
STEW TY (stewie925)
Changed in trove:
assignee: nobody → STEW TY (stewie925)
Revision history for this message
STEW TY (stewie925) wrote :

Hello amrith,

I assigned myself to this bug (for the Trove component) last week.

I found that this was previously worked on but was abandoned - Gerrit link is https://review.openstack.org/#/c/281232/.

Comments have been added in the Gerrit link to show the proposed changes. Would like to hear your input if I can continue working on it, as it was previously abandoned? Thank you.

Revision history for this message
Amrith Kumar (amrith) wrote :

Hi Stewie,

Please look at how it was fixed in some other projects and I think we can do the same thing in Trove.

For example, https://review.openstack.org/#/c/280766/

If you'd like I can restore the abandoned change and you can submit changes against that, or you can submit a new change of your own. I suspect that the simplest change(s) for this fix will be different from the abandoned change and you may be better off just making a new review. If on the other hand your proposed change is similar to the one proposed earlier, it will be better to just restore that one. Your call.

Thanks,

-amrith

Revision history for this message
STEW TY (stewie925) wrote :

Thank you Amrith! Based on your response it looks like we do NOT need to incorporate the fix that was in the 'abandoned' review. So I will start with a NEW review - again appreciate your input!

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to trove (master)

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

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

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

Changed in trove:
assignee: STEW TY (stewie925) → Petr Malik (pmalik)
Changed in trove:
assignee: Petr Malik (pmalik) → STEW TY (stewie925)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to trove (master)

Reviewed: https://review.openstack.org/322275
Committed: https://git.openstack.org/cgit/openstack/trove/commit/?id=3edcd5cdcf0d7d3928c67c1310a472df8d8af62a
Submitter: Jenkins
Branch: master

commit 3edcd5cdcf0d7d3928c67c1310a472df8d8af62a
Author: Petr Malik <email address hidden>
Date: Fri May 27 12:55:25 2016 -0400

    Catch exceptions from backup runner

    The backup runner context manager may throw BackupErrors.
    The backupagent currently only checks for the success of the storage
    save action and any exceptions, but not those from the runner
    __enter__/__exit__ methods.

    This issue was discovered when fixing backup unittests
    in change: 312611
    The unittests assert that the backup would be marked as FAILED, but
    was marked as COMPLETED instead.

    This patch just moves the 'with clause' of the backup runner to the
    try-except block to intercept any exceptions originating from
    the backup procedures.

    Change-Id: I27d0cf1b9a174ca69eb82d26f14a4c0d03f75382
    Partial-Bug: 1544522

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Reviewed: https://review.openstack.org/312611
Committed: https://git.openstack.org/cgit/openstack/trove/commit/?id=3420886b8d24b570823cb500cf1feb9031d4a887
Submitter: Jenkins
Branch: master

commit 3420886b8d24b570823cb500cf1feb9031d4a887
Author: stewie925 <email address hidden>
Date: Wed May 4 08:37:05 2016 -0700

    Rename called_once_with methods correctly

    * Remove 'self.assertTrue' enclosing the '.called_once_with'
    * methods and rename '.called_once_with' method name to
    * '.assert_called_once_with'.

    Change-Id: I04d1c99df9983733b6d2579ba71097b2cebc6a54
    Closes-Bug: #1544522

Changed in trove:
status: In Progress → Fix Released
Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/trove 6.0.0.0b2

This issue was fixed in the openstack/trove 6.0.0.0b2 development milestone.

Revision history for this message
Davanum Srinivas (DIMS) (dims-v) wrote : Fix included in openstack/python-designateclient 2.2.0

This issue was fixed in the openstack/python-designateclient 2.2.0 release.

Changed in nova:
assignee: nobody → Takashi NATSUME (natsume-takashi)
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/675041

Changed in nova:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/stein)

Fix proposed to branch: stable/stein
Review: https://review.opendev.org/676838

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.opendev.org/675041
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=cf7d28eb6ea47818e9f3584f65ec025f5a46326b
Submitter: Zuul
Branch: master

commit cf7d28eb6ea47818e9f3584f65ec025f5a46326b
Author: Takashi NATSUME <email address hidden>
Date: Wed Aug 7 14:38:45 2019 +0900

    Fix non-existent method of Mock

    There is no method called_once_with() in Mock object.
    Use assert_called_once_with() or assert_has_calls() instead.

    Change-Id: I9f73fcbe7c3dfd64e75ac8224c13934b03443cd5
    Closes-Bug: #1544522

Changed in nova:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/rocky)

Fix proposed to branch: stable/rocky
Review: https://review.opendev.org/676840

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/queens)

Fix proposed to branch: stable/queens
Review: https://review.opendev.org/676844

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/pike)

Fix proposed to branch: stable/pike
Review: https://review.opendev.org/676848

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/ocata)

Fix proposed to branch: stable/ocata
Review: https://review.opendev.org/676850

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/stein)

Reviewed: https://review.opendev.org/676838
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=d90186068b197f0912fa2bf525bb752f2d8f3c31
Submitter: Zuul
Branch: stable/stein

commit d90186068b197f0912fa2bf525bb752f2d8f3c31
Author: Takashi NATSUME <email address hidden>
Date: Wed Aug 7 14:38:45 2019 +0900

    Fix non-existent method of Mock

    There is no method called_once_with() in Mock object.
    Use assert_called_once_with() or assert_has_calls() instead.

    Conflicts:
        nova/tests/unit/conductor/tasks/test_live_migrate.py
        nova/tests/unit/virt/libvirt/test_driver.py

    NOTE(takashin): The conflict is due to not having the following changes
    in stable/stein.

        I734cc01dce13f9e75a16639faf890ddb1661b7eb
        Ief2c959d7c339e11b19e521de6e7d1be2f8722f8

    The changes for ComputeAPIAPICellUnitTestCase (Cells v1 test cases) was
    added in nova/tests/unit/compute/test_compute_api.py
    because the following change has not been applied in stable/stein.

        Ib0e0b708c46e4330e51f8f8fdfbb02d45aaf0f44

    Change-Id: I9f73fcbe7c3dfd64e75ac8224c13934b03443cd5
    Closes-Bug: #1544522
    (cherry picked from commit cf7d28eb6ea47818e9f3584f65ec025f5a46326b)

tags: added: in-stable-stein
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 20.0.0.0rc1

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

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/rocky)

Reviewed: https://review.opendev.org/676840
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=a5f39bd9c3771b4cf64c1a5b68bb850988e1fc73
Submitter: Zuul
Branch: stable/rocky

commit a5f39bd9c3771b4cf64c1a5b68bb850988e1fc73
Author: Takashi NATSUME <email address hidden>
Date: Wed Aug 7 14:38:45 2019 +0900

    Fix non-existent method of Mock

    There is no method called_once_with() in Mock object.
    Use assert_called_once_with() or assert_has_calls() instead.

    NOTE(takashin): Additional changes are also applied to
    nova/tests/unit/virt/libvirt/test_vif.py
    because the following change has not been applied in stable/rocky.

        I047856982251fddc631679fb2dbcea0f3b0db097

    Change-Id: I9f73fcbe7c3dfd64e75ac8224c13934b03443cd5
    Closes-Bug: #1544522
    (cherry picked from commit cf7d28eb6ea47818e9f3584f65ec025f5a46326b)
    (cherry picked from commit d90186068b197f0912fa2bf525bb752f2d8f3c31)

tags: added: in-stable-rocky
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 19.0.3

This issue was fixed in the openstack/nova 19.0.3 release.

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

This issue was fixed in the openstack/nova 18.2.3 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/queens)

Reviewed: https://review.opendev.org/676844
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=8d50b509ece98db3dec94f1779b0fa0f1e2b319b
Submitter: Zuul
Branch: stable/queens

commit 8d50b509ece98db3dec94f1779b0fa0f1e2b319b
Author: Takashi NATSUME <email address hidden>
Date: Wed Aug 7 14:38:45 2019 +0900

    Fix non-existent method of Mock

    There is no method called_once_with() in Mock object.
    Use assert_called_once_with() or assert_has_calls() instead.

    Conflicts:
        nova/tests/unit/compute/test_compute_api.py
        nova/tests/unit/console/test_websocketproxy.py
        nova/tests/unit/virt/libvirt/test_driver.py

    NOTE(takashin): The conflict is due to not having the following changes
    in stable/queens.

        I4636a8d270ce01c1831bc951c4497ad472bc9aa8
        If1b6e5f20d2ea82d94f5f0550f13189fc9bc16c4
        Icdd039bb4374269d9da38e7f8d2e15e05ca8aadb

    Change-Id: I9f73fcbe7c3dfd64e75ac8224c13934b03443cd5
    Closes-Bug: #1544522
    (cherry picked from commit cf7d28eb6ea47818e9f3584f65ec025f5a46326b)
    (cherry picked from commit d90186068b197f0912fa2bf525bb752f2d8f3c31)
    (cherry picked from commit a5f39bd9c3771b4cf64c1a5b68bb850988e1fc73)

tags: added: in-stable-queens
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 17.0.13

This issue was fixed in the openstack/nova 17.0.13 release.

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.