diff --git a/CHANGES/806.bugfix b/CHANGES/806.bugfix new file mode 100644 index 000000000..7e27280d3 --- /dev/null +++ b/CHANGES/806.bugfix @@ -0,0 +1,2 @@ +Adds workaround to handle collections that do not have a ``requires_ansible`` in the +``meta/runtime.yml`` data. This can happen in collections from ``galaxy.ansible.com``. diff --git a/pulp_ansible/app/tasks/collections.py b/pulp_ansible/app/tasks/collections.py index 2dfbed07e..d52db4d7a 100644 --- a/pulp_ansible/app/tasks/collections.py +++ b/pulp_ansible/app/tasks/collections.py @@ -1046,7 +1046,9 @@ def _post_save(self, batch): ) if runtime_metadata: runtime_yaml = yaml.safe_load(runtime_metadata) - collection_version.requires_ansible = runtime_yaml.get("requires_ansible") + if runtime_yaml: + collection_version.requires_ansible = runtime_yaml.get( + "requires_ansible") manifest_data = json.load( get_file_obj_from_tarball(tar, "MANIFEST.json", artifact.file.name) ) diff --git a/pulp_ansible/tests/functional/api/collection/v2/test_sync.py b/pulp_ansible/tests/functional/api/collection/v2/test_sync.py index bd764f44a..642632cd2 100644 --- a/pulp_ansible/tests/functional/api/collection/v2/test_sync.py +++ b/pulp_ansible/tests/functional/api/collection/v2/test_sync.py @@ -134,6 +134,22 @@ def test_sync_with_invalid_requirements(self): ) self.assertRaises(ApiException, self.remote_collection_api.create, body) + def test_sync_collection_missing_requires_ansible(self): + """Sync a collection with the expected `requires_ansible` data missing.""" + body = gen_ansible_remote( + url="https://galaxy.ansible.com", + requirements_file="collections:\n - name: inexio.thola\n version: 1.0.0", + sync_dependencies=False, + ) + remote = self.remote_collection_api.create(body) + self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) + + repo = self._create_repo_and_sync_with_remote(remote) + + content = self.cv_api.list(repository_version=f"{repo.pulp_href}versions/1/") + self.assertGreaterEqual(len(content.results), 1) + + @unittest.skipUnless( "MIRROR_GALAXY" in os.environ, "'MIRROR_GALAXY' env var is not defined",