Skip to content

Commit cc255c6

Browse files
committed
Reuse property-pre-set:netvm event for processing default_netvm change
Do not duplicate the check if changing to non-running netvm. But more importantly, call the property-pre-set event to unset old netvm. Otherwise setting the new one will fail (property-reset:netvm handler assumes matching pre-(re)set handler detached old value already). DO not use property-pre-reset:netvm here, because it can't know the new value yet (pre-reset is used when changing non-default to default value, so normally it can check what is the default value at the call time - but here it wouldn't work because the default value is going to change). Fixes QubesOS/qubes-issues#10125
1 parent 74b8cbc commit cc255c6

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

qubes/app.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,18 +1700,18 @@ def on_property_pre_set_default_netvm(
17001700
self, event, name, newvalue, oldvalue=None
17011701
):
17021702
# pylint: disable=unused-argument,invalid-name
1703-
if (
1704-
newvalue is not None
1705-
and oldvalue is not None
1706-
and oldvalue.is_running()
1707-
and not newvalue.is_running()
1708-
and self.domains.get_vms_connected_to(oldvalue)
1709-
):
1710-
raise qubes.exc.QubesVMNotRunningError(
1711-
newvalue,
1712-
"Cannot change {!r} to domain that "
1713-
"is not running ({!r}).".format(name, newvalue.name),
1714-
)
1703+
for vm in self.domains:
1704+
if hasattr(vm, "netvm") and vm.property_is_default("netvm"):
1705+
# Use pre-set event instead of pre-reset, so it can get both
1706+
# old and new values, and perform necessary actions.
1707+
# Especially, it needs to detach old netvm.
1708+
vm.fire_event(
1709+
"property-pre-set:netvm",
1710+
pre_event=True,
1711+
name="netvm",
1712+
newvalue=newvalue,
1713+
oldvalue=oldvalue,
1714+
)
17151715

17161716
@qubes.events.handler("property-set:default_netvm")
17171717
def on_property_set_default_netvm(

0 commit comments

Comments
 (0)