Skip to content

Commit

Permalink
qvm_start_daemon: improve reset property handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fepitre committed May 10, 2024
1 parent a1b6764 commit 626f183
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions qubesadmin/tools/qvm_start_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def on_domain_stopped(self, vm, _event, **_kwargs):
self.cleanup_guid(stubdom_xid)
self.cleanup_pacat_process(stubdom_xid)

def on_property_audiovm_set(self, vm, _event, **_kwargs):
def on_property_audiovm_set(self, vm, event, **kwargs):
"""Handler for catching event related to dynamic AudioVM set/unset"""
if vm.name not in self.xid_cache:
try:
Expand All @@ -745,7 +745,13 @@ def on_property_audiovm_set(self, vm, _event, **_kwargs):
log.error("vm.name: failed to determine XID: %s", str(e))
return
xid, stubdom_xid = self.xid_cache[vm.name]
newvalue = _kwargs.get("newvalue", None)
# We ensure that on_property_audiovm_set is really called with
# newvalue as kwarg to not fallback all the times to vm.audiovm
# in order to have newvalue=None as requested.
if "newvalue" in kwargs: # pylint: disable=consider-using-get
newvalue = kwargs["newvalue"]

Check warning on line 752 in qubesadmin/tools/qvm_start_daemon.py

View check run for this annotation

Codecov / codecov/patch

qubesadmin/tools/qvm_start_daemon.py#L751-L752

Added lines #L751 - L752 were not covered by tests
else:
newvalue = str(getattr(vm, "audiovm", None))

Check warning on line 754 in qubesadmin/tools/qvm_start_daemon.py

View check run for this annotation

Codecov / codecov/patch

qubesadmin/tools/qvm_start_daemon.py#L754

Added line #L754 was not covered by tests
if newvalue != self.app.local_name:
if xid != -1:
self.cleanup_pacat_process(xid)
Expand All @@ -756,8 +762,11 @@ def on_property_audiovm_set(self, vm, _event, **_kwargs):
del self.xid_cache[vm.name]
except KeyError:
return
elif (newvalue == self.app.local_name and
vm.get_power_state() == "Running"):
if (

Check warning on line 765 in qubesadmin/tools/qvm_start_daemon.py

View check run for this annotation

Codecov / codecov/patch

qubesadmin/tools/qvm_start_daemon.py#L765

Added line #L765 was not covered by tests
event in ["property-set:audiovm", "property-reset:audiovm"]
and newvalue == self.app.local_name
and vm.get_power_state() == "Running"
):
asyncio.ensure_future(self.start_audio(vm))

def cleanup_guid(self, xid):
Expand Down Expand Up @@ -799,8 +808,12 @@ def register_events(self, events):
self.on_connection_established)
events.add_handler('domain-stopped', self.on_domain_stopped)

for event in ["property-set:audiovm", "property-pre-set:audiovm",
"property-pre-del:audiovm"]:
for event in [

Check warning on line 811 in qubesadmin/tools/qvm_start_daemon.py

View check run for this annotation

Codecov / codecov/patch

qubesadmin/tools/qvm_start_daemon.py#L811

Added line #L811 was not covered by tests
"property-set:audiovm",
"property-pre-set:audiovm",
"property-pre-reset:audiovm",
"property-reset:audiovm"
]:
events.add_handler(event, self.on_property_audiovm_set)

def is_watched(self, vm):
Expand Down

0 comments on commit 626f183

Please sign in to comment.