[virt-tools-list] [virt-manager] [PATCHv2 1/2] Keep the value of filesystem/source when attribute is changed

Radostin Stoyanov rstoyanov1 at gmail.com
Mon Jun 19 08:18:47 UTC 2017


When the attribute of filesystem/source is changed the old value was
not assigned to the new attribute.
---
 tests/xmlparse-xml/change-filesystems-out.xml |  4 ++--
 tests/xmlparse.py                             |  2 +-
 virtinst/devicefilesystem.py                  | 21 ++++++++++++++++++++-
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/tests/xmlparse-xml/change-filesystems-out.xml b/tests/xmlparse-xml/change-filesystems-out.xml
index 1af7544..0c89084 100644
--- a/tests/xmlparse-xml/change-filesystems-out.xml
+++ b/tests/xmlparse-xml/change-filesystems-out.xml
@@ -47,8 +47,8 @@
       <source usage="123" units="KiB"/>
       <target dir="/bar/baz"/>
     </filesystem>
-    <filesystem type="block">
-      <source dev="/dev/new"/>
+    <filesystem type="file">
+      <source dev="/dev/new" file="/dev/new"/>
       <target dir="/bar/baz"/>
       <readonly/>
     </filesystem>
diff --git a/tests/xmlparse.py b/tests/xmlparse.py
index 8526a60..cc29ead 100644
--- a/tests/xmlparse.py
+++ b/tests/xmlparse.py
@@ -781,9 +781,9 @@ class XMLParseTest(unittest.TestCase):
         check("units", "MB", "KiB")
 
         check = self._make_checker(dev6)
-        check("type", "block")
         check("source", "/foo/bar", "/dev/new")
         check("readonly", False, True)
+        check("type", "block", "file")
 
         check = self._make_checker(dev7)
         check("type", "file")
diff --git a/virtinst/devicefilesystem.py b/virtinst/devicefilesystem.py
index 951b716..fee9e87 100644
--- a/virtinst/devicefilesystem.py
+++ b/virtinst/devicefilesystem.py
@@ -54,7 +54,7 @@ class VirtualFilesystem(VirtualDevice):
         DRIVER_DEFAULT]
 
 
-    type = XMLProperty("./@type",
+    _type_prop = XMLProperty("./@type",
                        default_cb=lambda s: None,
                        default_name=TYPE_DEFAULT)
     accessmode = XMLProperty("./@accessmode",
@@ -111,6 +111,25 @@ class VirtualFilesystem(VirtualDevice):
         return setattr(self, self._type_to_source_prop(), val)
     source = property(_get_source, _set_source)
 
+    def _get_type(self):
+        return getattr(self, '_type_prop')
+    def _set_type(self, val):
+        # Get type/value of the attrubute of "source" property
+        old_source_type = self._type_to_source_prop()
+        old_source_value = self.source
+
+        # Update "type" property
+        new_type = setattr(self, '_type_prop', val)
+
+        # If the attribute type of 'source' property has changed
+        # restore the value
+        if old_source_type != self._type_to_source_prop():
+            self.source = old_source_value
+
+        return new_type
+
+    type = property(_get_type, _set_type)
+
     def set_defaults(self, guest):
         ignore = guest
 
-- 
2.9.4

_______________________________________________
virt-tools-list mailing list
virt-tools-list at redhat.com
https://www.redhat.com/mailman/listinfo/virt-tools-list




More information about the virt-tools-list mailing list