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:
Ihar Hrachyshka 2014-12-08 13:51:02 +01:00
parent b4a0fa3c34
commit e33349e216
3 changed files with 4 additions and 4 deletions

View File

@ -44,12 +44,12 @@ class BrocadeSVIPlugin_TestCases(test_l3_plugin.TestL3NatBasePlugin):
LOG.info(_("rbridge id %s"), self._switch['rbridge_id']) LOG.info(_("rbridge id %s"), self._switch['rbridge_id'])
self._driver = mock.MagicMock() 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) self.l3_plugin = importutils.import_object(L3_SVC_PLUGIN)
with mock.patch.object(self.l3_plugin, with mock.patch.object(self.l3_plugin,
'brocade_init', new=mocked_brocade_init): 'brocade_init', new=mocked_brocade_init):
super(BrocadeSVIPlugin_TestCases, self).setUp() super(BrocadeSVIPlugin_TestCases, self).setUp()
self.context = oslo_context.get_admin_context()
self.context.session = db.get_session()
class TestBrocadeSVINatBase(test_l3_plugin.L3NatExtensionTestCase, class TestBrocadeSVINatBase(test_l3_plugin.L3NatExtensionTestCase,

View File

@ -184,7 +184,6 @@ class AgentDBTestCase(AgentDBTestMixIn,
fmt = 'json' fmt = 'json'
def setUp(self): def setUp(self):
self.adminContext = context.get_admin_context()
plugin = 'neutron.tests.unit.test_agent_ext_plugin.TestAgentPlugin' plugin = 'neutron.tests.unit.test_agent_ext_plugin.TestAgentPlugin'
# for these tests we need to enable overlapping ips # for these tests we need to enable overlapping ips
cfg.CONF.set_default('allow_overlapping_ips', True) cfg.CONF.set_default('allow_overlapping_ips', True)
@ -195,6 +194,7 @@ class AgentDBTestCase(AgentDBTestMixIn,
ext_mgr = AgentTestExtensionManager() ext_mgr = AgentTestExtensionManager()
self.addCleanup(self.restore_resource_attribute_map) self.addCleanup(self.restore_resource_attribute_map)
super(AgentDBTestCase, self).setUp(plugin=plugin, ext_mgr=ext_mgr) super(AgentDBTestCase, self).setUp(plugin=plugin, ext_mgr=ext_mgr)
self.adminContext = context.get_admin_context()
def restore_resource_attribute_map(self): def restore_resource_attribute_map(self):
# Restore the originak RESOURCE_ATTRIBUTE_MAP # Restore the originak RESOURCE_ATTRIBUTE_MAP

View File

@ -51,7 +51,6 @@ class MacLearningDBTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
fmt = 'json' fmt = 'json'
def setUp(self): def setUp(self):
self.adminContext = context.get_admin_context()
test_lib.test_config['config_files'] = [ test_lib.test_config['config_files'] = [
vmware.get_fake_conf('nsx.ini.full.test')] vmware.get_fake_conf('nsx.ini.full.test')]
cfg.CONF.set_override('api_extensions_path', vmware.NSXEXT_PATH) 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) self.addCleanup(self.restore_resource_attribute_map)
super(MacLearningDBTestCase, self).setUp(plugin=vmware.PLUGIN_NAME, super(MacLearningDBTestCase, self).setUp(plugin=vmware.PLUGIN_NAME,
ext_mgr=ext_mgr) ext_mgr=ext_mgr)
self.adminContext = context.get_admin_context()
def restore_resource_attribute_map(self): def restore_resource_attribute_map(self):
# Restore the original RESOURCE_ATTRIBUTE_MAP # Restore the original RESOURCE_ATTRIBUTE_MAP