From: Cédric Ollivier Date: Thu, 10 Apr 2025 07:29:15 +0000 (+0200) Subject: Request checksum when required X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=3e2e41de927b7859f3e1cbb056466df39c66e6e9;p=functest-xtesting.git Request checksum when required 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 --- diff --git a/xtesting/core/campaign.py b/xtesting/core/campaign.py index 98b2f1a8..72207436 100644 --- a/xtesting/core/campaign.py +++ b/xtesting/core/campaign.py @@ -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 diff --git a/xtesting/core/testcase.py b/xtesting/core/testcase.py index 559f35a6..65d875f6 100644 --- a/xtesting/core/testcase.py +++ b/xtesting/core/testcase.py @@ -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 diff --git a/xtesting/tests/unit/core/test_testcase.py b/xtesting/tests/unit/core/test_testcase.py index f7d1b940..2e481697 100644 --- a/xtesting/tests/unit/core/test_testcase.py +++ b/xtesting/tests/unit/core/test_testcase.py @@ -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(