fix(reliability): probe section existence via uci show, not an option key
This commit is contained in:
@@ -34,9 +34,10 @@ def _pool_size():
|
|||||||
def _ensure_pineapd_section():
|
def _ensure_pineapd_section():
|
||||||
"""Stock daemon rewrites and profile restores can drop the whole
|
"""Stock daemon rewrites and profile restores can drop the whole
|
||||||
`config pineapd` section; every @pineapd[0] option write fails with
|
`config pineapd` section; every @pineapd[0] option write fails with
|
||||||
'Invalid argument' until it exists again."""
|
'Invalid argument' until it exists again. Probes SECTION existence
|
||||||
rc, out, err = device_run(['uci', '-q', 'get',
|
(`uci -q show @pineapd[0]`) — never an option, which may legitimately
|
||||||
'pineapd.@pineapd[0].logrecon'])
|
be absent from a rewritten section."""
|
||||||
|
rc, out, err = device_run(['uci', '-q', 'show', 'pineapd.@pineapd[0]'])
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
return False
|
return False
|
||||||
device_run(['uci', 'add', 'pineapd', 'pineapd'])
|
device_run(['uci', 'add', 'pineapd', 'pineapd'])
|
||||||
|
|||||||
@@ -4643,13 +4643,17 @@ PINEAPD_RUNTIME_UCI.add('pineapd.@ssidpool[0].disable')
|
|||||||
|
|
||||||
|
|
||||||
def _apply_uci_wanted(wanted):
|
def _apply_uci_wanted(wanted):
|
||||||
"""Idempotently apply a wanted UCI key/value set. Returns changed keys."""
|
"""Idempotently apply a wanted UCI key/value set. Returns changed keys.
|
||||||
|
A failed `uci set` (e.g. missing anchor section) is NOT reported as
|
||||||
|
applied."""
|
||||||
actions = []
|
actions = []
|
||||||
for key, value in wanted.items():
|
for key, value in wanted.items():
|
||||||
rc, out, err = device_run(['uci', 'get', key])
|
rc, out, err = device_run(['uci', 'get', key])
|
||||||
if rc != 0 or out.strip() != value:
|
if rc != 0 or out.strip() != value:
|
||||||
device_run(['uci', 'set', '%s=%s' % (key, value)])
|
src_rc, s_out, s_err = device_run(
|
||||||
actions.append(key)
|
['uci', 'set', '%s=%s' % (key, value)])
|
||||||
|
if src_rc == 0:
|
||||||
|
actions.append(key)
|
||||||
return actions
|
return actions
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -109,8 +109,7 @@ class SectionRecreateTest(unittest.TestCase):
|
|||||||
def fake_run(args, timeout=20, input_data=None):
|
def fake_run(args, timeout=20, input_data=None):
|
||||||
a = list(args)
|
a = list(args)
|
||||||
self.calls.append(a)
|
self.calls.append(a)
|
||||||
if a[:4] == ['uci', '-q', 'get',
|
if a[:3] == ['uci', '-q', 'show']:
|
||||||
'pineapd.@pineapd[0].logrecon']:
|
|
||||||
return (1, '', '') # section missing
|
return (1, '', '') # section missing
|
||||||
if a[:2] == ['uci', 'get']:
|
if a[:2] == ['uci', 'get']:
|
||||||
got = self.uci.get(a[2])
|
got = self.uci.get(a[2])
|
||||||
|
|||||||
Reference in New Issue
Block a user