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/272.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added cli options for configuring excluded package metadata fields on remotes, repositories and publications
29 changes: 28 additions & 1 deletion pulp-glue-deb/src/pulp_glue/deb/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
_ = translation.gettext


def _tuple_to_list(field_name: str, body: EntityDefinition) -> None:
"""Convert a repeated cli option tuple to an API list"""
if field_name not in body:
return

value = body[field_name]
if not isinstance(value, tuple):
return

if not value:
body.pop(field_name)
else:
body[field_name] = [item for item in value if item]


class PulpDebGenericContentContext(PulpContentContext):
ENTITY = "deb generic content"
ENTITIES = "deb generic contents"
Expand Down Expand Up @@ -137,6 +152,7 @@ class PulpAptPublicationContext(PulpEntityContext):

def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> EntityDefinition:
body = super().preprocess_entity(body)
_tuple_to_list("excluded_package_metadata_fields", body)
version = body.pop("version", None)
if version is not None:
repository_href = body.pop("repository")
Expand All @@ -145,7 +161,12 @@ def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> En


class PulpVerbatimPublicationContext(PulpEntityContext):
APT_ONLY: ClassVar[set[str]] = {"simple", "structured", "signing_service"}
APT_ONLY: ClassVar[set[str]] = {
"simple",
"structured",
"signing_service",
"excluded_package_metadata_fields",
}
ENTITY = _("verbatim publication")
ENTITIES = _("verbatim publications")
HREF = "deb_verbatim_publication_href"
Expand Down Expand Up @@ -199,6 +220,7 @@ def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> En
raise PulpException("Must have at least one distribution for remote.")
self.tuple_to_whitespace_separated_string("components", body)
self.tuple_to_whitespace_separated_string("architectures", body)
_tuple_to_list("excluded_package_metadata_fields", body)
return body


Expand All @@ -219,3 +241,8 @@ class PulpAptRepositoryContext(PulpRepositoryContext):
RESOURCE_TYPE = "apt"
VERSION_CONTEXT = PulpAptRepositoryVersionContext
CAPABILITIES = {"pulpexport": [PluginRequirement("deb", "2.20.0")]}

def preprocess_entity(self, body: EntityDefinition, partial: bool = False) -> EntityDefinition:
body = super().preprocess_entity(body)
_tuple_to_list("excluded_package_metadata_fields", body)
return body
10 changes: 10 additions & 0 deletions src/pulpcore/cli/deb/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ def publication(ctx: click.Context, pulp_ctx: PulpCLIContext, /, publication_typ
context_table={"deb:apt": PulpSigningServiceContext},
help=_("Apt only: Signing service to use, pass in name or href"),
),
pulp_option(
"--excluded-package-metadata-field",
"excluded_package_metadata_fields",
multiple=True,
help=_(
"Apt only: Custom package metadata field to omit from generated Packages indices. "
"Can be specified multiple times."
),
needs_plugins=[PluginRequirement("deb", specifier=">=3.11.0")],
),
]
publication.add_command(list_command(decorators=publication_filter_options))
publication.add_command(show_command(decorators=lookup_options))
Expand Down
12 changes: 12 additions & 0 deletions src/pulpcore/cli/deb/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
load_string_callback,
name_option,
pass_pulp_context,
pulp_option,
show_command,
update_command,
)

from pulp_glue.common.context import PluginRequirement
from pulp_glue.common.i18n import get_translation
from pulp_glue.deb.context import PulpAptRemoteContext

Expand Down Expand Up @@ -63,6 +65,16 @@ def remote(ctx: click.Context, pulp_ctx: PulpCLIContext, /, remote_type: str) ->
"Will sync all available if specified once with the empty string."
),
),
pulp_option(
"--excluded-package-metadata-field",
"excluded_package_metadata_fields",
multiple=True,
help=_(
"Custom package metadata field to exclude during sync. "
"Can be specified multiple times. Pass an empty string to clear the list."
),
needs_plugins=[PluginRequirement("deb", specifier=">=3.11.0")],
),
]

