Restart modem: pause Smart Power auto power-cycle until the modem is back
Lint / JS (eslint) (push) Successful in 14s
Lint / Python (flake8) (push) Successful in 1m5s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m13s
Lint / Python (flake8) (pull_request) Successful in 1m14s
Test / Python Tests (pytest) (push) Successful in 1m51s
Security / Python Security (bandit) (pull_request) Successful in 1m25s
Lint / JS (eslint) (pull_request) Successful in 19s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Test / Python Tests (pytest) (pull_request) Successful in 1m32s
Lint / JS (eslint) (push) Successful in 14s
Lint / Python (flake8) (push) Successful in 1m5s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m13s
Lint / Python (flake8) (pull_request) Successful in 1m14s
Test / Python Tests (pytest) (push) Successful in 1m51s
Security / Python Security (bandit) (pull_request) Successful in 1m25s
Lint / JS (eslint) (pull_request) Successful in 19s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Test / Python Tests (pytest) (pull_request) Successful in 1m32s
UniFi Smart Power on the RPDU's modem outlet saw the internet down while the modem rebooted and cut its power mid-boot: once during the 11-20 restart and twice after the 11-24 AT&T-app reboot. UniFi only exposes auto power-cycle as on or off, so the button now turns it off for every outlet that has it on, and the monitor turns it back on when the restart ends (back, or after 30 minutes). - UnifiClient.auto_power_cycle_outlets / set_auto_power_cycle: sends the device's outlet_overrides back with only cycle_enabled changed, then reads them again to confirm. The only UniFi setting Gandalf changes. - A failed pause doesn't stop the restart; a failed restart turns it back on. A failed restore is retried every cycle and shown as broken in Needs attention until it works. - The panel note and confirm text mention the pause. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a7792063ba
commit
a5d4fc3156
9 files changed
+304
-19
No files matched your search
@@ -1411,3 +1411,90 @@ class TestFinishModemRestart:
|
||||
def test_finished_restart_is_left_alone(self, mon, db):
|
||||
out, km = self._run(mon, db, self._restart(300, finished_at=1.0), {'reachable': True})
|
||||
assert out is None and not km.called
|
||||
|
||||
OUTLET = {'device_id': 'pdu1', 'device': 'RPDU', 'index': 13, 'name': 'AT&T Modem'}
|
||||
|
||||
def test_back_turns_smart_power_on_again(self, mon, db):
|
||||
mon.unifi = MagicMock()
|
||||
out, _ = self._run(mon, db, self._restart(300, smart_power_paused=[self.OUTLET]),
|
||||
{'reachable': True, 'wan_problems': [], 'uptime_s': 200})
|
||||
mon.unifi.set_auto_power_cycle.assert_called_once_with('pdu1', 13, True)
|
||||
assert out['smart_power_restored'] is True and out['smart_power_error'] is None
|
||||
|
||||
def test_smart_power_retried_after_the_restart_finished(self, mon, db):
|
||||
mon.unifi = MagicMock()
|
||||
mon.unifi.set_auto_power_cycle.side_effect = monitor.UnifiWriteError('HTTP 500')
|
||||
out, _ = self._run(mon, db, self._restart(300, smart_power_paused=[self.OUTLET]),
|
||||
{'reachable': True, 'wan_problems': [], 'uptime_s': 200})
|
||||
assert out['finished_at'] and not out.get('smart_power_restored')
|
||||
assert 'HTTP 500' in out['smart_power_error']
|
||||
# Next cycle: finished, but auto power-cycle is still off, so it tries again
|
||||
mon.unifi.set_auto_power_cycle.side_effect = None
|
||||
out, _ = self._run(mon, db, out, {'reachable': True})
|
||||
assert out['smart_power_restored'] is True
|
||||
|
||||
def test_restored_smart_power_is_left_alone(self, mon, db):
|
||||
mon.unifi = MagicMock()
|
||||
out, _ = self._run(mon, db, self._restart(300, finished_at=1.0, smart_power_paused=[self.OUTLET],
|
||||
smart_power_restored=True), {'reachable': True})
|
||||
assert out is None and not mon.unifi.set_auto_power_cycle.called
|
||||
|
||||
|
||||
def _pdu(overrides, dev_id='pdu1'):
|
||||
return {'_id': dev_id, 'name': 'RPDU', 'outlet_overrides': overrides}
|
||||
|
||||
|
||||
class TestSmartPowerWrites:
|
||||
MODEM = {'name': 'AT&T Modem', 'index': 13, 'relay_state': True, 'cycle_enabled': True}
|
||||
OTHER = {'name': 'storage-01', 'index': 14, 'relay_state': True, 'cycle_enabled': False}
|
||||
|
||||
def _client(self, reads):
|
||||
c = monitor.UnifiClient({'controller': 'https://udm.test', 'api_key': 'k'})
|
||||
replies = iter(reads)
|
||||
c.session.get = MagicMock(side_effect=lambda *a, **k: MagicMock(json=lambda: {'data': next(replies)}))
|
||||
c.session.put = MagicMock(return_value=MagicMock())
|
||||
return c
|
||||
|
||||
def test_lists_outlets_with_auto_power_cycle(self):
|
||||
c = self._client([[_pdu([self.MODEM, self.OTHER])]])
|
||||
assert c.auto_power_cycle_outlets() == [{'device_id': 'pdu1', 'device': 'RPDU', 'index': 13,
|
||||
'name': 'AT&T Modem'}]
|
||||
|
||||
def test_changes_only_that_flag(self):
|
||||
after = dict(self.MODEM, cycle_enabled=False)
|
||||
c = self._client([[_pdu([self.MODEM, self.OTHER])], [_pdu([after, self.OTHER])]])
|
||||
c.set_auto_power_cycle('pdu1', 13, False)
|
||||
url = c.session.put.call_args.args[0]
|
||||
assert url.endswith('/proxy/network/api/s/default/rest/device/pdu1')
|
||||
sent = c.session.put.call_args.kwargs['json']['outlet_overrides']
|
||||
assert sent == [after, self.OTHER] # relay states and the other outlet untouched
|
||||
|
||||
def test_already_set_sends_nothing(self):
|
||||
c = self._client([[_pdu([self.MODEM])]])
|
||||
c.set_auto_power_cycle('pdu1', 13, True)
|
||||
assert not c.session.put.called
|
||||
|
||||
def test_change_not_confirmed_is_an_error(self):
|
||||
c = self._client([[_pdu([self.MODEM])], [_pdu([self.MODEM])]])
|
||||
with pytest.raises(monitor.UnifiWriteError, match='still reports'):
|
||||
c.set_auto_power_cycle('pdu1', 13, False)
|
||||
|
||||
def test_unknown_outlet_is_an_error(self):
|
||||
c = self._client([[_pdu([self.OTHER])]])
|
||||
with pytest.raises(monitor.UnifiWriteError, match='no override entry'):
|
||||
c.set_auto_power_cycle('pdu1', 13, False)
|
||||
assert not c.session.put.called
|
||||
|
||||
def test_pause_and_restore(self):
|
||||
unifi = MagicMock()
|
||||
unifi.auto_power_cycle_outlets.return_value = [{'device_id': 'pdu1', 'index': 13, 'device': 'RPDU'}]
|
||||
paused, err = monitor.pause_smart_power(unifi)
|
||||
assert err is None and len(paused) == 1
|
||||
unifi.set_auto_power_cycle.assert_called_with('pdu1', 13, False)
|
||||
assert monitor.restore_smart_power(unifi, paused) is None
|
||||
unifi.set_auto_power_cycle.assert_called_with('pdu1', 13, True)
|
||||
|
||||
def test_pause_failure_is_reported(self):
|
||||
unifi = MagicMock()
|
||||
unifi.auto_power_cycle_outlets.side_effect = monitor.UnifiWriteError('reading outlets: 401')
|
||||
assert monitor.pause_smart_power(unifi) == ([], 'reading outlets: 401')
|
||||
Reference in new issue
Block a user