chore: initialize containerized Python learning workbook (2026 DevOps/SRE)

This commit is contained in:
soda64 committed 2026-11-30 22:55:56 +01:00
commit ae4c421815
63 files changed
+1273

No files matched your search

@@ -0,0 +1,46 @@
import pytest
from devops_ops import count_error_lines, extract_k8s_images, retry_call
SAMPLE_DEPLOYMENT = """
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
template:
spec:
containers:
- name: app
image: ghcr.io/org/web:1.2.0
- name: sidecar
image: envoyproxy/envoy:v1.31
"""
def test_extract_k8s_images() -> None:
assert extract_k8s_images(SAMPLE_DEPLOYMENT) == [
"ghcr.io/org/web:1.2.0",
"envoyproxy/envoy:v1.31",
]
def test_count_error_lines() -> None:
logs = "INFO start\nWARN retry\nERROR db timeout\nCRITICAL oom\n"
assert count_error_lines(logs) == 2
def test_retry_call() -> None:
calls = 0
def flaky() -> str:
nonlocal calls
calls += 1
if calls < 3:
raise RuntimeError("transient")
return "ok"
assert retry_call(flaky, attempts=3) == "ok"
assert calls == 3
with pytest.raises(RuntimeError):
retry_call(lambda: (_ for _ in ()).throw(RuntimeError("always")), attempts=2)