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().
Reviewed: https:/ /review. openstack. org/43579 github. com/openstack/ glance/ commit/ de22b642f79b5af 589ccd437d36b88 3a6a52c475
Committed: http://
Submitter: Jenkins
Branch: master
commit de22b642f79b5af 589ccd437d36b88 3a6a52c475
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 get_bind_ addr_default_ value get_path_ non_exist
following failure:
test_
test_
Analysis tests/unit/ api/test_ cmd.py" . d.setUp, the sys.argv is overrided to ['glance-api']. tests/unit" (since glance- api.conf" is read in "setUp" via config. cfg:ConfigOpts. __call_ _ -> _pre_setup -> find_config_files. glance- api.conf.
--------
The root cause is resided in "glance/
In TestGlanceApiCm
Since sys.argv is "global" variable, and this test entry it run
firstly by nosetests while running tests in "glance/
nosetests search test items alphabetically), the other test entries
will inherit the sys.argv value ['glance-api']. Finally the system
config file "/etc/glance/
oslo.
CONF.bind_port and CONF.bind_host is set to the value reading from
system config file: /etc/glance/
A simplied call backtrace: piCmd.setUp --> sys.argv = ['glance-api'] JSONRequestDese rializerTest. setUp >glance/ common/ config. py:parse_ args
->oslo. config. cfg:ConfigOpts. __call_ _
->CONF. bind_port CONF.bind_host is set
TestGlanceA
->
-
wsgi. get_bind_ addr() will read the CONF.bind_port and CONF.bind_host bind_addr( ) bind_addr_ default_ value got passed, but failed while
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_
will return the expected value. This is the reason that individual
test of test_get_
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 \ glance. tests.unit. common. test_config: TestPasteApp
--tests=
tox -evenv -- nosetests glance. tests.unit. common. test_wsgi: JSONRequestDese rializerTest
--tests=
Fixes Bug #1204186
Change-Id: I2dac8e506fa794 d1faa9509258936 d78e2f981d8