From a581c1eafcf7be0663439011a24dcece2e16f04d Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Tue, 6 Dec 2016 16:20:48 +0000 Subject: [PATCH] Make "enabled_drivers" config option more resilient to failures Do not fail to start the ironic-conductor service if there's a trailing comma or an empty value as part of the "enabled_drivers" or "enabled_network_interfaces" configuration option, instead, log a warning alerting the operation of the wrong syntax. Change-Id: Id9141c014263de5e72641613d970fd481a6aaa74 Closes-Bug: #1647783 --- ironic/common/driver_factory.py | 7 +++++++ ironic/tests/unit/common/test_driver_factory.py | 8 ++++++++ .../error-resilient-enabled_drivers-4e9c864ed6eaddd1.yaml | 6 ++++++ 3 files changed, 21 insertions(+) create mode 100644 releasenotes/notes/error-resilient-enabled_drivers-4e9c864ed6eaddd1.yaml diff --git a/ironic/common/driver_factory.py b/ironic/common/driver_factory.py index 94d51ed3e1..64ffc377dc 100644 --- a/ironic/common/driver_factory.py +++ b/ironic/common/driver_factory.py @@ -182,6 +182,13 @@ class BaseDriverFactory(object): duplicated_drivers = [] cls._enabled_driver_list = [] for item, cnt in counter: + if not item: + LOG.warning( + _LW('An empty driver was specified in the "%s" ' + 'configuration option and will be ignored. Please ' + 'fix your ironic.conf file to avoid this warning ' + 'message.'), cls._enabled_driver_list_config_option) + continue if cnt > 1: duplicated_drivers.append(item) cls._enabled_driver_list.append(item) diff --git a/ironic/tests/unit/common/test_driver_factory.py b/ironic/tests/unit/common/test_driver_factory.py index f2b2e890b3..b15f746462 100644 --- a/ironic/tests/unit/common/test_driver_factory.py +++ b/ironic/tests/unit/common/test_driver_factory.py @@ -71,6 +71,14 @@ class DriverLoadTestCase(base.TestCase): ['fake'], driver_factory.DriverFactory._extension_manager.names()) self.assertTrue(mock_log.called) + @mock.patch.object(driver_factory.LOG, 'warning', autospec=True) + def test_driver_empty_entry(self, mock_log): + self.config(enabled_drivers=['fake', '']) + driver_factory.DriverFactory._init_extension_manager() + self.assertEqual( + ['fake'], driver_factory.DriverFactory._extension_manager.names()) + self.assertTrue(mock_log.called) + @mock.patch.object(driver_factory, '_warn_if_unsupported') def test_driver_init_checks_unsupported(self, mock_warn): self.config(enabled_drivers=['fake']) diff --git a/releasenotes/notes/error-resilient-enabled_drivers-4e9c864ed6eaddd1.yaml b/releasenotes/notes/error-resilient-enabled_drivers-4e9c864ed6eaddd1.yaml new file mode 100644 index 0000000000..723a3a59e2 --- /dev/null +++ b/releasenotes/notes/error-resilient-enabled_drivers-4e9c864ed6eaddd1.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - Fixes an issue where the ironic-conductor service would not + run if a trailing comma or empty driver was specified in the + ``[DEFAULT]enabled_drivers`` configuration option. The service now + runs and logs a warning.