From bdb46ffd9df43e7c4d7c595e976337057361c9e2 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 19 Jun 2012 14:22:44 +0100 Subject: [PATCH] Adjust the libvirt config classes' API contract for parsing Don't not automatically invoke the 'parse_dom' method from the LibvirtConfigObject constructor, because this is too early in construction - no child class constructors have initialized yet. Instead require the 'parse_dom' method to be invoked after the bare object has been constructed. Also make the default impl of 'parse_dom' take an etree.Element instance and validate its root element name. Add a convenient 'parse_str' method for turning a XML string into an etree.Element instance & parsing it. Change-Id: I7eda2b59869f3b4ef9dce1602cbb05f7662f4528 Signed-off-by: Daniel P. Berrange --- nova/tests/test_libvirt_config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nova/tests/test_libvirt_config.py b/nova/tests/test_libvirt_config.py index 1e0818bd..4f9970e7 100644 --- a/nova/tests/test_libvirt_config.py +++ b/nova/tests/test_libvirt_config.py @@ -53,6 +53,11 @@ class LibvirtConfigTest(LibvirtConfigBaseTest): xml = etree.tostring(root) self.assertXmlEqual(xml, "bar") + def test_config_parse(self): + inxml = "" + obj = config.LibvirtConfigObject(root_name="demo") + obj.parse_str(inxml) + class LibvirtConfigGuestTimerTest(LibvirtConfigBaseTest): def test_config_platform(self):