]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
tests: initialize admin context after super().setUp call
authorIhar Hrachyshka <ihrachys@redhat.com>
Mon, 8 Dec 2014 12:51:02 +0000 (13:51 +0100)
committerIhar Hrachyshka <ihrachys@redhat.com>
Mon, 15 Dec 2014 11:09:55 +0000 (12:09 +0100)
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

neutron/tests/unit/ml2/drivers/brocade/test_brocade_l3_plugin.py
neutron/tests/unit/test_agent_ext_plugin.py
neutron/tests/unit/vmware/extensions/test_maclearning.py

index 8ef5987e4bac6fb7e4e07ec13735ebd0e031b698..81cffc2fa53452dcdd27c2d34bb5f68bd045e6c2 100644 (file)
@@ -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,
index e5f5557e090b86dca01306376493b30b5eb09c68..850430c1640b5a6da5c04b6744b3a3a71f4dffa7 100644 (file)
@@ -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
index 70d65731a86e53d8ed905f087f64890c7da9a493..7b934321996b1fec9c15b780af8c4128c57880cb 100644 (file)
@@ -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