Skip to content

Commit

Permalink
Store manifest in FilePublication
Browse files Browse the repository at this point in the history
closes #7838
  • Loading branch information
lubosmj authored and dkliban committed Dec 22, 2020
1 parent b191fa0 commit 3a0cb2a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 34 deletions.
2 changes: 2 additions & 0 deletions CHANGES/7838.bugfix
@@ -0,0 +1,2 @@
Fixed a bug which caused the plugin to report the default manifest's name instead of the specified
one in the publication endpoint.
19 changes: 19 additions & 0 deletions pulp_file/app/migrations/0008_add_manifest_field.py
@@ -0,0 +1,19 @@
# Generated by Django 2.2.17 on 2020-12-05 18:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('file', '0007_filefilesystemexporter'),
]

operations = [
migrations.AddField(
model_name='filepublication',
name='manifest',
field=models.TextField(default='PULP_MANIFEST'),
preserve_default=False,
),
]
2 changes: 2 additions & 0 deletions pulp_file/app/models.py
Expand Up @@ -86,6 +86,8 @@ class FilePublication(Publication):

TYPE = "file"

manifest = models.TextField()

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"

Expand Down
1 change: 0 additions & 1 deletion pulp_file/app/serializers.py
Expand Up @@ -98,7 +98,6 @@ class FilePublicationSerializer(PublicationSerializer):
)
manifest = serializers.CharField(
help_text=_("Filename to use for manifest file containing metadata for all the files."),
required=False,
default="PULP_MANIFEST",
)

Expand Down
1 change: 1 addition & 0 deletions pulp_file/app/tasks/publishing.py
Expand Up @@ -33,6 +33,7 @@ def publish(manifest, repository_version_pk):

with WorkingDirectory():
with FilePublication.create(repo_version, pass_through=True) as publication:
publication.manifest = manifest
manifest = Manifest(manifest)
manifest.write(populate(publication))
PublishedMetadata.create_from_file(
Expand Down
84 changes: 51 additions & 33 deletions pulp_file/tests/functional/api/test_publish.py
Expand Up @@ -33,6 +33,31 @@ class PublishAnyRepoVersionTestCase(unittest.TestCase):
* `Pulp Smash #897 <https://github.com/pulp/pulp-smash/issues/897>`_
"""

@classmethod
def setUpClass(cls):
"""Create class-wide variables."""
cls.cfg = config.get_config()

client = gen_file_client()
cls.repo_api = RepositoriesFileApi(client)
cls.remote_api = RemotesFileApi(client)
cls.publications = PublicationsFileApi(client)

def setUp(self):
"""Create a new repository before each test."""
body = gen_file_remote()
remote = self.remote_api.create(body)
self.addCleanup(self.remote_api.delete, remote.pulp_href)

repo = self.repo_api.create(gen_repo())
self.addCleanup(self.repo_api.delete, repo.pulp_href)

repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
sync_response = self.repo_api.sync(repo.pulp_href, repository_sync_data)
monitor_task(sync_response.task)

self.repo = self.repo_api.read(repo.pulp_href)

def test_all(self):
"""Test whether a particular repository version can be published.
Expand All @@ -46,52 +71,45 @@ def test_all(self):
6. Assert that an exception is raised when providing two different
repository versions to be published at same time.
"""
cfg = config.get_config()
client = gen_file_client()
repo_api = RepositoriesFileApi(client)
remote_api = RemotesFileApi(client)
publications = PublicationsFileApi(client)

body = gen_file_remote()
remote = remote_api.create(body)
self.addCleanup(remote_api.delete, remote.pulp_href)

repo = repo_api.create(gen_repo())
self.addCleanup(repo_api.delete, repo.pulp_href)

repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
monitor_task(sync_response.task)

# Step 1
repo = repo_api.read(repo.pulp_href)
for file_content in get_content(repo.to_dict())[FILE_CONTENT_NAME]:
modify_repo(cfg, repo.to_dict(), remove_units=[file_content])
version_hrefs = tuple(ver["pulp_href"] for ver in get_versions(repo.to_dict()))
for file_content in get_content(self.repo.to_dict())[FILE_CONTENT_NAME]:
modify_repo(self.cfg, self.repo.to_dict(), remove_units=[file_content])
version_hrefs = tuple(ver["pulp_href"] for ver in get_versions(self.repo.to_dict()))
non_latest = choice(version_hrefs[:-1])

# Step 2
publish_data = FileFilePublication(repository=repo.pulp_href)
publish_response = publications.create(publish_data)
created_resources = monitor_task(publish_response.task).created_resources
publication_href = created_resources[0]
self.addCleanup(publications.delete, publication_href)
publication = publications.read(publication_href)
publish_data = FileFilePublication(repository=self.repo.pulp_href)
publication = self.create_publication(publish_data)

# Step 3
self.assertEqual(publication.repository_version, version_hrefs[-1])

# Step 4
publish_data = FileFilePublication(repository_version=non_latest)
publish_response = publications.create(publish_data)
created_resources = monitor_task(publish_response.task).created_resources
publication_href = created_resources[0]
publication = publications.read(publication_href)
publication = self.create_publication(publish_data)

# Step 5
self.assertEqual(publication.repository_version, non_latest)

# Step 6
with self.assertRaises(ApiException):
body = {"repository": repo.pulp_href, "repository_version": non_latest}
publications.create(body)
body = {"repository": self.repo.pulp_href, "repository_version": non_latest}
self.publications.create(body)

def test_custom_manifest(self):
"""Test whether a repository version can be published with a specified manifest."""
publish_data = FileFilePublication(repository=self.repo.pulp_href)
publication = self.create_publication(publish_data)
self.assertEqual(publication.manifest, "PULP_MANIFEST")

publish_data = FileFilePublication(repository=self.repo.pulp_href, manifest="listing")
publication = self.create_publication(publish_data)
self.assertEqual(publication.manifest, "listing")

def create_publication(self, publish_data):
"""Create a new publication from the passed data."""
publish_response = self.publications.create(publish_data)
created_resources = monitor_task(publish_response.task).created_resources
publication_href = created_resources[0]
self.addCleanup(self.publications.delete, publication_href)
return self.publications.read(publication_href)

0 comments on commit 3a0cb2a

Please sign in to comment.