Skip to content

Commit

Permalink
Ensure that /tmp is not used but the current worker working directory.
Browse files Browse the repository at this point in the history
Also log the real traceback to make it possible to troubleshoot the failure.

backports #9551
https://pulp.plan.io/issues/9551

fixes #9629

(cherry picked from commit fdcc1b4)
  • Loading branch information
dralley committed Dec 21, 2021
1 parent 4c25271 commit c2ea1d8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES/9629.bugfix
@@ -0,0 +1,2 @@
Ensured that RPM plugin uses only a worker working directory and not /tmp which could have caused the out-of-disc-space issue since it's not expected that Pulp uses /tmp.
(backported from #9551)
9 changes: 8 additions & 1 deletion pulp_rpm/app/serializers/package.py
@@ -1,3 +1,6 @@
import logging
import traceback

from gettext import gettext as _

from rest_framework import serializers
Expand All @@ -12,6 +15,9 @@
from pulp_rpm.app.shared_utils import _prepare_package


log = logging.getLogger(__name__)


class PackageSerializer(SingleArtifactContentUploadSerializer, ContentChecksumSerializer):
"""
A Serializer for Package.
Expand Down Expand Up @@ -237,7 +243,8 @@ def deferred_validate(self, data):
try:
new_pkg = _prepare_package(data["artifact"], data["relative_path"])
except OSError:
raise NotAcceptable(detail="RPM file cannot be parsed for metadata.")
log.info(traceback.format_exc())
raise NotAcceptable(detail="RPM file cannot be parsed for metadata")

attrs = {key: new_pkg[key] for key in Package.natural_key_fields()}
package = Package.objects.filter(**attrs)
Expand Down
2 changes: 1 addition & 1 deletion pulp_rpm/app/shared_utils.py
Expand Up @@ -23,7 +23,7 @@ def _prepare_package(artifact, filename):
filename: name of file uploaded by user
"""
artifact_file = storage.open(artifact.file.name)
with tempfile.NamedTemporaryFile("wb", suffix=filename) as temp_file:
with tempfile.NamedTemporaryFile("wb", dir=".", suffix=filename) as temp_file:
shutil.copyfileobj(artifact_file, temp_file)
temp_file.flush()
cr_pkginfo = createrepo_c.package_from_rpm(temp_file.name)
Expand Down
5 changes: 2 additions & 3 deletions pulp_rpm/app/tasks/publishing.py
Expand Up @@ -204,7 +204,7 @@ def handle_sub_repos(self, distribution_tree):
relative_path__in=[".treeinfo", "treeinfo"]
)
artifact_file = storage.open(original_treeinfo_content_artifact.artifact.file.name)
with tempfile.NamedTemporaryFile("wb") as temp_file:
with tempfile.NamedTemporaryFile("wb", dir=".") as temp_file:
shutil.copyfileobj(artifact_file, temp_file)
temp_file.flush()
treeinfo = PulpTreeInfo()
Expand All @@ -219,9 +219,8 @@ def handle_sub_repos(self, distribution_tree):
main_variant = treeinfo.original_parser._sections.get("general", {}).get(
"variant", None
)
treeinfo_file = tempfile.NamedTemporaryFile()
treeinfo_file = tempfile.NamedTemporaryFile(dir=".")
treeinfo.dump(treeinfo_file.name, main_variant=main_variant)

PublishedMetadata.create_from_file(
relative_path=original_treeinfo_content_artifact.relative_path,
publication=self.publication,
Expand Down
2 changes: 1 addition & 1 deletion pulp_rpm/app/tasks/synchronizing.py
Expand Up @@ -415,7 +415,7 @@ def get_treeinfo_data(remote, remote_url):
main_variant = treeinfo.original_parser._sections.get("general", {}).get(
"variant", None
)
treeinfo_file = tempfile.NamedTemporaryFile(delete=False)
treeinfo_file = tempfile.NamedTemporaryFile(dir=".", delete=False)
treeinfo.dump(treeinfo_file.name, main_variant=main_variant)
store_metadata_for_mirroring(repository, treeinfo_file.name, namespace)
break
Expand Down

0 comments on commit c2ea1d8

Please sign in to comment.