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 23ec01dc3f)
This commit is contained in:
Alex Schultz 2020-03-16 10:12:32 -06:00
parent d2e9011fd2
commit 69158f6782
1 changed files with 27 additions and 9 deletions

View File

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