From 6b3ba13018fbdb984fc52d96373554a6560fcb40 Mon Sep 17 00:00:00 2001 From: David Vallee Delisle Date: Thu, 14 Apr 2022 09:04:31 -0400 Subject: [PATCH] Adding testing on build_catalog To help with finding issues with this function we should test it. Change-Id: I9059568eefc3626691a445d022e544f202936839 --- .../tests/image/test_image_export.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tripleo_common/tests/image/test_image_export.py b/tripleo_common/tests/image/test_image_export.py index 1d6fc2df5..c82647f3c 100644 --- a/tripleo_common/tests/image/test_image_export.py +++ b/tripleo_common/tests/image/test_image_export.py @@ -382,6 +382,44 @@ URI: sha256:1234abcd/index.json for d in deleted: self.assertFalse(os.path.exists(d), 'deleted still exists: %s' % d) + def test_build_catalog(self): + prefix = 'docker://localhost:8787/t' + url1 = urlparse('%s/nova-api:latest' % prefix) + url2 = urlparse('%s/namespace/nova-compute:abc' % prefix) + url3 = urlparse('%s/yet/another/namespace/nova-compute:abc' % prefix) + expected_list = set([ + 't/namespace/nova-compute', + 't/yet/another/namespace/nova-compute', + 't/nova-api' + ]) + manifest = { + 'schemaVersion': 1, + 'fsLayers': [ + {'blobSum': 'sha256:aeb786'}, + {'blobSum': 'sha256:4dc536'}, + ], + 'mediaType': 'application/vnd.docker.' + 'distribution.manifest.v2+json', + } + self._write_test_image( + url=url1, + manifest=manifest + ) + self._write_test_image( + url=url2, + manifest=manifest + ) + self._write_test_image( + url=url3, + manifest=manifest + ) + + image_export.build_catalog() + catalog = os.path.join(image_export.IMAGE_EXPORT_DIR, 'v2', '_catalog') + with open(catalog, 'r') as f: + data = json.load(f) + self.assertTrue(set(data['repositories']) == expected_list) + def test_delete_image(self): url1 = urlparse('docker://localhost:8787/t/nova-api:latest') url2 = urlparse('docker://localhost:8787/t/nova-api:abc')