Skip to content

Commit 4150bd4

Browse files
committed
Decouple workflows for importing refs and commits
closes #19
1 parent 513b6c2 commit 4150bd4

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

CHANGES/19.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Decoupled workflows for importing all refs and commits. To import everything from a tarball, one
2+
should use the ``import-all`` command. When importing commits assigned to a specific ref, it is
3+
recommended to use the ``import-commits`` command.

pulpcore/cli/ostree/context.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,22 @@ class PulpOstreeRepositoryContext(PulpRepositoryContext):
9898
DELETE_ID = "repositories_ostree_ostree_delete"
9999
SYNC_ID = "repositories_ostree_ostree_sync"
100100
MODIFY_ID = "repositories_ostree_ostree_modify"
101-
IMPORT_ID: ClassVar[str] = "repositories_ostree_ostree_import_commits"
101+
IMPORT_ALL_ID: ClassVar[str] = "repositories_ostree_ostree_import_all"
102+
IMPORT_COMMITS_ID: ClassVar[str] = "repositories_ostree_ostree_import_commits"
102103
VERSION_CONTEXT = PulpOstreeRepositoryVersionContext
103104
CAPABILITIES = {
104105
"sync": [PluginRequirement("ostree")],
106+
"import_all": [PluginRequirement("ostree", min="2.0.0a6.dev")],
105107
"import_commits": [PluginRequirement("ostree")],
106108
}
107109

110+
def import_all(self, href: str, artifact: str, repository_name: str) -> Any:
111+
body: Dict[str, Any] = {
112+
"artifact": artifact,
113+
"repository_name": repository_name,
114+
}
115+
return self.pulp_ctx.call(self.IMPORT_ALL_ID, parameters={self.HREF: href}, body=body)
116+
108117
def import_commits(
109118
self,
110119
href: str,
@@ -124,7 +133,7 @@ def import_commits(
124133
body["parent_commit"] = parent_commit
125134

126135
return self.pulp_ctx.call(
127-
self.IMPORT_ID,
136+
self.IMPORT_COMMITS_ID,
128137
parameters={self.HREF: href},
129138
body=body,
130139
)

pulpcore/cli/ostree/repository.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,36 @@ def sync(
186186
repository_ctx.sync(href=repository_href, body=body)
187187

188188

189-
@repository.command()
189+
@repository.command(help=_("Import all refs and commits from a tarball"))
190+
@click.option("--file", type=click.File("rb"), required=True)
191+
@chunk_size_option
192+
@name_option
193+
@click.option(
194+
"--repository_name",
195+
type=str,
196+
required=True,
197+
help=_("Name of a repository which contains the imported commits"),
198+
)
199+
@pass_repository_context
200+
@pass_pulp_context
201+
def import_all(
202+
pulp_ctx: PulpContext,
203+
repository_ctx: PulpOstreeRepositoryContext,
204+
file: IO[bytes],
205+
chunk_size: int,
206+
repository_name: str,
207+
) -> None:
208+
repository_href = repository_ctx.pulp_href
209+
artifact_href = PulpArtifactContext(pulp_ctx).upload(file, chunk_size)
210+
kwargs = {
211+
"href": repository_href,
212+
"artifact": artifact_href,
213+
"repository_name": repository_name,
214+
}
215+
repository_ctx.import_all(**kwargs)
216+
217+
218+
@repository.command(help=_("Import commits from a tarball to a specific ref"))
190219
@click.option("--file", type=click.File("rb"), required=True)
191220
@chunk_size_option
192221
@name_option

tests/scripts/pulp_ostree/test_import_publish.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ wget --no-parent -r "$OSTREE_REMOTE_URL"
1414
tar --exclude="index.html" -cvf "fixtures_small_repo.tar" -C "$OSTREE_DOWNLOADED_REPO_PATH" "small"
1515

1616
expect_succ pulp ostree repository create --name "cli_test_ostree_repository"
17-
expect_succ pulp ostree repository import-commits --name "cli_test_ostree_repository" \
18-
--file "fixtures_small_repo.tar" \
19-
--repository_name "small"
17+
18+
if pulp debug has-plugin --name "ostree" --min-version "2.0.0a6.dev"
19+
then
20+
expect_succ pulp ostree repository import-all --name "cli_test_ostree_repository" \
21+
--file "fixtures_small_repo.tar" \
22+
--repository_name "small"
23+
else
24+
expect_succ pulp ostree repository import-commits --name "cli_test_ostree_repository" \
25+
--file "fixtures_small_repo.tar" \
26+
--repository_name "small"
27+
fi
2028

2129
tar -xvf fixtures_small_repo.tar
2230
# extract the latest commit checksum from the ref 'stable'

0 commit comments

Comments
 (0)