From cf93be323b30889dac3149feb3f124f372514dbd Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Oct 10 2019 14:51:02 +0000 Subject: Handle S3 downloading errors gracefully Fixes: #40 Signed-off-by: Aurélien Bompard --- diff --git a/robosignatory/coreos.py b/robosignatory/coreos.py index 2f14b3b..9453c93 100644 --- a/robosignatory/coreos.py +++ b/robosignatory/coreos.py @@ -8,6 +8,7 @@ import tempfile import boto3 import robosignatory.utils as utils +from botocore.exceptions import ClientError from six.moves.urllib.parse import urlparse from fedora_messaging.api import Message, publish @@ -112,7 +113,10 @@ class SignerWrapper(object): local_filepath = os.path.join(tmpdir, os.path.basename(filepath)) log.info("Downloading %s", filepath) - self.bucket.download_file(filepath, local_filepath) + try: + self.bucket.download_file(filepath, local_filepath) + except ClientError as e: + raise SigningFailed("Could not download {}: {}".format(filepath, e)) log.info("Checking hash for %s", filepath) if utils.get_hash(local_filepath) != checksum: diff --git a/tests/test_coreos.py b/tests/test_coreos.py index c4bf595..1a4af34 100644 --- a/tests/test_coreos.py +++ b/tests/test_coreos.py @@ -4,6 +4,7 @@ import copy from collections import namedtuple import mock +from botocore.exceptions import ClientError from fedora_messaging.api import Message from fedora_messaging.testing import mock_sends @@ -160,3 +161,16 @@ class TestCoreOS(unittest.TestCase): self.consumer.bucket.download_file.assert_called() run_command.assert_called() self.consumer.bucket.upload_file.assert_not_called() + + def test_download_failed(self): + self.consumer.bucket.download_file.side_effect = ClientError({}, None) + expected_response = self._get_response_message( + ARTIFACTS_MESSAGE, failed=True, + failure_msg='Could not download some/path/test1: An error occurred ' + '(Unknown) when calling the None operation: Unknown') + + with mock_sends(expected_response): + self.consumer.consume(ARTIFACTS_MESSAGE) + + self.consumer.bucket.download_file.assert_called() + self.consumer.bucket.upload_file.assert_not_called()