#41 Handle S3 downloading errors gracefully
Merged 4 years ago by abompard. Opened 4 years ago by abompard.
abompard/robosignatory coreos  into  master

file modified
+5 -1
@@ -8,6 +8,7 @@ 

  

  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 @@ 

          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:

file modified
+14
@@ -4,6 +4,7 @@ 

  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 @@ 

          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()

Fixes: #40

Signed-off-by: Aurélien Bompard aurelien@bompard.org

Pull-Request has been merged by abompard

4 years ago