Modem: read uptime again, firewall drop counts, AT&T speed tests
Lint / JS (eslint) (push) Successful in 24s
Lint / Python (flake8) (push) Successful in 1m2s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m26s
Test / Python Tests (pytest) (push) Successful in 1m57s
Lint / Python (flake8) (pull_request) Successful in 1m25s
Lint / JS (eslint) (pull_request) Successful in 24s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 1m9s
Test / Python Tests (pytest) (pull_request) Successful in 1m14s

- Uptime: firmware 6.40 shows "Time Since Last Reboot" as D:HH:MM:SS,
  which the parser (expecting seconds) read as nothing, so uptime was
  blank and restart detection never fired. Both formats are read now.
- Firewall drops (logged in, every 5 minutes): the Logs page counted
  per hour for a day, split into incoming connections over the
  firmware's fixed flood limit (50 per second) and invalid packets. A
  lower bound, since the log keeps one entry per 2 s. Panel only.
- The modem's own speed test history (logged in, every 30 minutes):
  latest down and up results on the panel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-19 18:50:37 -05:00
1 parent 2a9111d8e8
commit 0370358363
6 files changed
+229 -9

No files matched your search

+59
View File
@@ -455,3 +455,62 @@ class TestModemAdmin:
a.session.request = MagicMock(side_effect=requests.ConnectionError('boom'))
with pytest.raises(modem.ModemUnreachable):
a.nat_sessions()
FW_LOG = '''<table><tr><th>No.</th><th>Date/Time</th></tr>
<tr class="b"><td class="heading" scope="row">2</td><td>2026-11-19T18:32:04.984186</td><td>198.51.100.20</td>
<td>203.0.113.7</td><td>TCP</td><td>FLOOD limit 50pps burst 100</td></tr>
<tr class="a"><td class="heading" scope="row">1</td><td>2026-11-19T18:32:02.983868</td><td>203.0.113.7</td>
<td>198.51.100.30</td><td>TCP</td><td>Invalid IP Packet</td></tr>
</table>'''
SPEED_PAGE = '''<h2>Test History</h2><table><thead><th scope="col">Test Completion Time</th></thead><tbody>
<tr class="b"><td scope="row" class="heading" width="47%">
11/06/2026 08:46:05</td>
<td>upstream</td>
<td> 1242.810000</td>
<td> 28</td>
<td> 19.000000</td>
<td> Success</td></tr>
<tr class="a"><td scope="row" class="heading" width="47%">
11/06/2026 08:45:57</td>
<td>downstream</td>
<td> 1167.400000</td>
<td> 28</td>
<td> 28.000000</td>
<td> Success</td></tr>
</tbody></table>'''
class TestModemExtras:
@pytest.mark.parametrize('raw,expected', [
('03:06:29:34', ((3 * 24 + 6) * 60 + 29) * 60 + 34), # firmware 6.40
('28951', 28951), # older firmware
('0:00:05:00', 300),
('', None), (None, None), ('soon', None),
])
def test_uptime_formats(self, raw, expected):
assert modem.parse_uptime(raw) == expected
def test_status_reads_dhms_uptime(self):
sysinfo = SYSINFO.replace('<td class="col2">28951</td>', '<td class="col2">03:06:29:34</td>')
assert sysinfo != SYSINFO
assert modem.build_status(fiber_page(), broadband_page(), sysinfo)['uptime_s'] == 282574
def test_firewall_log_oldest_first(self):
rows = modem.parse_firewall_log(FW_LOG)
assert [r['ts'] for r in rows] == ['2026-11-19T18:32:02.983868', '2026-11-19T18:32:04.984186']
assert rows[1]['reason'] == 'FLOOD limit 50pps burst 100' and rows[1]['proto'] == 'TCP'
@pytest.mark.parametrize('reason,kind', [
('FLOOD limit 50pps burst 100', 'flood'), ('Invalid IP Packet', 'invalid'), ('Port scan', 'other')])
def test_firewall_kind(self, reason, kind):
assert modem.firewall_kind(reason) == kind
def test_speed_tests(self):
assert modem.parse_speed_tests(SPEED_PAGE) == [
{'at': '11/06/2026 08:46:05', 'direction': 'upstream', 'mbps': 1242.8, 'latency_ms': 19.0, 'ok': True},
{'at': '11/06/2026 08:45:57', 'direction': 'downstream', 'mbps': 1167.4, 'latency_ms': 28.0, 'ok': True},
]
def test_speed_tests_missing(self):
assert modem.parse_speed_tests('<html></html>') == []