diff --git a/tools/computer-test.py b/tools/computer-test.py
index 5cb21d6d2dd2dbe0dfb64faebac39c40dbd78f02..6cebf6777dc9b6cce9c51a83cff135e817dea318 100644
--- a/tools/computer-test.py
+++ b/tools/computer-test.py
@@ -135,18 +135,47 @@ class GuestCancellation(unittest.TestCase):
finally:
computer.DEADLINE.reset(token)
- def test_windows_console_remains_available_without_guest_agent(self):
+ def test_console_remains_available_without_guest_agent(self):
+ for platform in ['windows', 'linux']:
+ def virsh(action, *args, **kwargs):
+ return 'running' if action == 'domstate' else ''+platform+''
+ with self.subTest(platform=platform), patch.object(computer.vms, 'virsh', virsh), patch.object(computer, 'qga', side_effect=ValueError('Disconnected')), patch.object(computer, 'worker') as work:
+ status = computer.handle('fixture', {'action': 'status'})
+ self.assertEqual(status['readiness'], 'agent_unavailable')
+ self.assertEqual(status['capabilities'], ['shot', 'input'])
+ self.assertEqual(status['text_encoding'], 'ascii')
+ actions = [{'type': 'text', 'text': 'recovery console'}]
+ with patch.object(computer, 'desktop', new_callable=AsyncMock, return_value={'completed': 1}) as desktop:
+ self.assertEqual(computer.handle('fixture', {'action': 'input', 'actions': actions, 'screenshot': False}), {'completed': 1})
+ desktop.assert_awaited_once_with('fixture', actions, platform, False, False)
+ work.assert_not_called()
+ self.assertFalse((computer.vms.DISKS / 'fixture' / 'computer-operation.json').exists())
+
+ def test_status_distinguishes_disabled_commands_from_a_starting_worker(self):
def virsh(action, *args, **kwargs):
- return 'running' if action == 'domstate' else 'windows'
- with patch.object(computer.vms, 'virsh', virsh), patch.object(computer, 'qga', side_effect=ValueError('Disconnected')), patch.object(computer, 'worker') as work:
- status = computer.handle('fixture', {'action': 'status'})
- self.assertEqual(status['capabilities'], ['shot', 'input'])
- self.assertEqual(status['text_encoding'], 'ascii')
- actions = [{'type': 'text', 'text': 'recovery console'}]
- with patch.object(computer, 'desktop', new_callable=AsyncMock, return_value={'completed': 1}) as desktop:
- self.assertEqual(computer.handle('fixture', {'action': 'input', 'actions': actions, 'screenshot': False}), {'completed': 1})
- desktop.assert_awaited_once_with('fixture', actions, 'windows', False, False)
+ return 'running' if action == 'domstate' else ''
+ with patch.object(computer.vms, 'virsh', virsh), patch.object(computer, 'worker') as work:
+ with patch.object(computer, 'qga', return_value={'supported_commands':[{'name':'guest-exec','enabled':False}]}):
+ status = computer.handle('fixture', {'action':'status'})
+ self.assertEqual(status['readiness'], 'agent_unsupported')
work.assert_not_called()
+ with patch.object(computer, 'qga', return_value={'supported_commands':[{'name':'guest-exec','enabled':True}]}):
+ work.side_effect = ValueError('Sign in to the VM desktop before using this tool.')
+ status = computer.handle('fixture', {'action':'status'})
+ self.assertEqual(status['readiness'], 'worker_starting')
+ self.assertIn('Sign in', status['worker_error'])
+ work.side_effect = None
+ work.return_value = {'runtimes':['bash']}
+ status = computer.handle('fixture', {'action':'status'})
+ self.assertEqual(status['readiness'], 'ready')
+ self.assertEqual(status['runtimes'], ['bash'])
+
+ def test_legacy_mac_status_keeps_its_private_transport(self):
+ def virsh(action, *args, **kwargs):
+ return 'running' if action == 'domstate' else 'macos'
+ with patch.object(computer.vms, 'virsh', virsh), patch.object(computer, 'qga', side_effect=AssertionError('This Mac has no QGA channel')), patch.object(computer, 'worker', return_value={'runtimes':['bash']}) as work:
+ self.assertEqual(computer.handle('fixture', {'action':'status'})['readiness'], 'ready')
+ work.assert_called_once_with('fixture', 'macos', {'action':'status'})
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)]:
diff --git a/tools/vm-computer.py b/tools/vm-computer.py
index 695f272bd1adefb682bbdf4d0cc41441cd401f23..41123566ae908d5c3d6d63bcec67bbd68c14813f 100644
--- a/tools/vm-computer.py
+++ b/tools/vm-computer.py
@@ -214,7 +214,7 @@ async def capture(name, actions, platform, screenshot=True, native_text=True):
else:
text = action['text']
if any(not (32 <= ord(char) <= 126 or char in '\n\r\t') for char in text):
- raise ValueError('This legacy guest supports ASCII text only. Use key actions for other keyboard input.')
+ raise ValueError('This connection supports ASCII text only. Use key actions for other keyboard input.')
shifted = dict(zip('~!@#$%^&*()_+{}|:"<>?', '`1234567890-=[]\\;\',./'))
for char in text.replace('\r\n', '\n'):
shift = char in shifted
@@ -600,15 +600,20 @@ def handle(name, request):
'worker_error': 'The previous operation needs cleanup. Inspect its screenshot or restart the VM before retrying.'}
finish_operation(name, unfinished)
native_text = True
- if platform == 'windows' and (request['action'] == 'status' or request['action'] == 'input' and any(a['type'] == 'text' for a in request['actions'])):
+ if platform in ('windows', 'linux') and (request['action'] == 'status' or request['action'] == 'input' and any(a['type'] == 'text' for a in request['actions'])):
try:
info = qga(name, 'guest-info')
native_text = any(command['name'] == 'guest-exec' and command['enabled'] for command in info['supported_commands'])
except (ValueError, subprocess.TimeoutExpired):
native_text = False
+ if request['action'] == 'status':
+ return {**status, 'readiness': 'agent_unavailable', 'text_encoding': 'ascii',
+ 'worker_error': 'The guest agent is unavailable. Wait for startup or ask an administrator to check its installation.'}
if request['action'] == 'status':
if not native_text:
- return {**status, 'text_encoding': 'ascii', 'worker_error': 'Desktop input is available. Commands, Unicode text and UI actions need a working guest agent with command support.'}
+ 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.'}
+ status['readiness'] = 'worker_starting'
try:
status.update(worker(name,platform,request))
status['readiness'] = 'ready'