From 51040e0f9d74b047e8838784e6119d0a6cfca5c0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 26 Apr 2023 14:44:47 +0200 Subject: [libvirt] Remove config validation on construction Instead, we should do this explicitly after instantiating, so we can give the user the option to ignore this error and proceed. --- .../openslx/libvirt/xml/LibvirtXmlDocument.java | 28 +++++++--------------- .../libvirt/xml/LibvirtXmlDocumentTest.java | 3 ++- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlDocument.java b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlDocument.java index c428988..06f8ba8 100644 --- a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlDocument.java +++ b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlDocument.java @@ -117,10 +117,9 @@ public abstract class LibvirtXmlDocument implements LibvirtXmlSerializable, Libv * * @throws LibvirtXmlDocumentException creation of XML context failed. * @throws LibvirtXmlSerializationException serialization of the XML content failed. - * @throws LibvirtXmlValidationException XML content is not a valid Libvirt XML. */ public LibvirtXmlDocument( String xml ) - throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException + throws LibvirtXmlDocumentException, LibvirtXmlSerializationException { this( xml, null ); } @@ -133,14 +132,12 @@ public abstract class LibvirtXmlDocument implements LibvirtXmlSerializable, Libv * * @throws LibvirtXmlDocumentException creation of XML context failed. * @throws LibvirtXmlSerializationException serialization of the XML content failed. - * @throws LibvirtXmlValidationException XML content is not a valid Libvirt XML. */ public LibvirtXmlDocument( String xml, InputStream rngSchema ) - throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException + throws LibvirtXmlDocumentException, LibvirtXmlSerializationException { this.createXmlContext( rngSchema ); this.fromXml( xml ); - this.validateXml(); } /** @@ -150,10 +147,9 @@ public abstract class LibvirtXmlDocument implements LibvirtXmlSerializable, Libv * * @throws LibvirtXmlDocumentException creation of XML context failed. * @throws LibvirtXmlSerializationException serialization of the XML content failed. - * @throws LibvirtXmlValidationException XML content is not a valid Libvirt XML. */ public LibvirtXmlDocument( File xml ) - throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException + throws LibvirtXmlDocumentException, LibvirtXmlSerializationException { this( xml, null ); } @@ -166,14 +162,12 @@ public abstract class LibvirtXmlDocument implements LibvirtXmlSerializable, Libv * * @throws LibvirtXmlDocumentException creation of XML context failed. * @throws LibvirtXmlSerializationException serialization of the XML content failed. - * @throws LibvirtXmlValidationException XML content is not a valid Libvirt XML. */ public LibvirtXmlDocument( File xml, InputStream rngSchema ) - throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException + throws LibvirtXmlDocumentException, LibvirtXmlSerializationException { this.createXmlContext( rngSchema ); this.fromXml( xml ); - this.validateXml(); } /** @@ -183,10 +177,9 @@ public abstract class LibvirtXmlDocument implements LibvirtXmlSerializable, Libv * * @throws LibvirtXmlDocumentException creation of XML context failed. * @throws LibvirtXmlSerializationException serialization of the XML content failed. - * @throws LibvirtXmlValidationException XML content is not a valid Libvirt XML. */ public LibvirtXmlDocument( InputStream xml ) - throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException + throws LibvirtXmlDocumentException, LibvirtXmlSerializationException { this( xml, null ); } @@ -199,14 +192,12 @@ public abstract class LibvirtXmlDocument implements LibvirtXmlSerializable, Libv * * @throws LibvirtXmlDocumentException creation of XML context failed. * @throws LibvirtXmlSerializationException serialization of the XML content failed. - * @throws LibvirtXmlValidationException XML content is not a valid Libvirt XML. */ public LibvirtXmlDocument( InputStream xml, InputStream rngSchema ) - throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException + throws LibvirtXmlDocumentException, LibvirtXmlSerializationException { this.createXmlContext( rngSchema ); this.fromXml( xml ); - this.validateXml(); } /** @@ -216,10 +207,9 @@ public abstract class LibvirtXmlDocument implements LibvirtXmlSerializable, Libv * * @throws LibvirtXmlDocumentException creation of XML context failed. * @throws LibvirtXmlSerializationException serialization of the XML content failed. - * @throws LibvirtXmlValidationException XML content is not a valid Libvirt XML. */ public LibvirtXmlDocument( InputSource xml ) - throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException + throws LibvirtXmlDocumentException, LibvirtXmlSerializationException { this( xml, null ); } @@ -232,14 +222,12 @@ public abstract class LibvirtXmlDocument implements LibvirtXmlSerializable, Libv * * @throws LibvirtXmlDocumentException creation of XML context failed. * @throws LibvirtXmlSerializationException serialization of the XML content failed. - * @throws LibvirtXmlValidationException XML content is not a valid Libvirt XML. */ public LibvirtXmlDocument( InputSource xml, InputStream rngSchema ) - throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException + throws LibvirtXmlDocumentException, LibvirtXmlSerializationException { this.createXmlContext( rngSchema ); this.fromXml( xml ); - this.validateXml(); } /** diff --git a/src/test/java/org/openslx/libvirt/xml/LibvirtXmlDocumentTest.java b/src/test/java/org/openslx/libvirt/xml/LibvirtXmlDocumentTest.java index 15d203c..56ceeed 100644 --- a/src/test/java/org/openslx/libvirt/xml/LibvirtXmlDocumentTest.java +++ b/src/test/java/org/openslx/libvirt/xml/LibvirtXmlDocumentTest.java @@ -152,7 +152,8 @@ public class LibvirtXmlDocumentTest public void testValidateIncorrectXmlFile() { Executable validateXmlDocument = () -> { - this.newLibvirtXmlDocumentValidationInstance( "qemu-kvm_default-ubuntu-20-04-vm-invalid.xml", "domain.rng" ); + LibvirtXmlDocument doc = this.newLibvirtXmlDocumentValidationInstance( "qemu-kvm_default-ubuntu-20-04-vm-invalid.xml", "domain.rng" ); + doc.validateXml(); }; assertThrows( LibvirtXmlValidationException.class, validateXmlDocument ); -- cgit v1.2.3-55-g7522