xmlbuilder: Make clear() remove unknown XML properties

This commit is contained in:
Cole Robinson 2014-01-25 14:57:10 -05:00
parent 16c8c31cbd
commit 9f5a842a3a
4 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,20 @@
<domain type="test">
<name>test-cpu-unknown-clear</name>
<memory unit="KiB">8388608</memory>
<currentMemory unit="KiB">2097152</currentMemory>
<vcpu placement="static">2</vcpu>
<os>
<type arch="i686">hvm</type>
<boot dev="hd"/>
</os>
<cpu>
<foo bar="baz"/>
<blah/>
</cpu>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
</devices>
</domain>

View File

@ -0,0 +1,16 @@
<domain type="test">
<name>test-cpu-unknown-clear</name>
<memory unit="KiB">8388608</memory>
<currentMemory unit="KiB">2097152</currentMemory>
<vcpu placement="static">2</vcpu>
<os>
<type arch="i686">hvm</type>
<boot dev="hd"/>
</os>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
</devices>
</domain>

View File

@ -1104,6 +1104,16 @@ class XMLParseTest(unittest.TestCase):
# Misc tests #
##############
def testCPUUnknownClear(self):
# Make sure .clear() even removes XML elements we don't know about
basename = "clear-cpu-unknown-vals"
infile = "tests/xmlparse-xml/%s-in.xml" % basename
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
guest = virtinst.Guest(conn, parsexml=file(infile).read())
guest.cpu.clear()
utils.diff_compare(guest.get_xml_config(), outfile)
def testzzzzCheckProps(self):
# pylint: disable=W0212
# Access to protected member, needed to unittest stuff

View File

@ -855,6 +855,9 @@ class XMLBuilder(object):
for prop in props:
prop.clear(self)
_remove_xpath_node(self._xmlstate.xml_ctx,
self.get_root_xpath())
def validate(self):
"""
Validate any set values and raise an exception if there's