47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""Rychlý test SeaweedFS Filer (port 8888) — PUT / HEAD / GET / DELETE."""
|
|
import hashlib
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
FILER = "http://192.168.1.50:8888"
|
|
PAYLOAD = b"SeaweedFS VTMF test " + b"x" * 1000
|
|
SHA256 = hashlib.sha256(PAYLOAD).hexdigest()
|
|
PATH = f"/vtmf-documents/_test/{SHA256[:8]}"
|
|
URL = FILER + PATH
|
|
|
|
|
|
def req(method, data=None):
|
|
r = urllib.request.Request(URL, method=method, data=data,
|
|
headers={"Content-Type": "text/plain"} if data else {})
|
|
try:
|
|
with urllib.request.urlopen(r, timeout=10) as resp:
|
|
return resp.status, resp.read()
|
|
except urllib.error.HTTPError as e:
|
|
return e.code, b""
|
|
|
|
|
|
print(f"Filer: {FILER}")
|
|
print(f"Path: {PATH}\n")
|
|
|
|
status, _ = req("PUT", PAYLOAD)
|
|
assert status in (200, 201), f"PUT selhal: {status}"
|
|
print(f"[ok] PUT → {status}")
|
|
|
|
status, _ = req("HEAD")
|
|
assert status == 200, f"HEAD selhal: {status}"
|
|
print(f"[ok] HEAD → {status}")
|
|
|
|
status, body = req("GET")
|
|
assert status == 200 and body == PAYLOAD, f"GET selhal: {status}, délka={len(body)}"
|
|
print(f"[ok] GET → {status}, {len(body)} B")
|
|
|
|
status, _ = req("DELETE")
|
|
assert status in (200, 204), f"DELETE selhal: {status}"
|
|
print(f"[ok] DELETE → {status}")
|
|
|
|
status, _ = req("HEAD")
|
|
assert status == 404, f"Po DELETE HEAD vrátil {status}, čekal 404"
|
|
print(f"[ok] HEAD po DELETE → 404 (soubor odstraněn)\n")
|
|
|
|
print("SeaweedFS Filer OK.")
|