Stage B of review fixes: daemon state lock, image build check, RIPEstat retries

Job state is changed under one RLock, the Dockerfile copies all root
modules and imports them at build time, RIPEstat requests go through a
retrying session with the sourceapp parameter (ripestat_sourceapp) and a
capped Retry-After. Adds the summary and marks review findings 5-10 fixed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5 committed 2026-09-21 10:12:48 +03:00
1 parent d6b69d0842
commit aaf41adc79
8 files changed
+164 -28

No files matched your search

+43
View File
@@ -97,3 +97,46 @@ def test_fqdn_keeps_only_global_addresses(files, monkeypatch):
monkeypatch.setattr(cc.socket, "getaddrinfo", lambda *args, **kwargs: [answers[1]])
(files / "config.json").write_text('{"fqdns": ["x.example"]}')
assert cc.FQDNCollector().resolve_fqdn("x.example") == []
def test_ripestat_session_retries_and_sourceapp(files, monkeypatch):
calls = []
real_make_session = cc.make_session
class Response:
def raise_for_status(self):
pass
def json(self):
return {"data": {"prefixes": [{"prefix": "1.0.0.0/24"}]}}
class Session:
def get(self, url, params, timeout):
calls.append((params, timeout))
return Response()
def close(self):
pass
monkeypatch.setattr(cc, "make_session", lambda: Session())
assert cc.CIDRCollector().fetch_prefixes(1) == ["1.0.0.0/24"]
assert calls[0][0] == {"resource": "AS1", "sourceapp": "ripe-cidr-collector"} and calls[0][1] == cc.RIPESTAT_TIMEOUT
# Своё имя приложения из config.json (например, с контактом)
(files / "config.json").write_text('{"asns": [], "ripestat_sourceapp": "my-app admin@example.org"}')
assert cc.CIDRCollector().fetch_prefixes(2) == ["1.0.0.0/24"]
assert calls[1][0]["sourceapp"] == "my-app admin@example.org"
# После исчерпания повторов источник пропускается (None), сбор ничего не удаляет
collector = cc.CIDRCollector()
monkeypatch.setattr(collector, "sourceapp", "x")
Session.get = lambda self, url, params, timeout: (_ for _ in ()).throw(cc.requests.exceptions.RetryError("x"))
assert collector.fetch_prefixes(3) is None
# Настройка сессии: повторы на сбои и коды 429/5xx, пауза Retry-After ограничена потолком
retry = real_make_session().get_adapter("https://stat.ripe.net").max_retries
assert retry.total == cc.RIPESTAT_RETRIES and 503 in retry.status_forcelist and 429 in retry.status_forcelist
class Response: # сервер просит подождать час: пауза ограничена потолком
headers = {"Retry-After": "3600"}
assert retry.get_retry_after(Response()) == cc.MAX_RETRY_AFTER