test_get_free_namespace_port fails on systems without sysctl

Bug #1619028 reported by Corey Wright
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Low
Corey Wright

Bug Description

If the unit test test_get_free_namespace_port runs on a system without sysctl, then the test fails as it tries to execute sysctl, because sysctl doesn't exist.

======================================================================
FAIL: neutron.tests.unit.tests.common.test_net_helpers.PortAllocationTestCase.test_get_free_namespace_port
neutron.tests.unit.tests.common.test_net_helpers.PortAllocationTestCase.test_get_free_namespace_port
----------------------------------------------------------------------
_StringException: Empty attachments:
  pythonlogging:''
  stderr
  stdout

Traceback (most recent call last):
  File "neutron/tests/unit/tests/common/test_net_helpers.py", line 65, in test_get_free_namespace_port
    n_const.PROTO_NAME_TCP)
  File "neutron/tests/common/net_helpers.py", line 215, in get_free_namespace_port
    return get_unused_port(used_ports)
  File "neutron/tests/common/net_helpers.py", line 186, in get_unused_port
    ['sysctl', '-n', 'net.ipv4.ip_local_port_range'])
  File "neutron/agent/linux/utils.py", line 117, in execute
    addl_env=addl_env)
  File "neutron/agent/linux/utils.py", line 87, in create_process
    stderr=subprocess.PIPE)
  File "neutron/common/utils.py", line 85, in subprocess_popen
    close_fds=close_fds, env=env)
  File "/var/lib/jenkins/workspace/test-neutron-rax-patches-change/virtualenv/local/lib/python2.7/site-packages/eventlet/green/subprocess.py", line 53, in __init__
    subprocess_orig.Popen.__init__(self, args, 0, *argss, **kwds)
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Code under test shouldn't be allowed to execute local commands for multiple reasons:
0. a test system is not a deployment system
1. the command might not exist
2. the command's output might be system-dependent
3. the command might unintentionally alter the state of the system

The execution of sysctl should be mocked.

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/363917

Changed in neutron:
assignee: nobody → Corey Wright (coreywright)
status: New → In Progress
Changed in neutron:
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

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

commit 5e4204804ea4b364d27d014d13ecb529bc370ea6
Author: Corey Wright <email address hidden>
Date: Wed Aug 31 14:34:13 2016 -0500

    Mock call to sysctl for test_get_free_namespace_port

    The code under test shouldn't execute local commands for multiple
    reasons (eg the command doesn't exist on the test system), so mock out
    the execution of sysctl in test_get_free_namespace_port (copying the
    code from test_get_unused_port).

    Change-Id: I58aa578274310ae2ca015069f99edb84716fb0b5
    Closes-bug: #1619028

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 9.0.0.0b3

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

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.