From: Ihar Hrachyshka Date: Mon, 8 Dec 2014 12:51:02 +0000 (+0100) Subject: tests: initialize admin context after super().setUp call X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e33349e216e9361f4d93e012b91dd69b4bea9e92;p=openstack-build%2Fneutron-build.git tests: initialize admin context after super().setUp call New policy code requires that CONF is already initialized when policy checks are invoked. It means that no Neutron context objects should be created before BaseTestCase.setUp() is called that will set configuration, among other things. Ideally, we would just make sure that all test cases invoke super().setUp() as the very first line of any subclass setUp() methods. But since some of test cases require prior setup (like mocking extension manager) before proceeding to base class, we end up with magically shuffling context instantiations to occur below super() calls. Change-Id: Ib1039ea1ff9480ca57f9cb0c917469d0d2ad28b8 Closes-Bug: #1400301 --- diff --git a/neutron/tests/unit/ml2/drivers/brocade/test_brocade_l3_plugin.py b/neutron/tests/unit/ml2/drivers/brocade/test_brocade_l3_plugin.py index 8ef5987e4..81cffc2fa 100644 --- a/neutron/tests/unit/ml2/drivers/brocade/test_brocade_l3_plugin.py +++ b/neutron/tests/unit/ml2/drivers/brocade/test_brocade_l3_plugin.py @@ -44,12 +44,12 @@ class BrocadeSVIPlugin_TestCases(test_l3_plugin.TestL3NatBasePlugin): LOG.info(_("rbridge id %s"), self._switch['rbridge_id']) self._driver = mock.MagicMock() - self.context = oslo_context.get_admin_context() - self.context.session = db.get_session() self.l3_plugin = importutils.import_object(L3_SVC_PLUGIN) with mock.patch.object(self.l3_plugin, 'brocade_init', new=mocked_brocade_init): super(BrocadeSVIPlugin_TestCases, self).setUp() + self.context = oslo_context.get_admin_context() + self.context.session = db.get_session() class TestBrocadeSVINatBase(test_l3_plugin.L3NatExtensionTestCase, diff --git a/neutron/tests/unit/test_agent_ext_plugin.py b/neutron/tests/unit/test_agent_ext_plugin.py index e5f5557e0..850430c16 100644 --- a/neutron/tests/unit/test_agent_ext_plugin.py +++ b/neutron/tests/unit/test_agent_ext_plugin.py @@ -184,7 +184,6 @@ class AgentDBTestCase(AgentDBTestMixIn, fmt = 'json' def setUp(self): - self.adminContext = context.get_admin_context() plugin = 'neutron.tests.unit.test_agent_ext_plugin.TestAgentPlugin' # for these tests we need to enable overlapping ips cfg.CONF.set_default('allow_overlapping_ips', True) @@ -195,6 +194,7 @@ class AgentDBTestCase(AgentDBTestMixIn, ext_mgr = AgentTestExtensionManager() self.addCleanup(self.restore_resource_attribute_map) super(AgentDBTestCase, self).setUp(plugin=plugin, ext_mgr=ext_mgr) + self.adminContext = context.get_admin_context() def restore_resource_attribute_map(self): # Restore the originak RESOURCE_ATTRIBUTE_MAP diff --git a/neutron/tests/unit/vmware/extensions/test_maclearning.py b/neutron/tests/unit/vmware/extensions/test_maclearning.py index 70d65731a..7b9343219 100644 --- a/neutron/tests/unit/vmware/extensions/test_maclearning.py +++ b/neutron/tests/unit/vmware/extensions/test_maclearning.py @@ -51,7 +51,6 @@ class MacLearningDBTestCase(test_db_plugin.NeutronDbPluginV2TestCase): fmt = 'json' def setUp(self): - self.adminContext = context.get_admin_context() test_lib.test_config['config_files'] = [ vmware.get_fake_conf('nsx.ini.full.test')] cfg.CONF.set_override('api_extensions_path', vmware.NSXEXT_PATH) @@ -76,6 +75,7 @@ class MacLearningDBTestCase(test_db_plugin.NeutronDbPluginV2TestCase): self.addCleanup(self.restore_resource_attribute_map) super(MacLearningDBTestCase, self).setUp(plugin=vmware.PLUGIN_NAME, ext_mgr=ext_mgr) + self.adminContext = context.get_admin_context() def restore_resource_attribute_map(self): # Restore the original RESOURCE_ATTRIBUTE_MAP