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

Adds new Distribution MasterModel #1198

Merged
merged 1 commit into from Apr 1, 2021

Conversation

bmbouter
Copy link
Member

@bmbouter bmbouter commented Mar 19, 2021

Added the following new objects related to a new Distribution
MasterModel:

  • pulpcore.plugin.models.Distribution - A new MasterModel
    Distribution which replaces the
    pulpcore.plugin.models.BaseDistribution. This now contains the
    repository, repository_version, and publication fields on
    the MasterModel instead of on the detail models as was done with
    pulpcore.plugin.models.BaseDistribution.

  • pulpcore.plugin.serializer.DistributionSerializer - A serializer
    plugin writers should use with the new
    pulpcore.plugin.models.Distribution.

  • pulpcore.plugin.viewset.DistributionViewSet - The viewset that
    replaces the deprecated
    pulpcore.plugin.viewset.BaseDistributionViewSet.

  • pulpcore.plugin.viewset.NewDistributionFilter - The filter that
    pairs with the Distribution model.

closes #8384

@pulpbot
Copy link
Member

pulpbot commented Mar 19, 2021

WARNING!!! This PR is not attached to an issue. In most cases this is not advisable. Please see our PR docs for more information about how to attach this PR to an issue.


if error:
msg = _(
"The attributes 'repository' and 'repository_version' must be used exclusively."
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't necessarily need to be true. We could have the same semantics as publication-based distributions, where one particular {publication | repository_version} is being pointed to, but the existence of "repository" or not tells it whether or not to auto-distribute.

I'm not opposed to this but we should have a good justification for the different semantics.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah this was a copy/paste from what we had. The thing really is that we can't have a distribution point to both a repository and a publication at the same time. Let me try to work on this validation to make that true instead and tell me what you think.

@bmbouter
Copy link
Member Author

bmbouter commented Mar 24, 2021

I added the overlapping cross-model base path support. I'm hand-testing it because pulpcore's CI doesn't have two plugins with heterogeneous Distribution types. This code isn't going to be around long enough to justify adding two plugins for dedicated tests. So what I did was:

  1. Install pulp_file with this PR checked out: Switches FileDistribution use Distribution pulp_file#481
  2. Made a pulp_file distribution with pulp file distribution create --name mydistro --base-path foo
  3. Created an ansible repo (needed to create an ansible distribution). pulp ansible repository create --name ansiblerepo
  1. Created a distribution and correctly received the overlapping error cross-model.
pulp ansible distribution create --name asdf --base-path foo/bar --repository ansiblerepo
Error: {"base_path":["Overlaps with existing distribution 'mydistro'"]}

@bmbouter
Copy link
Member Author

I added the overlapping cross-model name uniqueness support. I'm hand-testing it because pulpcore's CI doesn't have two plugins with heterogeneous Distribution types. This code isn't going to be around long enough to justify adding two plugins for dedicated tests. So what I did was:

  1. Install pulp_file with this PR checked out: Switches FileDistribution use Distribution pulp_file#481
  2. Made a pulp_file distribution with pulp file distribution create --name mydistro --base-path foo
  3. Created an ansible repo (needed to create an ansible distribution). pulp ansible repository create --name ansiblerepo
  1. Created a distribution and correctly received the overlapping error cross-model.
pulp ansible distribution create --name mydistro --base-path another --repository ansiblerepo
Error: {"name":["This field must be unique."]}


Subclasses are expected to use either the ``publication`` or ``repository_version`` field, but
not both. The content app that serves content is not prepared to serve content both ways at the
same time.
Copy link
Contributor

@dralley dralley Mar 24, 2021

Choose a reason for hiding this comment

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

I wish we could unify this either by attaching publication to repository version, or using publication.pass_through for "RepositoryVersionDistributions"

No action item here, just a thought.

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be nice to unify, but some plugins don't need a publication at all so I'm not sure creating an object would make sense to them. I see where you're coming from though. Either way maybe we can still unify in the future somehow.

@bmbouter bmbouter force-pushed the new-distribution-master-model branch from 669e4fb to 9fda294 Compare March 25, 2021 13:08
bmbouter added a commit to bmbouter/pulp_file that referenced this pull request Mar 26, 2021
pulpcore==3.12 introduces a new MasterModel named `Distribution`
designed to replace the `BaseDistribution` MasterModel. This PR switches
the `FileDistribution` to use `Distribution`. It also ships a migration
which moves the data from the `BaseDistribution` table to the
`Distribution` field.

Required PR: pulp/pulpcore#1198

closes #8387
@bmbouter bmbouter force-pushed the new-distribution-master-model branch 2 times, most recently from 4a52067 to c9fcfdf Compare March 26, 2021 18:48
bmbouter added a commit to bmbouter/pulp_file that referenced this pull request Mar 26, 2021
pulpcore==3.12 introduces a new MasterModel named `Distribution`
designed to replace the `BaseDistribution` MasterModel. This PR switches
the `FileDistribution` to use `Distribution`. It also ships a migration
which moves the data from the `BaseDistribution` table to the
`Distribution` field.

Required PR: pulp/pulpcore#1198

closes #8387
bmbouter added a commit to bmbouter/pulp_file that referenced this pull request Mar 26, 2021
pulpcore==3.12 introduces a new MasterModel named `Distribution`
designed to replace the `BaseDistribution` MasterModel. This PR switches
the `FileDistribution` to use `Distribution`. It also ships a migration
which moves the data from the `BaseDistribution` table to the
`Distribution` field.

Required PR: pulp/pulpcore#1198

closes #8387
bmbouter added a commit to bmbouter/pulp_file that referenced this pull request Mar 29, 2021
pulpcore==3.12 introduces a new MasterModel named `Distribution`
designed to replace the `BaseDistribution` MasterModel. This PR switches
the `FileDistribution` to use `Distribution`. It also ships a migration
which moves the data from the `BaseDistribution` table to the
`Distribution` field.

Required PR: pulp/pulpcore#1198

closes #8387


class DistributionRepositoryVersionSerializerMixin:
repository = DetailRelatedField(
Copy link
Member Author

Choose a reason for hiding this comment

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

I think repository needs to either be copied to DistributionPublicationSerializerMixin or it needs to become its own mixin. @daviddavis @dralley @mdellweg wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why should it be copied if it's now present and usable by both? I would think it would be part of the standard distribution serializer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Won't the help text be slightly different for publication distributions vs repo version distributions?

Copy link
Contributor

@dralley dralley Mar 30, 2021

Choose a reason for hiding this comment

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

I don't think it necessarily has to be. Something like The latest version of this repository will be distributed automatically is still true even if there's a publication step that happens in the middle.

It's actually not even true that the latest publication is what gets served, at least not atm.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm moving repository to DistributionSerializer itself. Also I have to remove these Mixins because the tests point out that we can't create a distribution that has a publication due to the error: {"publication":["Invalid hyperlink - Incorrect URL match."]}.

To work around that I tried setting:

  • view_name_pattern=r"publication(-.*/.*)?-detail",
  • view_name_pattern=r"publications(-.*/.*)?-detail",
  • view_name_pattern="publication-detail",

None of ^ worked.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the consequence of removing the mixins, unnecessary fields?

Copy link
Member Author

Choose a reason for hiding this comment

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

Plugins will have to copy the block now shown in the docstring of DistributionSerializer. We can't provide a de-duplicated copy.

@bmbouter bmbouter force-pushed the new-distribution-master-model branch from c9fcfdf to 48b1874 Compare March 30, 2021 15:10
@bmbouter bmbouter changed the title New Distribution MasterModel Adds new Distribution MasterModel Mar 30, 2021
@bmbouter bmbouter force-pushed the new-distribution-master-model branch 3 times, most recently from 7aa903e to 7351dda Compare March 30, 2021 15:54
@bmbouter bmbouter marked this pull request as ready for review March 30, 2021 15:55
@bmbouter bmbouter force-pushed the new-distribution-master-model branch 3 times, most recently from 092a2f0 to 6ed39c5 Compare March 30, 2021 19:01
bmbouter added a commit to bmbouter/pulp_file that referenced this pull request Mar 30, 2021
pulpcore==3.12 introduces a new MasterModel named `Distribution`
designed to replace the `BaseDistribution` MasterModel. This PR switches
the `FileDistribution` to use `Distribution`. It also ships a migration
which moves the data from the `BaseDistribution` table to the
`Distribution` field.

Required PR: pulp/pulpcore#1198

closes #8387
@bmbouter
Copy link
Member Author

FYI I wrote up the two issues to resolve the NewDistributionFilter name this PR introduces:

  1. Rename it when we remove the current DistributionFilter: https://pulp.plan.io/issues/8480
  2. Eventually remove it: https://pulp.plan.io/issues/8479

@bmbouter bmbouter force-pushed the new-distribution-master-model branch 2 times, most recently from 7aae22f to b0db519 Compare March 30, 2021 19:50
bmbouter added a commit to bmbouter/pulp_file that referenced this pull request Mar 30, 2021
pulpcore==3.12 introduces a new MasterModel named `Distribution`
designed to replace the `BaseDistribution` MasterModel. This PR switches
the `FileDistribution` to use `Distribution`. It also ships a migration
which moves the data from the `BaseDistribution` table to the
`Distribution` field.

Required PR: pulp/pulpcore#1198

closes #8387
validators=[
UniqueValidator(queryset=models.BaseDistribution.objects.all()),
UniqueValidator(queryset=models.Distribution.objects.all()),
],
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

pulpcore/app/serializers/publication.py Outdated Show resolved Hide resolved
@bmbouter bmbouter force-pushed the new-distribution-master-model branch from b0db519 to 319cdb9 Compare March 31, 2021 12:56
bmbouter added a commit to bmbouter/pulp_file that referenced this pull request Mar 31, 2021
pulpcore==3.12 introduces a new MasterModel named `Distribution`
designed to replace the `BaseDistribution` MasterModel. This PR switches
the `FileDistribution` to use `Distribution`. It also ships a migration
which moves the data from the `BaseDistribution` table to the
`Distribution` field.

Required PR: pulp/pulpcore#1198

closes #8387
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.

Looks good to me.

@bmbouter bmbouter force-pushed the new-distribution-master-model branch 2 times, most recently from 461decc to d5ce7d1 Compare March 31, 2021 19:44
def validate(self, data):
super().validate(data)

publication_in_data = "publication" in data
Copy link
Member Author

Choose a reason for hiding this comment

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

@dralley check this portion out, it's revised.


if error:
msg = _(
"The attributes 'publication' and 'repository_version' must be used exclusively."
Copy link
Contributor

@dralley dralley Mar 31, 2021

Choose a reason for hiding this comment

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

This is very slightly unclear I think. Maybe say something like

Only one of the attributes 'publication' and 'repository_version' may be used simultaneously.

@bmbouter bmbouter force-pushed the new-distribution-master-model branch 2 times, most recently from dfa89ed to 3142a24 Compare April 1, 2021 15:19
Added the following new objects related to a new ``Distribution``
MasterModel:

* ``pulpcore.plugin.models.Distribution`` - A new MasterModel
  ``Distribution`` which replaces the
  ``pulpcore.plugin.models.BaseDistribution``. This now contains the
  ``repository``, ``repository_version``, and ``publication`` fields on
  the MasterModel instead of on the detail models as was done with
  ``pulpcore.plugin.models.BaseDistribution``.

* ``pulpcore.plugin.serializer.DistributionSerializer`` - A serializer
  plugin writers should use with the new
  ``pulpcore.plugin.models.Distribution``.

* ``pulpcore.plugin.viewset.DistributionViewSet`` - The viewset that
  replaces the deprecated
  ``pulpcore.plugin.viewset.BaseDistributionViewSet``.

* ``pulpcore.plugin.viewset.NewDistributionFilter`` - The filter that
  pairs with the ``Distribution`` model.

closes #8384
@bmbouter bmbouter force-pushed the new-distribution-master-model branch from 3142a24 to d92b6ea Compare April 1, 2021 18:38
warnings.warn(
_(
"BaseDistributionSerializer is deprecated and could be removed as early as "
"pulpcore==3.13; use pulpcore.plugin.serializers.DistributionSerializer instead."
Copy link
Contributor

Choose a reason for hiding this comment

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

I would almost suggest putting a link to the Pulp File PR in here since it is a fairly "involved" migration process.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually one of the other ones calls out the migration specifically. I'm going to merge for now if that's alright.

Copy link
Contributor

@dralley dralley left a comment

Choose a reason for hiding this comment

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

See suggestion, otherwise LGTM

@bmbouter bmbouter merged commit d55f1c2 into pulp:master Apr 1, 2021
@bmbouter bmbouter deleted the new-distribution-master-model branch April 1, 2021 19:41
bmbouter added a commit to pulp/pulp_file that referenced this pull request Apr 1, 2021
pulpcore==3.12 introduces a new MasterModel named `Distribution`
designed to replace the `BaseDistribution` MasterModel. This PR switches
the `FileDistribution` to use `Distribution`. It also ships a migration
which moves the data from the `BaseDistribution` table to the
`Distribution` field.

Required PR: pulp/pulpcore#1198

closes #8387
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

5 participants