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
This commit is contained in:
parent
638dbf6143
commit
5cf08b5b03
@ -157,7 +157,8 @@ class PropertyHolder(object):
|
|||||||
self._method_prefix + 'Get',
|
self._method_prefix + 'Get',
|
||||||
item,
|
item,
|
||||||
None)
|
None)
|
||||||
except qubesadmin.exc.QubesDaemonAccessError:
|
except (qubesadmin.exc.QubesDaemonAccessError,
|
||||||
|
qubesadmin.exc.QubesVMNotFoundError):
|
||||||
raise qubesadmin.exc.QubesPropertyAccessError(item)
|
raise qubesadmin.exc.QubesPropertyAccessError(item)
|
||||||
is_default, value = self._deserialize_property(property_str)
|
is_default, value = self._deserialize_property(property_str)
|
||||||
if self.app.cache_enabled:
|
if self.app.cache_enabled:
|
||||||
@ -179,7 +180,8 @@ class PropertyHolder(object):
|
|||||||
self._method_prefix + 'GetDefault',
|
self._method_prefix + 'GetDefault',
|
||||||
item,
|
item,
|
||||||
None)
|
None)
|
||||||
except qubesadmin.exc.QubesDaemonAccessError:
|
except (qubesadmin.exc.QubesDaemonAccessError,
|
||||||
|
qubesadmin.exc.QubesVMNotFoundError):
|
||||||
raise qubesadmin.exc.QubesPropertyAccessError(item)
|
raise qubesadmin.exc.QubesPropertyAccessError(item)
|
||||||
if not property_str:
|
if not property_str:
|
||||||
raise AttributeError(item + ' has no default')
|
raise AttributeError(item + ' has no default')
|
||||||
@ -224,7 +226,8 @@ class PropertyHolder(object):
|
|||||||
self._method_prefix + 'Get',
|
self._method_prefix + 'Get',
|
||||||
item,
|
item,
|
||||||
None)
|
None)
|
||||||
except qubesadmin.exc.QubesDaemonNoResponseError:
|
except (qubesadmin.exc.QubesDaemonNoResponseError,
|
||||||
|
qubesadmin.exc.QubesVMNotFoundError):
|
||||||
raise qubesadmin.exc.QubesPropertyAccessError(item)
|
raise qubesadmin.exc.QubesPropertyAccessError(item)
|
||||||
is_default, value = self._deserialize_property(property_str)
|
is_default, value = self._deserialize_property(property_str)
|
||||||
if self.app.cache_enabled:
|
if self.app.cache_enabled:
|
||||||
@ -353,7 +356,8 @@ class PropertyHolder(object):
|
|||||||
self._method_prefix + 'Reset',
|
self._method_prefix + 'Reset',
|
||||||
key,
|
key,
|
||||||
None)
|
None)
|
||||||
except qubesadmin.exc.QubesDaemonNoResponseError:
|
except (qubesadmin.exc.QubesDaemonNoResponseError,
|
||||||
|
qubesadmin.exc.QubesVMNotFoundError):
|
||||||
raise qubesadmin.exc.QubesPropertyAccessError(key)
|
raise qubesadmin.exc.QubesPropertyAccessError(key)
|
||||||
else:
|
else:
|
||||||
if isinstance(value, qubesadmin.vm.QubesVM):
|
if isinstance(value, qubesadmin.vm.QubesVM):
|
||||||
@ -366,7 +370,8 @@ class PropertyHolder(object):
|
|||||||
self._method_prefix + 'Set',
|
self._method_prefix + 'Set',
|
||||||
key,
|
key,
|
||||||
str(value).encode('utf-8'))
|
str(value).encode('utf-8'))
|
||||||
except qubesadmin.exc.QubesDaemonNoResponseError:
|
except (qubesadmin.exc.QubesDaemonNoResponseError,
|
||||||
|
qubesadmin.exc.QubesVMNotFoundError):
|
||||||
raise qubesadmin.exc.QubesPropertyAccessError(key)
|
raise qubesadmin.exc.QubesPropertyAccessError(key)
|
||||||
|
|
||||||
def __delattr__(self, name):
|
def __delattr__(self, name):
|
||||||
@ -378,7 +383,8 @@ class PropertyHolder(object):
|
|||||||
self._method_prefix + 'Reset',
|
self._method_prefix + 'Reset',
|
||||||
name
|
name
|
||||||
)
|
)
|
||||||
except qubesadmin.exc.QubesDaemonNoResponseError:
|
except (qubesadmin.exc.QubesDaemonNoResponseError,
|
||||||
|
qubesadmin.exc.QubesVMNotFoundError):
|
||||||
raise qubesadmin.exc.QubesPropertyAccessError(name)
|
raise qubesadmin.exc.QubesPropertyAccessError(name)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user