Skip to content

Commit

Permalink
Improve "No valid Release file found" error message
Browse files Browse the repository at this point in the history
fixes pulp#399
  • Loading branch information
Manisha15 committed Mar 9, 2023
1 parent ea8c59a commit 19d22d7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES/399.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve the pulp_deb "No valid Release file found" error message for gpg validation fail.
34 changes: 30 additions & 4 deletions pulp_deb/app/tasks/synchronizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from collections import defaultdict
from tempfile import NamedTemporaryFile
from debian import deb822
from urllib.parse import quote, urlparse, urlunparse
from urllib.parse import quote, urlparse, urlunparse, urljoin
from django.conf import settings
from django.db.utils import IntegrityError

Expand Down Expand Up @@ -75,12 +75,31 @@ class NoReleaseFile(Exception):
Exception to signal, that no file representing a release is present.
"""

def __init__(self, distribution, *args, **kwargs):
def __init__(self, path, *args, **kwargs):
"""
Exception to signal, that no file representing a release is present.
"""
super().__init__(
"No valid Release file found for '{}'.".format(distribution), *args, **kwargs
"Could not find a Release file at '{}', try checking the 'url' and "
"'distributions' option on your remote".format(path),
*args,
**kwargs,
)


class NoValidSignatureForKey(Exception):
"""
Exception to signal, that verification of release file with provided GPG key fails.
"""

def __init__(self, url, *args, **kwargs):
"""
Exception to signal, that verification of release file with provided GPG key fails.
"""
super().__init__(
"Unable to verify any Release files from '{}' using the GPG key provided.".format(url),
*args,
**kwargs,
)


Expand Down Expand Up @@ -317,6 +336,7 @@ async def run(self):
Update release content with information obtained from its artifact.
"""
dropped_count = 0
async with ProgressReport(
message="Update ReleaseFile units", code="update.release_file"
) as pb:
Expand All @@ -343,6 +363,7 @@ async def run(self):
log.warning(_("Verification of Release failed. Dropping it."))
d_content.d_artifacts.remove(da_names.pop("Release"))
d_content.d_artifacts.remove(da_names.pop("Release.gpg"))
dropped_count += 1
else:
release_file_artifact = da_names["Release"].artifact
release_file.relative_path = da_names["Release"].relative_path
Expand All @@ -367,13 +388,18 @@ async def run(self):
else:
log.warning(_("Verification of InRelease failed. Dropping it."))
d_content.d_artifacts.remove(da_names.pop("InRelease"))
dropped_count += 1
else:
release_file_artifact = da_names["InRelease"].artifact
release_file.relative_path = da_names["InRelease"].relative_path

if not d_content.d_artifacts:
# No (proper) artifacts left -> distribution not found
raise NoReleaseFile(distribution=release_file.distribution)
if dropped_count > 0:
raise NoValidSignatureForKey(url=self.remote.url)
else:
release_file_path = os.path.dirname(d_content.content.relative_path)
raise NoReleaseFile(path=urljoin(self.remote.url, release_file_path))

release_file.sha256 = release_file_artifact.sha256
release_file.artifact_set_sha256 = _get_artifact_set_sha256(
Expand Down
13 changes: 11 additions & 2 deletions pulp_deb/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ def test_invalid_distribution(self):
with self.assertRaises(PulpTaskError) as exc:
self.do_test(distribution="no_dist")
error = exc.exception.task.error
self.assertIn("No valid Release file found", error["description"])
self.assertIn(
"Could not find a Release file at '{}', try checking the 'url' and "
"'distributions' option on your remote".format(DEB_FIXTURE_URL),
error["description"],
)

def test_missing_package_indices_1(self):
"""Sync a repository missing a set of Package indices.
Expand Down Expand Up @@ -163,7 +167,12 @@ def test_invalid_signature(self):
distribution="nosuite", url=DEB_INVALID_FIXTURE_URL, gpgkey=DEB_SIGNING_KEY
)
error = exc.exception.task.error
self.assertIn("No valid Release file found", error["description"])
self.assertIn(
"Unable to verify any Release files from '{}' using the GPG key provided.".format(
DEB_INVALID_FIXTURE_URL
),
error["description"],
)

def do_test(self, url=DEB_FIXTURE_URL, distribution=DEB_FIXTURE_DISTRIBUTIONS, **kwargs):
"""Sync a repository given ``url`` on the remote."""
Expand Down

0 comments on commit 19d22d7

Please sign in to comment.