Use of MagicMocks causes unnecessary memory use

Bug #1316401 reported by Kevin Benton
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Undecided
Kevin Benton
Icehouse
Fix Released
Undecided
Unassigned

Bug Description

There are many locations throughout the code-base that make use of MagicMocks to capture and prevent external calls. However, several of them never have assertions made on them so the fact that they record all of the calls made to them is a waste of memory. This is especially true for long-lived ones that span many tests and may record hundreds of calls (e.g. RPC notifier mocks).

Changed in neutron:
assignee: nobody → Kevin Benton (kevinbenton)
Revision history for this message
Openstack Gerrit (openstack-gerrit) wrote : Fix proposed to neutron (master)

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

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

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

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

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

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

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

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

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

Aaron Rosen (arosen)
tags: added: icehouse-backport-potential
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (stable/icehouse)

Fix proposed to branch: stable/icehouse
Review: https://review.openstack.org/97123

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

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

commit 4f96dd72e37ddcdbf756d711537a8b025183b73c
Author: Kevin Benton <email address hidden>
Date: Thu May 29 20:49:48 2014 -0700

    Remove unnecessary MagicMocks in cisco unit tests

    Two patches that just return static data never have
    assertions made on the MagicMocks generated. This
    replaces the magicmocks with lambdas to make the code
    easier to read and to get a minor performance gain.

    Change-Id: I064c57a66a0f7a8e3080f39cf48bd4b67cf304e3
    Partial-Bug: #1316401

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

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

commit 2df56ffe93fc5d0ce343df683d8846865b73b716
Author: Kevin Benton <email address hidden>
Date: Thu May 29 20:59:00 2014 -0700

    Remove function replacement with mock patch

    In the hyperv unit tests, an rpc method is
    manually replaced with a MagicMock using setattr.
    This prevents it from being cleaned up by mock.patch.stopall.
    This patch replaces it with a short-lived patch call
    in a with statement.

    Change-Id: I7b10a8115c474977e3acd16dc49d6f3ae67b0c3b
    Partial-Bug: #1316401

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

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

commit 76b60b204cca36395bae78fea1e773525c672f76
Author: Kevin Benton <email address hidden>
Date: Thu May 29 21:08:24 2014 -0700

    Improve module-level mocks in midonet tests

    Remove unnecessary module-level mocks and replace
    them with test-specific mocks so they don't persist
    through the entire test suite.

    Partial-Bug: #1316401
    Change-Id: I49039749bb700ec0a88639f4772701ba3b920352

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

Reviewed: https://review.openstack.org/97123
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=5d9a034e4b3081362db82cbc0f4d12aaf8c7dc32
Submitter: Jenkins
Branch: stable/icehouse

commit 5d9a034e4b3081362db82cbc0f4d12aaf8c7dc32
Author: Kevin Benton <email address hidden>
Date: Thu May 29 20:59:00 2014 -0700

    Remove function replacement with mock patch

    In the hyperv unit tests, an rpc method is
    manually replaced with a MagicMock using setattr.
    This prevents it from being cleaned up by mock.patch.stopall.
    This patch replaces it with a short-lived patch call
    in a with statement.

    Change-Id: I7b10a8115c474977e3acd16dc49d6f3ae67b0c3b
    Partial-Bug: #1316401
    (cherry picked from commit 2df56ffe93fc5d0ce343df683d8846865b73b716)

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

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

commit 66a24ab397e26963fef99d58f3f8ee2c9a6a52eb
Author: Kevin Benton <email address hidden>
Date: Tue May 6 04:19:08 2014 +0000

    Improve usage of MagicMocks in ML2 and L3 tests

    Removes usage of a MagicMock in a case where it's not needed.
    Replaces a manual function replacement with a mock.patch call
    so it's correctly cleaned up by mock.patch.stopall.

    Partial-Bug: #1316401
    Change-Id: I8f2f7e9eca2aeaa3b65be1b451e96ed2146950f4

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

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

commit 6c203529230c739bdd2c94f0a77d4b22037a994b
Author: Kevin Benton <email address hidden>
Date: Thu May 29 20:55:21 2014 -0700

    Removes unnecessary Embrane module-level mocks

    The embrane unit tests install a magicmock into
    the system modules at the module level which
    persists across all unit tests and isn't required.
    This patch removes the unnecessary and limits the
    life of the module mocks where they are necessary.

    Partial-Bug: #1316401
    Change-Id: Iaa38ee0c6821d46a6d78eefef39006df2c1c47e5

Chuck Short (zulcss)
tags: removed: icehouse-backport-potential
Revision history for this message
Cedric Brandily (cbrandily) wrote :

This bug is > 365 days without activity. We are unsetting assignee and milestone and setting status to Incomplete in order to allow its expiry in 60 days.

If the bug is still valid, then update the bug status.

Changed in neutron:
assignee: Kevin Benton (kevinbenton) → nobody
status: In Progress → Incomplete
Changed in neutron:
status: Incomplete → Fix Released
assignee: nobody → Kevin Benton (kevinbenton)
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.