Skip to content

Commit 5f7b10e

Browse files
committed
Stop asserting task error descriptions for invalid deb sync
1 parent 9c134b8 commit 5f7b10e

4 files changed

Lines changed: 48 additions & 23 deletions

File tree

pulp_deb/app/tasks/synchronizing.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from django.conf import settings
1919
from django.db.utils import IntegrityError
2020

21-
from pulpcore.plugin.exceptions import DigestValidationError
21+
from pulpcore.plugin.exceptions import DigestValidationError, PulpException
2222
from rest_framework.exceptions import ValidationError
2323

2424

@@ -80,44 +80,62 @@
8080
log = logging.getLogger(__name__)
8181

8282

83-
class NoReleaseFile(Exception):
83+
class DebException(PulpException):
84+
"""
85+
Base class for expected sync failures.
86+
"""
87+
88+
error_code = "DEB0000"
89+
90+
def __init__(self, message, details=None):
91+
super().__init__()
92+
self.message = message
93+
self.details = details
94+
95+
def __str__(self):
96+
return f"[{self.error_code}] {self.message}"
97+
98+
99+
class NoReleaseFile(DebException):
84100
"""
85101
Exception to signal, that no file representing a release is present.
86102
"""
87103

104+
error_code = "DEB0001"
105+
88106
def __init__(self, url, *args, **kwargs):
89107
"""
90108
Exception to signal, that no file representing a release is present.
91109
"""
92110
super().__init__(
93111
"Could not find a Release file at '{}', try checking the 'url' and "
94112
"'distributions' option on your remote".format(url),
95-
*args,
96-
**kwargs,
97113
)
98114

99115

100-
class NoValidSignatureForKey(Exception):
116+
class NoValidSignatureForKey(DebException):
101117
"""
102118
Exception to signal, that verification of release file with provided GPG key fails.
103119
"""
104120

121+
error_code = "DEB0002"
122+
105123
def __init__(self, url, *args, **kwargs):
106124
"""
107125
Exception to signal, that verification of release file with provided GPG key fails.
108126
"""
109127
super().__init__(
110128
"Unable to verify any Release files from '{}' using the GPG key provided.".format(url),
111-
*args,
112-
**kwargs,
113129
)
114130

115131

116-
class NoPackageIndexFile(Exception):
132+
class NoPackageIndexFile(DebException):
117133
"""
118134
Exception to signal, that no file representing a package index is present.
119135
"""
120136

137+
error_code = "DEB0003"
138+
121139
def __init__(self, relative_dir, *args, **kwargs):
122140
"""
123141
Exception to signal, that no file representing a package index is present.
@@ -129,41 +147,41 @@ def __init__(self, relative_dir, *args, **kwargs):
129147
"(ignore_missing_package_indices='True') or system wide "
130148
"(FORCE_IGNORE_MISSING_PACKAGE_INDICES setting)."
131149
)
132-
super().__init__(_(message).format(relative_dir), *args, **kwargs)
133-
134-
pass
150+
super().__init__(_(message).format(relative_dir))
135151

136152

137-
class MissingReleaseFileField(Exception):
153+
class MissingReleaseFileField(DebException):
138154
"""
139155
Exception signifying that the upstream release file is missing a required field.
140156
"""
141157

158+
error_code = "DEB0004"
159+
142160
def __init__(self, distribution, field, *args, **kwargs):
143161
"""
144162
The upstream release file is missing a required field.
145163
"""
146164
message = "The release file for distribution '{}' is missing the required field '{}'."
147-
super().__init__(_(message).format(distribution, field), *args, **kwargs)
165+
super().__init__(_(message).format(distribution, field))
148166

149167

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

175+
error_code = "DEB0005"
176+
157177
def __init__(self, release_file_path, unknown_value, *args, **kwargs):
158178
message = (
159179
"The Release file at '{}' contains the 'No-Support-for-Architecture-all' field, with "
160180
"unknown value '{}'! pulp_deb currently only understands the value 'Packages' for "
161181
"this field, please open an issue at https://github.com/pulp/pulp_deb/issues "
162182
"specifying the remote you are attempting to sync, so that we can improve pulp_deb!"
163183
)
164-
super().__init__(_(message).format(unknown_value), *args, **kwargs)
165-
166-
pass
184+
super().__init__(_(message).format(release_file_path, unknown_value))
167185

168186

169187
def synchronize(remote_pk, repository_pk, mirror, optimize):

pulp_deb/tests/functional/api/test_duplicate_packages.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from pulp_deb.tests.functional.utils import (
1919
get_counts_from_content_summary,
2020
get_local_package_absolute_path,
21+
get_task_error_message,
2122
)
2223

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

134135
# Assert the error message.
135-
assert "Cannot create repository version since there are newly added packages with" in str(
136-
exception.value.task.error["description"]
137-
)
136+
msg = get_task_error_message(exception.value.task.error)
137+
assert "Cannot create repository version since there are newly added packages with" in msg

pulp_deb/tests/functional/api/test_sync.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
DEB_REPORT_CODE_SKIP_COMPLETE,
2222
DEB_SIGNING_KEY,
2323
)
24-
from pulp_deb.tests.functional.utils import get_counts_from_content_summary
24+
from pulp_deb.tests.functional.utils import get_counts_from_content_summary, get_task_error_message
2525

2626

2727
@pytest.mark.parallel
@@ -121,7 +121,7 @@ def test_sync_missing_package_indices(
121121
@pytest.mark.parametrize(
122122
"repo_name, remote_args, expected",
123123
[
124-
("http://i-am-an-invalid-url.com/invalid/", {}, ["Cannot connect"]),
124+
("http://i-am-an-invalid-url.com/invalid/", {}, ["cannot connect"]),
125125
(
126126
DEB_FIXTURE_STANDARD_REPOSITORY_NAME,
127127
{"distributions": "no_dist"},
@@ -162,8 +162,9 @@ def test_sync_invalid_cases(
162162
# Verify a PulpTaskError is raised and the error message is as expected
163163
with pytest.raises(PulpTaskError) as exc:
164164
deb_sync_repository(remote, repo)
165+
msg = get_task_error_message(exc.value.task.error).lower()
165166
for exp in expected:
166-
assert exp in str(exc.value.task.error["description"])
167+
assert exp.lower() in msg
167168

168169

169170
@pytest.mark.parallel

pulp_deb/tests/functional/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,9 @@ def get_counts_from_content_summary(content_summary):
109109
for key in content:
110110
content[key] = content[key]["count"]
111111
return content
112+
113+
114+
def get_task_error_message(error):
115+
if not error:
116+
return ""
117+
return str(error.get("description") or error.get("detail") or error.get("message") or error)

0 commit comments

Comments
 (0)