Merge "Try to standardize retrieval of an Exception's description"
This commit is contained in:
commit
4b5c8f13d9
@ -99,6 +99,10 @@ class IronicException(Exception):
|
||||
|
||||
return self.args[0]
|
||||
|
||||
def __unicode__(self):
|
||||
"""Return a unicode representation of the exception message."""
|
||||
return unicode(self.args[0])
|
||||
|
||||
def format_message(self):
|
||||
if self.__class__.__name__.endswith('_Remote'):
|
||||
return self.args[0]
|
||||
|
@ -41,6 +41,7 @@ from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_service import loopingcall
|
||||
from oslo_utils import excutils
|
||||
import six
|
||||
|
||||
from ironic.common import boot_devices
|
||||
from ironic.common import exception
|
||||
@ -401,7 +402,7 @@ def _exec_ipmitool(driver_info, command):
|
||||
except processutils.ProcessExecutionError as e:
|
||||
with excutils.save_and_reraise_exception() as ctxt:
|
||||
err_list = [x for x in IPMITOOL_RETRYABLE_FAILURES
|
||||
if x in e.args[0]]
|
||||
if x in six.text_type(e)]
|
||||
if ((time.time() > end_time) or
|
||||
(num_tries == 0) or
|
||||
not err_list):
|
||||
|
@ -69,9 +69,9 @@ class MSFTOCSClientApi(object):
|
||||
url, auth=auth.HTTPBasicAuth(self._username, self._password))
|
||||
response.raise_for_status()
|
||||
except requests_exceptions.RequestException as ex:
|
||||
LOG.exception(_LE("HTTP call failed: %s"), ex)
|
||||
raise exception.MSFTOCSClientApiException(
|
||||
_("HTTP call failed: %s") % ex.args[0])
|
||||
msg = _("HTTP call failed: %s") % ex
|
||||
LOG.exception(msg)
|
||||
raise exception.MSFTOCSClientApiException(msg)
|
||||
|
||||
xml_response = response.text
|
||||
LOG.debug("Call to %(url)s got response: %(xml_response)s",
|
||||
|
@ -25,6 +25,7 @@ from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_service import loopingcall
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
from six.moves.urllib import parse as urlparse
|
||||
|
||||
from ironic.common import boot_devices
|
||||
@ -580,8 +581,8 @@ class Management(base.ManagementInterface):
|
||||
except seamicro_client_exception.ClientException as ex:
|
||||
LOG.error(_LE("Seamicro set boot device failed for node "
|
||||
"%(node)s with the following error: %(error)s"),
|
||||
{'node': task.node.uuid, 'error': ex.args[0]})
|
||||
raise exception.IronicException(message=ex.args[0])
|
||||
{'node': task.node.uuid, 'error': ex})
|
||||
raise exception.IronicException(message=six.text_type(ex))
|
||||
|
||||
def get_boot_device(self, task):
|
||||
"""Get the current boot device for the task's node.
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
import six
|
||||
|
||||
from ironic.common import exception
|
||||
from ironic.common import states
|
||||
@ -279,7 +280,7 @@ class TestInspectPrivateMethods(db_base.DbTestCase):
|
||||
self.node,
|
||||
ilo_mock)
|
||||
self.assertEqual(
|
||||
result.format_message(),
|
||||
six.text_type(result),
|
||||
("Failed to inspect hardware. Reason: Server didn't return the "
|
||||
"key(s): cpu_arch"))
|
||||
|
||||
|
@ -31,6 +31,7 @@ import mock
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
|
||||
from ironic.common import boot_devices
|
||||
from ironic.common import driver_factory
|
||||
@ -348,7 +349,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
|
||||
ValueError,
|
||||
self._test__make_password_file,
|
||||
mock_sleep, 12345, ValueError('we should fail'))
|
||||
self.assertEqual('we should fail', result.args[0])
|
||||
self.assertEqual('we should fail', six.text_type(result))
|
||||
|
||||
@mock.patch.object(tempfile, 'NamedTemporaryFile',
|
||||
new=mock.MagicMock(side_effect=OSError('Test Error')))
|
||||
@ -367,7 +368,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
|
||||
result = self.assertRaises(
|
||||
OverflowError,
|
||||
self._test__make_password_file, mock_sleep, 12345)
|
||||
self.assertEqual('Test Error', result.args[0])
|
||||
self.assertEqual('Test Error', six.text_type(result))
|
||||
|
||||
def test__make_password_file_write_exception(self, mock_sleep):
|
||||
# Test exception in _make_password_file for write()
|
||||
|
Loading…
Reference in New Issue
Block a user