test failure induced by reading system config file
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

tanglei528/glance,rickerc/glance_audit,saeki-masaki/glance,stevelle/glance,darren-wang/gl,scripnichenko/glance,ozamiatin/glance,akash1808/glance,stevelle/glance,rajalokan/glance,saeki-masaki/glance,klmitch/glance,vuntz/glance,redhat-openstack/glance,ozamiatin/glance,rajalokan/glance,sigmavirus24/glance,openstack/glance,citrix-openstack-build/glance,wkoathp/glance,jumpstarter-io/glance,sigmavirus24/glance,cloudbau/glance,ntt-sic/glance,vuntz/glance,paramite/glance,wkoathp/glance,dims/glance,akash1808/glance,paramite/glance,takeshineshiro/glance,kfwang/Glance-OVA-OVF,jumpstarter-io/glance,darren-wang/gl,klmitch/glance,cloudbau/glance,SUSE-Cloud/glance,JioCloud/glance,scripnichenko/glance,citrix-openstack-build/glance,kfwang/Glance-OVA-OVF,openstack/glance,dims/glance,SUSE-Cloud/glance,JioCloud/glance,tanglei528/glance,takeshineshiro/glance,redhat-openstack/glance,ntt-sic/glance,rickerc/glance_audit,openstack/glance