processutils checks whether stdlib is monkey patched during import

Bug #1418541 reported by Ihar Hrachyshka on 2015-02-05
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Undecided
Ihar Hrachyshka
oslo.concurrency
Undecided
Unassigned

Bug Description

Neutron does not monkey patch in neutron/__init__.py. Since oslo.concurrency.processutils depends on time being patched at the moment of its import, testr test loader may fail depending on whether eventlet was patched before the import or after. It's not the best solution, so let's try to postpone the check till execute() call.

Ben Nemec (bnemec) wrote :

I believe this is working as intended, and catching a legitimate bug in the calling code. See my comments on https://review.openstack.org/#/c/153216/ for a full explanation.

Changed in oslo.concurrency:
status: New → Invalid
Changed in neutron:
assignee: nobody → Terry Wilson (otherwiseguy)
status: New → In Progress

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

commit 24b11ded7f6ff12f9484aecdb8d30498bf1b9025
Author: Terry Wilson <email address hidden>
Date: Thu Jan 22 13:52:43 2015 -0600

    monkey patch stdlib before importing other modules

    Some oslo libraries assume that stdlib is already patched when
    they are imported (e.g. oslo_concurrency.processutils tests the
    'time' module for monkey_patching to detect which 'subprocess'
    module to import.

    This can cause issues when things like test frameworks import
    modules that monkey_patch, as the order imports are made can break
    this kind of check. It is always good to monkey patch as soon as
    possible, hence trying to do the patching in neutron/__init__.py.

    This is an alternative to https://review.openstack.org/#/c/153225/
    which just patches neutron/tests/__init__.py. Unfortunately, just
    monkey_patching in tests/__init__.py didn't fix all of the issues
    I ran into. For example, tempest tests were failing with timeouts.

    Closes-bug: #1418541
    Change-Id: I7f2115a99acae5b6d61aab2f7334f498b8d99858

Changed in neutron:
status: In Progress → Fix Committed

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

The original fix was reverted, so reopening the bug.

Changed in neutron:
assignee: Terry Wilson (otherwiseguy) → Ihar Hrachyshka (ihar-hrachyshka)
status: Fix Committed → Confirmed

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

Changed in neutron:
status: Confirmed → In Progress

Change abandoned by Ihar Hrachyshka (<email address hidden>) on branch: master
Review: https://review.openstack.org/155388

Change abandoned by Ihar Hrachyshka (<email address hidden>) on branch: master
Review: https://review.openstack.org/155386

Change abandoned by Ihar Hrachyshka (<email address hidden>) on branch: master
Review: https://review.openstack.org/155413

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

commit 81ea614570397fbe0722060d3faa703e7ded9151
Author: Ihar Hrachyshka <email address hidden>
Date: Thu Feb 12 13:51:21 2015 +0100

    Don't monkey patch netns_cleanup

    There is no reason to monkey patch the tool (it does not rely on any
    special kind of model of concurrency). It's better to avoid eventlet
    wherever possible, and there are discussions on whether we want to start
    dropping eventlet usage agent by agent, so it's worth keeping as much of
    code out of monkey business.

    Related-Bug: #1418541
    Change-Id: I1c1bb5a23e191da660efe9d4179ffaf5fec647f9

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

commit ea76d10e7492eb90f6777940304c67691caa366b
Author: Ihar Hrachyshka <email address hidden>
Date: Thu Feb 5 14:21:38 2015 +0100

    tests: monkey patch stdlib before importing other modules

    Some oslo libraries assume that stdlib is already patched when they are
    imported (f.e. oslo.concurrency.processutils currently checks whether
    time module is monkey patched on import to detect which subprocess
    module should be used).

    For services, we achieve this by moving monkey_patch() calls as high in
    import list as possible. But for tests, we don't control the order in
    which testr loads test cases. So to be on safe side, we should make sure
    any attempt to load a test case from the tree results in eventlet patch.

    We can't put the monkey_patch() call into e.g. neutron/__init__.py to
    reuse it both for tests and for services, because in that case we may
    break flake8 that loads hacking checks from neutron.* namespace and
    relies on proper (unpatched) subprocess module.

    Closes-Bug: #1418541
    Change-Id: Id58409000d0e086f3fb664a15935af4f1708c396

Changed in neutron:
status: In Progress → Fix Committed

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

commit 37115731515895ea224b1dafd71250d0b002ad40
Author: Ihar Hrachyshka <email address hidden>
Date: Wed Feb 18 11:42:43 2015 +0100

    Monkey patch all the code inside neutron/cmd/eventlet/...

    The directory is initially empty.

    We are going to maintain entry points for all services and agents that
    run in eventlet mode in this directory, and monkey patch them from
    there, instead of spreading monkey_patch() calls throughout the library.

    This will guarantee us that all the services that are maintained in this
    part of the tree monkey patch stdlib properly, before doing any other
    imports.

    This is also useful to track which parts of the project require
    eventlet. This will later help to migrate services one by one out of
    eventlet to real threads in case we decide to move this direction.

    Related-Bug: #1417386
    Related-Bug: #1418541
    Change-Id: I2bc16ca4422c01d64e9fac4910214dbb0d0326ff

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

commit 1ae0a4b632425b2f229fd86b9e7730cb4015e60b
Author: Ihar Hrachyshka <email address hidden>
Date: Wed Feb 18 12:11:07 2015 +0100

    Moved several services into neutron.cmd.eventlet

    - dhcp-agent
    - l3-agent
    - metadata-agent
    - metadata-proxy
    - metering-agent
    - server

    This allows us to remove explicit monkey_patch() call.

    Also removed ability to execute neutron-server avoiding a corresponding
    entry point.

    Depends-On: I2d7081dbd4cb532332e3b66667bb8c71aa5a6658

    Related-Bug: #1418541
    Change-Id: I89e3e8e23374ab1a9a1844b3caaa88e162418546

Thierry Carrez (ttx) on 2015-03-19
Changed in neutron:
milestone: none → kilo-3
status: Fix Committed → Fix Released

Change abandoned by Ihar Hrachyshka (<email address hidden>) on branch: master
Review: https://review.openstack.org/155412
Reason: Decision was to migrate plugins case by case, allowing vendors to do the work.

Thierry Carrez (ttx) on 2015-04-30
Changed in neutron:
milestone: kilo-3 → 2015.1.0
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers