On Mon, Sep 26, 2022 at 02:09:23PM +0200, Ján Tomko wrote:
On a Monday in 2022, Daniel P. Berrangé wrote:
> On Fri, Sep 23, 2022 at 05:42:13PM +0200, Peter Krempa wrote:
> > Introduce a new config option 'xml_validator' into the daemon config
> > file which will allow users to make libvirt daemons use a custom XML
> > validator.
> >
> > The rationale is that validators such as 'jing'[1] provide drastically
> > better error specification when compared to the native libxml2 validator
> > we use. A drawback though is that jing is written in Java and thus
> > unusable by libvirt directly and also not a popular package present in
> > distros.
> >
> > For power users and developers it still is worth having this feature to
> > provide better errors in a native way.
>
> I kinda wonder if those users need it integrated in libvirt
> though, as opposed to just calling jing themselves when
> needed. It feels like a fairly narrow set of users benefitting
> here from this change, made even smaller by the fact that those
> users have to remember to reconfigure libvirt to enable this.
>
>
I would be more convinced if jing was still packaged for Fedora.
>
> > An example showing the quality of the errors:
> >
> > XML used:
> >
> > <vcpu placement='static'
current='1'>asdf8</vcpu>
> >
> > native validator:
> > error: XML document failed to validate against schema: Unable to validate doc
against /home/pipo/libvirt/src/conf/schemas/domain.rng
> > Extra element vcpu in interleave
> > Invalid sequence in interleave
> > Element domain failed to validate content
> >
> > jing:
> > error: XML document failed to validate against schema: Unable to validate doc
against /home/pipo/libvirt/src/conf/schemas/domain.rng
> > /dev/stdin:6:52: error: character content of element "vcpu"
invalid; must be an integer
>
> No doubt the errors are way better, but a power user
> can just invoke this script below themselves if they
> ever want to understand a XML problem better.
>
> >
> > Example script to make this feature work with jing:
> >
> > #!/bin/bash
> > java -jar /home/pipo/git/jing-trang/build/jing.jar $1 /dev/stdin 2>&1
|| exit 1
> >
> > [1]
https://github.com/relaxng/jing-trang
>
> To me this is only compelling if there's an option we can reasonably
> wire up out of the box.
Would switching to a different schema format make finding a validator
with frendlier messages easier?
XSD (XML Schema) is the main alternative to RNG, and I'm not seeing
obviously great choices for validation. Xerces-C seems to be the
closest option, but that's C++ not C so would involve wrapped access
somehow. It'd also mean either we're parsing twice, or we replace
libxml with xerces for parsing too. Neither is hugely appealing.
I do wonder if it is practical to "merely" improve libxml's RNG
error messages. It feels like libxml knows the the 'vcpu' element
content was invalid, not matching integer, but it has thrown
away that information, and reported a more generic error at the
level above, that no elements in the RNG <interleave> matched.
I can understand why libxml might have some this - the <interleave>
could contain many branches all defining a 'vcpu' element, so when
finding no match it would have to decide which interleave choice
was the cloest match and report the error message from that context.
To add to complexity, the difference might be far away in nesting
RNG defintion, from where the interleave occurs.
None the less, ting does look to be making such an intelligent
analysis to decide which is the best error to report. I wonder if
they've done something very clever with global scoring a "distance"
value, or if they've just done some limited tweaks in certain areas.
With regards,
Daniel
--
|:
https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|:
https://libvirt.org -o-
https://fstop138.berrange.com :|
|:
https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|