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