Catch unknown exceptions in validate driver ifaces

The method validate_driver_interfaces in conductor manager
catches only known exceptions. But some third-party can
break this method.

Adding catch of general Exception to this method to avoid
not desirable failure and write detailed information about
exception to result and logs.

Change-Id: Ia3105b21cd42396568317bb26ff4be22cf5c5649
Closes-Bug: 1646854
This commit is contained in:
Galyna Zholtkevych 2016-12-02 16:51:47 +02:00
parent 0a124c2bc0
commit 3467da690f
3 changed files with 34 additions and 0 deletions

View File

@ -1438,6 +1438,18 @@ class ConductorManager(base_manager.BaseConductorManager):
exception.UnsupportedDriverExtension) as e:
result = False
reason = str(e)
except Exception as e:
result = False
reason = (_('Unexpected exception, traceback saved '
'into log by ironic conductor service '
'that is running on %(host)s: %(error)s')
% {'host': self.host, 'error': e})
LOG.exception(_LE(
'Unexpected exception occurred while validating '
'%(iface)s driver interface for driver '
'%(driver)s: %(err)s on node %(node)s.'),
{'iface': iface_name, 'driver': task.node.driver,
'err': e, 'node': task.node.uuid})
else:
reason = _('not supported')

View File

@ -2610,6 +2610,24 @@ class MiscTestCase(mgr_utils.ServiceSetUpMixin, mgr_utils.CommonMixIn,
self.assertEqual(reason, ret['deploy']['reason'])
mock_iwdi.assert_called_once_with(self.context, node.instance_info)
@mock.patch.object(images, 'is_whole_disk_image')
def test_validate_driver_interfaces_validation_fail_unexpected(
self, mock_iwdi):
node = obj_utils.create_test_node(self.context, driver='fake')
with mock.patch(
'ironic.drivers.modules.fake.FakeDeploy.validate'
) as deploy:
deploy.side_effect = Exception('boom')
ret = self.service.validate_driver_interfaces(self.context,
node.uuid)
reason = ('Unexpected exception, traceback saved '
'into log by ironic conductor service '
'that is running on test-host: boom')
self.assertFalse(ret['deploy']['result'])
self.assertEqual(reason, ret['deploy']['reason'])
mock_iwdi.assert_called_once_with(self.context, node.instance_info)
@mock.patch.object(manager.ConductorManager, '_fail_if_in_state',
autospec=True)
@mock.patch.object(manager.ConductorManager, '_mapped_to_this_conductor')

View File

@ -0,0 +1,4 @@
---
fixes:
- Catch unknown exceptions with traceback
when validating driver interfaces.