|
@@ -17,7 +17,6 @@
|
|
|
#
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
-
|
|
|
import io
|
|
|
import os
|
|
|
import unittest.mock
|
|
@@ -55,7 +54,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('test-vm', 'qubes.VMShell', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|
|
@@ -91,14 +89,12 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('test-vm', 'qubes.VMShell', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|
|
|
}),
|
|
|
('test-vm', 'qubes.VMShell', b'command; exit\n'),
|
|
|
('test-vm2', 'qubes.VMShell', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|
|
@@ -107,7 +103,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
])
|
|
|
self.assertAllCalled()
|
|
|
|
|
|
- @unittest.expectedFailure
|
|
|
def test_002_passio(self):
|
|
|
self.app.expected_calls[
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
|
@@ -121,19 +116,51 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
echo = subprocess.Popen(['echo', 'some-data'], stdout=subprocess.PIPE)
|
|
|
with unittest.mock.patch('sys.stdin', echo.stdout):
|
|
|
ret = qubesadmin.tools.qvm_run.main(
|
|
|
- ['--no-gui', '--pass-io', 'test-vm', 'command'],
|
|
|
+ ['--no-gui', '--pass-io', '--filter-escape-chars',
|
|
|
+ 'test-vm', 'command'],
|
|
|
app=self.app)
|
|
|
-
|
|
|
+ echo.stdout.close()
|
|
|
+ echo.wait()
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('test-vm', 'qubes.VMShell', {
|
|
|
- 'filter_esc': self.default_filter_esc(),
|
|
|
- 'localcmd': None,
|
|
|
+ 'filter_esc': True,
|
|
|
'stdout': None,
|
|
|
'stderr': None,
|
|
|
'user': None,
|
|
|
}),
|
|
|
- ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n')
|
|
|
+ # TODO: find a way to compare b'some-data\n' sent from another
|
|
|
+ # proces
|
|
|
+ ('test-vm', 'qubes.VMShell', b'command; exit\n')
|
|
|
+ ])
|
|
|
+ self.assertAllCalled()
|
|
|
+
|
|
|
+ def test_002_passio_service(self):
|
|
|
+ self.app.expected_calls[
|
|
|
+ ('dom0', 'admin.vm.List', None, None)] = \
|
|
|
+ b'0\x00test-vm class=AppVM state=Running\n'
|
|
|
+ # self.app.expected_calls[
|
|
|
+ # ('test-vm', 'admin.vm.List', None, None)] = \
|
|
|
+ # b'0\x00test-vm class=AppVM state=Running\n'
|
|
|
+ echo = subprocess.Popen(['echo', 'some-data'], stdout=subprocess.PIPE)
|
|
|
+ with unittest.mock.patch('sys.stdin', echo.stdout):
|
|
|
+ ret = qubesadmin.tools.qvm_run.main(
|
|
|
+ ['--no-gui', '--service', '--pass-io', '--filter-escape-chars',
|
|
|
+ 'test-vm', 'test.service'],
|
|
|
+ app=self.app)
|
|
|
+ echo.stdout.close()
|
|
|
+ echo.wait()
|
|
|
+ self.assertEqual(ret, 0)
|
|
|
+ self.assertEqual(self.app.service_calls, [
|
|
|
+ ('test-vm', 'test.service', {
|
|
|
+ 'filter_esc': True,
|
|
|
+ 'stdout': None,
|
|
|
+ 'stderr': None,
|
|
|
+ 'user': None,
|
|
|
+ }),
|
|
|
+ # TODO: find a way to compare b'some-data\n' sent from another
|
|
|
+ # proces
|
|
|
+ ('test-vm', 'test.service', b'')
|
|
|
])
|
|
|
self.assertAllCalled()
|
|
|
|
|
@@ -156,12 +183,12 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
['--no-gui', '--filter-esc', '--pass-io', 'test-vm',
|
|
|
'command'],
|
|
|
app=self.app)
|
|
|
-
|
|
|
+ echo.stdout.close()
|
|
|
+ echo.wait()
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('test-vm', 'qubes.VMShell', {
|
|
|
'filter_esc': True,
|
|
|
- 'localcmd': None,
|
|
|
'stdout': None,
|
|
|
'stderr': None,
|
|
|
'user': None,
|
|
@@ -189,11 +216,12 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
'test-vm', 'command'],
|
|
|
app=self.app)
|
|
|
|
|
|
+ echo.stdout.close()
|
|
|
+ echo.wait()
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('test-vm', 'qubes.VMShell', {
|
|
|
'filter_esc': self.default_filter_esc(),
|
|
|
- 'localcmd': None,
|
|
|
'stdout': None,
|
|
|
'stderr': None,
|
|
|
'user': None,
|
|
@@ -224,11 +252,12 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
'test-vm', 'command'],
|
|
|
app=self.app)
|
|
|
|
|
|
+ echo.stdout.close()
|
|
|
+ echo.wait()
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('test-vm', 'qubes.VMShell', {
|
|
|
'filter_esc': False,
|
|
|
- 'localcmd': None,
|
|
|
'stdout': None,
|
|
|
'stderr': None,
|
|
|
'user': None,
|
|
@@ -239,7 +268,8 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
stdout.close()
|
|
|
self.assertAllCalled()
|
|
|
|
|
|
- def test_005_localcmd(self):
|
|
|
+ @unittest.mock.patch('subprocess.Popen')
|
|
|
+ def test_005_localcmd(self, mock_popen):
|
|
|
self.app.expected_calls[
|
|
|
('dom0', 'admin.vm.List', None, None)] = \
|
|
|
b'0\x00test-vm class=AppVM state=Running\n'
|
|
@@ -249,6 +279,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
# self.app.expected_calls[
|
|
|
# ('test-vm', 'admin.vm.List', None, None)] = \
|
|
|
# b'0\x00test-vm class=AppVM state=Running\n'
|
|
|
+ mock_popen.return_value.wait.return_value = 0
|
|
|
ret = qubesadmin.tools.qvm_run.main(
|
|
|
['--no-gui', '--pass-io', '--localcmd', 'local-command',
|
|
|
'test-vm', 'command'],
|
|
@@ -256,13 +287,16 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('test-vm', 'qubes.VMShell', {
|
|
|
- 'localcmd': 'local-command',
|
|
|
- 'stdout': None,
|
|
|
+ 'stdout': subprocess.PIPE,
|
|
|
+ 'stdin': subprocess.PIPE,
|
|
|
'stderr': None,
|
|
|
'user': None,
|
|
|
}),
|
|
|
('test-vm', 'qubes.VMShell', b'command; exit\n')
|
|
|
])
|
|
|
+ mock_popen.assert_called_once_with('local-command',
|
|
|
+ # TODO: check if the right stdin/stdout objects are used
|
|
|
+ stdout=unittest.mock.ANY, stdin=unittest.mock.ANY, shell=True)
|
|
|
self.assertAllCalled()
|
|
|
|
|
|
def test_006_run_single_with_gui(self):
|
|
@@ -290,7 +324,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
}),
|
|
|
('test-vm', 'qubes.WaitForSession', b'user'),
|
|
|
('test-vm', 'qubes.VMShell', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|
|
@@ -321,7 +354,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
}),
|
|
|
('test-vm', 'qubes.WaitForSession', b'user'),
|
|
|
('test-vm', 'service.name', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|
|
@@ -336,7 +368,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('$dispvm', 'test.service', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|
|
@@ -351,7 +382,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('$dispvm:test-vm', 'test.service', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|
|
@@ -375,7 +405,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('disp123', 'test.service', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|
|
@@ -400,7 +429,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('disp123', 'test.service', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|
|
@@ -431,7 +459,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('test-vm', 'qubes.VMShell', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|
|
@@ -452,7 +479,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
ret = qubesadmin.tools.qvm_run.main(
|
|
|
['--no-gui', '--no-autostart', 'test-vm3', 'command'],
|
|
|
app=self.app)
|
|
|
- self.assertEqual(ret, 0)
|
|
|
+ self.assertEqual(ret, 1)
|
|
|
self.assertEqual(self.app.service_calls, [])
|
|
|
self.assertAllCalled()
|
|
|
|
|
@@ -474,7 +501,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('disp123', 'qubes.VMShell+WaitForSession', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|
|
@@ -503,7 +529,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('disp123', 'qubes.VMShell', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|
|
@@ -529,7 +554,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
|
|
|
self.assertEqual(ret, 0)
|
|
|
self.assertEqual(self.app.service_calls, [
|
|
|
('test-vm', 'qubes.VMShell', {
|
|
|
- 'localcmd': None,
|
|
|
'stdout': subprocess.DEVNULL,
|
|
|
'stderr': subprocess.DEVNULL,
|
|
|
'user': None,
|