Lab7: HTTPS, mTLS, OpenBao, трек 2 PKI на оценку 5
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"""Точечные сбои для проверки. Без строки в fault_injections код их не включает."""
|
||||
import uuid
|
||||
|
||||
from psycopg.pq import TransactionStatus
|
||||
|
||||
|
||||
def _idle(conn):
|
||||
# Чтение выше могло открыть транзакцию. Её откат не теряет запись:
|
||||
# сама запись начинается следующим transaction() и делает COMMIT.
|
||||
if conn.info.transaction_status != TransactionStatus.IDLE:
|
||||
conn.rollback()
|
||||
|
||||
|
||||
def take_fault(conn, kind, attachment_id=None):
|
||||
_idle(conn)
|
||||
with conn.transaction():
|
||||
row = conn.execute(
|
||||
"""
|
||||
UPDATE fault_injections AS target
|
||||
SET armed = false
|
||||
WHERE target.id = (
|
||||
SELECT id
|
||||
FROM fault_injections
|
||||
WHERE armed
|
||||
AND kind = %s
|
||||
AND (attachment_id IS NULL OR attachment_id = %s)
|
||||
ORDER BY created_at
|
||||
FOR UPDATE SKIP LOCKED
|
||||
LIMIT 1
|
||||
)
|
||||
RETURNING id
|
||||
""",
|
||||
(kind, attachment_id),
|
||||
).fetchone()
|
||||
return row is not None
|
||||
|
||||
|
||||
def arm_fault(conn, kind, attachment_id=None):
|
||||
fault_id = uuid.uuid4()
|
||||
_idle(conn)
|
||||
with conn.transaction():
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO fault_injections (id, kind, attachment_id, armed)
|
||||
VALUES (%s, %s, %s, true)
|
||||
""",
|
||||
(fault_id, kind, attachment_id),
|
||||
)
|
||||
return str(fault_id)
|
||||
Reference in New Issue
Block a user