Test test_get_bind_addr_default_value picks up port value from system config file

Bug #1204186 reported by Stuart McLaren
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Fix Released
Undecided
Kui Shi

Bug Description

When I run the tests, eg with

$ tox -epy27

I see the following error:

======================================================================
FAIL: glance.tests.unit.common.test_wsgi.JSONRequestDeserializerTest.test_get_bind_addr_default_value
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/home/ubuntu/git/glance.new/glance/glance/tests/unit/common/test_wsgi.py", line 250, in test_get_bind_addr_default_value
    self.assertEqual(expected, actual)
  File "/home/ubuntu/git/glance.new/glance/.tox/venv/local/lib/python2.7/site-packages/testtools/testcase.py", line 322, in assertEqual
    self.assertThat(observed, matcher, message)
  File "/home/ubuntu/git/glance.new/glance/.tox/venv/local/lib/python2.7/site-packages/testtools/testcase.py", line 417, in assertThat
    raise MismatchError(matchee, matcher, mismatch, verbose)
MismatchError: ('0.0.0.0', '123456') != ('0.0.0.0', 9291)

Slowest 5 tests took 70.04 secs:
    21.68 TestScrubber.test_scrubber_delete_handles_exception
    21.66 TestScrubber.test_scrubber_app
    16.27 TestScrubber.test_delayed_delete
    6.56 TestBinGlanceCacheManage.test_queue
    3.87 TestRootApi.test_version_configurations
----------------------------------------------------------------------
Ran 1530 tests in 300.360s

Port 9291 [sic] is being picked up from /etc/glance/glance-api.conf

$ grep 9291 /etc/glance/glance-api.conf
bind_port = 9291

The unit test should be independent of any config files present on the system.

Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

Funnily enough I'm only able to reproduce this by running all the tests, eg if I run:

$ tox -evenv -- nosetests --tests=glance.tests.unit.common.test_wsgi:JSONRequestDeserializerTest.test_get_bind_addr_default_value
GLOB sdist-make: /home/ubuntu/git/glance.new/glance/setup.py
venv inst-nodeps: /home/ubuntu/git/glance.new/glance/.tox/dist/glance-2013.2.a20.g0f669d5.zip
venv runtests: commands[0] | nosetests --tests=glance.tests.unit.common.test_wsgi:JSONRequestDeserializerTest.test_get_bind_addr_default_value

JSONRequestDeserializerTest
    test_get_bind_addr_default_value OK 0.00

----------------------------------------------------------------------
Ran 1 test in 0.004s

OK
__________________________________________________________________________________ summary ___________________________________________________________________________________
  venv: commands succeeded
  congratulations :)

It seems to work ok.

Just
$ tox -evenv
reproduces

I'm not sure if there's a 'better' way to run a single test which would reproduce without having to run all tests.

Feilong Wang (flwang)
Changed in glance:
status: New → Confirmed
Kui Shi (skuicloud)
Changed in glance:
assignee: nobody → Kui Shi (skuicloud)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to glance (master)

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

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

Reviewed: https://review.openstack.org/43579
Committed: http://github.com/openstack/glance/commit/de22b642f79b5af589ccd437d36b883a6a52c475
Submitter: Jenkins
Branch: master

commit de22b642f79b5af589ccd437d36b883a6a52c475
Author: Kui Shi <email address hidden>
Date: Sat Aug 24 16:23:51 2013 +0800

    test failure induced by reading system config file

    run run_tests.sh or tox to test the glance code, it will get
    following failure:
    test_get_bind_addr_default_value
    test_get_path_non_exist

    Analysis
    --------
    The root cause is resided in "glance/tests/unit/api/test_cmd.py".
    In TestGlanceApiCmd.setUp, the sys.argv is overrided to ['glance-api'].
    Since sys.argv is "global" variable, and this test entry it run
    firstly by nosetests while running tests in "glance/tests/unit"(since
    nosetests search test items alphabetically), the other test entries
    will inherit the sys.argv value ['glance-api']. Finally the system
    config file "/etc/glance/glance-api.conf" is read in "setUp" via
    oslo.config.cfg:ConfigOpts.__call__ -> _pre_setup -> find_config_files.
    CONF.bind_port and CONF.bind_host is set to the value reading from
    system config file: /etc/glance/glance-api.conf.

    A simplied call backtrace:
    TestGlanceApiCmd.setUp --> sys.argv = ['glance-api']
     ->JSONRequestDeserializerTest.setUp
      ->glance/common/config.py:parse_args
       ->oslo.config.cfg:ConfigOpts.__call__
        ->CONF.bind_port CONF.bind_host is set

    wsgi.get_bind_addr() will read the CONF.bind_port and CONF.bind_host
    to return value. if system config file is not read, CONF.bind_host
    is set to "0.0.0.0", CONF.bind_port is not set. wsgi.get_bind_addr()
    will return the expected value. This is the reason that individual
    test of test_get_bind_addr_default_value got passed, but failed while
    testing all.

    The failure of test_get_path_non_exist is induced by same reason.

    Test case should clear up the setting in tearDown(), especially the
    "global" setting, e.g. sys.argv.

    Solution
    --------
    The solution is simple:
    In class TestGlanceApiCmd, add a private variable to backup the
    sys.argv in setUp(), and restore it in tearDown().

    Test method
    -----------
    $ ./run_tests.sh

    $ tox -evenv -- nosetests \
    --tests=glance.tests.unit.common.test_config:TestPasteApp

    tox -evenv -- nosetests
    --tests=glance.tests.unit.common.test_wsgi:JSONRequestDeserializerTest

    Fixes Bug #1204186

    Change-Id: I2dac8e506fa794d1faa9509258936d78e2f981d8

Changed in glance:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in glance:
milestone: none → havana-3
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in glance:
milestone: havana-3 → 2013.2
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.