Browse Source

Uniformly handle QubesVMNotFoundError when accessing a property

If domain was just removed, it the qrexec call may result in a
QubesVMNotFoundError exception. If it was removed earlier, and the
caller is in connecting via qrexec, the call will be rejected at the
policy level. Treat both situations uniformely - with
QubesPropertyAccessError. This allows using convenient `getattr()` to
define placeholder value (if appropriate), or try/except with a single
exception instead of two.

QubesOS/qubes-issues#5105
Marek Marczykowski-Górecki 2 years ago
parent
commit
5cf08b5b03
1 changed files with 12 additions and 6 deletions
  1. 12 6
      qubesadmin/base.py

+ 12 - 6
qubesadmin/base.py

@@ -157,7 +157,8 @@ class PropertyHolder(object):
                 self._method_prefix + 'Get',
                 item,
                 None)
-        except qubesadmin.exc.QubesDaemonAccessError:
+        except (qubesadmin.exc.QubesDaemonAccessError,
+                qubesadmin.exc.QubesVMNotFoundError):
             raise qubesadmin.exc.QubesPropertyAccessError(item)
         is_default, value = self._deserialize_property(property_str)
         if self.app.cache_enabled:
@@ -179,7 +180,8 @@ class PropertyHolder(object):
                 self._method_prefix + 'GetDefault',
                 item,
                 None)
-        except qubesadmin.exc.QubesDaemonAccessError:
+        except (qubesadmin.exc.QubesDaemonAccessError,
+                qubesadmin.exc.QubesVMNotFoundError):
             raise qubesadmin.exc.QubesPropertyAccessError(item)
         if not property_str:
             raise AttributeError(item + ' has no default')
@@ -224,7 +226,8 @@ class PropertyHolder(object):
                 self._method_prefix + 'Get',
                 item,
                 None)
-        except qubesadmin.exc.QubesDaemonNoResponseError:
+        except (qubesadmin.exc.QubesDaemonNoResponseError,
+                qubesadmin.exc.QubesVMNotFoundError):
             raise qubesadmin.exc.QubesPropertyAccessError(item)
         is_default, value = self._deserialize_property(property_str)
         if self.app.cache_enabled:
@@ -353,7 +356,8 @@ class PropertyHolder(object):
                     self._method_prefix + 'Reset',
                     key,
                     None)
-            except qubesadmin.exc.QubesDaemonNoResponseError:
+            except (qubesadmin.exc.QubesDaemonNoResponseError,
+                    qubesadmin.exc.QubesVMNotFoundError):
                 raise qubesadmin.exc.QubesPropertyAccessError(key)
         else:
             if isinstance(value, qubesadmin.vm.QubesVM):
@@ -366,7 +370,8 @@ class PropertyHolder(object):
                     self._method_prefix + 'Set',
                     key,
                     str(value).encode('utf-8'))
-            except qubesadmin.exc.QubesDaemonNoResponseError:
+            except (qubesadmin.exc.QubesDaemonNoResponseError,
+                    qubesadmin.exc.QubesVMNotFoundError):
                 raise qubesadmin.exc.QubesPropertyAccessError(key)
 
     def __delattr__(self, name):
@@ -378,7 +383,8 @@ class PropertyHolder(object):
                 self._method_prefix + 'Reset',
                 name
             )
-        except qubesadmin.exc.QubesDaemonNoResponseError:
+        except (qubesadmin.exc.QubesDaemonNoResponseError,
+                qubesadmin.exc.QubesVMNotFoundError):
             raise qubesadmin.exc.QubesPropertyAccessError(name)