Correct base64 error handling
The base64 module can raise many exceptions, TypeError doesn't even seem one of them. Capture all errors and provide the exact message. Change-Id: Id3748e729f8dd31aa6d2d7084bd01088cd9a7ecd
This commit is contained in:
parent
ebdf6784cb
commit
0704bcdd9b
|
@ -548,9 +548,11 @@ def _get_configdrive(configdrive, node_uuid, tempdir=None):
|
|||
|
||||
try:
|
||||
data = io.BytesIO(base64.decode_as_bytes(data))
|
||||
except TypeError:
|
||||
error_msg = (_('Config drive for node %s is not base64 encoded '
|
||||
'or the content is malformed.') % node_uuid)
|
||||
except Exception as exc:
|
||||
error_msg = (_('Config drive for node %(node)s is not base64 encoded '
|
||||
'or the content is malformed. %(cls)s: %(err)s.')
|
||||
% {'node': node_uuid, 'err': exc,
|
||||
'cls': type(exc).__name__})
|
||||
if is_url:
|
||||
error_msg += _(' Downloaded from "%s".') % configdrive
|
||||
raise exception.InstanceDeployFailure(error_msg)
|
||||
|
|
|
@ -22,7 +22,6 @@ from unittest import mock
|
|||
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import base64
|
||||
from oslo_utils import imageutils
|
||||
import requests
|
||||
|
||||
|
@ -961,14 +960,10 @@ class GetConfigdriveTestCase(base.IronicLibTestCase):
|
|||
'http://1.2.3.4/cd', 'fake-node-uuid')
|
||||
self.assertFalse(mock_copy.called)
|
||||
|
||||
@mock.patch.object(base64, 'decode_as_bytes', autospec=True)
|
||||
def test_get_configdrive_base64_error(self, mock_b64, mock_requests,
|
||||
mock_copy):
|
||||
mock_b64.side_effect = TypeError
|
||||
def test_get_configdrive_base64_error(self, mock_requests, mock_copy):
|
||||
self.assertRaises(exception.InstanceDeployFailure,
|
||||
disk_utils._get_configdrive,
|
||||
'malformed', 'fake-node-uuid')
|
||||
mock_b64.assert_called_once_with('malformed')
|
||||
self.assertFalse(mock_copy.called)
|
||||
|
||||
@mock.patch.object(gzip, 'GzipFile', autospec=True)
|
||||
|
|
Loading…
Reference in New Issue