tools/qvm-run: exit the shell after executing requested command

Since we use qubes.VMShell service now and send requested command on its
stdin, we need to terminate that shell after requested command -
otherwise the service will not terminate automatically waiting for
further input (next commands).
This commit is contained in:
Marek Marczykowski-Górecki 2017-05-18 09:54:26 +02:00
parent d0bcd3ead2
commit 8686ef423a
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 11 additions and 10 deletions

View File

@ -53,7 +53,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
'stderr': subprocess.DEVNULL, 'stderr': subprocess.DEVNULL,
'user': None, 'user': None,
}), }),
('test-vm', 'qubes.VMShell', b'command\n') ('test-vm', 'qubes.VMShell', b'command; exit\n')
]) ])
self.assertAllCalled() self.assertAllCalled()
@ -77,7 +77,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
'stderr': subprocess.DEVNULL, 'stderr': subprocess.DEVNULL,
'user': None, 'user': None,
}), }),
('test-vm', 'qubes.VMShell', b'command\n'), ('test-vm', 'qubes.VMShell', b'command; exit\n'),
('test-vm2', 'qubes.VMShell', { ('test-vm2', 'qubes.VMShell', {
'filter_esc': True, 'filter_esc': True,
'localcmd': None, 'localcmd': None,
@ -85,7 +85,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
'stderr': subprocess.DEVNULL, 'stderr': subprocess.DEVNULL,
'user': None, 'user': None,
}), }),
('test-vm2', 'qubes.VMShell', b'command\n') ('test-vm2', 'qubes.VMShell', b'command; exit\n')
]) ])
self.assertAllCalled() self.assertAllCalled()
@ -111,7 +111,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
'stderr': None, 'stderr': None,
'user': None, 'user': None,
}), }),
('test-vm', 'qubes.VMShell', b'command\nsome-data\n') ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n')
]) ])
self.assertAllCalled() self.assertAllCalled()
@ -139,7 +139,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
'stderr': None, 'stderr': None,
'user': None, 'user': None,
}), }),
('test-vm', 'qubes.VMShell', b'command\nsome-data\n') ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n')
]) ])
self.assertEqual(stdout.getvalue(), '\033[0;31m\033[0m') self.assertEqual(stdout.getvalue(), '\033[0;31m\033[0m')
stdout.close() stdout.close()
@ -170,7 +170,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
'stderr': None, 'stderr': None,
'user': None, 'user': None,
}), }),
('test-vm', 'qubes.VMShell', b'command\nsome-data\n') ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n')
]) ])
self.assertEqual(stdout.getvalue(), '') self.assertEqual(stdout.getvalue(), '')
stdout.close() stdout.close()
@ -201,7 +201,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
'stderr': None, 'stderr': None,
'user': None, 'user': None,
}), }),
('test-vm', 'qubes.VMShell', b'command\nsome-data\n') ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n')
]) ])
self.assertEqual(stdout.getvalue(), '') self.assertEqual(stdout.getvalue(), '')
stdout.close() stdout.close()
@ -227,7 +227,7 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
'stderr': None, 'stderr': None,
'user': None, 'user': None,
}), }),
('test-vm', 'qubes.VMShell', b'command\n') ('test-vm', 'qubes.VMShell', b'command; exit\n')
]) ])
self.assertAllCalled() self.assertAllCalled()
@ -259,6 +259,6 @@ class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
'stderr': subprocess.DEVNULL, 'stderr': subprocess.DEVNULL,
'user': None, 'user': None,
}), }),
('test-vm', 'qubes.VMShell', b'command\n') ('test-vm', 'qubes.VMShell', b'command; exit\n')
]) ])
self.assertAllCalled() self.assertAllCalled()

View File

@ -268,7 +268,8 @@ class QubesVM(qubesadmin.base.PropertyHolder):
''' # pylint: disable=redefined-builtin ''' # pylint: disable=redefined-builtin
if input is None: if input is None:
input = b'' input = b''
return b''.join((command.rstrip('\n').encode('utf-8'), b'\n', input)) return b''.join((command.rstrip('\n').encode('utf-8'),
b'; exit\n', input))
def run(self, command, input=None, **kwargs): def run(self, command, input=None, **kwargs):
'''Run a shell command inside the domain using qubes.VMShell qrexec. '''Run a shell command inside the domain using qubes.VMShell qrexec.