| ... | @@ -135,18 +135,47 @@ class GuestCancellation(unittest.TestCase): | ... | @@ -135,18 +135,47 @@ class GuestCancellation(unittest.TestCase): |
| 135 | finally: | 135 | finally: |
| 136 | computer.DEADLINE.reset(token) | 136 | computer.DEADLINE.reset(token) |
| 137 | | 137 | |
| 138 | def test_windows_console_remains_available_without_guest_agent(self): | 138 | def test_console_remains_available_without_guest_agent(self): |
| | 139 | for platform in ['windows', 'linux']: |
| | 140 | def virsh(action, *args, **kwargs): |
| | 141 | return 'running' if action == 'domstate' else '<domain><metadata><vm xmlns="https://paperclover.net/snowglobe"><platform>'+platform+'</platform></vm></metadata></domain>' |
| | 142 | 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: |
| | 143 | status = computer.handle('fixture', {'action': 'status'}) |
| | 144 | self.assertEqual(status['readiness'], 'agent_unavailable') |
| | 145 | self.assertEqual(status['capabilities'], ['shot', 'input']) |
| | 146 | self.assertEqual(status['text_encoding'], 'ascii') |
| | 147 | actions = [{'type': 'text', 'text': 'recovery console'}] |
| | 148 | with patch.object(computer, 'desktop', new_callable=AsyncMock, return_value={'completed': 1}) as desktop: |
| | 149 | self.assertEqual(computer.handle('fixture', {'action': 'input', 'actions': actions, 'screenshot': False}), {'completed': 1}) |
| | 150 | desktop.assert_awaited_once_with('fixture', actions, platform, False, False) |
| | 151 | work.assert_not_called() |
| | 152 | self.assertFalse((computer.vms.DISKS / 'fixture' / 'computer-operation.json').exists()) |
| | 153 | |
| | 154 | def test_status_distinguishes_disabled_commands_from_a_starting_worker(self): |
| 139 | def virsh(action, *args, **kwargs): | 155 | def virsh(action, *args, **kwargs): |
| 140 | return 'running' if action == 'domstate' else '<domain><metadata><vm xmlns="https://paperclover.net/snowglobe"><platform>windows</platform></vm></metadata></domain>' | 156 | return 'running' if action == 'domstate' else '<domain/>' |
| 141 | with patch.object(computer.vms, 'virsh', virsh), patch.object(computer, 'qga', side_effect=ValueError('Disconnected')), patch.object(computer, 'worker') as work: | 157 | with patch.object(computer.vms, 'virsh', virsh), patch.object(computer, 'worker') as work: |
| 142 | status = computer.handle('fixture', {'action': 'status'}) | 158 | with patch.object(computer, 'qga', return_value={'supported_commands':[{'name':'guest-exec','enabled':False}]}): |
| 143 | self.assertEqual(status['capabilities'], ['shot', 'input']) | 159 | status = computer.handle('fixture', {'action':'status'}) |
| 144 | self.assertEqual(status['text_encoding'], 'ascii') | 160 | self.assertEqual(status['readiness'], 'agent_unsupported') |
| 145 | actions = [{'type': 'text', 'text': 'recovery console'}] | | |
| 146 | with patch.object(computer, 'desktop', new_callable=AsyncMock, return_value={'completed': 1}) as desktop: | | |
| 147 | self.assertEqual(computer.handle('fixture', {'action': 'input', 'actions': actions, 'screenshot': False}), {'completed': 1}) | | |
| 148 | desktop.assert_awaited_once_with('fixture', actions, 'windows', False, False) | | |
| 149 | work.assert_not_called() | 161 | work.assert_not_called() |
| | 162 | with patch.object(computer, 'qga', return_value={'supported_commands':[{'name':'guest-exec','enabled':True}]}): |
| | 163 | work.side_effect = ValueError('Sign in to the VM desktop before using this tool.') |
| | 164 | status = computer.handle('fixture', {'action':'status'}) |
| | 165 | self.assertEqual(status['readiness'], 'worker_starting') |
| | 166 | self.assertIn('Sign in', status['worker_error']) |
| | 167 | work.side_effect = None |
| | 168 | work.return_value = {'runtimes':['bash']} |
| | 169 | status = computer.handle('fixture', {'action':'status'}) |
| | 170 | self.assertEqual(status['readiness'], 'ready') |
| | 171 | self.assertEqual(status['runtimes'], ['bash']) |
| | 172 | |
| | 173 | def test_legacy_mac_status_keeps_its_private_transport(self): |
| | 174 | def virsh(action, *args, **kwargs): |
| | 175 | return 'running' if action == 'domstate' else '<domain><metadata><vm xmlns="https://paperclover.net/snowglobe"><platform>macos</platform></vm></metadata></domain>' |
| | 176 | 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: |
| | 177 | self.assertEqual(computer.handle('fixture', {'action':'status'})['readiness'], 'ready') |
| | 178 | work.assert_called_once_with('fixture', 'macos', {'action':'status'}) |
| 150 | | 179 | |
| 151 | def test_failed_cleanup_keeps_status_available_and_blocks_later_control(self): | 180 | def test_failed_cleanup_keeps_status_available_and_blocks_later_control(self): |
| 152 | for platform, identity in [('linux', 'snowglobe-computer-request-' + 'a' * 32), ('windows', 'a' * 32)]: | 181 | for platform, identity in [('linux', 'snowglobe-computer-request-' + 'a' * 32), ('windows', 'a' * 32)]: |