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

3.14-cherrypicks #1515

Merged
merged 2 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES/9103.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improved disk usage during the synchronization.
(backported from #8295)
2 changes: 2 additions & 0 deletions CHANGES/9110.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a bug where on-demand downloads would fill up ``/var/run/`` by not deleting downloaded files.
(backported from #9000)
6 changes: 3 additions & 3 deletions pulpcore/app/models/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class FileSystem(FileSystemStorage):
"""
Django's FileSystemStorage with modified _save() and get_available_name behaviors

The _save() will check if the file is saved in MEDIA_ROOT first. If it is, a move is used. This
The _save() will check if the file is saved in DEPLOY_ROOT first. If it is, a move is used. This
will move all files created by the Downloaders and uploaded files from the user. If it is saved
in-memory or outside of MEDIA_ROOT, the data is written in chunks to the new location.
in-memory or outside of DEPLOY_ROOT, the data is written/copied in chunks to the new location.
"""

def get_available_name(self, name, max_length=None):
Expand Down Expand Up @@ -63,7 +63,7 @@ def _save(self, name, content, max_length=None):

try:
if hasattr(content, "temporary_file_path") and content.temporary_file_path().startswith(
settings.MEDIA_ROOT
str(settings.DEPLOY_ROOT)
):
file_move_safe(content.temporary_file_path(), full_path)
else:
Expand Down
2 changes: 2 additions & 0 deletions pulpcore/content/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def save_heartbeat_blocking():


async def server(*args, **kwargs):
os.chdir(settings.WORKING_DIRECTORY)

asyncio.ensure_future(_heartbeat())
for pulp_plugin in pulp_plugin_configs():
if pulp_plugin.name != "pulpcore.app":
Expand Down
6 changes: 6 additions & 0 deletions pulpcore/content/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,12 @@ def _save_artifact(self, download_result, remote_artifact):
**download_result.artifact_attributes, file=download_result.path
)
artifact.save()
else:
# The file needs to be unlinked because it was not used to create an artifact.
# The artifact must have already been saved while servicing another request for
# the same artifact.
os.unlink(download_result.path)

update_content_artifact = True
if content_artifact._state.adding:
# This is the first time pull-through content was requested.
Expand Down
14 changes: 8 additions & 6 deletions pulpcore/tests/unit/content/test_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tempfile

from unittest.mock import Mock

from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase

from pulpcore.content import Handler
Expand All @@ -20,28 +21,29 @@ def setUp(self):
)
self.ra2 = Mock(content_artifact=self.ca2)

def download_result_mock(self, path):
def download_result_mock(self):
dr = Mock()
dr.artifact_attributes = {"size": 0}
for digest_type in Artifact.DIGEST_FIELDS:
dr.artifact_attributes[digest_type] = "abc123"
dr.path = SimpleUploadedFile(name=path, content="")
tmp_file = tempfile.NamedTemporaryFile(delete=False)
dr.path = tmp_file.name
return dr

def test_save_artifact(self):
"""Artifact needs to be created."""
cch = Handler()
new_artifact = cch._save_artifact(self.download_result_mock("c1"), self.ra1)
new_artifact = cch._save_artifact(self.download_result_mock(), self.ra1)
c1 = Content.objects.get(pk=self.c1.pk)
self.assertIsNotNone(new_artifact)
self.assertEqual(c1._artifacts.get().pk, new_artifact.pk)

def test_save_artifact_artifact_already_exists(self):
"""Artifact turns out to already exist."""
cch = Handler()
new_artifact = cch._save_artifact(self.download_result_mock("c1"), self.ra1)
new_artifact = cch._save_artifact(self.download_result_mock(), self.ra1)

existing_artifact = cch._save_artifact(self.download_result_mock("c2"), self.ra2)
existing_artifact = cch._save_artifact(self.download_result_mock(), self.ra2)
c2 = Content.objects.get(pk=self.c2.pk)
self.assertEqual(existing_artifact.pk, new_artifact.pk)
self.assertEqual(c2._artifacts.get().pk, existing_artifact.pk)