Request checksum when required 47/74847/1
authorCédric Ollivier <cedric.ollivier@orange.com>
Thu, 10 Apr 2025 07:29:15 +0000 (09:29 +0200)
committerCédric Ollivier <cedric.ollivier@orange.com>
Thu, 10 Apr 2025 07:58:59 +0000 (09:58 +0200)
Set via boto config:
request_checksum_calculation="when_required"
response_checksum_validation="when_required"

https://github.com/boto/boto3/issues/4400#issuecomment-2600742103

Change-Id: I3efca93d57d01ea68159085a348ce6a1cc88dd00
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
(cherry picked from commit 3e2e41de927b7859f3e1cbb056466df39c66e6e9)

xtesting/core/campaign.py
xtesting/core/testcase.py
xtesting/tests/unit/core/test_testcase.py

index 98b2f1a..7220743 100644 (file)
@@ -183,7 +183,10 @@ class Campaign():
                     for filename in files:
                         zfile.write(os.path.join(root, filename))
             b3resource = boto3.resource(
-                's3', endpoint_url=os.environ["S3_ENDPOINT_URL"])
+                's3', endpoint_url=os.environ["S3_ENDPOINT_URL"],
+                config=botocore.config.Config(
+                    request_checksum_calculation="when_required",
+                    response_checksum_validation="when_required"))
             dst_s3_url = os.environ["S3_DST_URL"]
             multipart_threshold = 5 * 1024 ** 5 if "google" in os.environ[
                 "S3_ENDPOINT_URL"] else 8 * 1024 * 1024
index 559f35a..65d875f 100644 (file)
@@ -285,7 +285,10 @@ class TestCase(metaclass=abc.ABCMeta):
         """
         try:
             b3resource = boto3.resource(
-                's3', endpoint_url=os.environ["S3_ENDPOINT_URL"])
+                's3', endpoint_url=os.environ["S3_ENDPOINT_URL"],
+                config=botocore.config.Config(
+                    request_checksum_calculation="when_required",
+                    response_checksum_validation="when_required"))
             dst_s3_url = os.environ["S3_DST_URL"]
             multipart_threshold = 5 * 1024 ** 5 if "google" in os.environ[
                 "S3_ENDPOINT_URL"] else 8 * 1024 * 1024
index f7d1b94..2e48169 100644 (file)
@@ -354,14 +354,16 @@ class TestCaseTesting(unittest.TestCase):
         self.assertEqual(self.test.publish_artifacts(),
                          testcase.TestCase.EX_PUBLISH_ARTIFACTS_ERROR)
         args[0].assert_called_once_with(
-            's3', endpoint_url=os.environ['S3_ENDPOINT_URL'])
+            's3', endpoint_url=os.environ['S3_ENDPOINT_URL'],
+            config=mock.ANY)
 
     @mock.patch('boto3.resource', side_effect=Exception)
     def test_publish_artifacts_exc3(self, *args):
         self.assertEqual(self.test.publish_artifacts(),
                          testcase.TestCase.EX_PUBLISH_ARTIFACTS_ERROR)
         args[0].assert_called_once_with(
-            's3', endpoint_url=os.environ['S3_ENDPOINT_URL'])
+            's3', endpoint_url=os.environ['S3_ENDPOINT_URL'],
+            config=mock.ANY)
 
     @mock.patch('boto3.resource')
     def test_publish_artifacts_exc4(self, *args):
@@ -369,7 +371,8 @@ class TestCaseTesting(unittest.TestCase):
         self.assertEqual(self.test.publish_artifacts(),
                          testcase.TestCase.EX_PUBLISH_ARTIFACTS_ERROR)
         args[0].assert_called_once_with(
-            's3', endpoint_url=os.environ['S3_ENDPOINT_URL'])
+            's3', endpoint_url=os.environ['S3_ENDPOINT_URL'],
+            config=mock.ANY)
 
     @mock.patch('boto3.resource')
     def test_publish_artifacts_exc5(self, *args):
@@ -380,7 +383,8 @@ class TestCaseTesting(unittest.TestCase):
         self.assertEqual(self.test.publish_artifacts(),
                          testcase.TestCase.EX_PUBLISH_ARTIFACTS_ERROR)
         args[0].assert_called_once_with(
-            's3', endpoint_url=os.environ['S3_ENDPOINT_URL'])
+            's3', endpoint_url=os.environ['S3_ENDPOINT_URL'],
+            config=mock.ANY)
 
     @mock.patch('mimetypes.guess_type', return_value=(None, None))
     @mock.patch('boto3.resource')
@@ -390,7 +394,8 @@ class TestCaseTesting(unittest.TestCase):
                          testcase.TestCase.EX_OK)
         args[0].assert_called_once_with(self.test.res_dir)
         args[1].assert_called_once_with(
-            's3', endpoint_url=os.environ['S3_ENDPOINT_URL'])
+            's3', endpoint_url=os.environ['S3_ENDPOINT_URL'],
+            config=mock.ANY)
 
     @mock.patch('mimetypes.guess_type', return_value=(None, None))
     @mock.patch('boto3.resource')
@@ -404,7 +409,8 @@ class TestCaseTesting(unittest.TestCase):
                          testcase.TestCase.EX_OK)
         args[0].assert_called_once_with(self.test.res_dir)
         args[1].assert_called_once_with(
-            's3', endpoint_url=os.environ['S3_ENDPOINT_URL'])
+            's3', endpoint_url=os.environ['S3_ENDPOINT_URL'],
+            config=mock.ANY)
 
     @mock.patch('mimetypes.guess_type', return_value=(None, None))
     @mock.patch('os.path.exists', return_value=True)
@@ -417,7 +423,9 @@ class TestCaseTesting(unittest.TestCase):
                          testcase.TestCase.EX_OK)
         args[0].assert_called_once_with(self.test.res_dir)
         expected = [
-            mock.call('s3', endpoint_url=os.environ['S3_ENDPOINT_URL']),
+            mock.call(
+                's3', endpoint_url=os.environ['S3_ENDPOINT_URL'],
+                config=mock.ANY),
             mock.call().meta.client.head_bucket(Bucket='xtesting'),
             mock.call().Bucket('xtesting'),
             mock.call().Bucket().upload_file(
@@ -451,7 +459,9 @@ class TestCaseTesting(unittest.TestCase):
                          testcase.TestCase.EX_OK)
         args[0].assert_called_once_with(self.test.res_dir)
         expected = [
-            mock.call('s3', endpoint_url=os.environ['S3_ENDPOINT_URL']),
+            mock.call(
+                's3', endpoint_url=os.environ['S3_ENDPOINT_URL'],
+                config=mock.ANY),
             mock.call().meta.client.head_bucket(Bucket='xtesting'),
             mock.call().Bucket('xtesting'),
             mock.call().Bucket().upload_file(