vm: raise CalledProcessError instead of QubesVMError on failed service call

follow core-admin change.
This commit is contained in:
Marek Marczykowski-Górecki 2017-06-21 05:05:35 +02:00
parent ba2057a2c6
commit 5ac7632dd0
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -21,6 +21,9 @@
'''Qubes VM objects.''' '''Qubes VM objects.'''
import logging import logging
import subprocess
import qubesadmin.base import qubesadmin.base
import qubesadmin.exc import qubesadmin.exc
import qubesadmin.storage import qubesadmin.storage
@ -273,10 +276,10 @@ class QubesVM(qubesadmin.base.PropertyHolder):
stdouterr = p.communicate(input=input) stdouterr = p.communicate(input=input)
if p.returncode: if p.returncode:
raise qubesadmin.exc.QubesVMError( exc = subprocess.CalledProcessError(p.returncode, service)
'VM {}: service {!r} failed with retcode {!r}; ' # Python < 3.5 didn't have those
'stdout={!r} stderr={!r}'.format(self, exc.output, exc.stderr = stdouterr
service, p.returncode, *stdouterr)) raise exc
return stdouterr return stdouterr
@ -293,8 +296,13 @@ class QubesVM(qubesadmin.base.PropertyHolder):
'''Run a shell command inside the domain using qubes.VMShell qrexec. '''Run a shell command inside the domain using qubes.VMShell qrexec.
''' # pylint: disable=redefined-builtin ''' # pylint: disable=redefined-builtin
return self.run_service_for_stdio('qubes.VMShell', try:
input=self.prepare_input_for_vmshell(command, input), **kwargs) return self.run_service_for_stdio('qubes.VMShell',
input=self.prepare_input_for_vmshell(command, input), **kwargs)
except subprocess.CalledProcessError as e:
e.cmd = command
raise e
# pylint: disable=abstract-method # pylint: disable=abstract-method
class AdminVM(QubesVM): class AdminVM(QubesVM):