On Tue, May 28, 2019 at 01:35:55PM +0200, csfakian(a)redhat.com wrote:
From: Christos Sfakianakis <csfakian(a)redhat.com>
Add a __delattr__ method to catch deletion of RemoteDevice
objects from the self._objects dictionary. The objects need
to have already been marked for deletion, or the call is routed
to the superclass.
Signed-off-by: Christos Sfakianakis <csfakian(a)redhat.com>
---
lnst/Controller/Namespace.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lnst/Controller/Namespace.py b/lnst/Controller/Namespace.py
index 88f82eb..db09156 100644
--- a/lnst/Controller/Namespace.py
+++ b/lnst/Controller/Namespace.py
@@ -195,6 +195,13 @@ class Namespace(object):
if not self._custom_setattr(name, value):
super(Namespace, self).__setattr__(name, value)
+ def __delattr__(self, name):
+ if name in self._objects and isinstance(self._objects[name], RemoteDevice):
+ if self._objects[name].deleted:
+ del self._objects[name]
+ else:
+ super(Namespace, self).__delattr__(name)
+
I now realize I missed something when looking at this with you. There's
a second "else" clause for the parent "if" which isn't defined and
so
just silently does nothing instead of the default behaviour...
So the actual condition should be:
if name in self._objects and isinstance(self._objects[name], RemoteDevice):
if self._objects[name].deleted:
del self._objects[name]
else:
super(Namespace, self).__delattr__(name)
To ensure that only the one specific case has a non-default behaviour.
Sorry about that, that's my fault for not noticing...
-Ondrej