Skip to content

Commit 23298f9

Browse files
committed
Add option to wait for domain shutdown
By waiting for the full shutdown, it becomes possible to receive appropriate exception, that would allow adapting the client to react differently. A timeout can be interpreted and the method adjusted to kill the domain.
1 parent 506bee2 commit 23298f9

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

qubesadmin/tests/vm/actions.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ def test_001_shutdown(self):
4040
self.vm.shutdown()
4141
self.assertAllCalled()
4242

43+
def test_001_shutdown_force(self):
44+
self.app.expected_calls[
45+
('test-vm', 'admin.vm.Shutdown', 'force', None)] = \
46+
b'0\x00'
47+
self.vm.shutdown(force=True)
48+
self.assertAllCalled()
49+
50+
def test_001_shutdown_wait(self):
51+
self.app.expected_calls[
52+
('test-vm', 'admin.vm.Shutdown', 'wait', None)] = \
53+
b'0\x00'
54+
self.vm.shutdown(wait=True)
55+
self.assertAllCalled()
56+
57+
def test_001_shutdown_force_wait(self):
58+
self.app.expected_calls[
59+
('test-vm', 'admin.vm.Shutdown', 'force+wait', None)] = \
60+
b'0\x00'
61+
self.vm.shutdown(force=True, wait=True)
62+
self.assertAllCalled()
63+
4364
def test_002_kill(self):
4465
self.app.expected_calls[
4566
('test-vm', 'admin.vm.Kill', None, None)] = \

qubesadmin/vm/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,22 @@ def start(self):
113113
"""
114114
self.qubesd_call(self._method_dest, "admin.vm.Start")
115115

116-
def shutdown(self, force=False):
116+
def shutdown(self, force=False, wait=False):
117117
"""
118118
Shutdown domain.
119119
120120
:return:
121121
"""
122-
# TODO: wait parameter (using event?)
122+
arg_list = []
123123
if force:
124-
self.qubesd_call(self._method_dest, "admin.vm.Shutdown", "force")
125-
else:
126-
self.qubesd_call(self._method_dest, "admin.vm.Shutdown")
124+
arg_list.append("force")
125+
if wait:
126+
arg_list.append("wait")
127+
args = "+".join(arg_list)
128+
params = [self._method_dest, "admin.vm.Shutdown"]
129+
if args:
130+
params.append(args)
131+
self.qubesd_call(*params)
127132

128133
def kill(self):
129134
"""

0 commit comments

Comments
 (0)