tests that mock os.path.exists should initialize policy first

Bug #1426369 reported by Ihar Hrachyshka
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Undecided
Ihar Hrachyshka

Bug Description

Some tests mock os.path.exists. By doing so, they break config file search code located in oslo.config.find_file. This results in the following failures when running those tests separately. Note that tests pass in case test runner initialized policy before in another test case.

======================================================================
ERROR: neutron.tests.unit.test_metadata_agent.TestUnixDomainMetadataProxy.test_init_exists_unlink_no_file
----------------------------------------------------------------------
Empty attachments:
  pythonlogging:''
  pythonlogging:'neutron.api.extensions'

Traceback (most recent call last):
  File "neutron/tests/unit/test_metadata_agent.py", line 595, in test_init_exists_unlink_no_file
    agent.UnixDomainMetadataProxy(mock.Mock())
  File "neutron/agent/metadata/agent.py", line 323, in __init__
    self._init_state_reporting()
  File "neutron/agent/metadata/agent.py", line 326, in _init_state_reporting
    self.context = context.get_admin_context_without_session()
  File "neutron/context.py", line 176, in get_admin_context_without_session
    read_deleted=read_deleted)
  File "neutron/context.py", line 68, in __init__
    self.is_advsvc = policy.check_is_advsvc(self)
  File "neutron/policy.py", line 440, in check_is_advsvc
    init()
  File "neutron/policy.py", line 79, in init
    _ENFORCER.load_rules(True)
  File "neutron/openstack/common/policy.py", line 241, in load_rules
    self.policy_path = self._get_policy_path(self.policy_file)
  File "neutron/openstack/common/policy.py", line 287, in _get_policy_path
    raise cfg.ConfigFilesNotFoundError((path,))
ConfigFilesNotFoundError: Failed to find some config files: policy.json

Solution is to initialize policy at the start of any unit test.

Changed in neutron:
assignee: nobody → Ihar Hrachyshka (ihar-hrachyshka)
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/159863

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

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

commit 1349891fce528365e5d1abce95d019ce40275234
Author: Ihar Hrachyshka <email address hidden>
Date: Fri Feb 27 15:19:47 2015 +0100

    tests: initialize policy in BaseTestCase

    This is needed to avoid test cases breaking policy file search code from
    oslo.config by mocking out stdlib functions from os module like
    os.path.isdir or os.path.exists.

    This also allows us to remove explicit policy setup from test_api_v2 and
    test_policy files.

    Note that for test_netns_cleanup, test_ovs_cleanup, and test_config, we
    removed test_setup_conf test cases. They test a function that is used in
    other test cases only, and hence do not belong to the suite. This allows
    us to avoid hacks around those test cases that do not play nice with
    global config-file options we set in BaseTestCase.

    Change-Id: If14a3c741837193ad104467f0cf4486a6a386e6d
    Closes-Bug: #1426369

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