Keep the value of filesystem/source when attribute is changed

When the attribute of filesystem/source is changed the old value was
not assigned to the new attribute.
This commit is contained in:
Radostin Stoyanov 2017-06-19 01:18:47 -07:00 committed by Cole Robinson
parent 4be3d030b5
commit 0dfc371f18
3 changed files with 23 additions and 4 deletions

View File

@ -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>

View File

@ -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")

View File

@ -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