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

Add content copy feature #1328

Merged
merged 1 commit into from May 23, 2019
Merged

Add content copy feature #1328

merged 1 commit into from May 23, 2019

Conversation

dralley
Copy link
Contributor

@dralley dralley commented Apr 20, 2019

Also moved upload under app/tasks, because it's a task

closes #4716
https://pulp.plan.io/issues/4716

@dralley
Copy link
Contributor Author

dralley commented Apr 20, 2019

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)

  • Should we be taking a repository version as a source, instead of a repository? Or allow it to be specified as either a repository version OR a repository, like we do with publications?
  • Do we need to allow changing the "base_version" to use when creating the new repository version in the destination repo, also?

@dralley dralley force-pushed the upload-support branch 2 times, most recently from 84ffad7 to 486f3f1 Compare April 20, 2019 05:41
source_repo: repository to copy units from
dest_repo: repository to copy units to
"""
content_to_copy = RepositoryVersion.latest(source_repo).content
Copy link
Contributor Author

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

Copy link
Member

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.

Args:
source_repo: repository to copy units from
dest_repo: repository to copy units to
Optional:
Copy link
Member

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.

Copy link
Member

@bmbouter bmbouter left a 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.

@nixocio
Copy link

nixocio commented Apr 22, 2019

@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.

@nixocio
Copy link

nixocio commented Apr 22, 2019

@dralley, is this a simple copy? No dependencies resolution, right?

@dralley
Copy link
Contributor Author

dralley commented Apr 22, 2019

@kersommoura correct

@dralley dralley force-pushed the upload-support branch 5 times, most recently from 44b0a34 to eafade8 Compare April 25, 2019 20:30
@pep8speaks
Copy link

pep8speaks commented Apr 25, 2019

Hello @dralley! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-05-23 18:54:07 UTC

@dralley dralley force-pushed the upload-support branch 2 times, most recently from b1b9fa4 to 913a4cb Compare April 26, 2019 03:21
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.
Copy link
Member

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?


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\"]"``
Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

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="

Copy link
Contributor Author

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.

)

RPM_PLUGIN_TYPE_CHOICE_MAP = {
'packages': RPM_PLUGIN_TYPES.PACKAGE,
Copy link
Member

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

@ipanova
Copy link
Member

ipanova commented Apr 26, 2019

@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

@nixocio
Copy link

nixocio commented Apr 26, 2019

I will write tests for this feature as well.

default=['package', 'errata']
)

def validate(self, data):
Copy link
Contributor Author

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?


RPM_PLUGIN_TYPE_CHOICE_MAP = {
'packages': RPM_PLUGIN_TYPES.PACKAGE,
'errata': RPM_PLUGIN_TYPES.ERRATA
Copy link
Member

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',
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 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?

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 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

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@dralley dralley May 23, 2019

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:
Copy link
Member

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:
    ...

@dralley dralley force-pushed the upload-support branch 2 times, most recently from c8fd4b9 to 84b4203 Compare April 26, 2019 14:23
"but not both.")
)

if not source_repo and source_repo_version:
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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 :)

@dralley dralley force-pushed the upload-support branch 3 times, most recently from c17bd4d to 3e3e453 Compare May 1, 2019 01:58
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.
Copy link
Member

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.

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.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe replace / with 'or' ?

...
}

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.
Copy link
Member

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?


Args:
source_repo: repository to copy units from
dest_repo: repository to copy units to
Copy link
Member

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?

substitution = RPM_PLUGIN_TYPE_CHOICE_MAP.get(t)
if not substitution:
raise serializers.ValidationError(_(
"'{}' is an invalid type, please use one of {}".format(
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

@bmbouter bmbouter left a 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!

@nixocio
Copy link

nixocio commented May 16, 2019

@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.

@dralley
Copy link
Contributor Author

dralley commented May 20, 2019

Now that I'm back from Summit and being sick I'm going to re-focus on getting this merged. Hopefully today.

@dralley dralley force-pushed the upload-support branch 4 times, most recently from 7ca0a2f to 040eeb4 Compare May 23, 2019 18:35
Copy link
Contributor

@daviddavis daviddavis left a 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
@dralley dralley merged commit 672769e into pulp:master May 23, 2019
@dralley dralley deleted the upload-support branch May 23, 2019 19:45
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.

None yet

7 participants