Keep OPNsense telemetry when the script worker cannot start and build it for FreeBSD 14.1

A worker linked on the FreeBSD 15 test guest needs FBSD_1.9 and does not load on
OPNsense 24.7; the agent then retried the job session every 30 s and never sent a
heartbeat or inventory. The agent now pauses script capabilities for an hour and
reconnects without them. tools/dev_opnsense_worker.py links the worker against the
official FreeBSD 14.1 pkgbase libraries. The installer checks that the worker loads
before binding it and reports success only after a heartbeat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 12:17:34 +01:00
co-authored by Claude Opus 5.5
parent 19163a2efe
commit 93429e4394
8 changed files with 216 additions and 15 deletions
+41
View File
@@ -76,5 +76,46 @@ class Reconnect(unittest.TestCase):
self.assertEqual(captures[0],captures[1])
def test_broken_worker_pauses_scripts_but_keeps_heartbeat(self):
with tempfile.TemporaryDirectory() as temp:
db = sqlite3.connect(':memory:')
db.executescript('CREATE TABLE sequence(id INTEGER PRIMARY KEY,n INTEGER);INSERT INTO sequence VALUES(1,0);'
'CREATE TABLE pending(id INTEGER PRIMARY KEY,envelope BLOB,observed INTEGER);')
worker = Path(temp)/'worker'
# Same effect as a loader failure: exits before printing "ready".
worker.write_text('#!/bin/sh\nexit 1\n')
worker.chmod(0o755)
binding = Path(temp)/'binding.json'
binding.write_text('{}')
seen = []
def gateway(_ctx,path,data,media):
req = a.pb.MessageBatch.FromString(data).messages[0]
reply = a.pb.Envelope()
reply.CopyFrom(req)
kind = req.WhichOneof('payload')
seen.append((kind, list(req.client_hello.capabilities)))
if kind == 'client_hello':
reply.connection_generation = len(seen)
reply.server_hello.CopyFrom(a.pb.ServerHello(connection_generation=len(seen),max_message_bytes=1024*1024))
else:
reply.ack.CopyFrom(a.pb.Ack(message_id=req.message_id))
return a.pb.MessageBatch(protocol_major=1,messages=[reply]).SerializeToString()
with patch.object(a,'context'), patch.object(a,'renew',return_value=False), \
patch.object(a,'post',gateway), patch.object(a,'WORKER',worker), patch.object(a,'BINDING',binding), \
patch.object(a,'worker_paused_until',0.0), \
patch.object(a,'usage',return_value=(a.pb.SystemUsage(),[])), \
patch.object(a.time,'clock_gettime',return_value=100), \
patch.object(a.time,'CLOCK_UPTIME',1,create=True), patch.object(a.time,'sleep',side_effect=StopIteration):
identity = {'agent_id':str(uuid.uuid4()),'asset_id':str(uuid.uuid4())}
with self.assertRaisesRegex(ValueError,'telemetry continues'):
a.session(db,identity,str(uuid.uuid4()),str(uuid.uuid4()))
with self.assertRaises(StopIteration):
a.session(db,identity,str(uuid.uuid4()),str(uuid.uuid4()))
self.assertEqual([k for k,_ in seen],['client_hello','client_hello','heartbeat'])
self.assertIn('run_script',seen[0][1])
self.assertEqual(seen[1][1],['heartbeat/1','opnsense.base/1'])
if __name__=='__main__':
unittest.main()