Repair an installed Linux lifecycle when rerunning its HTTPS installer

This commit is contained in:
2026-11-17 16:22:17 +01:00
parent fbd24b6d75
commit 95aa70766b
2 changed files with 12 additions and 0 deletions
+8
View File
@@ -280,6 +280,14 @@ def install(base, token_file):
remote((base, token), '/agent/v1/bootstrap/current?platform=' + PLATFORM, metadata)
require(read(metadata)['tenant_id'] == config['tenant'], 'different enrollment tenant')
save_token(ROOT, token, pwd.getpwnam('rmm-discovery').pw_gid)
# An operator rerunning the HTTPS installer can update the lifecycle
# harness without replacing the device identity or its stable verifier.
with (ROOT / 'release.lock').open('rb') as lock:
fcntl.flock(lock, fcntl.LOCK_EX)
harness = ROOT / 'lifecycle.py'
current = Path(__file__).read_bytes()
if harness.read_bytes() != current:
save(harness, current)
enable()
require(healthy(read(ROOT / 'current/manifest.json')['version'], 0), 'awaiting authenticated device heartbeat')
service('enable', '--now', TIMER)
+4
View File
@@ -26,6 +26,8 @@ class EnrollmentRetry(unittest.TestCase):
(root / 'current').mkdir(parents=True)
(root / 'config.json').write_text(json.dumps({'bootstrap': self.base, 'tenant': self.tenant}))
(root / 'current/manifest.json').write_text('{"version":"1.0"}')
(root / 'lifecycle.py').write_bytes(b'previous installer')
(root / 'release.lock').touch()
self.state = folder / 'device'
self.state.mkdir()
for field, value in [('ROOT',root),('STATE',self.state)]:
@@ -63,6 +65,7 @@ class EnrollmentRetry(unittest.TestCase):
remote = self.bootstrap_tenant(self.tenant)
lifecycle.install(self.base,None)
self.assertEqual(identity.read_text(), '{"agent_id":"original"}')
self.assertEqual((lifecycle.ROOT / 'lifecycle.py').read_bytes(), src.read_bytes())
remote.assert_not_called()
self.save.assert_not_called()
self.enable.assert_called_once()
@@ -90,6 +93,7 @@ class EnrollmentRetry(unittest.TestCase):
lifecycle.install(self.base,self.token)
self.save.assert_not_called()
self.enable.assert_not_called()
self.assertEqual((lifecycle.ROOT / 'lifecycle.py').read_bytes(), b'previous installer')
if __name__ == '__main__':