diff --git a/.github/workflows/scripts/install.sh b/.github/workflows/scripts/install.sh index 81126e22..b99832a0 100755 --- a/.github/workflows/scripts/install.sh +++ b/.github/workflows/scripts/install.sh @@ -79,7 +79,7 @@ cat >> vars/main.yaml << VARSYAML pulp_env: {} pulp_settings: null pulp_scheme: https -pulp_default_container: ghcr.io/pulp/pulp-ci-centos:latest +pulp_default_container: ghcr.io/pulp/pulp-ci-centos9:latest VARSYAML if [ "$TEST" = "s3" ]; then diff --git a/CHANGES/366.bugfix b/CHANGES/366.bugfix new file mode 100644 index 00000000..ac95bbc1 --- /dev/null +++ b/CHANGES/366.bugfix @@ -0,0 +1,2 @@ +Fixed an issue with `rpm-ostree` having multiples commits in the same tar file and breaking +Pulp `import-commits`. diff --git a/pulp_ostree/app/tasks/importing.py b/pulp_ostree/app/tasks/importing.py index ad1ccc2d..cf8ea47b 100644 --- a/pulp_ostree/app/tasks/importing.py +++ b/pulp_ostree/app/tasks/importing.py @@ -139,6 +139,9 @@ async def load_next_commits(self, parent_commit, checksum, has_referenced_parent parent_checksum = OSTree.commit_get_parent(parent_commit) + # keep a reference to the parent's commit checksum + first_parent_checksum = parent_checksum + while parent_checksum: commit = OstreeCommit(checksum=checksum, _pulp_domain=self.domain) commit_dc = self.create_dc(relative_path, commit) @@ -172,6 +175,8 @@ async def load_next_commits(self, parent_commit, checksum, has_referenced_parent await self.submit_previous_commits_and_related_objects() + return first_parent_checksum, commit_dc + async def copy_from_storage_to_tmp(self, parent_commit, objs): file_path = os.path.join(self.repo_path, parent_commit.relative_path) commit_file = await parent_commit._artifacts.aget() diff --git a/pulp_ostree/tests/functional/api/test_import.py b/pulp_ostree/tests/functional/api/test_import.py index 7e02086f..7a61cc69 100644 --- a/pulp_ostree/tests/functional/api/test_import.py +++ b/pulp_ostree/tests/functional/api/test_import.py @@ -276,3 +276,77 @@ def test_version_removal( ) response.raise_for_status() assert exc.value.response.status_code == 404, repo_version2_href + + +@pytest.mark.parallel +def test_import_commits_same_ref( + artifacts_api_client, + gen_object_with_cleanup, + monitor_task, + ostree_repository_factory, + ostree_repositories_api_client, + ostree_repositories_versions_api_client, + tmp_path, +): + """Import a repository with import-all, then import single commits with import-commits.""" + os.chdir(tmp_path) + repo_name = "repo" + sample_dir = tmp_path / str(uuid.uuid4()) + sample_file1 = sample_dir / str(uuid.uuid4()) + sample_file2 = sample_dir / str(uuid.uuid4()) + branch_name = "foo" + + # 1. create a first file + sample_dir.mkdir() + sample_file1.touch() + + # 2. initialize a local OSTree repository and commit the created file + subprocess.run(["ostree", f"--repo={repo_name}", "init", "--mode=archive"]) + subprocess.run( + ["ostree", f"--repo={repo_name}", "commit", f"--branch={branch_name}", f"{sample_dir}/"] + ) + subprocess.run(["tar", "-cvf", f"{repo_name}.tar", f"{repo_name}/"]) + + artifact = gen_object_with_cleanup(artifacts_api_client, f"{repo_name}.tar") + repo = ostree_repository_factory(name=repo_name) + commit_data = OstreeImportAll(artifact.pulp_href, repo_name) + response = ostree_repositories_api_client.import_all(repo.pulp_href, commit_data) + repo_version = monitor_task(response.task).created_resources[0] + + repository_version = ostree_repositories_versions_api_client.read(repo_version) + added_content = repository_version.content_summary.added + assert added_content["ostree.config"]["count"] == 1 + assert added_content["ostree.summary"]["count"] == 1 + assert added_content["ostree.refs"]["count"] == 1 + assert added_content["ostree.commit"]["count"] == 1 + + parent_commit = "" + with open(f"{repo_name}/refs/heads/{branch_name}", "r") as ref: + parent_commit = ref.read().strip() + + # 3. commit a second file + sample_file2.touch() + subprocess.run( + [ + "ostree", + f"--repo={repo_name}", + "commit", + f"--branch={branch_name}", + f"{sample_dir}/", + f"--parent={parent_commit}", + ] + ) + subprocess.run(["tar", "-cvf", f"{repo_name}.tar", f"{repo_name}/"]) + + artifact = gen_object_with_cleanup(artifacts_api_client, f"{repo_name}.tar") + + add_data = OstreeImportCommitsToRef(artifact.pulp_href, repo_name, branch_name) + response = ostree_repositories_api_client.import_commits(repo.pulp_href, add_data) + repo_version = monitor_task(response.task).created_resources[0] + + repository_version = ostree_repositories_versions_api_client.read(repo_version) + added_content = repository_version.content_summary.added + assert added_content["ostree.refs"]["count"] == 1 + assert added_content["ostree.commit"]["count"] == 1 + assert added_content["ostree.content"]["count"] == 2 + assert added_content["ostree.summary"]["count"] == 1 diff --git a/template_config.yml b/template_config.yml index 4f4834be..88f8f108 100644 --- a/template_config.yml +++ b/template_config.yml @@ -9,7 +9,7 @@ check_commit_message: true check_gettext: true check_manifest: true check_stray_pulpcore_imports: true -ci_base_image: ghcr.io/pulp/pulp-ci-centos +ci_base_image: ghcr.io/pulp/pulp-ci-centos9 ci_env: {} ci_trigger: '{pull_request: {branches: [''*'']}}' ci_update_docs: true