Migration 5: end the stale UPS battery known condition
CI / Lint (flake8, house style) (pull_request) Successful in 1m24s
CI / Test (pytest) (pull_request) Successful in 1m29s
CI / Security (bandit, pip-audit) (pull_request) Successful in 1m6s
CI / Integration (MariaDB) (pull_request) Successful in 1m50s
CI / Scan (secrets, workflows, shell, patterns) (pull_request) Successful in 1m38s
CI / UI (screenshots) (pull_request) Successful in 1m48s
CI / Deploy (pull_request) Skipped

The APC UPS was replaced by a UniFi UPS 2U Pro on 2026-08-08 (Tinker 387982348, closed
2026-09-25); the 'old battery' entry seeded in migration 3 came from Grafana silences that
predate it. Ended, not deleted, so the history stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-26 13:54:26 -05:00
1 parent af5fb0c609
commit 5e7e2fc695
2 files changed
+13 -4

No files matched your search

+6 -4
View File
@@ -105,14 +105,16 @@ def test_known_conditions_seeded_and_managed(db):
db.migrate()
s = Store(db)
seeded = s.known_conditions()
# The UPS battery entry is seeded by migration 3 and ended by migration 5 (UPS replaced).
assert [(k['kind'], k['subject'], k['ticket_id']) for k in seeded] == [
('reboot', 'compute-storage-02', '693930698'), ('ceph_flag', 'noout', '693930698'),
('ups_battery', 'ups', None)]
('reboot', 'compute-storage-02', '693930698'), ('ceph_flag', 'noout', '693930698')]
ended = db.query("SELECT ended_by FROM known_conditions WHERE kind='ups_battery'")
assert ended == [{'ended_by': 'operator: UPS replaced (Tinker 387982348)'}]
new = s.add_known_condition('reboot', 'pbs', '1', 'testing', 'jared', 1795410668.0)
assert len(s.known_conditions()) == 4
assert len(s.known_conditions()) == 3
assert s.end_known_condition(new, 'jared', 1795410700.0) == 1
assert s.end_known_condition(new, 'jared', 1795410700.0) == 0
assert len(s.known_conditions()) == 3
assert len(s.known_conditions()) == 2
s.save_incident({'key': 'k', 'state': 'pending', 'priority': 3, 'kind': 'x', 'subject': 's', 'mode': 'shadow',
'first_seen': 1.0, 'last_seen': 1.0}, 2.0)
s.delete_incident('k')
+7
View File
@@ -161,6 +161,13 @@ MIGRATIONS: List[str] = [
KEY idx_links_incident (incident_key, removed_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
""",
# 5: the UPS battery known condition was stale: the APC unit was replaced by a UniFi UPS 2U
# Pro on 2026-08-08 (Tinker 387982348, closed 2026-09-25). End it, keep the history.
"""
UPDATE known_conditions SET ended_at=UTC_TIMESTAMP(3),
ended_by='operator: UPS replaced (Tinker 387982348)'
WHERE kind='ups_battery' AND ended_at IS NULL;
""",
]