Qualify tenant-scoped bootstrap rotation and fresh Windows scripting
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
"""Retry coverage for the HTTPS Linux bootstrap without installing on the test host."""
|
||||
from contextlib import ExitStack
|
||||
from contextlib import ExitStack, redirect_stdout
|
||||
from importlib.util import module_from_spec, spec_from_file_location
|
||||
import io
|
||||
import json
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -29,12 +31,26 @@ class EnrollmentRetry(unittest.TestCase):
|
||||
for field, value in [('ROOT',root),('STATE',self.state)]:
|
||||
self.stack.enter_context(patch.object(lifecycle,field,value))
|
||||
self.enable = self.stack.enter_context(patch.object(lifecycle,'enable'))
|
||||
self.service = self.stack.enter_context(patch.object(lifecycle,'service'))
|
||||
self.healthy = self.stack.enter_context(patch.object(lifecycle,'healthy',return_value=True))
|
||||
self.save = self.stack.enter_context(patch.object(lifecycle,'save_token'))
|
||||
self.stack.enter_context(patch.object(lifecycle.pwd,'getpwnam'))
|
||||
self.token = folder / 'retry.token'
|
||||
self.token.write_text('0' * 64)
|
||||
|
||||
def test_unresolved_effects_delay_release_without_blocking_closed_jobs(self):
|
||||
with sqlite3.connect(self.state / 'journal.sqlite') as db:
|
||||
db.execute('CREATE TABLE job_attempts (state TEXT)')
|
||||
for state, expected in [('running','busy'), ('unknown','busy'), ('awaiting_reboot','busy'),
|
||||
('closed_unknown','idle'), ('accepted','idle'), ('succeeded','idle')]:
|
||||
with self.subTest(state=state):
|
||||
db.execute('DELETE FROM job_attempts')
|
||||
db.execute('INSERT INTO job_attempts VALUES(?)', (state,))
|
||||
db.commit()
|
||||
with redirect_stdout(io.StringIO()) as output:
|
||||
lifecycle.device_idle()
|
||||
self.assertEqual(output.getvalue().strip(), expected)
|
||||
|
||||
def bootstrap_tenant(self, tenant):
|
||||
def answer(source, route, target):
|
||||
self.assertEqual(source, (self.base,'0' * 64))
|
||||
@@ -57,6 +73,17 @@ class EnrollmentRetry(unittest.TestCase):
|
||||
self.save.assert_called_once()
|
||||
self.healthy.assert_called_once_with('1.0',0)
|
||||
|
||||
def test_timer_starts_only_after_confirmed_first_connection(self):
|
||||
self.bootstrap_tenant(self.tenant)
|
||||
self.healthy.return_value = False
|
||||
with self.assertRaisesRegex(ValueError, 'awaiting authenticated device heartbeat'):
|
||||
lifecycle.install(self.base,self.token)
|
||||
self.enable.assert_called_once()
|
||||
self.service.assert_not_called()
|
||||
self.healthy.return_value = True
|
||||
lifecycle.install(self.base,self.token)
|
||||
self.service.assert_called_once_with('enable','--now',lifecycle.TIMER)
|
||||
|
||||
def test_token_for_another_tenant_cannot_replace_initial_token(self):
|
||||
self.bootstrap_tenant('22222222-2222-4222-8222-222222222222')
|
||||
with self.assertRaisesRegex(ValueError,'different enrollment tenant'):
|
||||
|
||||
Reference in New Issue
Block a user