Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new content subgroup to repository commands #194

Merged
merged 1 commit into from
Apr 29, 2021

Conversation

gerrod3
Copy link
Contributor

@gerrod3 gerrod3 commented Apr 1, 2021

fixes: #171

@mdellweg I marked the current repository content commands as deprecated to give time for users to update their usage to the new commands, but I can remove them if you want me to.

I set up the factory to allow for plugins that have multiple content types (ansible) and for plugins that have content that requires multiple fields for uniqueness (ansible, file). This requires some complex dynamic option generation in the factory, but I think the tradeoff is worth for the ease of adding this content subgroup to new plugins.

@@ -112,7 +114,7 @@ def sync(
)


@repository.command()
@repository.command(deprecated=True)
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

@mdellweg mdellweg left a comment

Choose a reason for hiding this comment

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

Left some comments.
I still need to convince myself, that the magic around the dynamic natural key content lookup is a good thing (or at least the best we can get...).

pulpcore/cli/common/context.py Outdated Show resolved Hide resolved
pulpcore/cli/common/generic.py Outdated Show resolved Hide resolved
pulpcore/cli/common/generic.py Outdated Show resolved Hide resolved
pulpcore/cli/common/generic.py Outdated Show resolved Hide resolved
pulpcore/cli/common/generic.py Outdated Show resolved Hide resolved
pulpcore/cli/common/generic.py Outdated Show resolved Hide resolved
pulpcore/cli/common/generic.py Outdated Show resolved Hide resolved
@@ -82,6 +83,7 @@ def repository(ctx: click.Context, pulp_ctx: PulpContext, repo_type: str) -> Non
repository.add_command(task_command(decorators=nested_lookup_options))
repository.add_command(version_command(decorators=nested_lookup_options))
repository.add_command(label_command(decorators=nested_lookup_options))
repository.add_command(repository_content_command(contexts={"file": PulpFileContentContext}))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be "file:file".
In the end nothing prevents us from adding content managed by another plugin to a repository.
e.g., I always wanted to test, whether we can replace pulp_deb's GenericContent by FileContent (they are basically identical).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there nothing in the code to prevent this? I know the plugin's repository models has a CONTENT_TYPES list field, but I'm not sure if that's check when adding content. Going with that naming scheme could be a lot of extra typing for plugin's with more than one content type and I'm not sure if there's benefit for allowing cross-plugin content sharing.

Copy link
Member

Choose a reason for hiding this comment

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

We can probably add that later...if needed
Of course we would add the "file:" by default for the user.

tests/scripts/pulp_file/test_content.sh Show resolved Hide resolved
@gerrod3
Copy link
Contributor Author

gerrod3 commented Apr 13, 2021

Left some comments.
I still need to convince myself, that the magic around the dynamic natural key content lookup is a good thing (or at least the best we can get...).

Have you seen this https://github.com/pulp/pulp-cli/pull/195/files#diff-2330f1d2bec4c88428af0e90f4ad6feff6a1663af7be7b9fedb645ed98846f68R218, I think I could do a similar thing with a group option variant. With a group option the options would be defined before hand and they could use a generic callback that has access to all options for the lookup to get the content context. I will take a look into this and see if I can simplify the crazy magic code.

@mdellweg
Copy link
Member

Left some comments.
I still need to convince myself, that the magic around the dynamic natural key content lookup is a good thing (or at least the best we can get...).

Have you seen this https://github.com/pulp/pulp-cli/pull/195/files#diff-2330f1d2bec4c88428af0e90f4ad6feff6a1663af7be7b9fedb645ed98846f68R218, I think I could do a similar thing with a group option variant. With a group option the options would be defined before hand and they could use a generic callback that has access to all options for the lookup to get the content context. I will take a look into this and see if I can simplify the crazy magic code.

Hmm, Something like that may actually work. Better yet, this mutex option will show up in the Help screen nonetheless. And only bug out in the parsing step. Worth a try.

@gerrod3 gerrod3 force-pushed the content_factory branch 5 times, most recently from f2250b0 to ef69910 Compare April 20, 2021 18:59
@gerrod3 gerrod3 requested a review from mdellweg April 20, 2021 19:13
Copy link
Member

@mdellweg mdellweg left a comment

Choose a reason for hiding this comment

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

Again, a lot to digest here...
But looking at the amount of code to add to the file section, i must say that it is pretty much very descriptive and not much boiler plate. 👍

repo_ctx.modify(repo_ctx.pulp_href, add_content=[content_ctx.pulp_href], base_version=bv)

@click.command("remove")
@click.option("--all", is_flag=True, help=_("Remove all content from 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.

Oh wow, that is new. ;)

pulpcore/cli/common/generic.py Outdated Show resolved Hide resolved
pulpcore/cli/common/context.py Show resolved Hide resolved
pulpcore/cli/file/context.py Outdated Show resolved Hide resolved
@gerrod3 gerrod3 force-pushed the content_factory branch 3 times, most recently from 7b6eae9 to ed43993 Compare April 21, 2021 15:31
@mdellweg mdellweg added this to the 0.8.0 milestone Apr 22, 2021
Copy link
Member

@mdellweg mdellweg left a comment

Choose a reason for hiding this comment

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

Sorry, the size of the PR is probably the reason i find something new every time i look at it.

CHANGES/171.feature Outdated Show resolved Hide resolved
Comment on lines +70 to +97
value = opts.get(self.name)
if self.callback is not None:
value = self.callback(ctx, self, {o: opts[o] for o in all_options}) # type: ignore
if self.expose_value:
ctx.params[self.name] = value
return value, args
Copy link
Member

Choose a reason for hiding this comment

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

I didn't look into the upstream implementation, but is this something, we could do with a super().handle_parse_result()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. super().handle_parse_result() does some casting and ensures the value passed in is a string that can be converted to the option's type. There is no easy way to ensure that the conversion won't mess up the combined value.

Copy link
Member

Choose a reason for hiding this comment

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

Ah i see, this is combining the value. Is this parsing step not called for each command in the group? how is this not clashing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This parsing step is called for each option in the group, but only the option that has the callback will get the final value from processing each value in the group. This does mean that you can't supply defaults to these grouped options as the defaults are only filled in from super().handle_parse_result(). However, you can have a callback for each option in the group and all those callbacks will receive the values for each option in the group.

Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines 529 to 530
bv = f"{repo_ctx.pulp_href}versions/{base_version}/" if base_version is not None else None
repo_ctx.modify(repo_ctx.pulp_href, add_content=[content_ctx.pulp_href], base_version=bv)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bv = f"{repo_ctx.pulp_href}versions/{base_version}/" if base_version is not None else None
repo_ctx.modify(repo_ctx.pulp_href, add_content=[content_ctx.pulp_href], base_version=bv)
base_version_href = f"{repo_ctx.pulp_href}versions/{base_version}/" if base_version is not None else None
repo_ctx.modify(repo_ctx.pulp_href, add_content=[content_ctx.pulp_href], base_version=base_version_href)

If we moved the first line to callback that returns a RepositoryVersionContext, we would get another GET call, but also a better error message if the base_version did not exist. WDYT?

@mdellweg mdellweg merged commit a3f3abe into pulp:develop Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Intuitive workflow for adding content to repositories
3 participants