def test_verify_fail_no_build(self): workflow = self.workflow(build_process_failed=True) tasker = MockerTasker() plugin = VerifyMediaTypesPlugin(tasker, workflow) results = plugin.run() assert results == []
def test_source_container(self, expected_media_types): """ Test that v2 schema 1 images are not reported for source containers """ registry = { 'url': 'https://container-registry.example.com/v2', 'version': 'v2', 'insecure': True, } if expected_media_types is not None: registry['expected_media_types'] = expected_media_types workflow = self.workflow(registries=[registry], group=False, limit_media_types=[ MEDIA_TYPE_DOCKER_V2_SCHEMA2, ], registry_types=[ MEDIA_TYPE_DOCKER_V2_SCHEMA1, MEDIA_TYPE_DOCKER_V2_SCHEMA2, ]) workflow.prebuild_results[PLUGIN_FETCH_SOURCES_KEY] = {} tasker = MockerTasker() plugin = VerifyMediaTypesPlugin(tasker, workflow) results = plugin.run() assert results == [MEDIA_TYPE_DOCKER_V2_SCHEMA2]
def test_verify_fail_bad_results(self, caplog): """ All results are garbage, so fail """ workflow = self.workflow(fail="bad_results") tasker = MockerTasker() plugin = VerifyMediaTypesPlugin(tasker, workflow) expect_media_types = [] expect_missing_types = sorted([ MEDIA_TYPE_DOCKER_V2_MANIFEST_LIST, MEDIA_TYPE_DOCKER_V2_SCHEMA1, MEDIA_TYPE_DOCKER_V2_SCHEMA2, MEDIA_TYPE_OCI_V1, MEDIA_TYPE_OCI_V1_INDEX ]) expected_msg = "expected media types {0} ".format(expect_missing_types) available_msg = "not in available media types {0}, ".format( expect_media_types) registry_msg = "for registry {0}".format( 'container-registry.example.com') failmsg = expected_msg + available_msg + registry_msg with pytest.raises(KeyError) as exc: plugin.run() assert 'expected media types were not found' in str(exc.value) assert failmsg in caplog.text
def test_verify_fail_no_image(self): workflow = self.workflow() workflow.tag_conf = TagConf() tasker = MockerTasker() plugin = VerifyMediaTypesPlugin(tasker, workflow) with pytest.raises(ValueError) as exc: plugin.run() assert "no unique image set, impossible to verify media types" in str(exc.value)
def test_verify_fail_pulp_image(self, caplog): workflow = self.workflow() workflow.push_conf.add_pulp_registry('pulp', crane_uri='crane.example.com', server_side_sync=False) tasker = MockerTasker() plugin = VerifyMediaTypesPlugin(tasker, workflow) results = plugin.run() assert not results assert "pulp registry configure, verify_media_types should not run" in caplog.text()
def test_verify_fail_no_build(self): """ Build was unsuccessful, return an empty list """ workflow = self.workflow(build_process_failed=True) tasker = MockerTasker() plugin = VerifyMediaTypesPlugin(tasker, workflow) results = plugin.run() assert results == []
def test_verify_malformed_two_registries(self, registries, platforms, platform_descriptors, group, no_amd64, expected_results): workflow = self.workflow(registries=registries, platforms=platforms, platform_descriptors=platform_descriptors, group=group, no_amd64=no_amd64) tasker = MockerTasker() plugin = VerifyMediaTypesPlugin(tasker, workflow) results = plugin.run() assert results == sorted(expected_results)
def test_verify_successful_complicated(self, registry_types, platform_descriptors, group, no_amd64, expected_results): workflow = self.workflow(registry_types=registry_types, platform_descriptors=platform_descriptors, group=group, no_amd64=no_amd64) tasker = MockerTasker() plugin = VerifyMediaTypesPlugin(tasker, workflow) results = plugin.run() assert results == sorted(expected_results)
def test_verify_successful_simple(self): workflow = self.workflow() tasker = MockerTasker() # Set the timeout parameters so that we retry exactly once, but quickly. # With the get_manifest_digests() API, the 'broken_response' case isn't # distinguishable from no manifest yet, so we retry until timout plugin = VerifyMediaTypesPlugin(tasker, workflow) results = plugin.run() assert results == sorted([MEDIA_TYPE_DOCKER_V1, MEDIA_TYPE_DOCKER_V2_SCHEMA1, MEDIA_TYPE_DOCKER_V2_SCHEMA2, MEDIA_TYPE_DOCKER_V2_MANIFEST_LIST])
def test_verify_fail_no_image(self): """ If there is no image, this plugin shouldn't run and how did we get here? """ workflow = self.workflow() workflow.tag_conf = TagConf() tasker = MockerTasker() plugin = VerifyMediaTypesPlugin(tasker, workflow) with pytest.raises(ValueError) as exc: plugin.run() assert "no unique image set, impossible to verify media types" in str( exc.value)
def test_verify_successful_two_registries(self, registries, platform_descriptors, group, expected_results): """ Two registries, everything behaves correctly """ workflow = self.workflow(registries=registries, platform_descriptors=platform_descriptors, group=group) tasker = MockerTasker() plugin = VerifyMediaTypesPlugin(tasker, workflow) results = plugin.run() assert results == sorted(expected_results)
def test_verify_fail_bad_results(self): workflow = self.workflow(fail="bad_results") tasker = MockerTasker() plugin = VerifyMediaTypesPlugin(tasker, workflow) expect_media_types = [MEDIA_TYPE_DOCKER_V1] expect_missing_types = sorted([MEDIA_TYPE_DOCKER_V2_MANIFEST_LIST, MEDIA_TYPE_DOCKER_V2_SCHEMA1, MEDIA_TYPE_DOCKER_V2_SCHEMA2]) missing_msg = "expected media types {0} ".format(expect_missing_types) media_msg = "not in available media types {0}".format(expect_media_types) failmsg = missing_msg + media_msg with pytest.raises(KeyError) as exc: plugin.run() assert failmsg in str(exc.value)
def test_verify_malformed_two_registries(self, registries, platforms, platform_descriptors, group, expected_results): """ Configuration is bad, but not so bad as to cause a problem """ workflow = self.workflow(registries=registries, platforms=platforms, platform_descriptors=platform_descriptors, group=group) tasker = MockerTasker() plugin = VerifyMediaTypesPlugin(tasker, workflow) results = plugin.run() assert results == sorted(expected_results)