Call config_parse in base test setup

Some of the tests (e.g. NeutronDbPluginV2AsMixinTestCase) do not call
config_parse so if the database engine is not already been setup by another
test before the config object is reset on teardown, the database connection
will fail since the database config is then empty.

This patch adds a new setup_config method called during the base test case
setUp method which calls config_parse by default to load the default config.
Tests that couldn't use the default config were then modified to override the
setup_config method.

Some other unit tests were slightly adjusted to pass using the default config.

Closes-Bug: #1346673
Change-Id: I3724200fa932115c0a8c264640b1a9dbe431a1cc
This commit is contained in:
Kevin Benton 2014-07-19 00:54:09 -07:00
parent 4a2f3e5092
commit 057d6aad57
7 changed files with 23 additions and 1 deletions

View File

@ -190,6 +190,12 @@ class BaseTestCase(testtools.TestCase):
if sys.version_info < (2, 7) and getattr(self, 'fmt', '') == 'xml':
raise self.skipException('XML Testing Skipped in Py26')
self.setup_config()
def setup_config(self):
"""Tests that need a non-default config can override this method."""
self.config_parse()
def config(self, **kw):
"""Override some configuration values.

View File

@ -54,10 +54,12 @@ class OFAAgentTestCase(base.BaseTestCase):
super(OFAAgentTestCase, self).setUp()
self.fake_oflib_of = fake_oflib.patch_fake_oflib_of().start()
self.mod_agent = importutils.import_module(self._AGENT_NAME)
self.ryuapp = mock.Mock()
def setup_config(self):
cfg.CONF.set_default('firewall_driver',
'neutron.agent.firewall.NoopFirewallDriver',
group='SECURITYGROUP')
self.ryuapp = mock.Mock()
cfg.CONF.register_cli_opts([
cfg.StrOpt('ofp-listen-host', default='',
help='openflow listen host'),

View File

@ -22,6 +22,10 @@ from neutron.tests import base
class TestNetnsCleanup(base.BaseTestCase):
def setup_config(self):
# don't use default config
pass
def test_setup_conf(self):
expected_opts = interface.OPTS
conf = util.setup_conf()

View File

@ -26,6 +26,10 @@ from neutron.tests import base
class TestOVSCleanup(base.BaseTestCase):
def setup_config(self):
# don't use default config
pass
def test_setup_conf(self):
conf = util.setup_conf()
self.assertEqual(conf.external_network_bridge, 'br-ex')

View File

@ -24,6 +24,10 @@ from neutron.tests import base
class ConfigurationTest(base.BaseTestCase):
def setup_config(self):
# don't use default config
pass
def test_defaults(self):
self.assertEqual('0.0.0.0', cfg.CONF.bind_host)
self.assertEqual(9696, cfg.CONF.bind_port)

View File

@ -645,6 +645,7 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
def test_enable_isolated_metadata_proxy_with_metadata_network(self):
cfg.CONF.set_override('enable_metadata_network', True)
cfg.CONF.set_override('debug', True)
cfg.CONF.set_override('verbose', False)
cfg.CONF.set_override('log_file', 'test.log')
class_path = 'neutron.agent.linux.ip_lib.IPWrapper'
self.external_process_p.stop()

View File

@ -1470,6 +1470,7 @@ class TestL3AgentEventHandler(base.BaseTestCase):
'interface_driver', 'neutron.agent.linux.interface.NullDriver'
)
cfg.CONF.set_override('use_namespaces', True)
cfg.CONF.set_override('verbose', False)
agent_config.register_root_helper(cfg.CONF)
device_exists_p = mock.patch(