Restart modem button: silence Gandalf and Uptime Kuma, restart, end both
Lint / Python (flake8) (push) Failing after 15s
Lint / JS (eslint) (push) Successful in 1m43s
Lint / Deploy (push) Skipped
Test / Python Tests (pytest) (push) Failing after 21s
Security / Python Security (bandit) (push) Successful in 2m3s
Lint / Python (flake8) (pull_request) Failing after 15s
Lint / JS (eslint) (pull_request) Failing after 15s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 2m17s
Lint / Notify on failure (push) Successful in 3s
Test / Python Tests (pytest) (pull_request) Successful in 2m58s

Admins get a Restart modem button on the WAN / Fiber panel (needs
modem.access_code). After a confirmation it:

1. switches an Uptime Kuma maintenance window on (new kuma.py: logs in
   over Kuma 2's Socket.IO API and resumes/pauses one pre-made manual
   window, uptime_kuma.maintenance_id); if Kuma fails it stops and asks
   whether to go on without it,
2. starts Gandalf maintenance (global suppression, 20 minutes at most),
3. posts the gateway's Restart Device form (ModemAdmin.restart), undoing
   1 and 2 if that fails.

The monitor waits for the modem to answer with its WAN up and an uptime
showing it restarted, then switches Kuma off, ends the suppression and
records how long it took; after 30 minutes it ends both regardless. The
panel shows the restart in progress and the result for an hour.

New dependency: python-socketio[client].

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-19 19:27:25 -05:00
1 parent f097e4882c
commit c2ff072eb2
13 files changed
+488 -10

No files matched your search

+30
View File
@@ -389,6 +389,8 @@ class FakeGateway:
return MagicMock(status_code=302 if ok else 200, text='' if ok else LOGIN_FORM)
if not self.logged_in:
return MagicMock(status_code=200, text=LOGIN_FORM)
if path == '/cgi-bin/restart.ha' and method == 'GET':
return MagicMock(status_code=200, text=DIAG_FORM.replace('diag.ha', 'restart.ha'))
if path == '/cgi-bin/nattable.ha':
return MagicMock(status_code=200, text=NAT_PAGE)
if path == '/cgi-bin/diag.ha' and method == 'POST':
@@ -514,3 +516,31 @@ class TestModemExtras:
def test_speed_tests_missing(self):
assert modem.parse_speed_tests('<html></html>') == []
class TestModemRestart:
def _admin(self):
gw = FakeGateway()
a = modem.ModemAdmin({'url': 'http://192.0.2.254', 'access_code': 'secret'}, sleep=lambda s: None)
a.session.request = MagicMock(side_effect=gw)
return a, gw
def test_posts_the_restart_form(self):
a, gw = self._admin()
a.session.post = MagicMock(return_value=MagicMock(status_code=200, text='Restarting...'))
assert a.restart() == 'accepted'
data = a.session.post.call_args.kwargs['data']
assert data == {'nonce': 'ffee00112233445566778899aabbccdd', 'Restart': 'Restart'}
assert a.session.post.call_args.args[0].endswith('/cgi-bin/restart.ha')
assert ('POST', '/cgi-bin/login.ha') in gw.calls # logged in to read the form
def test_connection_dropped_mid_restart(self):
a, _ = self._admin()
a.session.post = MagicMock(side_effect=requests.ConnectionError('reset'))
assert a.restart() == 'unconfirmed'
def test_refused(self):
a, _ = self._admin()
a.session.post = MagicMock(return_value=MagicMock(status_code=200, text=LOGIN_FORM))
with pytest.raises(modem.ModemDataInvalid, match='refused'):
a.restart()