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
Add content copy feature #1328
Add content copy feature #1328
Conversation
|
Parameter names are temporary, we can vote on what to do about those. Things to discuss (preferably on the issue: https://pulp.plan.io/issues/4716)
|
84ffad7
to
486f3f1
Compare
pulp_rpm/app/tasks/copy.py
Outdated
| source_repo: repository to copy units from | ||
| dest_repo: repository to copy units to | ||
| """ | ||
| content_to_copy = RepositoryVersion.latest(source_repo).content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're leaving this in the plugin, I would suggest that we limit it to only copying RPMs and Errata, and not everything in .content
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dralley that makes sense to me. Let's also clearly label the feature as only handling those types.
pulp_rpm/app/viewsets.py
Outdated
| Args: | ||
| source_repo: repository to copy units from | ||
| dest_repo: repository to copy units to | ||
| Optional: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line looks out of place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this code looks great! I want to request documentation for the feature that we can merge along with the feature. I think maybe a workflow section? Anyways, somewhere in the docs.
|
@dralley. It would be nice if we could add documentation, mainly the work flows for an user point view, around new features as we add them. |
|
@dralley, is this a simple copy? No dependencies resolution, right? |
|
@kersommoura correct |
44b0a34
to
eafade8
Compare
b1b9fa4
to
913a4cb
Compare
docs/workflows/copy.rst
Outdated
| Copy RPM content between repositories | ||
| ===================================== | ||
|
|
||
| If you want to copy all of the RPM content in one repository into another repository, you can do so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/in one/from a repository?
docs/workflows/copy.rst
Outdated
|
|
||
| You can also specify which types of content you would like to copy by providing a value for the "types" parameter. Types that are not listed will not be copied. The supported types are "packages" and "errata". For example, this query will copy only errata, and not packages. | ||
|
|
||
| ``http POST http://localhost:24817/pulp/api/v3/rpm/copy/ source_repo=${SRC_REPO_HREF} dest_repo=${DEST_REPO_HREF} types:="[\"errata\"]"`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do make the connection of errata and update record terminology in our docs? users copy errata and in the repo version summary they see instead update record. I am wondering - won't it be better if we just stick to update record?
this reminds me of our bitter experience in pulp2 about tasks state naming failed vs errored, sucessful vs finished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind, the endpoint for errata is /pulp/api/v3/content/rpm/errata/ so i guess it's ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dralley any reason we did not go with comma separated values? types=rpm,errata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ipanova only because this is the way things were already being done for
"add_content_units="
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ipanova Personally I think we should also change the _type string so that they show up as errata in the repository version also. The only place I've ever seen the update record terminology used is in the createrepo_c source code - I can't seem to find any other documentation calling it that vs. errata. So I don't think it's a secret "official" name vs. a marketing term or anything like that.
pulp_rpm/app/constants.py
Outdated
| ) | ||
|
|
||
| RPM_PLUGIN_TYPE_CHOICE_MAP = { | ||
| 'packages': RPM_PLUGIN_TYPES.PACKAGE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a typo here which leads to
{
"non_field_errors": [
"'package' is an invalid type, please use one of ['packages', 'errata']"
]
}
s/packages/package
|
@dralley i tested copy and works ok, i also tested invalid content types and copy of rpm related content from a mixed repo that contained rpm+ docker stuff |
|
I will write tests for this feature as well. |
| default=['package', 'errata'] | ||
| ) | ||
|
|
||
| def validate(self, data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not thrilled with this implementation - anyone know a better way?
pulp_rpm/app/constants.py
Outdated
|
|
||
| RPM_PLUGIN_TYPE_CHOICE_MAP = { | ||
| 'packages': RPM_PLUGIN_TYPES.PACKAGE, | ||
| 'errata': RPM_PLUGIN_TYPES.ERRATA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errata is a plural of Erratum, so if we use singular form for packages, we should use singular form for errata as well.
| @@ -1,5 +1,16 @@ | |||
| from types import SimpleNamespace | |||
|
|
|||
|
|
|||
| RPM_PLUGIN_TYPES = SimpleNamespace( | |||
| PACKAGE='rpm.package', | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the type of hardcode I hoped to avoid. Is it bad to do:
PACKAGE = models.Package.TYPE ? Is it because of prepending with app_label that we need to hardcode the type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it because of prepending with app_label that we need to hardcode the type?
Yup, because the value saved in _type is not the same as models.Package.TYPE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likely not a popular opinion:
Maybe we can use existing names and if we don't go fancy with simple namespaces, it can be done [arguably] easier.
E.g. for the available types use Package.TYPE,
for the type to look for in db add app_label to it.
content_filter_choice = (Package, UpdateRecord)
supported_types = [model.TYPE for model in content_filter_choice] # to validate users' input
final_types = ['{app_label}.{type}'.format(app_label=model._meta.app_label, type=model.TYPE)
for model in user_specified_types]
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do this as part of the refactor if you want, I'm not opposed. If others are fine with it also than it works for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do this as part of the refactor if you want, I'm not opposed. If others are fine with it also than it works for me. I'm not sure I want to do it right now though, I'd rather just get it merged.
| source_repo = data.get('source_repo') | ||
| source_repo_version = data.get('source_repo_version') | ||
|
|
||
| if not source_repo and not source_repo_version: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative way as an attempt to improve readability (not critical and maybe not a better option):
How about to eliminate bad combinarions first and then deal with the rest one by one?
if repo and repo_version:
raise ...
if not repo and not repo_version:
raise ...
if repo:
...
if repo_version:
...
c8fd4b9
to
84b4203
Compare
| "but not both.") | ||
| ) | ||
|
|
||
| if not source_repo and source_repo_version: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking: you already know that only one of them is set, so if source_repo_version: is enough.
Same for the source_repo condition below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to leave the logic there just to make what it's doing more clear, even if it's not strictly necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that's subjective, so up to you.
What's more straightforward and readable for one, might not be the same for the other :)
c17bd4d
to
3e3e453
Compare
docs/workflows/copy.rst
Outdated
| Copy workflow | ||
| ------------- | ||
|
|
||
| You can use the copy endpoint to copy RPM-related content present in one repository / repository version to another repository. If you specify a repository, then the latest repository version for that repository will be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick. Can all the text lines be line wrapped at 100 chars? It's ok to me if some of the links or quoted items go over 100 lines.
docs/workflows/copy.rst
Outdated
| Copy workflow | ||
| ------------- | ||
|
|
||
| You can use the copy endpoint to copy RPM-related content present in one repository / repository version to another repository. If you specify a repository, then the latest repository version for that repository will be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe replace / with 'or' ?
docs/workflows/copy.rst
Outdated
| ... | ||
| } | ||
|
|
||
| You can also specify which types of content you would like to copy by providing a value for the "types" parameter. Types that are not listed will not be copied. The supported types are "package" and "errata". For example, this query will copy only errata, and not packages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this paragraph declare the default also?
pulp_rpm/app/viewsets.py
Outdated
|
|
||
| Args: | ||
| source_repo: repository to copy units from | ||
| dest_repo: repository to copy units to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also takes source_repo_version right?
pulp_rpm/app/serializers.py
Outdated
| substitution = RPM_PLUGIN_TYPE_CHOICE_MAP.get(t) | ||
| if not substitution: | ||
| raise serializers.ValidationError(_( | ||
| "'{}' is an invalid type, please use one of {}".format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't translate correctly because some languages possibly reorder items. Only name based replacement is safe for string formatting for translation strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case this probably won't matter, but I try to follow the practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dralley I read through the code and everything looks pretty good to me. I left some requested changes, mostly small things, but hopefully you can look at those and incorporate them with your rebase. I'm lgtm-ing now since the fixes are small. Also would you be willing to file a copy story for QE so they know how to test this? Thank you!
|
@bmbouter, @dralley already filed a test case https://pulp.plan.io/issues/4721. As soon as this one is merged we can work on it. |
|
Now that I'm back from Summit and being sick I'm going to re-focus on getting this merged. Hopefully today. |
7ca0a2f
to
040eeb4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Also moved upload under app/tasks, because it's a task closes #4716 https://pulp.plan.io/issues/4716
Also moved upload under app/tasks, because it's a task
closes #4716
https://pulp.plan.io/issues/4716