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
This commit is contained in:
parent
e6aada633f
commit
cd43fcfc87
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user