Skip to content

Commit

Permalink
wip/draft
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hyagi committed Jun 17, 2024
1 parent 3c65ed1 commit fbcced9
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES/366.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed an issue with `rpm-ostree` having multiples commits in the same tar file and breaking
Pulp `import-commits`.
5 changes: 5 additions & 0 deletions pulp_ostree/app/tasks/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
74 changes: 74 additions & 0 deletions pulp_ostree/tests/functional/api/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fbcced9

Please sign in to comment.