Skip to content

Commit

Permalink
Adds workaround for requires_ansible
Browse files Browse the repository at this point in the history
Collections on galaxy.ansible.com may not have the expected
`requires_ansible` data.

closes #806
  • Loading branch information
bmbouter authored and mdellweg committed Jan 28, 2022
1 parent 750e8b0 commit 85fed51
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES/806.bugfix
Original file line number Diff line number Diff line change
@@ -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``.
5 changes: 4 additions & 1 deletion pulp_ansible/app/tasks/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,10 @@ 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)
)
Expand Down
15 changes: 15 additions & 0 deletions pulp_ansible/tests/functional/api/collection/v2/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ 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",
Expand Down

0 comments on commit 85fed51

Please sign in to comment.