diff --git a/tools/computer-test.py b/tools/computer-test.py index 8e6881c637dca1beba2656991bf59ba429d5ab5d..736412cd9e49863691e9686d5c71d5f1b087f2dd 100644 --- a/tools/computer-test.py +++ b/tools/computer-test.py @@ -268,6 +268,24 @@ class GuestCancellation(unittest.TestCase): self.assertEqual(computer.handle('fixture', {'action':'status'})['readiness'], 'ready') work.assert_called_once_with('fixture', 'macos', {'action':'status'}) + def test_windows_status_waits_for_personalization_before_using_template_session(self): + root = 'windowswindows-v4' + with patch.object(computer.vms, 'virsh', side_effect=lambda action, *a, **k: 'running' if action == 'domstate' else root), \ + patch.object(computer, 'qga', return_value={'supported_commands':[{'name':'guest-exec','enabled':True}]}), \ + patch.object(computer.vms, 'windows_setup') as setup, patch.object(computer, 'worker') as work: + for phase in ['starting', 'personalizing', 'signingIn', 'failed']: + setup.return_value = phase + status = computer.handle('fixture', {'action':'status'}) + self.assertEqual(status['readiness'], 'setup_failed' if phase == 'failed' else 'personalizing') + self.assertEqual(status['setup'], phase) + self.assertEqual(status['capabilities'], ['shot', 'input']) + work.assert_not_called() + setup.return_value = 'ready' + work.return_value = {'execution_context':{'user':'fixture'}} + status = computer.handle('fixture', {'action':'status'}) + self.assertEqual(status['readiness'], 'ready') + self.assertEqual(status['execution_context']['user'], 'fixture') + def test_failed_cleanup_keeps_status_available_and_blocks_later_control(self): for platform, identity in [('linux', 'snowglobe-computer-request-' + 'a' * 32), ('windows', 'a' * 32)]: operation = {'platform': platform, 'id': identity} diff --git a/tools/vm-computer.py b/tools/vm-computer.py index 67c51e5f6cba58f8c298b05081efc3ce03fb4dbc..5a7317e72151d1d6edffa630ce286e6bcfbad0b2 100644 --- a/tools/vm-computer.py +++ b/tools/vm-computer.py @@ -625,6 +625,11 @@ def handle(name, request, *, active_snapshot=None): if not native_text: return {**status, 'readiness': 'agent_unsupported', 'text_encoding': 'ascii', 'worker_error': 'The guest agent does not support commands. Use console input or ask an administrator to update the agent.'} + if platform == 'windows' and root.findtext(f'metadata/{vms.NS}vm/{vms.NS}setup') in {'windows-v3', 'windows-v4'}: + setup = vms.windows_setup(name) + if setup != 'ready': + return {**status, 'readiness': 'setup_failed' if setup == 'failed' else 'personalizing', 'setup': setup, + 'worker_error': 'Windows account setup failed. Inspect the console and C:\\Snowglobe\\setup.log.' if setup == 'failed' else 'Windows is applying the VM account. Wait for setup to finish.'} status['readiness'] = 'worker_starting' try: status.update(worker(name,platform,request))