44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
|
|
"""Tests for recognising Jenkins workspace storage exhaustion."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from ariadne.services import hermes_storage_signals as module
|
||
|
|
|
||
|
|
|
||
|
|
def _bundle(*lines: str, tail: str = "") -> dict:
|
||
|
|
return {"jenkins": {"console_failures": [{"text": "\n".join(lines)}], "console_tail": tail}}
|
||
|
|
|
||
|
|
|
||
|
|
def test_a_full_workspace_volume_is_recognised() -> None:
|
||
|
|
matched, marker = module.has_storage_exhaustion_signature(
|
||
|
|
_bundle("cp: error writing '/home/jenkins/agent/workspace/x': No space left on device")
|
||
|
|
)
|
||
|
|
assert matched is True
|
||
|
|
assert marker == "no space left on device"
|
||
|
|
|
||
|
|
|
||
|
|
def test_the_tail_is_searched_too() -> None:
|
||
|
|
matched, _ = module.has_storage_exhaustion_signature(
|
||
|
|
_bundle("nothing here", tail="workspace volume full: disk quota exceeded")
|
||
|
|
)
|
||
|
|
assert matched is True
|
||
|
|
|
||
|
|
|
||
|
|
def test_a_full_disk_without_a_workspace_hint_is_not_this_failure() -> None:
|
||
|
|
"""Reclaiming Jenkins workspaces would not address it."""
|
||
|
|
|
||
|
|
matched, marker = module.has_storage_exhaustion_signature(
|
||
|
|
_bundle("etcd: No space left on device")
|
||
|
|
)
|
||
|
|
assert (matched, marker) == (False, None)
|
||
|
|
|
||
|
|
|
||
|
|
def test_a_workspace_mention_without_a_storage_marker_does_not_match() -> None:
|
||
|
|
matched, _ = module.has_storage_exhaustion_signature(_bundle("workspace checkout failed"))
|
||
|
|
assert matched is False
|
||
|
|
|
||
|
|
|
||
|
|
def test_never_raises_on_hostile_input() -> None:
|
||
|
|
for bad in (None, 7, {}, {"jenkins": None}, {"jenkins": {"console_failures": "no"}}):
|
||
|
|
assert module.has_storage_exhaustion_signature(bad) == (False, None)
|