From 188bc2799bdc77930f656ec0a423cd42887f76fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 12 Aug 2017 15:15:19 +0200 Subject: [PATCH] tests: add DispVM tests Especially for one service call wrapper QubesOS/qubes-issues#3016 --- qubesadmin/tests/vm/dispvm.py | 87 +++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 qubesadmin/tests/vm/dispvm.py diff --git a/qubesadmin/tests/vm/dispvm.py b/qubesadmin/tests/vm/dispvm.py new file mode 100644 index 0000000..c186b12 --- /dev/null +++ b/qubesadmin/tests/vm/dispvm.py @@ -0,0 +1,87 @@ +# -*- encoding: utf-8 -*- +# +# The Qubes OS Project, http://www.qubes-os.org +# +# Copyright (C) 2017 Marek Marczykowski-Górecki +# +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with this program; if not, see . + +import qubesadmin.tests +import qubesadmin.vm + +class TC_00_Dispvm(qubesadmin.tests.QubesTestCase): + def test_000_local_create_default(self): + self.app.qubesd_connection_type = 'socket' + self.app.expected_calls[ + ('dom0', 'admin.vm.CreateDisposable', None, None)] = b'0\0disp123' + self.app.expected_calls[ + ('disp123', 'admin.vm.Kill', None, None)] = b'0\0' + vm = qubesadmin.vm.DispVM.from_appvm(self.app, None) + (stdout, stderr) = vm.run_service_for_stdio('test.service') + vm.cleanup() + self.assertEqual(self.app.service_calls, [ + ('disp123', 'test.service', {}), + ('disp123', 'test.service', b''), + ]) + self.assertAllCalled() + + def test_001_local_create_specific(self): + self.app.qubesd_connection_type = 'socket' + self.app.expected_calls[ + ('test-vm', 'admin.vm.CreateDisposable', None, None)] = \ + b'0\0disp123' + self.app.expected_calls[ + ('disp123', 'admin.vm.Kill', None, None)] = b'0\0' + vm = qubesadmin.vm.DispVM.from_appvm(self.app, 'test-vm') + (stdout, stderr) = vm.run_service_for_stdio('test.service') + vm.cleanup() + self.assertEqual(self.app.service_calls, [ + ('disp123', 'test.service', {}), + ('disp123', 'test.service', b''), + ]) + self.assertAllCalled() + + def test_002_local_no_run_cleanup(self): + self.app.qubesd_connection_type = 'socket' + vm = qubesadmin.vm.DispVM.from_appvm(self.app, None) + vm.cleanup() + self.assertEqual(self.app.service_calls, []) + self.assertAllCalled() + + def test_010_remote_create_default(self): + vm = qubesadmin.vm.DispVM.from_appvm(self.app, None) + (stdout, stderr) = vm.run_service_for_stdio('test.service') + vm.cleanup() + self.assertEqual(self.app.service_calls, [ + ('$dispvm', 'test.service', {}), + ('$dispvm', 'test.service', b''), + ]) + self.assertAllCalled() + + def test_011_remote_create_specific(self): + vm = qubesadmin.vm.DispVM.from_appvm(self.app, 'test-vm') + (stdout, stderr) = vm.run_service_for_stdio('test.service') + vm.cleanup() + self.assertEqual(self.app.service_calls, [ + ('$dispvm:test-vm', 'test.service', {}), + ('$dispvm:test-vm', 'test.service', b''), + ]) + self.assertAllCalled() + + def test_012_remote_no_run_cleanup(self): + vm = qubesadmin.vm.DispVM.from_appvm(self.app, None) + vm.cleanup() + self.assertEqual(self.app.service_calls, []) + self.assertAllCalled()