distribution_help = _("Distribution to sync; can be specified multiple times.")
Expand Down
10 changes: 10 additions & 0 deletions src/pulpcore/cli/deb/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ def repository(ctx: click.Context, pulp_ctx: PulpCLIContext, /, repo_type: str)
nested_lookup_options = [repository_href_option, repository_lookup_option]
update_options = [
click.option("--description"),
pulp_option(
"--excluded-package-metadata-field",
"excluded_package_metadata_fields",
multiple=True,
help=_(
"Custom package metadata field to exclude by default from structured publications. "
"Can be specified multiple times. Pass an empty string to clear the list."
),
needs_plugins=[PluginRequirement("deb", specifier=">=3.11.0")],
),
remote_option,
# pulp_option(
# "--autopublish/--no-autopublish",
Expand Down
14 changes: 14 additions & 0 deletions tests/scripts/pulp_deb/test_deb_remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ assert "$(echo "$OUTPUT" | jq -r .components)" == "foo"
assert "$(echo "$OUTPUT" | jq -r .architectures)" == "foo"
expect_succ pulp deb remote update --name "${ENTITIES_NAME}"

if pulp debug has-plugin --name deb --specifier ">=3.12.0.dev"; then
expect_succ pulp deb remote update --name "${ENTITIES_NAME}" \
--excluded-package-metadata-field "Phased-Update-Percentage" \
--excluded-package-metadata-field "X-Test-Field"
expect_succ pulp deb remote show --name "${ENTITIES_NAME}"
assert "$(echo "$OUTPUT" | jq -c .excluded_package_metadata_fields)" == \
'["Phased-Update-Percentage","X-Test-Field"]'

expect_succ pulp deb remote update --name "${ENTITIES_NAME}" \
--excluded-package-metadata-field ""
expect_succ pulp deb remote show --name "${ENTITIES_NAME}"
assert "$(echo "$OUTPUT" | jq -c .excluded_package_metadata_fields)" == '[]'
fi

# Try some possible modifications of the remote's distribution:
expect_succ pulp deb remote update --name "${ENTITIES_NAME}" --distribution "bar"
expect_succ pulp deb remote show --name "${ENTITIES_NAME}"
Expand Down
30 changes: 24 additions & 6 deletions tests/scripts/pulp_deb/test_deb_sync_publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@ expect_succ pulp deb remote create \
--url "$DEB_REMOTE_URL" \
--distribution "$DEB_DISTRIBUTION"

expect_succ pulp deb repository create \
--name "${ENTITIES_NAME}_repo" \
--remote "${ENTITIES_NAME}_remote"
if pulp debug has-plugin --name deb --specifier ">=3.12.0.dev"; then
expect_succ pulp deb repository create \
--name "${ENTITIES_NAME}_repo" \
--remote "${ENTITIES_NAME}_remote" \
--excluded-package-metadata-field "Phased-Update-Percentage"
assert "$(echo "$OUTPUT" | jq -c .excluded_package_metadata_fields)" == \
'["Phased-Update-Percentage"]'
else
expect_succ pulp deb repository create \
--name "${ENTITIES_NAME}_repo" \
--remote "${ENTITIES_NAME}_remote"
fi

expect_succ pulp deb repository sync \
--name "${ENTITIES_NAME}_repo"
Expand All @@ -36,9 +45,18 @@ if pulp debug has-plugin --name deb --min-version 2.20.0.dev; then
--no-optimize
fi

expect_succ pulp deb publication create \
--repository "${ENTITIES_NAME}_repo" \
--simple
if pulp debug has-plugin --name deb --specifier ">=3.11.0"; then
expect_succ pulp deb publication create \
--repository "${ENTITIES_NAME}_repo" \
--simple \
--excluded-package-metadata-field "Phased-Update-Percentage"
assert "$(echo "$OUTPUT" | jq -c .excluded_package_metadata_fields)" == \
'["Phased-Update-Percentage"]'
else
expect_succ pulp deb publication create \
--repository "${ENTITIES_NAME}_repo" \
--simple
fi

PUBLICATION_HREF=$(echo "$OUTPUT" | jq -r .pulp_href)

Expand Down
Loading