From 61b2cf8e6e7cf520876443d1d64c100645746ae4 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Tue, 19 Feb 2013 11:34:00 +0000 Subject: [PATCH] Exit if DHCP agent interface_driver is not defined Fixes bug 1130052 In addition to this: Uses "raise SystemExit()" instaed of the exit for the L3 agent. Change-Id: I8130745c9de62619189e158944fa9e4ed25be774 --- quantum/agent/dhcp_agent.py | 10 ++++++++-- quantum/agent/l3_agent.py | 10 +++++----- quantum/tests/unit/test_dhcp_agent.py | 2 ++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/quantum/agent/dhcp_agent.py b/quantum/agent/dhcp_agent.py index 333fa86c3..fda604cd8 100644 --- a/quantum/agent/dhcp_agent.py +++ b/quantum/agent/dhcp_agent.py @@ -481,8 +481,14 @@ class DeviceManager(object): self.root_helper = config.get_root_helper(conf) self.plugin = plugin if not conf.interface_driver: - LOG.error(_('You must specify an interface driver')) - self.driver = importutils.import_object(conf.interface_driver, conf) + raise SystemExit(_('You must specify an interface driver')) + try: + self.driver = importutils.import_object(conf.interface_driver, + conf) + except: + msg = _("Error importing interface driver " + "'%s'") % conf.interface_driver + raise SystemExit(msg) def get_interface_name(self, network, port=None): """Return interface(device) name for use by the DHCP process.""" diff --git a/quantum/agent/l3_agent.py b/quantum/agent/l3_agent.py index d8f3eaf2f..9e45f2cad 100644 --- a/quantum/agent/l3_agent.py +++ b/quantum/agent/l3_agent.py @@ -154,15 +154,15 @@ class L3NATAgent(manager.Manager): self.router_info = {} if not self.conf.interface_driver: - LOG.error(_('An interface driver must be specified')) - sys.exit(1) + raise SystemExit(_('An interface driver must be specified')) try: self.driver = importutils.import_object(self.conf.interface_driver, self.conf) except: - LOG.exception(_("Error importing interface driver '%s'"), - self.conf.interface_driver) - sys.exit(1) + msg = _("Error importing interface driver " + "'%s'") % self.conf.interface_driver + raise SystemExit(msg) + self.context = context.get_admin_context_without_session() self.plugin_rpc = L3PluginApi(topics.PLUGIN, host) self.fullsync = True diff --git a/quantum/tests/unit/test_dhcp_agent.py b/quantum/tests/unit/test_dhcp_agent.py index b109f12e6..fbc6f03fc 100644 --- a/quantum/tests/unit/test_dhcp_agent.py +++ b/quantum/tests/unit/test_dhcp_agent.py @@ -113,6 +113,8 @@ class TestDhcpAgent(unittest.TestCase): cfg.CONF.register_opts(dhcp_agent.DeviceManager.OPTS) cfg.CONF.register_opts(dhcp_agent.DhcpAgent.OPTS) cfg.CONF.register_opts(dhcp_agent.DhcpLeaseRelay.OPTS) + cfg.CONF.set_override('interface_driver', + 'quantum.agent.linux.interface.NullDriver') self.driver_cls_p = mock.patch( 'quantum.agent.dhcp_agent.importutils.import_class') self.driver = mock.Mock(name='driver') -- 2.45.2