summaryrefslogtreecommitdiff
path: root/ironic_python_agent
diff options
context:
space:
mode:
authorJosh Gachnang <josh@pcsforeducation.com>2015-08-26 12:47:43 -0700
committerJosh Gachnang <josh@pcsforeducation.com>2015-09-21 15:54:02 -0700
commite17129dbad25a4deb833e2efc7301c97187d3ed7 (patch)
treeb96c8f25c652c48a66aa6c58ee243a7e99536a90 /ironic_python_agent
parent9783c6477daa94094358d119f51ce4e07a7d58dc (diff)
downloadironic-python-agent-e17129dbad25a4deb833e2efc7301c97187d3ed7.tar.gz
Add more info to checksum exception
If an image cannot be downloaded for some reason, it is helpful for operators to have the image path, checksum, and calculated checksums available easily from the API. Change-Id: I6a2fb46726245cebd730b5c51d4f25f8465f1658
Diffstat (limited to 'ironic_python_agent')
-rw-r--r--ironic_python_agent/errors.py12
-rw-r--r--ironic_python_agent/extensions/standby.py13
-rw-r--r--ironic_python_agent/tests/unit/extensions/test_standby.py8
-rw-r--r--ironic_python_agent/tests/unit/test_errors.py4
4 files changed, 23 insertions, 14 deletions
diff --git a/ironic_python_agent/errors.py b/ironic_python_agent/errors.py
index f551c95b..92c3825f 100644
--- a/ironic_python_agent/errors.py
+++ b/ironic_python_agent/errors.py
@@ -150,10 +150,14 @@ class ImageChecksumError(RESTError):
"""Error raised when an image fails to verify against its checksum."""
message = 'Error verifying image checksum'
-
- def __init__(self, image_id):
- details = 'Image with id {0} failed to verify against checksum.'
- details = details.format(image_id)
+ details_str = ('Image failed to verify against checksum. location: {0}; '
+ 'image ID: {1}; image checksum: {2}; verification '
+ 'checksum: {3}')
+
+ def __init__(self, image_id, image_location, checksum,
+ calculated_checksum):
+ details = self.details_str.format(image_location, image_id, checksum,
+ calculated_checksum)
super(ImageChecksumError, self).__init__(details)
diff --git a/ironic_python_agent/extensions/standby.py b/ironic_python_agent/extensions/standby.py
index c5618f9d..7e94a220 100644
--- a/ironic_python_agent/extensions/standby.py
+++ b/ironic_python_agent/extensions/standby.py
@@ -157,8 +157,7 @@ def _download_image(image_info):
LOG.info("Image downloaded from {0} in {1} seconds".format(image_location,
totaltime))
- if not _verify_image(image_info, image_location):
- raise errors.ImageChecksumError(image_info['id'])
+ _verify_image(image_info, image_location)
def _verify_image(image_info, image_location):
@@ -175,10 +174,12 @@ def _verify_image(image_info, image_location):
hash_digest = hash_.hexdigest()
if hash_digest == checksum:
return True
- log_msg = ('Image verification failed. Location: {0};'
- 'image hash: {1}; verification hash: {2}')
- LOG.warning(log_msg.format(image_location, checksum, hash_digest))
- return False
+
+ LOG.error(errors.ImageChecksumError.details_str.format(
+ image_location, image_info['id'], checksum, hash_digest))
+
+ raise errors.ImageChecksumError(image_location, image_info['id'], checksum,
+ hash_digest)
def _validate_image_info(ext, image_info=None, **kwargs):
diff --git a/ironic_python_agent/tests/unit/extensions/test_standby.py b/ironic_python_agent/tests/unit/extensions/test_standby.py
index bc3b9ea1..8b279944 100644
--- a/ironic_python_agent/tests/unit/extensions/test_standby.py
+++ b/ironic_python_agent/tests/unit/extensions/test_standby.py
@@ -236,7 +236,8 @@ class TestStandbyExtension(test_base.BaseTestCase):
image_info = self._build_fake_image_info()
response = requests_mock.return_value
response.status_code = 200
- verify_mock.return_value = False
+ verify_mock.side_effect = errors.ImageChecksumError(
+ 'foo', '/bar/foo', 'incorrect', 'correct')
self.assertRaises(errors.ImageChecksumError,
standby._download_image,
image_info)
@@ -266,8 +267,9 @@ class TestStandbyExtension(test_base.BaseTestCase):
open_mock.return_value.__enter__.return_value = file_mock
image_location = '/foo/bar'
- verified = standby._verify_image(image_info, image_location)
- self.assertFalse(verified)
+ self.assertRaises(errors.ImageChecksumError,
+ standby._verify_image,
+ image_info, image_location)
self.assertEqual(md5_mock.call_count, 1)
@mock.patch('ironic_python_agent.hardware.dispatch_to_managers',
diff --git a/ironic_python_agent/tests/unit/test_errors.py b/ironic_python_agent/tests/unit/test_errors.py
index 35fb931f..01918763 100644
--- a/ironic_python_agent/tests/unit/test_errors.py
+++ b/ironic_python_agent/tests/unit/test_errors.py
@@ -106,7 +106,9 @@ class TestErrors(test_base.BaseTestCase):
(errors.LookupAgentInterfaceError(DETAILS), SAME_DETAILS),
(errors.ImageDownloadError('image_id', DETAILS),
DIFF_CL_DETAILS),
- (errors.ImageChecksumError('image_id'), DIFF_CL_DETAILS),
+ (errors.ImageChecksumError(
+ 'image_id', '/foo/image_id', 'incorrect', 'correct'),
+ DIFF_CL_DETAILS),
(errors.ImageWriteError('device', 'exit_code', 'stdout',
'stderr'),
DIFF_CL_DETAILS),