Merge ~cjwatson/lp-archive:log-translate-fault into lp-archive:main

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 92362968bba97a7067802d30e010cda6754ddab0
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/lp-archive:log-translate-fault
Merge into: lp-archive:main
Diff against target: 191 lines (+71/-8)
2 files modified
lp_archive/archive.py (+1/-0)
tests/test_archive.py (+70/-8)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+438563@code.launchpad.net

Commit message

Log faults other than NotFound from translatePath

Description of the change

Otherwise it's quite hard to debug what's going on if the XML-RPC backend OOPSes.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lp_archive/archive.py b/lp_archive/archive.py
2index 27de11f..ef0a1a5 100644
3--- a/lp_archive/archive.py
4+++ b/lp_archive/archive.py
5@@ -84,6 +84,7 @@ def translate(
6 if f.faultCode == 320: # NotFound
7 return "Not found", 404, {"Content-Type": "text/plain"}
8 else:
9+ current_app.logger.info("%s %s: %s", archive, path, f.faultString)
10 return "Internal server error", 500, {"Content-Type": "text/plain"}
11 assert isinstance(url, str)
12 return "", 307, {"Location": url}
13diff --git a/tests/test_archive.py b/tests/test_archive.py
14index e5ef1dc..d6b926c 100644
15--- a/tests/test_archive.py
16+++ b/tests/test_archive.py
17@@ -1,6 +1,7 @@
18 # Copyright 2022 Canonical Ltd. This software is licensed under the
19 # GNU Affero General Public License version 3 (see the file LICENSE).
20
21+import logging
22 from datetime import datetime, timezone
23 from threading import Thread
24 from typing import Any
25@@ -61,7 +62,8 @@ def archive_proxy(app):
26 cache.clear()
27
28
29-def test_auth_failed(client, archive_proxy):
30+def test_auth_failed(client, archive_proxy, caplog):
31+ caplog.set_level(logging.INFO, logger="flask.app")
32 response = client.get(
33 "/~user/ubuntu/private/dists/focal/InRelease",
34 auth=("user", "secret"),
35@@ -76,9 +78,17 @@ def test_auth_failed(client, archive_proxy):
36 assert archive_proxy.call_log == [
37 ("checkArchiveAuthToken", "~user/ubuntu/private", "user", "secret")
38 ]
39+ assert caplog.record_tuples == [
40+ (
41+ "flask.app",
42+ logging.INFO,
43+ "user@~user/ubuntu/private: Password does not match.",
44+ )
45+ ]
46
47
48-def test_auth_not_found(client, archive_proxy):
49+def test_auth_not_found(client, archive_proxy, caplog):
50+ caplog.set_level(logging.INFO, logger="flask.app")
51 response = client.get(
52 "/~user/ubuntu/nonexistent/dists/focal/InRelease",
53 auth=("user", "secret"),
54@@ -93,9 +103,13 @@ def test_auth_not_found(client, archive_proxy):
55 assert archive_proxy.call_log == [
56 ("checkArchiveAuthToken", "~user/ubuntu/nonexistent", "user", "secret")
57 ]
58+ assert caplog.record_tuples == [
59+ ("flask.app", logging.INFO, "user@~user/ubuntu/nonexistent: Not found")
60+ ]
61
62
63-def test_auth_positive_cached(client, archive_proxy):
64+def test_auth_positive_cached(client, archive_proxy, caplog):
65+ caplog.set_level(logging.INFO, logger="flask.app")
66 response = client.get(
67 "/~user/ubuntu/authorized/dists/focal/InRelease",
68 auth=("user", "secret"),
69@@ -111,7 +125,15 @@ def test_auth_positive_cached(client, archive_proxy):
70 None,
71 ),
72 ]
73+ assert caplog.record_tuples == [
74+ (
75+ "flask.app",
76+ logging.INFO,
77+ "user@~user/ubuntu/authorized: Authorized.",
78+ )
79+ ]
80 archive_proxy.call_log = []
81+ caplog.clear()
82 response = client.get(
83 "/~user/ubuntu/authorized/dists/focal/InRelease",
84 auth=("user", "secret"),
85@@ -126,9 +148,17 @@ def test_auth_positive_cached(client, archive_proxy):
86 None,
87 ),
88 ]
89+ assert caplog.record_tuples == [
90+ (
91+ "flask.app",
92+ logging.INFO,
93+ "user@~user/ubuntu/authorized: Authorized.",
94+ )
95+ ]
96
97
98-def test_auth_negative_not_cached(client, archive_proxy):
99+def test_auth_negative_not_cached(client, archive_proxy, caplog):
100+ caplog.set_level(logging.INFO, logger="flask.app")
101 response = client.get(
102 "/~user/ubuntu/private/dists/focal/InRelease",
103 auth=("user", "secret"),
104@@ -138,7 +168,15 @@ def test_auth_negative_not_cached(client, archive_proxy):
105 assert archive_proxy.call_log == [
106 ("checkArchiveAuthToken", "~user/ubuntu/private", "user", "secret"),
107 ]
108+ assert caplog.record_tuples == [
109+ (
110+ "flask.app",
111+ logging.INFO,
112+ "user@~user/ubuntu/private: Password does not match.",
113+ )
114+ ]
115 archive_proxy.call_log = []
116+ caplog.clear()
117 response = client.get(
118 "/~user/ubuntu/private/dists/focal/InRelease",
119 auth=("user", "secret"),
120@@ -148,9 +186,17 @@ def test_auth_negative_not_cached(client, archive_proxy):
121 assert archive_proxy.call_log == [
122 ("checkArchiveAuthToken", "~user/ubuntu/private", "user", "secret"),
123 ]
124+ assert caplog.record_tuples == [
125+ (
126+ "flask.app",
127+ logging.INFO,
128+ "user@~user/ubuntu/private: Password does not match.",
129+ )
130+ ]
131
132
133-def test_translate(client, archive_proxy):
134+def test_translate(client, archive_proxy, caplog):
135+ caplog.set_level(logging.INFO, logger="flask.app")
136 response = client.get(
137 "/ubuntu/dists/focal/InRelease",
138 headers=[("Host", "snapshot.ubuntu.test")],
139@@ -162,9 +208,13 @@ def test_translate(client, archive_proxy):
140 ("checkArchiveAuthToken", "ubuntu", None, None),
141 ("translatePath", "ubuntu", "dists/focal/InRelease", None),
142 ]
143+ assert caplog.record_tuples == [
144+ ("flask.app", logging.INFO, "<anonymous>@ubuntu: Authorized.")
145+ ]
146
147
148-def test_translate_not_found(client, archive_proxy):
149+def test_translate_not_found(client, archive_proxy, caplog):
150+ caplog.set_level(logging.INFO, logger="flask.app")
151 response = client.get(
152 "/ubuntu/nonexistent", headers=[("Host", "snapshot.ubuntu.test")]
153 )
154@@ -176,9 +226,13 @@ def test_translate_not_found(client, archive_proxy):
155 ("checkArchiveAuthToken", "ubuntu", None, None),
156 ("translatePath", "ubuntu", "nonexistent", None),
157 ]
158+ assert caplog.record_tuples == [
159+ ("flask.app", logging.INFO, "<anonymous>@ubuntu: Authorized.")
160+ ]
161
162
163-def test_translate_at_timestamp(client, archive_proxy):
164+def test_translate_at_timestamp(client, archive_proxy, caplog):
165+ caplog.set_level(logging.INFO, logger="flask.app")
166 response = client.get(
167 "/ubuntu/20220101T120000Z/dists/focal/InRelease",
168 headers=[("Host", "snapshot.ubuntu.test")],
169@@ -195,9 +249,13 @@ def test_translate_at_timestamp(client, archive_proxy):
170 datetime(2022, 1, 1, 12, 0, 0, tzinfo=timezone.utc),
171 ),
172 ]
173+ assert caplog.record_tuples == [
174+ ("flask.app", logging.INFO, "<anonymous>@ubuntu: Authorized.")
175+ ]
176
177
178-def test_translate_oops(client, archive_proxy):
179+def test_translate_oops(client, archive_proxy, caplog):
180+ caplog.set_level(logging.INFO, logger="flask.app")
181 response = client.get(
182 "/ubuntu/oops", headers=[("Host", "snapshot.ubuntu.test")]
183 )
184@@ -209,3 +267,7 @@ def test_translate_oops(client, archive_proxy):
185 ("checkArchiveAuthToken", "ubuntu", None, None),
186 ("translatePath", "ubuntu", "oops", None),
187 ]
188+ assert caplog.record_tuples == [
189+ ("flask.app", logging.INFO, "<anonymous>@ubuntu: Authorized."),
190+ ("flask.app", logging.INFO, "ubuntu oops: Oops"),
191+ ]

Subscribers

People subscribed via source and target branches