Skip to content
Open
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
55 changes: 38 additions & 17 deletions pulp_deb/app/tasks/synchronizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.conf import settings
from django.db.utils import IntegrityError

from pulpcore.plugin.exceptions import DigestValidationError
from pulpcore.plugin.exceptions import DigestValidationError, PulpException
from rest_framework.exceptions import ValidationError


Expand Down Expand Up @@ -80,44 +80,65 @@
log = logging.getLogger(__name__)


class NoReleaseFile(Exception):
class DebException(PulpException):
"""
Base class for expected sync failures.
"""

error_code = "DEB0000"

def __init__(self, message, details=None):
try:
super().__init__()
except TypeError:
super().__init__(self.error_code)
self.message = message
self.details = details

def __str__(self):
return f"[{self.error_code}] {self.message}"


class NoReleaseFile(DebException):
"""
Exception to signal, that no file representing a release is present.
"""

error_code = "DEB0001"

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


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

error_code = "DEB0002"

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,
)


class NoPackageIndexFile(Exception):
class NoPackageIndexFile(DebException):
"""
Exception to signal, that no file representing a package index is present.
"""

error_code = "DEB0003"

def __init__(self, relative_dir, *args, **kwargs):
"""
Exception to signal, that no file representing a package index is present.
Expand All @@ -129,41 +150,41 @@ def __init__(self, relative_dir, *args, **kwargs):
"(ignore_missing_package_indices='True') or system wide "
"(FORCE_IGNORE_MISSING_PACKAGE_INDICES setting)."
)
super().__init__(_(message).format(relative_dir), *args, **kwargs)

pass
super().__init__(_(message).format(relative_dir))


class MissingReleaseFileField(Exception):
class MissingReleaseFileField(DebException):
"""
Exception signifying that the upstream release file is missing a required field.
"""

error_code = "DEB0004"

def __init__(self, distribution, field, *args, **kwargs):
"""
The upstream release file is missing a required field.
"""
message = "The release file for distribution '{}' is missing the required field '{}'."
super().__init__(_(message).format(distribution, field), *args, **kwargs)
super().__init__(_(message).format(distribution, field))


class UnknownNoSupportForArchitectureAllValue(Exception):
class UnknownNoSupportForArchitectureAllValue(DebException):
"""
Exception Signifying that the Release file contains the 'No-Support-for-Architecture-all' field,
but with a value other than 'Packages'. We interpret this as an error since this would likely
signify some unknown repo format, that pulp_deb is more likely to get wrong than right!
"""

error_code = "DEB0005"

def __init__(self, release_file_path, unknown_value, *args, **kwargs):
message = (
"The Release file at '{}' contains the 'No-Support-for-Architecture-all' field, with "
"unknown value '{}'! pulp_deb currently only understands the value 'Packages' for "
"this field, please open an issue at https://github.com/pulp/pulp_deb/issues "
"specifying the remote you are attempting to sync, so that we can improve pulp_deb!"
)
super().__init__(_(message).format(unknown_value), *args, **kwargs)

pass
super().__init__(_(message).format(release_file_path, unknown_value))


def synchronize(remote_pk, repository_pk, mirror, optimize):
Expand Down
6 changes: 3 additions & 3 deletions pulp_deb/tests/functional/api/test_duplicate_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pulp_deb.tests.functional.utils import (
get_counts_from_content_summary,
get_local_package_absolute_path,
get_task_error_message,
)

DUPLICATE_PACKAGE_DIR = "data/packages/duplicates/" # below pulp_deb/tests/functional/
Expand Down Expand Up @@ -132,6 +133,5 @@ def test_add_duplicates_to_repo(
deb_modify_repository(repository, {"add_content_units": [href1, href2]})

# Assert the error message.
assert "Cannot create repository version since there are newly added packages with" in str(
exception.value.task.error["description"]
)
msg = get_task_error_message(exception.value.task.error)
assert "Cannot create repository version since there are newly added packages with" in msg
7 changes: 4 additions & 3 deletions pulp_deb/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
DEB_REPORT_CODE_SKIP_COMPLETE,
DEB_SIGNING_KEY,
)
from pulp_deb.tests.functional.utils import get_counts_from_content_summary
from pulp_deb.tests.functional.utils import get_counts_from_content_summary, get_task_error_message


@pytest.mark.parallel
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_sync_missing_package_indices(
@pytest.mark.parametrize(
"repo_name, remote_args, expected",
[
("http://i-am-an-invalid-url.com/invalid/", {}, ["Cannot connect"]),
("http://i-am-an-invalid-url.com/invalid/", {}, ["cannot connect"]),
(
DEB_FIXTURE_STANDARD_REPOSITORY_NAME,
{"distributions": "no_dist"},
Expand Down Expand Up @@ -162,8 +162,9 @@ def test_sync_invalid_cases(
# Verify a PulpTaskError is raised and the error message is as expected
with pytest.raises(PulpTaskError) as exc:
deb_sync_repository(remote, repo)
msg = get_task_error_message(exc.value.task.error).lower()
for exp in expected:
assert exp in str(exc.value.task.error["description"])
assert exp.lower() in msg


@pytest.mark.parallel
Expand Down
6 changes: 6 additions & 0 deletions pulp_deb/tests/functional/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,9 @@ def get_counts_from_content_summary(content_summary):
for key in content:
content[key] = content[key]["count"]
return content


def get_task_error_message(error):
if not error:
return ""
return str(error.get("description") or error.get("detail") or error.get("message") or error)