Skip to content

Commit 8f68869

Browse files
committed
vm: add run_service(..., connection_timeout) argument
The connection_timeout value is about just establishing connection. It's rather short by default (5s), which is normally fine. But there are cases where it needs to be longer, for example when VM is resuming from sleep. QubesOS/qubes-issues#9942
1 parent 8c94603 commit 8f68869

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

qubes/tests/vm/qubesvm.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,6 +2975,24 @@ def test_700_run_service(self, mock_subprocess):
29752975
)
29762976
self.assertFalse(start_mock.called)
29772977

2978+
mock_subprocess.reset_mock()
2979+
start_mock.reset_mock()
2980+
with self.subTest("connection_timeout"):
2981+
vm.is_running = lambda: True
2982+
vm.is_qrexec_running = lambda stubdom=False: True
2983+
self.loop.run_until_complete(
2984+
vm.run_service("test.service", connection_timeout=10)
2985+
)
2986+
mock_subprocess.assert_called_once_with(
2987+
"/usr/bin/qrexec-client",
2988+
"-d",
2989+
"test-inst-vm",
2990+
"-w",
2991+
"10",
2992+
"user:QUBESRPC test.service dom0",
2993+
)
2994+
self.assertFalse(start_mock.called)
2995+
29782996
@unittest.mock.patch("qubes.vm.qubesvm.QubesVM.run")
29792997
def test_710_run_for_stdio(self, mock_run):
29802998
vm = self.get_vm(cls=qubes.vm.standalonevm.StandaloneVM, name="vm")

qubes/vm/qubesvm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,7 @@ async def run_service(
17691769
filter_esc=False,
17701770
autostart=False,
17711771
gui=False,
1772+
connection_timeout=None,
17721773
**kwargs,
17731774
):
17741775
"""Run service on this VM
@@ -1782,6 +1783,8 @@ async def run_service(
17821783
:param bool autostart: if :py:obj:`True`, machine will be started if \
17831784
it is not running
17841785
:param bool gui: when autostarting, also start gui daemon
1786+
:param int connection_timeout: override default qrexec connection
1787+
timeout (in seconds)
17851788
:rtype: asyncio.subprocess.Process
17861789
17871790
.. note::
@@ -1827,6 +1830,7 @@ async def run_service(
18271830
qubes.config.system_path["qrexec_client_path"],
18281831
"-d",
18291832
str(name),
1833+
*(("-w", str(connection_timeout)) if connection_timeout else ()),
18301834
*(("-t", "-T") if filter_esc else ()),
18311835
"{}:QUBESRPC {} {}".format(user, service, source),
18321836
**kwargs,

0 commit comments

Comments
 (0)