meshcore_fw_ota: the transfer as an Ansible-free engine shared with meshcore-tth's tools, plus a side channel via tempradio
ci / test (push) Failing after 15s
ci / test (push) Failing after 15s
module_utils/meshcore_ota_engine.py now holds the whole transfer (Console, Radio, binary and text rounds, update()); the module only maps its parameters. tools/ota_mesh_push.py and tools/ota_push.py of meshcore-tth import the same code, so the protocol lives in one place. New: - side/window: the node goes to another preset by `tempradio`, the companion is retuned (checked -- an openHop virtual companion acks set_radio as a no-op and is refused), a fresh login goes zero-hop and the delta follows; the window is renewed, and the node and companion come back at the end (or the node by its own timer). - SerialConsole: the node's USB console, the same calls as BleConsole. - `fw base` when `fw status` shows no base (failed/ready/rx): a node left after a refused package was taken for "not an -ota build", i.e. a full DFU, and `resume` could never pick its package. - asyncio.TimeoutError caught too: on Python 3.10 (dopey) a lost bitmap reply ended the whole transfer. - text: text chunks only; update(force=...) for `fw apply force`. Bench 16. 11. 2026 (x3 companion -> x1 -ota repeater, 866.5 -> side 866.0/SF7): the module from dopey (py3.10), the firmware role's ota.yml with mc_fw_ota_side, ota_mesh_push.py and ota_push.py over USB -- each applied a 2.7 kB delta, ~20 s airtime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8306d91b48
commit
185470de08
7 files changed
+922
-375
No files matched your search
@@ -7,11 +7,17 @@ from ansible_collections.tth.meshcore.plugins.module_utils.meshcore_ota import (
|
||||
Bucket,
|
||||
Package,
|
||||
crc16,
|
||||
fmt_preset,
|
||||
hops_of,
|
||||
lora_airtime,
|
||||
lora_params,
|
||||
parse_base,
|
||||
parse_missing,
|
||||
parse_preset,
|
||||
parse_radio,
|
||||
parse_status,
|
||||
pick,
|
||||
same_preset,
|
||||
text_missing,
|
||||
w_payload,
|
||||
)
|
||||
@@ -144,3 +150,38 @@ def test_bucket_paces_to_the_duty():
|
||||
def test_bucket_refuses_a_silly_duty():
|
||||
with pytest.raises(ValueError):
|
||||
Bucket(0)
|
||||
|
||||
|
||||
# ── side channel ────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
def test_parse_preset():
|
||||
assert parse_preset("869.525,62.5,7,5") == (869.525, 62.5, 7, 5)
|
||||
assert fmt_preset((869.525, 62.5, 7, 5)) == "869.525,62.5,7,5"
|
||||
assert fmt_preset((866.0, 62.5, 7, 5)) == "866,62.5,7,5" # tempradio parses it with strtof
|
||||
for bad in ("869.525,62.5,7", "869.525,62.5,13,5", "869.525,62.5,7,4", "x,62.5,7,5", "869.525,600,7,5"):
|
||||
with pytest.raises(ValueError):
|
||||
parse_preset(bad)
|
||||
|
||||
|
||||
def test_parse_radio():
|
||||
assert parse_radio("> 869.432,62.5,7,5") == (869.432, 62.5, 7, 5)
|
||||
assert parse_radio("> 866.5,62.5,8,5") == (866.5, 62.5, 8, 5)
|
||||
assert parse_radio("Unknown command") is None
|
||||
|
||||
|
||||
def test_same_preset_and_lora_params():
|
||||
si = {"radio_freq": 869.525, "radio_bw": 62.5, "radio_sf": 7, "radio_cr": 5}
|
||||
assert same_preset(si, (869.525, 62.5, 7, 5))
|
||||
assert not same_preset(si, (869.432, 62.5, 7, 5))
|
||||
assert not same_preset({}, (869.525, 62.5, 7, 5))
|
||||
assert lora_params((869.525, 62.5, 7, 5)) == (7, 62.5, 1)
|
||||
|
||||
|
||||
def test_parse_base():
|
||||
# `fw status` after a refused package shows no base -- `fw base` does
|
||||
assert parse_status("> failed: not newer than this image (pkg 1794864486, node 1794864486) [b2 d0]") is None
|
||||
sha = "d81446b7" + "0" * 56
|
||||
assert parse_base(f"> {sha}") == (None, "d81446b7")
|
||||
assert parse_base(f"> {sha} fresh {sha}") == (None, "d81446b7")
|
||||
assert parse_base("ERR: fw status|begin|w|missing") is None
|
||||
@@ -0,0 +1,144 @@
|
||||
"""The side channel of meshcore_ota_engine against a fake companion: what goes
|
||||
to the node and to the companion, and that both come back."""
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
import pytest
|
||||
from ansible_collections.tth.meshcore.plugins.module_utils import meshcore_ota_engine as engine
|
||||
from ansible_collections.tth.meshcore.plugins.module_utils.meshcore_ota_engine import OtaError, Radio
|
||||
|
||||
meshcore = pytest.importorskip("meshcore")
|
||||
EventType = meshcore.EventType
|
||||
|
||||
NODE = "1d7710553156342d8368f60c0382a0e77a615bbc672f79ea1d2179037bcda9b5"
|
||||
MAIN = {"radio_freq": 866.5, "radio_bw": 62.5, "radio_sf": 8, "radio_cr": 5}
|
||||
|
||||
|
||||
class Ev:
|
||||
def __init__(self, type_, payload):
|
||||
self.type, self.payload = type_, payload
|
||||
|
||||
|
||||
class Commands:
|
||||
def __init__(self, mc):
|
||||
self.mc = mc
|
||||
|
||||
async def send_device_query(self):
|
||||
return Ev(EventType.DEVICE_INFO, {"repeat": False})
|
||||
|
||||
async def set_radio(self, freq, bw, sf, cr, repeat=None):
|
||||
self.mc.calls.append(("set_radio", freq, bw, sf, cr, repeat))
|
||||
if self.mc.retunes:
|
||||
self.mc.self_info.update(radio_freq=freq, radio_bw=bw, radio_sf=sf, radio_cr=cr)
|
||||
|
||||
async def send_appstart(self):
|
||||
return Ev(EventType.SELF_INFO, dict(self.mc.self_info))
|
||||
|
||||
async def reset_path(self, contact):
|
||||
self.mc.calls.append(("reset_path",))
|
||||
|
||||
async def update_contact(self, contact, path=None, path_hash_mode=None):
|
||||
self.mc.calls.append(("update_contact", path, path_hash_mode))
|
||||
|
||||
|
||||
class MC:
|
||||
def __init__(self, retunes=True):
|
||||
self.calls = []
|
||||
self.retunes = retunes
|
||||
self.self_info = dict(MAIN)
|
||||
self.contacts = {}
|
||||
self.commands = Commands(self)
|
||||
|
||||
async def ensure_contacts(self, follow=False):
|
||||
pass
|
||||
|
||||
|
||||
def radio(retunes=True):
|
||||
r = Radio({"type": "serial", "port": "x"}, NODE, side=(866.0, 62.5, 7, 5), window=15, gap=0)
|
||||
mc = MC(retunes)
|
||||
r.link.mc = mc
|
||||
r.link.contact = {"public_key": NODE, "out_path": "c327a1b2", "out_path_len": 2, "out_path_hash_mode": 1}
|
||||
r.radio = (8, 62.5, 1)
|
||||
|
||||
async def cli(cmd, expect, **kw):
|
||||
mc.calls.append(("cmd", cmd))
|
||||
if cmd == "get radio":
|
||||
return "> 866.5,62.5,8,5"
|
||||
if cmd.startswith("tempradio"):
|
||||
return "OK - temp params for 3 mins"
|
||||
return "ok"
|
||||
|
||||
async def login():
|
||||
mc.calls.append(("login",))
|
||||
|
||||
r.link.cli = cli
|
||||
r.link.login = login
|
||||
return r, mc
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def no_sleep(monkeypatch):
|
||||
async def sleep(_secs):
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(engine.asyncio, "sleep", sleep)
|
||||
|
||||
|
||||
def test_side_there_and_back():
|
||||
r, mc = radio()
|
||||
|
||||
async def go():
|
||||
await r.start()
|
||||
assert r.radio == (7, 62.5, 1)
|
||||
await r.side.leave()
|
||||
|
||||
asyncio.run(go())
|
||||
assert mc.calls == [
|
||||
("cmd", "get radio"),
|
||||
("cmd", "tempradio 866,62.5,7,5,3"),
|
||||
("set_radio", 866.0, 62.5, 7, 5, 0),
|
||||
("login",),
|
||||
("cmd", "tempradio 866,62.5,7,5,15"), # the link works: the full window
|
||||
("cmd", "tempradio 866.5,62.5,8,5,1"), # the node back
|
||||
("set_radio", 866.5, 62.5, 8, 5, 0), # the companion back, client repeat as it was
|
||||
("update_contact", "c327a1b2", 1), # and its mesh path
|
||||
]
|
||||
assert r.radio == (8, 62.5, 1)
|
||||
|
||||
|
||||
def test_companion_that_does_not_retune():
|
||||
r, mc = radio(retunes=False)
|
||||
with pytest.raises(OtaError, match="did not retune"):
|
||||
asyncio.run(r.start())
|
||||
|
||||
asyncio.run(r.side.leave())
|
||||
# nothing to put back, and no `tempradio` back over a channel the node is not on
|
||||
assert [c for c in mc.calls if c[0] == "cmd"] == [("cmd", "get radio"), ("cmd", "tempradio 866,62.5,7,5,3")]
|
||||
assert sum(c[0] == "set_radio" for c in mc.calls) == 1
|
||||
|
||||
|
||||
def test_window_renewed_before_it_ends():
|
||||
r, mc = radio()
|
||||
asyncio.run(r.start())
|
||||
n = len(mc.calls)
|
||||
asyncio.run(r.ask("fw status", "status"))
|
||||
assert mc.calls[n:] == [("cmd", "fw status")] # a fresh window: nothing to renew
|
||||
r.side.renew = (15, time.monotonic() + 60) # a minute left
|
||||
asyncio.run(r.ask("fw status", "status"))
|
||||
assert mc.calls[n + 1 :] == [("cmd", "tempradio 866,62.5,7,5,15"), ("cmd", "fw status")]
|
||||
|
||||
|
||||
def test_after_apply_follows_the_node_home():
|
||||
r, mc = radio()
|
||||
|
||||
async def go():
|
||||
await r.start()
|
||||
await r.after_apply(0)
|
||||
|
||||
asyncio.run(go())
|
||||
# the reboot took the node back: no `tempradio` back, the companion follows
|
||||
cmds = [c for c in mc.calls if c[0] == "cmd"]
|
||||
assert ("cmd", "tempradio 866.5,62.5,8,5,1") not in cmds
|
||||
assert mc.calls[-1] == ("login",)
|
||||
assert ("set_radio", 866.5, 62.5, 8, 5, 0) in mc.calls
|
||||
Reference in new issue
Block a user