fix(reliability): recreate missing pineapd section; honest uci-set reporting
This commit is contained in:
@@ -96,3 +96,50 @@ class GuardTest(unittest.TestCase):
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
||||
class SectionRecreateTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.calls = []
|
||||
self.uci = {}
|
||||
self.old_server_run = server.device_run
|
||||
self.old_iface = server._iface_up
|
||||
server._iface_up = lambda name: True
|
||||
|
||||
def fake_run(args, timeout=20, input_data=None):
|
||||
a = list(args)
|
||||
self.calls.append(a)
|
||||
if a[:4] == ['uci', '-q', 'get',
|
||||
'pineapd.@pineapd[0].logrecon']:
|
||||
return (1, '', '') # section missing
|
||||
if a[:2] == ['uci', 'get']:
|
||||
got = self.uci.get(a[2])
|
||||
return (0, (got if got is not None else '') + '\n', '')
|
||||
if a[:2] == ['uci', 'set']:
|
||||
k, _, v = a[2].partition('=')
|
||||
self.uci[k] = v
|
||||
return (0, '', '')
|
||||
|
||||
def dual_run(args, timeout=20, input_data=None):
|
||||
# install the same fake for server-side helpers
|
||||
self.__dict__.setdefault('_srv', server)
|
||||
return fake_run(args, timeout=timeout, input_data=input_data)
|
||||
|
||||
mk8_guard.device_run = fake_run
|
||||
server.device_run = fake_run
|
||||
|
||||
def tearDown(self):
|
||||
server.device_run = self.old_server_run
|
||||
server._iface_up = self.old_iface
|
||||
|
||||
def test_recreates_missing_pineapd_section(self):
|
||||
result = mk8_guard.reconcile(clear_pool=False)
|
||||
self.assertIn(['uci', 'add', 'pineapd', 'pineapd'], self.calls)
|
||||
self.assertTrue(any('section recreated' in c for c in result['changed']))
|
||||
sets = [c for c in self.calls if c[:2] == ['uci', 'set']]
|
||||
self.assertEqual(len(sets),
|
||||
len(server.PINEAPD_SAFE_UCI) - 1
|
||||
+ len(mk8_guard.WANTED_EXTRA))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user