From 447b02836164f71d19ea0cdaf7bfed5c4d9483bb Mon Sep 17 00:00:00 2001 From: Haijiao Zhao Date: Tue, 10 Sep 2024 04:48:31 -0400 Subject: [PATCH] setup_attrs:Delete attribute if the value is explicitly set to None Signed-off-by: Haijiao Zhao --- virttest/libvirt_xml/base.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/virttest/libvirt_xml/base.py b/virttest/libvirt_xml/base.py index 8bceaaf453..c2f3ad7d16 100644 --- a/virttest/libvirt_xml/base.py +++ b/virttest/libvirt_xml/base.py @@ -304,6 +304,15 @@ def setup_attrs(self, **attrs): 'Cannot set attribute "%s" to %s object.' "There is no such attribute." % (key, self.__class__) ) + + # Delete attribute if the value is explicitly set to None + if value is None: + del_func = eval("self.del_%s" % key) + if not isinstance(del_func, propcan.PropCanBase): + logging.warning(f"Customized del func {del_func} might not work") + del_func() + continue + get_func = eval("self.get_%s" % key) # Skip Getters if they are customized