Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/1324.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for serving Python content form a repository version.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of the "we don't need no publication" effort, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it is more like "we can specify the repository version directly, even without using a publication"

18 changes: 18 additions & 0 deletions pulp-glue/src/pulp_glue/python/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> En
body["publication"] = None
if "repository" not in body and "publication" in body:
body["repository"] = None

if self.pulp_ctx.has_plugin(PluginRequirement("python", specifier=">=3.21.0")):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when you specify --version on pulp_python<3.21?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLI returns Error: {"version":["Unexpected field"]}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a corresponding "needs_version" to the top of this method?

version = body.pop("version", None)
if version is not None:
if repository_href := body.pop("repository", None):
body["repository_version"] = f"{repository_href}versions/{version}/"
body["repository"] = None
else:
current_entity = self.entity
if repository_href := current_entity.get("repository"):
body["repository_version"] = f"{repository_href}versions/{version}/"
body["repository"] = None
elif repository_version_href := current_entity.get("repository_version"):
repository_href = repository_version_href.partition("versions")[0]
body["repository_version"] = f"{repository_href}versions/{version}/"
elif "repository" in body:
body["repository_version"] = None

return body


Expand Down
9 changes: 9 additions & 0 deletions src/pulpcore/cli/python/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ def distribution(ctx: click.Context, pulp_ctx: PulpCLIContext, /, distribution_t
),
),
repository_option,
pulp_option(
"--version",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you specify the version and no repository?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repository_version is created based on the newly provided version and already existing repository (repository is then set to null). This is covered in tests.

type=int,
help=_(
"A repository version number, leave blank for latest."
" When set, repository will no longer be auto-distributed."
),
needs_plugins=[PluginRequirement("python", specifier=">=3.21.0")],
),
content_guard_option,
pulp_option(
"--allow-uploads/--block-uploads",
Expand Down
39 changes: 39 additions & 0 deletions tests/scripts/pulp_python/test_distribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cleanup() {
pulp python repository destroy --name "cli_test_python_distribution_repository" || true
pulp python remote destroy --name "cli_test_python_distribution_remote" || true
pulp python distribution destroy --name "cli_test_python_distro" || true
pulp python distribution destroy --name "cli_test_python_distro_repo_version" || true
}
trap cleanup EXIT

Expand Down Expand Up @@ -42,3 +43,41 @@ expect_succ pulp python distribution update \
--remote "cli_test_python_distribution_remote"

expect_succ pulp python distribution destroy --distribution "cli_test_python_distro"

# Test repository_version functionality
if pulp debug has-plugin --name "python" --specifier ">=3.21.0"; then
expect_succ pulp python distribution create \
--name "cli_test_python_distro_repo_version" \
--base-path "cli_test_python_distro_repo_version" \
--repository "cli_test_python_distribution_repository" \
--version 0
expect_succ pulp python distribution show --distribution "cli_test_python_distro_repo_version"
echo "$OUTPUT" | jq -e '.repository_version | contains("/versions/0/")'
echo "$OUTPUT" | jq -e '.repository == null'

expect_succ pulp python distribution update \
--distribution "cli_test_python_distro_repo_version" \
--repository "cli_test_python_distribution_repository" \
--version 1
expect_succ pulp python distribution show --distribution "cli_test_python_distro_repo_version"
echo "$OUTPUT" | jq -e '.repository_version | contains("/versions/1/")'
echo "$OUTPUT" | jq -e '.repository == null'

expect_succ pulp python distribution update \
--distribution "cli_test_python_distro_repo_version" \
--version 0
expect_succ pulp python distribution show --distribution "cli_test_python_distro_repo_version"
echo "$OUTPUT" | jq -e '.repository_version | contains("/versions/0/")'
echo "$OUTPUT" | jq -e '.repository == null'

expect_succ pulp python distribution update \
--distribution "cli_test_python_distro_repo_version" \
--repository "cli_test_python_distribution_repository"
expect_succ pulp python distribution show --distribution "cli_test_python_distro_repo_version"
echo "$OUTPUT" | jq -e '.repository_version == null'
echo "$OUTPUT" | jq -e '.repository != null'

expect_succ pulp python distribution destroy --distribution "cli_test_python_distro_repo_version"
else
echo "Python plugin version >=3.21.0 not available, skipping repository_version tests"
fi
Loading