diff --git a/pulp-glue/pulp_glue/common/context.py b/pulp-glue/pulp_glue/common/context.py index 7acd0860a..38adda784 100644 --- a/pulp-glue/pulp_glue/common/context.py +++ b/pulp-glue/pulp_glue/common/context.py @@ -1632,21 +1632,30 @@ def upload( self.needs_capability("upload") size = os.path.getsize(file.name) body: t.Dict[str, t.Any] = {**kwargs} - if not self.pulp_ctx.fake_mode: # Skip the uploading part in fake_mode + + if not self.pulp_ctx.fake_mode: if chunk_size > size: + # Small file: direct upload body["file"] = file - elif self.pulp_ctx.has_plugin(PluginRequirement("core", specifier=">=3.20.0")): - from pulp_glue.core.context import PulpUploadContext - - upload_href = PulpUploadContext(self.pulp_ctx).upload_file(file, chunk_size) - body["upload"] = upload_href else: - from pulp_glue.core.context import PulpArtifactContext + # Large file: chunked upload + if self.pulp_ctx.has_plugin(PluginRequirement("core", specifier=">=3.20.0")): + from pulp_glue.core.context import PulpUploadContext + + upload_href = PulpUploadContext(self.pulp_ctx).upload_file(file, chunk_size) + body["upload"] = upload_href + else: + from pulp_glue.core.context import PulpArtifactContext + + artifact_href = PulpArtifactContext(self.pulp_ctx).upload(file, chunk_size) + body["artifact"] = artifact_href + + # If no repository is provided, use synchronous upload endpoint + if repository is None: + return self.call("upload", body=body) - artifact_href = PulpArtifactContext(self.pulp_ctx).upload(file, chunk_size) - body["artifact"] = artifact_href - if repository: - body["repository"] = repository + # Repository is specified: use create endpoint (async path) + body["repository"] = repository return self.create(body=body) diff --git a/pulpcore/cli/rpm/content.py b/pulpcore/cli/rpm/content.py index 9dbc607a9..04c3726f0 100644 --- a/pulpcore/cli/rpm/content.py +++ b/pulpcore/cli/rpm/content.py @@ -389,11 +389,14 @@ def upload( _("You must specify one (and only one) of --file or --directory.") ) - # Sanity: If directory, repository required + # Sanity: If directory with temp repo, repository required final_dest_repo_ctx = kwargs["repository"] - if directory and not final_dest_repo_ctx: + if directory and kwargs["use_temp_repository"] and not final_dest_repo_ctx: raise click.ClickException( - _("You must specify a --repository to use --directory uploads.") + _( + "You must specify a --repository to use --use-temp-repository " + "with --directory uploads." + ) ) # Sanity: ignore publish|use_temp unless directory has been specified @@ -416,17 +419,20 @@ def upload( ) else: # Upload a directory-full of RPMs + dest_repo_ctx = None try: dest_repo_ctx = _determine_upload_repository(final_dest_repo_ctx, pulp_ctx, use_tmp) result = _upload_rpms(entity_ctx, dest_repo_ctx, directory, chunk_size) - if use_tmp: + if use_tmp and dest_repo_ctx: result = _copy_to_final(dest_repo_ctx, final_dest_repo_ctx, pulp_ctx) finally: if use_tmp and dest_repo_ctx: # Remove the tmp-upload repo dest_repo_ctx.delete() - final_version_number = _latest_version_number(final_dest_repo_ctx) + final_version_number = ( + _latest_version_number(final_dest_repo_ctx) if final_dest_repo_ctx else None + ) if final_version_number: click.echo( _( @@ -488,7 +494,7 @@ def _copy_to_final( def _upload_rpms( entity_ctx: PulpContentContext, - dest_repo_ctx: PulpRpmRepositoryContext, + dest_repo_ctx: t.Optional[PulpRpmRepositoryContext], directory: t.Any, chunk_size: int, ) -> t.Any: @@ -496,15 +502,28 @@ def _upload_rpms( rpm_names = glob.glob(rpms_path) if not rpm_names: raise click.ClickException(_("Directory {} has no .rpm files in it.").format(directory)) - click.echo( - _( - "About to upload {} files for {}.".format( - len(rpm_names), - dest_repo_ctx.entity["name"], - ) - ), - err=True, - ) + + # Build message based on whether we have a repository or not + if dest_repo_ctx: + click.echo( + _( + "About to upload {} files for {}.".format( + len(rpm_names), + dest_repo_ctx.entity["name"], + ) + ), + err=True, + ) + else: + click.echo( + _( + "About to upload {} files from {}.".format( + len(rpm_names), + directory, + ) + ), + err=True, + ) # Upload all *.rpm into the destination successful_uploads = 0 for name in rpm_names: @@ -525,9 +544,11 @@ def _upload_rpms( def _determine_upload_repository( - final_dest_repo_ctx: PulpRpmRepositoryContext, pulp_ctx: PulpCLIContext, use_tmp: bool -) -> PulpRpmRepositoryContext: - if use_tmp: + final_dest_repo_ctx: t.Optional[PulpRpmRepositoryContext], + pulp_ctx: PulpCLIContext, + use_tmp: bool, +) -> t.Optional[PulpRpmRepositoryContext]: + if use_tmp and final_dest_repo_ctx: dest_repo_ctx = PulpRpmRepositoryContext(pulp_ctx) body: t.Dict[str, t.Any] = { "name": f"uploadtmp_{final_dest_repo_ctx.entity['name']}_{uuid4()}",