Release LanUps 0.1.2 with native installers and monitoring updates

This commit is contained in:
tongtong committed 2026-11-28 21:18:14 +08:00
1 parent 90c57f020f
commit 5bdc79d8e4
30 files changed
+751 -270

No files matched your search

+31 -5
View File
@@ -27,7 +27,8 @@ def main(*command):
request = reader.readline()
if request == b'LIST VAR h1000m\n':
body = f'BEGIN LIST VAR h1000m\nVAR h1000m ups.status "{mode}"\nEND LIST VAR h1000m\n'
conn.sendall(b'ERR DATA-STALE\n' if mode == 'stale' else body.encode())
errors = {'stale': b'ERR DATA-STALE\n', 'disconnected': b'ERR DRIVER-NOT-CONNECTED\n'}
conn.sendall(errors.get(mode, body.encode()))
elif request == b'LIST UPS\n':
conn.sendall(b'BEGIN LIST UPS\nUPS h1000m "Test UPS"\nEND LIST UPS\n')
@@ -38,6 +39,8 @@ def main(*command):
env = dict(os.environ, LANUPS_AGENT_PORT=str(port), LANUPS_AGENT_TOKEN=str(token_path))
subprocess.run([*command, '--provision'], env=env, check=True)
token = token_path.read_text().strip()
endpoint = {'host': '127.0.0.1', 'port': nut.getsockname()[1], 'name': 'h1000m'}
token_path.with_suffix('.json').write_text(json.dumps(endpoint)) # Config written by older agents.
def call(path, method='GET', body=None, auth=True):
headers = {'X-LanUps-Token': token} if auth else {}
@@ -80,14 +83,23 @@ def main(*command):
process = start()
try:
wait(lambda state: state['dryRun'])
assert wait(lambda state: state['dryRun'])['shutdownImmediately'] is False
denied('status', 401, auth=False)
endpoint = {'host': '127.0.0.1', 'port': nut.getsockname()[1], 'name': 'h1000m'}
assert call('endpoint', 'PUT', endpoint) == endpoint
assert call(f"ups?host=127.0.0.1&port={endpoint['port']}") == ['h1000m']
wait(lambda state: flag(state) == 'OL')
assert wait(lambda state: flag(state) == 'OL')['update']['nutServerOnline'] is True
mode = 'disconnected'
disconnected = wait(lambda state: state['update']['error'] == 'ERR DRIVER-NOT-CONNECTED')
assert disconnected['update']['nutServerOnline'] is True
with socket.socket() as offline:
offline.bind(('127.0.0.1', 0)) # Reserve a port without starting a listener.
call('endpoint', 'PUT', dict(endpoint, port=offline.getsockname()[1]))
unavailable = wait(lambda state: state['update']['nutServerOnline'] is False)
assert unavailable['update']['error'] and unavailable['update']['lastReading'] is None
call('endpoint', 'PUT', endpoint)
mode = 'stale'
wait(lambda state: state['update']['error'] and not state['pending'])
assert wait(lambda state: state['update']['error'] == 'ERR DATA-STALE')['update']['nutServerOnline'] is True
print('PASS: separate NUT server and UPS connection status', flush=True)
mode = 'OB FSD'
first = wait(lambda state: state['pending'])['pending']['id']
denied('endpoint', 409, 'PUT', dict(endpoint, port=1))
@@ -102,6 +114,20 @@ def main(*command):
assert call(f'shutdown/{second}/confirm', 'POST') == 'confirm'
wait(lambda state: '已模拟关机' in (state['lastAction'] or ''))
mode = 'OL'
wait(lambda state: flag(state) == 'OL')
immediate = dict(endpoint, shutdownImmediately=True)
assert call('settings', 'PUT', immediate) == immediate
process.terminate()
process.wait()
process = start()
assert wait(lambda state: flag(state) == 'OL')['shutdownImmediately'] is True
mode = 'OB FSD'
result = wait(lambda state: (state['lastAction'] or '').startswith('收到关机指令,立即执行'), 7)
assert result['pending'] is None and '已模拟关机' in result['lastAction']
print('PASS: immediate shutdown preference persists and bypasses countdown in dry-run mode', flush=True)
call('settings', 'PUT', dict(endpoint, shutdownImmediately=False))
mode = 'OL'
wait(lambda state: flag(state) == 'OL')
mode = 'OB FSD'