From 69158f678236a5cf62c74a6a64e0aabac42e05ea Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Mon, 16 Mar 2020 10:12:32 -0600 Subject: [PATCH] Change how we test for call It appears that there are json comparison issues for some versions <= py35 so we need to check that the expected manifest matches in a different way to ensure compatibility between py27 and newer. Since we've dropped these versions of python in Ussuri, this only applies to older version. Change-Id: I011cb62850bb4f298f78a1cfede4e60044523be6 Closes-Bug: #1867648 (cherry picked from commit 23ec01dc3f9d16e1fe73c1bc96cb0983574098a6) --- .../tests/image/test_image_uploader.py | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/tripleo_common/tests/image/test_image_uploader.py b/tripleo_common/tests/image/test_image_uploader.py index cda1b0d15..2239b9763 100644 --- a/tripleo_common/tests/image/test_image_uploader.py +++ b/tripleo_common/tests/image/test_image_uploader.py @@ -2068,7 +2068,7 @@ class TestPythonImageUploader(base.TestCase): ], 'mediaType': image_uploader.MEDIA_MANIFEST_V2 }) - expected_manifest_str = json.dumps({ + expected_manifest = { 'config': { 'digest': 'sha256:1234', 'size': 2, @@ -2079,7 +2079,7 @@ class TestPythonImageUploader(base.TestCase): {'digest': 'sha256:bbbb'}, ], 'mediaType': image_uploader.MEDIA_MANIFEST_V2 - }, indent=3) + } expected_headers = { 'Content-Type': image_uploader.MEDIA_MANIFEST_V2 @@ -2090,10 +2090,16 @@ class TestPythonImageUploader(base.TestCase): ) calls = [mock.call(build_url, - data=expected_manifest_str.encode('utf-8'), + data=mock.ANY, headers=expected_headers, timeout=30)] target_put.assert_has_calls(calls) + # We're seeing ordering issues with the py27 checking this field + # so switch to checking it this way + call_manifest = json.loads( + target_put.call_args[1]['data'].decode('utf-8') + ) + self.assertEqual(expected_manifest, call_manifest) @mock.patch('tripleo_common.image.image_export.export_manifest_config') def test_copy_manifest_config_to_registry_export(self, export_mock): @@ -2114,7 +2120,7 @@ class TestPythonImageUploader(base.TestCase): {'digest': 'sha256:bbbb'}, ], }) - expected_manifest_str = json.dumps({ + expected_manifest = { 'config': { 'digest': 'sha256:1234', 'size': 2, @@ -2125,7 +2131,7 @@ class TestPythonImageUploader(base.TestCase): {'digest': 'sha256:bbbb'}, ], 'mediaType': image_uploader.MEDIA_MANIFEST_V2 - }, indent=3) + } self.uploader._copy_manifest_config_to_registry( target_url, manifest_str, config_str, @@ -2133,11 +2139,17 @@ class TestPythonImageUploader(base.TestCase): ) calls = [mock.call(target_url, - expected_manifest_str, + mock.ANY, image_uploader.MEDIA_MANIFEST_V2, config_str, multi_arch=False)] export_mock.assert_has_calls(calls) + # We're seeing ordering issues with the py27 checking this field + # so switch to checking it this way + call_manifest = json.loads( + export_mock.call_args[0][1] + ) + self.assertEqual(expected_manifest, call_manifest) @mock.patch('tripleo_common.image.image_uploader.' 'BaseImageUploader.check_status') @@ -2173,7 +2185,7 @@ class TestPythonImageUploader(base.TestCase): ], 'mediaType': image_uploader.MEDIA_OCI_MANIFEST_V1 }) - expected_manifest_str = json.dumps({ + expected_manifest = { 'config': { 'digest': 'sha256:1234', 'size': 2, @@ -2184,7 +2196,7 @@ class TestPythonImageUploader(base.TestCase): {'digest': 'sha256:bbbb'}, ], 'mediaType': image_uploader.MEDIA_MANIFEST_V2 - }, indent=3) + } expected_headers = { 'Content-Type': image_uploader.MEDIA_MANIFEST_V2 @@ -2195,10 +2207,16 @@ class TestPythonImageUploader(base.TestCase): ) calls = [mock.call(build_url, - data=expected_manifest_str.encode('utf-8'), + data=mock.ANY, headers=expected_headers, timeout=30)] target_put.assert_has_calls(calls) + # We're seeing ordering issues with the py27 checking this field + # so switch to checking it this way + call_manifest = json.loads( + target_put.call_args[1]['data'].decode('utf-8') + ) + self.assertEqual(expected_manifest, call_manifest) @mock.patch('os.environ') @mock.patch('subprocess.Popen')