From 9f5a842a3ab2bea5ba2ff6eb60206b30a1ad8a22 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sat, 25 Jan 2014 14:57:10 -0500 Subject: [PATCH] xmlbuilder: Make clear() remove unknown XML properties --- .../clear-cpu-unknown-vals-in.xml | 20 +++++++++++++++++++ .../clear-cpu-unknown-vals-out.xml | 16 +++++++++++++++ tests/xmlparse.py | 10 ++++++++++ virtinst/xmlbuilder.py | 3 +++ 4 files changed, 49 insertions(+) create mode 100644 tests/xmlparse-xml/clear-cpu-unknown-vals-in.xml create mode 100644 tests/xmlparse-xml/clear-cpu-unknown-vals-out.xml diff --git a/tests/xmlparse-xml/clear-cpu-unknown-vals-in.xml b/tests/xmlparse-xml/clear-cpu-unknown-vals-in.xml new file mode 100644 index 000000000..264340811 --- /dev/null +++ b/tests/xmlparse-xml/clear-cpu-unknown-vals-in.xml @@ -0,0 +1,20 @@ + + test-cpu-unknown-clear + 8388608 + 2097152 + 2 + + hvm + + + + + + + + destroy + restart + destroy + + + diff --git a/tests/xmlparse-xml/clear-cpu-unknown-vals-out.xml b/tests/xmlparse-xml/clear-cpu-unknown-vals-out.xml new file mode 100644 index 000000000..50c06b8f1 --- /dev/null +++ b/tests/xmlparse-xml/clear-cpu-unknown-vals-out.xml @@ -0,0 +1,16 @@ + + test-cpu-unknown-clear + 8388608 + 2097152 + 2 + + hvm + + + + destroy + restart + destroy + + + diff --git a/tests/xmlparse.py b/tests/xmlparse.py index 5e1496880..ef62757b4 100644 --- a/tests/xmlparse.py +++ b/tests/xmlparse.py @@ -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 diff --git a/virtinst/xmlbuilder.py b/virtinst/xmlbuilder.py index e1a5fe113..9416af272 100644 --- a/virtinst/xmlbuilder.py +++ b/virtinst/xmlbuilder.py @@ -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