fix: address s3-storage verify findings
- s3 healthcheck and fault hook probe wait for the volume server to register with master (first write after restart no longer waits ~5 s) - s3-bootstrap mounts /data as tmpfs: no anonymous volume per container - S3 client: NoSuchBucket and AccessDenied are 503 with their own error logs, not a missing object or rejected credentials; delete ignores only a missing key - test_isolated verifies prefix removal (weed shell exits 0 on errors) - s3_check derives ports from listening sockets in the s3 container - readiness without S3 is also checked with s3 paused Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -59,8 +59,11 @@ PROBES = {
|
||||
"postgres": 'pg_isready -q -h 127.0.0.1 -U "$POSTGRES_USER" '
|
||||
'-d "$POSTGRES_DB"',
|
||||
"valkey": 'test "$(valkey-cli -p "$VALKEY_PORT" ping)" = PONG',
|
||||
# master выбран, filer и шлюз S3 отвечают — как healthcheck сервиса s3
|
||||
# master выбран, том зарегистрирован у master, filer и шлюз S3
|
||||
# отвечают — как healthcheck сервиса s3
|
||||
"s3": "wget -q -O /dev/null http://127.0.0.1:9333/cluster/healthz && "
|
||||
"wget -q -O - http://127.0.0.1:9333/dir/status | "
|
||||
"grep -qF '\"DataNodes\":[{' && "
|
||||
"wget -q -O /dev/null http://127.0.0.1:8888/healthz && "
|
||||
'wget -q -O /dev/null "http://127.0.0.1:$S3_PORT/healthz"',
|
||||
}
|
||||
|
||||
@@ -41,6 +41,9 @@ TEST_DB_NAME_RE = re.compile(r"^test_[a-z0-9_]+$")
|
||||
# как S3_BUCKET_NAME_PATTERN в src/utils/constants.py
|
||||
BUCKET_NAME_RE = re.compile(r"^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$")
|
||||
DEFAULT_BUCKET = "messenger"
|
||||
# fs.rm отсутствующего пути: «rm: <путь>: filer: no entry is found in filer
|
||||
# store» — не ошибка уборки
|
||||
WEED_NO_ENTRY = "no entry is found"
|
||||
READY_TIMEOUT_S = 60
|
||||
LOG_TAIL_LINES = 50
|
||||
|
||||
@@ -119,11 +122,11 @@ def object_prefix(bucket: str, test_db: str) -> str:
|
||||
return f"/buckets/{bucket}/{test_db}"
|
||||
|
||||
|
||||
def remove_objects(prefix: str) -> None:
|
||||
"""Удалить объекты под префиксом временной базы; его отсутствие — не
|
||||
ошибка. `weed shell` в контейнере `s3`: ключ подписи — в его
|
||||
окружении, master и filer — на его loopback."""
|
||||
run(
|
||||
def weed_shell(command: str) -> str:
|
||||
"""Одна команда `weed shell` в контейнере `s3`: ключ подписи — в его
|
||||
окружении, master и filer — на его loopback. Вывод — stdout и stderr
|
||||
вместе."""
|
||||
result = run(
|
||||
"docker",
|
||||
"compose",
|
||||
"exec",
|
||||
@@ -131,10 +134,31 @@ def remove_objects(prefix: str) -> None:
|
||||
"s3",
|
||||
"sh",
|
||||
"-c",
|
||||
"exec weed shell -master=127.0.0.1:9333",
|
||||
stdin=f"fs.rm -r {prefix}\n",
|
||||
"exec weed shell -master=127.0.0.1:9333 2>&1",
|
||||
stdin=f"{command}\n",
|
||||
quiet=True,
|
||||
)
|
||||
return result.stdout
|
||||
|
||||
|
||||
def remove_objects(prefix: str) -> None:
|
||||
"""Удалить объекты под префиксом временной базы; его отсутствие — не
|
||||
ошибка. `weed shell` выходит с кодом 0 и при ошибке команды, поэтому
|
||||
успех проверяется отдельно: строк `rm:` с ошибкой нет, и `fs.ls`
|
||||
префикса пуст. Иначе — `RuntimeError` с первой строкой ошибки."""
|
||||
removed = weed_shell(f"fs.rm -r {prefix}")
|
||||
# отсутствие префикса fs.rm печатает так же строкой rm: — это не ошибка
|
||||
errors = [
|
||||
line
|
||||
for line in removed.splitlines()
|
||||
if line.startswith("rm:") and WEED_NO_ENTRY not in line
|
||||
]
|
||||
left = [
|
||||
line for line in weed_shell(f"fs.ls {prefix}").splitlines() if line
|
||||
]
|
||||
if errors or left:
|
||||
detail = errors[0] if errors else f"{len(left)} entries left"
|
||||
raise RuntimeError(f"objects {prefix}/ not removed: {detail}")
|
||||
|
||||
|
||||
def remove_container(name: str) -> None:
|
||||
@@ -196,7 +220,11 @@ def main() -> int:
|
||||
remove_container(container)
|
||||
drop_database(test_db)
|
||||
say(f"remove objects {prefix}/")
|
||||
remove_objects(prefix)
|
||||
try:
|
||||
remove_objects(prefix)
|
||||
except (subprocess.CalledProcessError, RuntimeError) as e:
|
||||
say(f"setup failed: {e}")
|
||||
return 1
|
||||
|
||||
results: dict[str, int] = {}
|
||||
failed = True
|
||||
@@ -275,7 +303,7 @@ def main() -> int:
|
||||
drop_database(test_db)
|
||||
say(f"remove objects {prefix}/")
|
||||
remove_objects(prefix)
|
||||
except subprocess.CalledProcessError as e:
|
||||
except (subprocess.CalledProcessError, RuntimeError) as e:
|
||||
say(f"cleanup failed: {e}")
|
||||
results["cleanup"] = 1
|
||||
|
||||
|
||||
@@ -353,8 +353,15 @@ def test_readiness_without_cache(api: Api, stand: Stand) -> None:
|
||||
|
||||
|
||||
@pytest.mark.spec("health", "Хранилище объектов недоступно")
|
||||
def test_readiness_without_object_storage(api: Api, stand: Stand) -> None:
|
||||
with outage(stand, "stop", "s3"):
|
||||
@pytest.mark.parametrize("action", ["stop", "pause"])
|
||||
def test_readiness_without_object_storage(
|
||||
api: Api,
|
||||
stand: Stand,
|
||||
action: str,
|
||||
) -> None:
|
||||
# pause: соединение с S3 есть, ответа нет — проверка, которая всё же
|
||||
# ходила бы в S3, ждала бы срока вызова (5 с), а не отказа соединения
|
||||
with outage(stand, action, "s3"):
|
||||
for path in ("/health/ready", "/health/live"):
|
||||
resp, took = timed(lambda path=path: api.request("GET", path))
|
||||
assert assert_ok(resp, 200, "Health") == {"status": "ok"}
|
||||
|
||||
Reference in New Issue
Block a user