def test_024_execute_startup_error(self, mock_subprocess, mock_qubesd_call): rule = qubespolicy.PolicyRule('@anyvm @anyvm allow') action = qubespolicy.PolicyAction('test.service', 'test-vm1', 'test-vm2', rule, 'test-vm2') mock_qubesd_call.side_effect = \ qubespolicy.QubesMgmtException('QubesVMError') with self.assertRaises(qubespolicy.QubesMgmtException): action.execute('some-ident') self.assertEqual(mock_qubesd_call.mock_calls, [unittest.mock.call('test-vm2', 'admin.vm.Start')]) self.assertEqual(mock_subprocess.mock_calls, [])
def test_023_execute_already_running(self, mock_subprocess, mock_qubesd_call): rule = qubespolicy.PolicyRule('$anyvm $anyvm allow') action = qubespolicy.PolicyAction('test.service', 'test-vm1', 'test-vm2', rule, 'test-vm2') mock_qubesd_call.side_effect = \ qubespolicy.QubesMgmtException('QubesVMNotHaltedError') action.execute('some-ident') self.assertEqual(mock_qubesd_call.mock_calls, [unittest.mock.call('test-vm2', 'admin.vm.Start')]) self.assertEqual(mock_subprocess.mock_calls, [unittest.mock.call([qubespolicy.QREXEC_CLIENT, '-d', 'test-vm2', '-c', 'some-ident', 'DEFAULT:QUBESRPC test.service test-vm1'])])