summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaohiro Tamura <naohirot@jp.fujitsu.com>2015-08-23 23:52:20 +0900
committerNaohiro Tamura <naohirot@jp.fujitsu.com>2015-08-24 09:36:55 +0900
commit85494ea7142881ed80b42f3d55bfb007556cfa6d (patch)
tree6b318cd29628269eecb50356ba3d94bb0a78118b
parentf28a83cde39fbe4ea389efa4d719e5c8b91b9393 (diff)
downloadironic-85494ea7142881ed80b42f3d55bfb007556cfa6d.tar.gz
Fix improper exception catching
This patch fixes so that iRMC management module can catch only specific exception and propagate unknown exception properly. This is a reflection of the gerrit review comment in iRMC inspection module [1] which advised that generic exception catching is not good. [1] https://review.openstack.org/#/c/196480/7/ironic/drivers/modules/irmc/inspect.py Change-Id: Ib97102cc149b1bdacd2ef06c23641a0754ce8b28
-rw-r--r--ironic/drivers/modules/irmc/management.py5
-rw-r--r--ironic/tests/drivers/irmc/test_management.py9
-rw-r--r--ironic/tests/drivers/third_party_driver_mock_specs.py1
3 files changed, 11 insertions, 4 deletions
diff --git a/ironic/drivers/modules/irmc/management.py b/ironic/drivers/modules/irmc/management.py
index b51e20e10..077ebf7e5 100644
--- a/ironic/drivers/modules/irmc/management.py
+++ b/ironic/drivers/modules/irmc/management.py
@@ -57,7 +57,10 @@ def _get_sensors_data(task):
report = irmc_common.get_irmc_report(task.node)
sensor = scci.get_sensor_data(report)
- except Exception as e:
+ except (exception.InvalidParameterValue,
+ exception.MissingParameterValue,
+ scci.SCCIInvalidInputError,
+ scci.SCCIClientError) as e:
LOG.error(_LE("SCCI get sensor data failed for node %(node_id)s "
"with the following error: %(error)s"),
{'node_id': task.node.uuid, 'error': e})
diff --git a/ironic/tests/drivers/irmc/test_management.py b/ironic/tests/drivers/irmc/test_management.py
index 6a582849d..2b8dde515 100644
--- a/ironic/tests/drivers/irmc/test_management.py
+++ b/ironic/tests/drivers/irmc/test_management.py
@@ -281,12 +281,15 @@ class IRMCManagementTestCase(db_base.DbTestCase):
@mock.patch.object(irmc_common, 'get_irmc_report', spec_set=True,
autospec=True)
- def test_management_interface_get_sensors_data_exception1(
+ def test_management_interface_get_sensors_data_exception(
self,
get_irmc_report_mock):
"""'FailedToGetSensorData Exception."""
- get_irmc_report_mock.side_effect = iter([Exception("Report Error")])
+ get_irmc_report_mock.side_effect = exception.InvalidParameterValue(
+ "Fake Error")
+ irmc_management.scci.SCCIInvalidInputError = Exception
+ irmc_management.scci.SCCIClientError = Exception
with task_manager.acquire(self.context, self.node.uuid) as task:
task.node.driver_info['irmc_sensor_method'] = 'scci'
@@ -294,5 +297,5 @@ class IRMCManagementTestCase(db_base.DbTestCase):
self.driver.management.get_sensors_data,
task)
self.assertEqual("Failed to get sensor data for node 1be26c0b-" +
- "03f2-4d2e-ae87-c02d7f33c123. Error: Report Error",
+ "03f2-4d2e-ae87-c02d7f33c123. Error: Fake Error",
str(e))
diff --git a/ironic/tests/drivers/third_party_driver_mock_specs.py b/ironic/tests/drivers/third_party_driver_mock_specs.py
index 9adc7051c..94666d043 100644
--- a/ironic/tests/drivers/third_party_driver_mock_specs.py
+++ b/ironic/tests/drivers/third_party_driver_mock_specs.py
@@ -94,6 +94,7 @@ SCCICLIENT_IRMC_SCCI_SPEC = (
'MOUNT_FD',
'UNMOUNT_FD',
'SCCIClientError',
+ 'SCCIInvalidInputError',
'get_share_type',
'get_client',
'get_report',