From b434287c88d8048f3aed29b1fe1f32bfe1584202 Mon Sep 17 00:00:00 2001 From: 3hhh Date: Fri, 9 Apr 2021 17:28:40 +0200 Subject: [PATCH 1/2] domains: Handle removal of VM during on_shutdown. Fixes QubesOS/qubes-issues#5105 --- qui/tray/domains.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/qui/tray/domains.py b/qui/tray/domains.py index b48d5969..bc696e52 100644 --- a/qui/tray/domains.py +++ b/qui/tray/domains.py @@ -698,19 +698,24 @@ def update_domain_item(self, vm, event, **kwargs): item.update_state(state) if event == 'domain-shutdown': - if getattr(vm, 'klass', None) == 'TemplateVM': - for menu_item in self.menu_items.values(): - try: - if not menu_item.vm.is_running(): - # A VM based on this template can only be - # outdated if the VM is currently running. + try: + if getattr(vm, 'klass', None) == 'TemplateVM': + for menu_item in self.menu_items.values(): + try: + if not menu_item.vm.is_running(): + # A VM based on this template can only be + # outdated if the VM is currently running. + continue + except exc.QubesPropertyAccessError: continue - except exc.QubesPropertyAccessError: - continue - if getattr(menu_item.vm, 'template', None) == vm and \ - any(vol.is_outdated() - for vol in menu_item.vm.volumes.values()): - menu_item.name.update_outdated(True) + if getattr(menu_item.vm, 'template', None) == vm and \ + any(vol.is_outdated() + for vol in menu_item.vm.volumes.values()): + menu_item.name.update_outdated(True) + except exc.QubesVMNotFoundError: + #attribute not available anymore as VM was removed in the meantime + pass + # if the VM was shut down, it is no longer outdated item.name.update_outdated(False) From c1412d81e66f2d0e24ae3b98d3e4ce244b8e7cd6 Mon Sep 17 00:00:00 2001 From: 3hhh Date: Sat, 10 Apr 2021 12:32:34 +0200 Subject: [PATCH 2/2] Make pylint happy --- qui/tray/domains.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/qui/tray/domains.py b/qui/tray/domains.py index bc696e52..5dda3ca1 100644 --- a/qui/tray/domains.py +++ b/qui/tray/domains.py @@ -669,6 +669,26 @@ def remove_domain_item(self, _submitter, _event, vm, **_kwargs): self.tray_menu.remove(vm_widget) del self.menu_items[vm] + def handle_domain_shutdown(self, vm): + try: + if getattr(vm, 'klass', None) == 'TemplateVM': + for menu_item in self.menu_items.values(): + try: + if not menu_item.vm.is_running(): + # A VM based on this template can only be + # outdated if the VM is currently running. + continue + except exc.QubesPropertyAccessError: + continue + if getattr(menu_item.vm, 'template', None) == vm and \ + any(vol.is_outdated() + for vol in menu_item.vm.volumes.values()): + menu_item.name.update_outdated(True) + except exc.QubesVMNotFoundError: + # attribute not available anymore as VM was removed + # in the meantime + pass + def update_domain_item(self, vm, event, **kwargs): ''' Update the menu item with the started menu for the specified vm in the tray''' @@ -698,24 +718,7 @@ def update_domain_item(self, vm, event, **kwargs): item.update_state(state) if event == 'domain-shutdown': - try: - if getattr(vm, 'klass', None) == 'TemplateVM': - for menu_item in self.menu_items.values(): - try: - if not menu_item.vm.is_running(): - # A VM based on this template can only be - # outdated if the VM is currently running. - continue - except exc.QubesPropertyAccessError: - continue - if getattr(menu_item.vm, 'template', None) == vm and \ - any(vol.is_outdated() - for vol in menu_item.vm.volumes.values()): - menu_item.name.update_outdated(True) - except exc.QubesVMNotFoundError: - #attribute not available anymore as VM was removed in the meantime - pass - + self.handle_domain_shutdown(vm) # if the VM was shut down, it is no longer outdated item.name.update_outdated(False)