[PATCH 00/12] tests: Schema testing improvements

This series: - cleans up the XML validator code a bit - adds testing of nodedevxml2xmlout directory - cleans up some mistakes in un-tested XML files - adds internal schema and improves testing of - cputestdata - simplifies file selection by using a custom schema - device schemas (e.g. qemuhotplugtest) After this series the outstanding list of XML files which are not validated is: ./examples/xml/test/testnodeinline.xml ./examples/xml/test/testnode.xml ./tests/virsh-auth.xml All of the above should be tested, but there's no schema for them yet. ./src/cpu_map/*.xml These are internal input-only data files distributed by libvirt. Creating a schema for them is possible, but not very justified and neither simple. ./tests/qemumigparamsdata/*.xml ./tests/qemumigrationcookiexmldata/*.xml Internal input and output files. Writing a schema could theoretically make sense as they are used for migration but currently doesn't seem to be worth it. ./tests/qemucapabilitiesdata/*.xml Internal input and output, for caching only, thus any incompatibility allows us to simply drop them. Not worth writing schema. ./tests/qemustatusxml2xmldata/*.xml Internal status XML, input/output. Writing schema might make sense to avoid regressions and have a scaffold for future. ./tests/networkxml2xmlupdatein/.xml Snippets of <network> xml, hard to write custom schema for. ./tests/nodedevmdevctldata/*.xml ./tests/virstorageutildata/*.xml Non-libvirt test data. Peter Krempa (12): virschematest: Test 'nodedevxml2xmlout' directory qemustatusxml2xml: Remove obsolete 'json' attribute util: xml: Refactor cleanup path in virXMLValidatorInit util: xml: Refactor cleanup in virXMLValidateAgainstSchema virschematest: Construct path to the schema in the SCHEMAS_PATH virschematest: Improve testing schemas in 'tests/cputestdata' schema: Introduce scaffolding for schema for <privateData> elements qemublocktestdata: Fix 'block-raw-reservations' case tests: qemublocktestdata/imagecreate: Remove bogus 'name="vda"' attribute from <disk> qemublocktest: Mark 'network-ssh-qcow2' input XML as invalid schema: Rename definition of disk 'target' element to 'diskTarget' virschematest: Add infrastructure for testing single devices src/conf/schemas/domainbackup.rng | 4 +- src/conf/schemas/domaincheckpoint.rng | 2 +- src/conf/schemas/domaincommon.rng | 12 ++- src/conf/schemas/domainsnapshot.rng | 2 +- src/conf/schemas/privatedata.rng | 30 +++++++ src/util/virxml.c | 23 ++--- tests/meson.build | 1 + tests/qemublocktest.c | 2 +- .../imagecreate/luks-encopts.xml | 2 +- .../imagecreate/luks-noopts.xml | 2 +- .../imagecreate/network-gluster-qcow2.xml | 2 +- .../imagecreate/network-rbd-qcow2.xml | 2 +- ...w2.json => network-ssh-qcow2-invalid.json} | 0 ...cow2.xml => network-ssh-qcow2-invalid.xml} | 2 +- .../imagecreate/qcow2-luks-encopts.xml | 2 +- .../imagecreate/qcow2-luks-noopts.xml | 2 +- .../imagecreate/qcow2-slice.xml | 2 +- tests/qemublocktestdata/imagecreate/qcow2.xml | 2 +- .../qemublocktestdata/imagecreate/raw-nbd.xml | 2 +- .../imagecreate/raw-slice.xml | 2 +- tests/qemublocktestdata/imagecreate/raw.xml | 2 +- .../xml2json/block-raw-reservations.xml | 2 +- .../migration-out-nbd-in.xml | 2 +- .../migration-out-nbd-tls-in.xml | 2 +- tests/qemustatusxml2xmldata/upgrade-in.xml | 2 +- tests/schemas/cpu-baseline.rng.in | 84 +++++++++++++++++++ tests/schemas/device.rng.in | 51 +++++++++++ tests/schemas/meson.build | 18 ++++ tests/schemas/privatedata.rng.in | 68 +++++++++++++++ tests/virschematest.c | 28 ++++--- 30 files changed, 304 insertions(+), 53 deletions(-) create mode 100644 src/conf/schemas/privatedata.rng rename tests/qemublocktestdata/imagecreate/{network-ssh-qcow2.json => network-ssh-qcow2-invalid.json} (100%) rename tests/qemublocktestdata/imagecreate/{network-ssh-qcow2.xml => network-ssh-qcow2-invalid.xml} (88%) create mode 100644 tests/schemas/cpu-baseline.rng.in create mode 100644 tests/schemas/device.rng.in create mode 100644 tests/schemas/meson.build create mode 100644 tests/schemas/privatedata.rng.in -- 2.38.1

Test the output files against the RNG schema. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virschematest.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/virschematest.c b/tests/virschematest.c index cae502a338..3c91bd37bb 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -280,6 +280,7 @@ static const struct testSchemaEntry schemaNetworkport[] = { static const struct testSchemaEntry schemaNodedev[] = { { .dir = "tests/nodedevschemadata" }, + { .dir = "tests/nodedevxml2xmlout" }, { .file = "examples/xml/test/testdev.xml" }, }; -- 2.38.1

On a Tuesday in 2022, Peter Krempa wrote:
Test the output files against the RNG schema.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virschematest.c | 1 + 1 file changed, 1 insertion(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

We no longer support HMP-only qemus. Remove the leftover attribute from the test files. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/qemustatusxml2xmldata/migration-out-nbd-in.xml | 2 +- tests/qemustatusxml2xmldata/migration-out-nbd-tls-in.xml | 2 +- tests/qemustatusxml2xmldata/upgrade-in.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/qemustatusxml2xmldata/migration-out-nbd-in.xml b/tests/qemustatusxml2xmldata/migration-out-nbd-in.xml index 636accf054..95eca028e9 100644 --- a/tests/qemustatusxml2xmldata/migration-out-nbd-in.xml +++ b/tests/qemustatusxml2xmldata/migration-out-nbd-in.xml @@ -1,6 +1,6 @@ <domstatus state='running' reason='booted' pid='15433'> <taint flag='high-privileges'/> - <monitor path='/var/lib/libvirt/qemu/domain-4-upstream/monitor.sock' json='1' type='unix'/> + <monitor path='/var/lib/libvirt/qemu/domain-4-upstream/monitor.sock' type='unix'/> <vcpus> <vcpu id='0' pid='15449'/> <vcpu id='1' pid='15450'/> diff --git a/tests/qemustatusxml2xmldata/migration-out-nbd-tls-in.xml b/tests/qemustatusxml2xmldata/migration-out-nbd-tls-in.xml index 2cd6c9a5e9..2e37184715 100644 --- a/tests/qemustatusxml2xmldata/migration-out-nbd-tls-in.xml +++ b/tests/qemustatusxml2xmldata/migration-out-nbd-tls-in.xml @@ -1,6 +1,6 @@ <domstatus state='running' reason='booted' pid='68472'> <taint flag='high-privileges'/> - <monitor path='/var/lib/libvirt/qemu/domain-3-upstream/monitor.sock' json='1' type='unix'/> + <monitor path='/var/lib/libvirt/qemu/domain-3-upstream/monitor.sock' type='unix'/> <namespaces> <mount/> </namespaces> diff --git a/tests/qemustatusxml2xmldata/upgrade-in.xml b/tests/qemustatusxml2xmldata/upgrade-in.xml index 7fa56429f4..6e00bb5ddf 100644 --- a/tests/qemustatusxml2xmldata/upgrade-in.xml +++ b/tests/qemustatusxml2xmldata/upgrade-in.xml @@ -1,5 +1,5 @@ <domstatus state='running' reason='booted' pid='195139'> - <monitor path='/var/lib/libvirt/qemu/domain-1-upstream/monitor.sock' json='1' type='unix'/> + <monitor path='/var/lib/libvirt/qemu/domain-1-upstream/monitor.sock' type='unix'/> <namespaces> <mount/> </namespaces> -- 2.38.1

On a Tuesday in 2022, Peter Krempa wrote:
We no longer support HMP-only qemus. Remove the leftover attribute from the test files.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/qemustatusxml2xmldata/migration-out-nbd-in.xml | 2 +- tests/qemustatusxml2xmldata/migration-out-nbd-tls-in.xml | 2 +- tests/qemustatusxml2xmldata/upgrade-in.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Automatically free 'validator' on errors. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virxml.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 35c0340779..e9595da97d 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1608,7 +1608,7 @@ virXMLValidatorRNGErrorIgnore(void *ctx G_GNUC_UNUSED, virXMLValidator * virXMLValidatorInit(const char *schemafile) { - virXMLValidator *validator = NULL; + g_autoptr(virXMLValidator) validator = NULL; validator = g_new0(virXMLValidator, 1); @@ -1619,7 +1619,7 @@ virXMLValidatorInit(const char *schemafile) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to create RNG parser for %s"), validator->schemafile); - goto error; + return NULL; } xmlRelaxNGSetParserErrors(validator->rngParser, @@ -1632,25 +1632,22 @@ virXMLValidatorInit(const char *schemafile) _("Unable to parse RNG %s: %s"), validator->schemafile, virBufferCurrentContent(&validator->buf)); - goto error; + return NULL; } if (!(validator->rngValid = xmlRelaxNGNewValidCtxt(validator->rng))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to create RNG validation context %s"), validator->schemafile); - goto error; + return NULL; } xmlRelaxNGSetValidErrors(validator->rngValid, virXMLValidatorRNGErrorCatch, virXMLValidatorRNGErrorIgnore, &validator->buf); - return validator; - error: - virXMLValidatorFree(validator); - return NULL; + return g_steal_pointer(&validator); } -- 2.38.1

On a Tuesday in 2022, Peter Krempa wrote:
Automatically free 'validator' on errors.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virxml.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Use automatic freeing of the validator context to remove 'ret'/'cleanup:'. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virxml.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index e9595da97d..a2fe2e6b6d 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1671,19 +1671,15 @@ int virXMLValidateAgainstSchema(const char *schemafile, xmlDocPtr doc) { - virXMLValidator *validator = NULL; - int ret = -1; + g_autoptr(virXMLValidator) validator = NULL; if (!(validator = virXMLValidatorInit(schemafile))) return -1; if (virXMLValidatorValidate(validator, doc) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - virXMLValidatorFree(validator); - return ret; + return 0; } -- 2.38.1

On a Tuesday in 2022, Peter Krempa wrote:
Use automatic freeing of the validator context to remove 'ret'/'cleanup:'.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virxml.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

'abs_top_srcdir' can be prepended to the schema in the macro. Apart from removing one needles string copy it will also allow pointing to schema files in the builddir which will come handy in upcoming patches. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virschematest.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/virschematest.c b/tests/virschematest.c index 3c91bd37bb..2a89f6a1c0 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -151,13 +151,10 @@ testSchemaGrammarReport(const void *opaque) static virXMLValidator * testSchemaGrammarLoad(const char *schema) { - g_autofree char *schema_path = NULL; g_autofree char *testname = NULL; virXMLValidator *ret; - schema_path = g_strdup_printf("%s/%s", abs_top_srcdir, schema); - - ret = virXMLValidatorInit(schema_path); + ret = virXMLValidatorInit(schema); testname = g_strdup_printf("test schema grammar file: '%s'", schema); @@ -335,7 +332,7 @@ mymain(void) { int ret = 0; -#define SCHEMAS_PATH "src/conf/schemas/" +#define SCHEMAS_PATH abs_top_srcdir "/src/conf/schemas/" #define DO_TEST(sch, ent) \ if (testSchemaEntries((sch), (ent), G_N_ELEMENTS(ent)) < 0) \ -- 2.38.1

On 11/1/22 9:01 AM, Peter Krempa wrote:
'abs_top_srcdir' can be prepended to the schema in the macro. Apart from removing one needles string copy it will also allow pointing to schema
needless
files in the builddir which will come handy in upcoming patches.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virschematest.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/tests/virschematest.c b/tests/virschematest.c index 3c91bd37bb..2a89f6a1c0 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -151,13 +151,10 @@ testSchemaGrammarReport(const void *opaque) static virXMLValidator * testSchemaGrammarLoad(const char *schema) { - g_autofree char *schema_path = NULL; g_autofree char *testname = NULL; virXMLValidator *ret;
- schema_path = g_strdup_printf("%s/%s", abs_top_srcdir, schema); - - ret = virXMLValidatorInit(schema_path); + ret = virXMLValidatorInit(schema);
testname = g_strdup_printf("test schema grammar file: '%s'", schema);
@@ -335,7 +332,7 @@ mymain(void) { int ret = 0;
-#define SCHEMAS_PATH "src/conf/schemas/" +#define SCHEMAS_PATH abs_top_srcdir "/src/conf/schemas/"
#define DO_TEST(sch, ent) \ if (testSchemaEntries((sch), (ent), G_N_ELEMENTS(ent)) < 0) \

On a Tuesday in 2022, Jonathon Jongsma wrote:
On 11/1/22 9:01 AM, Peter Krempa wrote:
'abs_top_srcdir' can be prepended to the schema in the macro. Apart from removing one needles string copy it will also allow pointing to schema
needless
^^^
files in the builddir which will come handy in upcoming patches.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virschematest.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

The 'cputestdata' directory has a collection of XML files with very complicated naming schemes for various input and output XML files. Rather than trying to write complex regexes for selecting specific files which diverged already multiple times we can introduce an internal schema file which will cover all of the 3 top level elements used in the XML files. Schema for <cpu> is taken from our main RNG schema, <cpuTest> is just a collection of <cpu> elements, and finally <cpudata> is a simple enough to describe inline. To keep the validator happy we have to generate the schema file to place full paths for the included documents. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 1 + tests/schemas/cpu-baseline.rng.in | 84 +++++++++++++++++++++++++++++++ tests/schemas/meson.build | 16 ++++++ tests/virschematest.c | 13 ++--- 4 files changed, 106 insertions(+), 8 deletions(-) create mode 100644 tests/schemas/cpu-baseline.rng.in create mode 100644 tests/schemas/meson.build diff --git a/tests/meson.build b/tests/meson.build index 1149211756..3365dce307 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -208,6 +208,7 @@ tests_deps += executable( ], ) +subdir('schemas') # build and define libvirt tests diff --git a/tests/schemas/cpu-baseline.rng.in b/tests/schemas/cpu-baseline.rng.in new file mode 100644 index 0000000000..1a3b19a45b --- /dev/null +++ b/tests/schemas/cpu-baseline.rng.in @@ -0,0 +1,84 @@ +<?xml version="1.0"?> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + <include href="@SCHEMADIR@/basictypes.rng"/> + <include href="@SCHEMADIR@/cputypes.rng"/> + + <start> + <ref name="cputestdata"/> + </start> + + <define name="cputestdata"> + <choice> + <ref name="guestcpu"/> + <ref name="hostcpu"/> + <ref name="cputest"/> + <ref name="cpudata"/> + </choice> + </define> + + <define name="cputest"> + <element name="cpuTest"> + <oneOrMore> + <choice> + <ref name="guestcpu"/> + <ref name="hostcpu"/> + </choice> + </oneOrMore> + </element> + </define> + + <define name="cpudata"> + <element name="cpudata"> + <attribute name="arch"> + <choice> + <value>x86</value> + </choice> + </attribute> + <interleave> + <oneOrMore> + <ref name="cpudata_cpuid"/> + </oneOrMore> + <zeroOrMore> + <ref name="cpudata_msr"/> + </zeroOrMore> + </interleave> + </element> + </define> + + <define name="cpudata_cpuid"> + <element name="cpuid"> + <attribute name="eax_in"> + <ref name="hexuint"/> + </attribute> + <attribute name="ecx_in"> + <ref name="hexuint"/> + </attribute> + <attribute name="eax"> + <ref name="hexuint"/> + </attribute> + <attribute name="ebx"> + <ref name="hexuint"/> + </attribute> + <attribute name="ecx"> + <ref name="hexuint"/> + </attribute> + <attribute name="edx"> + <ref name="hexuint"/> + </attribute> + </element> + </define> + + <define name="cpudata_msr"> + <element name="msr"> + <attribute name="index"> + <ref name="hexuint"/> + </attribute> + <attribute name="eax"> + <ref name="hexuint"/> + </attribute> + <attribute name="edx"> + <ref name="hexuint"/> + </attribute> + </element> + </define> +</grammar> diff --git a/tests/schemas/meson.build b/tests/schemas/meson.build new file mode 100644 index 0000000000..33c16bb2fb --- /dev/null +++ b/tests/schemas/meson.build @@ -0,0 +1,16 @@ +# we need to replace proper paths to our schemas in the test schemas +virschematest_test_schemas_conf = configuration_data({ + 'SCHEMADIR': meson.project_source_root() / 'src' / 'conf' / 'schemas', +}) + +virschematest_schemas = [ + 'cpu-baseline.rng.in', +] + +foreach file : virschematest_schemas + configure_file( + input: file, + output: '@BASENAME@', + configuration: virschematest_test_schemas_conf, + ) +endforeach diff --git a/tests/virschematest.c b/tests/virschematest.c index 2a89f6a1c0..29a1d59134 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -318,13 +318,8 @@ static const struct testSchemaEntry schemaStorageVol[] = { { .file = "examples/xml/test/testvol.xml" }, }; -static const struct testSchemaEntry schemaCpu[] = { - { . dir = "tests/cputestdata", - . dirRegex = "^[^-]+-cpuid-.*(-host|-guest|-json)\\.xml$" }, - { . dir = "tests/cputestdata", - . dirRegex = "^[^-]+-baseline-.*-result\\.xml$" }, - { . dir = "tests/cputestdata", - . dirRegex = "^[^-]+-(?!cpuid|baseline).*$" }, +static const struct testSchemaEntry testsCpuBaseline[] = { + { . dir = "tests/cputestdata" }, }; static int @@ -333,6 +328,7 @@ mymain(void) int ret = 0; #define SCHEMAS_PATH abs_top_srcdir "/src/conf/schemas/" +#define INTERNAL_SCHEMAS_PATH abs_builddir "/schemas/" #define DO_TEST(sch, ent) \ if (testSchemaEntries((sch), (ent), G_N_ELEMENTS(ent)) < 0) \ @@ -354,7 +350,8 @@ mymain(void) DO_TEST(SCHEMAS_PATH "storagepoolcaps.rng", schemaStoragepoolcaps); DO_TEST(SCHEMAS_PATH "storagepool.rng", schemaStoragePool); DO_TEST(SCHEMAS_PATH "storagevol.rng", schemaStorageVol); - DO_TEST(SCHEMAS_PATH "cpu.rng", schemaCpu); + + DO_TEST(INTERNAL_SCHEMAS_PATH "cpu-baseline.rng", testsCpuBaseline); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -- 2.38.1

On a Tuesday in 2022, Peter Krempa wrote:
The 'cputestdata' directory has a collection of XML files with very complicated naming schemes for various input and output XML files.
Rather than trying to write complex regexes for selecting specific files which diverged already multiple times we can introduce an internal schema file which will cover all of the 3 top level elements used in the XML files.
Schema for <cpu> is taken from our main RNG schema, <cpuTest> is just a collection of <cpu> elements, and finally <cpudata> is a simple enough to describe inline.
To keep the validator happy we have to generate the schema file to place full paths for the included documents.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/meson.build | 1 + tests/schemas/cpu-baseline.rng.in | 84 +++++++++++++++++++++++++++++++ tests/schemas/meson.build | 16 ++++++ tests/virschematest.c | 13 ++--- 4 files changed, 106 insertions(+), 8 deletions(-) create mode 100644 tests/schemas/cpu-baseline.rng.in create mode 100644 tests/schemas/meson.build
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Libvirt internally (e.g. in the status XML) stores additional data for various objects described by the XML. The data is usually stored in <privateData> or similar sub-elements. This patch adds possibility for internal schema files to describe the <privateData> elements by schema while still disallowing them for the public schema. This patch adds definitions for private data of <disk> and the corresponding storage source of a disk. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/schemas/domaincommon.rng | 3 +++ src/conf/schemas/privatedata.rng | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/conf/schemas/privatedata.rng diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng index ebdf21fe99..85e2e0c57b 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -6,6 +6,7 @@ <include href="networkcommon.rng"/> <include href="cputypes.rng"/> <include href="nwfilter_params.rng"/> + <include href="privatedata.rng"/> <!-- description and title element, may be placed anywhere under the root @@ -1698,6 +1699,7 @@ <interleave> <ref name="storageSourceExtra"/> <ref name="diskBackingChain"/> + <ref name="privateDataDeviceDisk"/> </interleave> </define> @@ -1773,6 +1775,7 @@ </element> </element> </optional> + <ref name="privateDataStorageSource"/> </define> <define name="diskSource"> diff --git a/src/conf/schemas/privatedata.rng b/src/conf/schemas/privatedata.rng new file mode 100644 index 0000000000..39551939fa --- /dev/null +++ b/src/conf/schemas/privatedata.rng @@ -0,0 +1,30 @@ +<?xml version="1.0"?> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + + <!-- This schema is provides scaffolding for having proper schema for private + data elements used by libvirt internally. + + Public schema must not implement any of the defines below. + + To override the definitions below use: + + <define name="..." combine="choice"> + --> + + <define name="privateDataStorageSource"> + <optional> + <element name="privateData"> + <notAllowed/> + </element> + </optional> + </define> + + <define name="privateDataDeviceDisk"> + <optional> + <element name="privateData"> + <notAllowed/> + </element> + </optional> + </define> + +</grammar> -- 2.38.1

On a Tuesday in 2022, Peter Krempa wrote:
Libvirt internally (e.g. in the status XML) stores additional data for various objects described by the XML. The data is usually stored in <privateData> or similar sub-elements.
This patch adds possibility for internal schema files to describe the <privateData> elements by schema while still disallowing them for the public schema.
This patch adds definitions for private data of <disk> and the corresponding storage source of a disk.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/schemas/domaincommon.rng | 3 +++ src/conf/schemas/privatedata.rng | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/conf/schemas/privatedata.rng
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

On Tue, Nov 01, 2022 at 03:01:45PM +0100, Peter Krempa wrote:
Libvirt internally (e.g. in the status XML) stores additional data for various objects described by the XML. The data is usually stored in <privateData> or similar sub-elements.
This patch adds possibility for internal schema files to describe the <privateData> elements by schema while still disallowing them for the public schema.
This patch adds definitions for private data of <disk> and the corresponding storage source of a disk.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/schemas/domaincommon.rng | 3 +++ src/conf/schemas/privatedata.rng | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/conf/schemas/privatedata.rng
This addition seems to have broken the validation: https://gitlab.com/libvirt/libvirt-python/-/jobs/3281787918
raise libvirtError('virDomainCheckpointCreateXML() failed')
E libvirt.libvirtError: internal error: Unable to parse RNG /builds/libvirt/libvirt-python/scratch/vroot/share/libvirt/schemas/domaincheckpoint.rng: xmlRelaxNG: could not load /builds/libvirt/libvirt-python/scratch/vroot/share/libvirt/schemas/privatedata.rng Presumably we need to add privatedata.rng to meson.build too ? 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 :|

On Mon, Nov 07, 2022 at 09:53:55 +0000, Daniel P. Berrangé wrote:
On Tue, Nov 01, 2022 at 03:01:45PM +0100, Peter Krempa wrote:
Libvirt internally (e.g. in the status XML) stores additional data for various objects described by the XML. The data is usually stored in <privateData> or similar sub-elements.
This patch adds possibility for internal schema files to describe the <privateData> elements by schema while still disallowing them for the public schema.
This patch adds definitions for private data of <disk> and the corresponding storage source of a disk.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/schemas/domaincommon.rng | 3 +++ src/conf/schemas/privatedata.rng | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/conf/schemas/privatedata.rng
This addition seems to have broken the validation:
https://gitlab.com/libvirt/libvirt-python/-/jobs/3281787918
raise libvirtError('virDomainCheckpointCreateXML() failed')
E libvirt.libvirtError: internal error: Unable to parse RNG /builds/libvirt/libvirt-python/scratch/vroot/share/libvirt/schemas/domaincheckpoint.rng: xmlRelaxNG: could not load /builds/libvirt/libvirt-python/scratch/vroot/share/libvirt/schemas/privatedata.rng
Presumably we need to add privatedata.rng to meson.build too ?
Oops, yes. And probably also in the spec file in case when we don't wildcard-include all schemas.

The 'reservations' element doesn't have an 'enabled' attribute according to our schema, remove it. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/qemublocktestdata/xml2json/block-raw-reservations.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemublocktestdata/xml2json/block-raw-reservations.xml b/tests/qemublocktestdata/xml2json/block-raw-reservations.xml index 3ebfe61186..bf59137fd4 100644 --- a/tests/qemublocktestdata/xml2json/block-raw-reservations.xml +++ b/tests/qemublocktestdata/xml2json/block-raw-reservations.xml @@ -1,7 +1,7 @@ <disk device='disk' type='block'> <driver name='qemu' type='raw'/> <source dev='/dev/blah'> - <reservations enabled='yes' managed='yes'/> + <reservations managed='yes'/> <privateData> <nodenames> <nodename type='storage' name='node-a-st'/> -- 2.38.1

On a Tuesday in 2022, Peter Krempa wrote:
The 'reservations' element doesn't have an 'enabled' attribute according to our schema, remove it.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/qemublocktestdata/xml2json/block-raw-reservations.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/qemublocktestdata/imagecreate/luks-encopts.xml | 2 +- tests/qemublocktestdata/imagecreate/luks-noopts.xml | 2 +- tests/qemublocktestdata/imagecreate/network-gluster-qcow2.xml | 2 +- tests/qemublocktestdata/imagecreate/network-rbd-qcow2.xml | 2 +- tests/qemublocktestdata/imagecreate/network-ssh-qcow2.xml | 2 +- tests/qemublocktestdata/imagecreate/qcow2-luks-encopts.xml | 2 +- tests/qemublocktestdata/imagecreate/qcow2-luks-noopts.xml | 2 +- tests/qemublocktestdata/imagecreate/qcow2-slice.xml | 2 +- tests/qemublocktestdata/imagecreate/qcow2.xml | 2 +- tests/qemublocktestdata/imagecreate/raw-nbd.xml | 2 +- tests/qemublocktestdata/imagecreate/raw-slice.xml | 2 +- tests/qemublocktestdata/imagecreate/raw.xml | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/qemublocktestdata/imagecreate/luks-encopts.xml b/tests/qemublocktestdata/imagecreate/luks-encopts.xml index bb0ee54adc..15a6038bde 100644 --- a/tests/qemublocktestdata/imagecreate/luks-encopts.xml +++ b/tests/qemublocktestdata/imagecreate/luks-encopts.xml @@ -1,4 +1,4 @@ -<disk device='disk' name='vda'> +<disk device='disk'> <driver type='raw'/> <source file='/var/lib/libvirt/images/i.img'> <privateData> diff --git a/tests/qemublocktestdata/imagecreate/luks-noopts.xml b/tests/qemublocktestdata/imagecreate/luks-noopts.xml index ac224b02de..fc4013afcf 100644 --- a/tests/qemublocktestdata/imagecreate/luks-noopts.xml +++ b/tests/qemublocktestdata/imagecreate/luks-noopts.xml @@ -1,4 +1,4 @@ -<disk device='disk' name='vda'> +<disk device='disk'> <driver type='raw'/> <source file='/var/lib/libvirt/images/i.img'> <privateData> diff --git a/tests/qemublocktestdata/imagecreate/network-gluster-qcow2.xml b/tests/qemublocktestdata/imagecreate/network-gluster-qcow2.xml index f3dbf24180..12d7de0f52 100644 --- a/tests/qemublocktestdata/imagecreate/network-gluster-qcow2.xml +++ b/tests/qemublocktestdata/imagecreate/network-gluster-qcow2.xml @@ -1,4 +1,4 @@ -<disk device='disk' name='vda' type='network'> +<disk device='disk' type='network'> <driver type='qcow2'/> <source protocol='gluster' name='asdf/i.qcow2'> <host name='example.com' port='1234'/> diff --git a/tests/qemublocktestdata/imagecreate/network-rbd-qcow2.xml b/tests/qemublocktestdata/imagecreate/network-rbd-qcow2.xml index 0f6c1ddb98..63aeaeb9be 100644 --- a/tests/qemublocktestdata/imagecreate/network-rbd-qcow2.xml +++ b/tests/qemublocktestdata/imagecreate/network-rbd-qcow2.xml @@ -1,4 +1,4 @@ -<disk device='disk' name='vda' type='network'> +<disk device='disk' type='network'> <driver type='qcow2'/> <source protocol='rbd' name='asdf/i.qcow2'> <host name='example.com' port='1234'/> diff --git a/tests/qemublocktestdata/imagecreate/network-ssh-qcow2.xml b/tests/qemublocktestdata/imagecreate/network-ssh-qcow2.xml index 4c44f81c81..046f7892db 100644 --- a/tests/qemublocktestdata/imagecreate/network-ssh-qcow2.xml +++ b/tests/qemublocktestdata/imagecreate/network-ssh-qcow2.xml @@ -1,4 +1,4 @@ -<disk device='disk' name='vda' type='network'> +<disk device='disk' type='network'> <driver type='qcow2'/> <source protocol='ssh' name='asdf/i.qcow2'> <host name='example.com' port='1234'/> diff --git a/tests/qemublocktestdata/imagecreate/qcow2-luks-encopts.xml b/tests/qemublocktestdata/imagecreate/qcow2-luks-encopts.xml index d6616bd164..0d0315167f 100644 --- a/tests/qemublocktestdata/imagecreate/qcow2-luks-encopts.xml +++ b/tests/qemublocktestdata/imagecreate/qcow2-luks-encopts.xml @@ -1,4 +1,4 @@ -<disk device='disk' name='vda'> +<disk device='disk'> <driver type='qcow2'/> <source file='/var/lib/libvirt/images/i.qcow2'> <privateData> diff --git a/tests/qemublocktestdata/imagecreate/qcow2-luks-noopts.xml b/tests/qemublocktestdata/imagecreate/qcow2-luks-noopts.xml index e2d1c42424..707d86b459 100644 --- a/tests/qemublocktestdata/imagecreate/qcow2-luks-noopts.xml +++ b/tests/qemublocktestdata/imagecreate/qcow2-luks-noopts.xml @@ -1,4 +1,4 @@ -<disk device='disk' name='vda'> +<disk device='disk'> <driver type='qcow2'/> <source file='/var/lib/libvirt/images/i.qcow2'> <privateData> diff --git a/tests/qemublocktestdata/imagecreate/qcow2-slice.xml b/tests/qemublocktestdata/imagecreate/qcow2-slice.xml index 6c5ae3107b..06ce282247 100644 --- a/tests/qemublocktestdata/imagecreate/qcow2-slice.xml +++ b/tests/qemublocktestdata/imagecreate/qcow2-slice.xml @@ -1,4 +1,4 @@ -<disk device='disk' name='vda'> +<disk device='disk'> <driver type='qcow2'/> <source file='/var/lib/libvirt/images/i.qcow2'> <slices> diff --git a/tests/qemublocktestdata/imagecreate/qcow2.xml b/tests/qemublocktestdata/imagecreate/qcow2.xml index f3c235f82f..6ca08dda7c 100644 --- a/tests/qemublocktestdata/imagecreate/qcow2.xml +++ b/tests/qemublocktestdata/imagecreate/qcow2.xml @@ -1,4 +1,4 @@ -<disk device='disk' name='vda'> +<disk device='disk'> <driver type='qcow2'/> <source file='/var/lib/libvirt/images/i.qcow2'> <privateData> diff --git a/tests/qemublocktestdata/imagecreate/raw-nbd.xml b/tests/qemublocktestdata/imagecreate/raw-nbd.xml index 256bf23797..9c5a4a5952 100644 --- a/tests/qemublocktestdata/imagecreate/raw-nbd.xml +++ b/tests/qemublocktestdata/imagecreate/raw-nbd.xml @@ -1,4 +1,4 @@ -<disk device='disk' name='vda' type='network'> +<disk device='disk' type='network'> <driver type='raw'/> <source protocol='nbd'> <host name='example.com' port='1234'/> diff --git a/tests/qemublocktestdata/imagecreate/raw-slice.xml b/tests/qemublocktestdata/imagecreate/raw-slice.xml index adc7a175ce..f440ba9922 100644 --- a/tests/qemublocktestdata/imagecreate/raw-slice.xml +++ b/tests/qemublocktestdata/imagecreate/raw-slice.xml @@ -1,4 +1,4 @@ -<disk device='disk' name='vda'> +<disk device='disk'> <driver type='raw'/> <source file='/var/lib/libvirt/images/i.img'> <slices> diff --git a/tests/qemublocktestdata/imagecreate/raw.xml b/tests/qemublocktestdata/imagecreate/raw.xml index 3a91600bd8..316b7abb12 100644 --- a/tests/qemublocktestdata/imagecreate/raw.xml +++ b/tests/qemublocktestdata/imagecreate/raw.xml @@ -1,4 +1,4 @@ -<disk device='disk' name='vda'> +<disk device='disk'> <driver type='raw'/> <source file='/var/lib/libvirt/images/i.img'> <privateData> -- 2.38.1

On a Tuesday in 2022, Peter Krempa wrote:
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/qemublocktestdata/imagecreate/luks-encopts.xml | 2 +- tests/qemublocktestdata/imagecreate/luks-noopts.xml | 2 +- tests/qemublocktestdata/imagecreate/network-gluster-qcow2.xml | 2 +- tests/qemublocktestdata/imagecreate/network-rbd-qcow2.xml | 2 +- tests/qemublocktestdata/imagecreate/network-ssh-qcow2.xml | 2 +- tests/qemublocktestdata/imagecreate/qcow2-luks-encopts.xml | 2 +- tests/qemublocktestdata/imagecreate/qcow2-luks-noopts.xml | 2 +- tests/qemublocktestdata/imagecreate/qcow2-slice.xml | 2 +- tests/qemublocktestdata/imagecreate/qcow2.xml | 2 +- tests/qemublocktestdata/imagecreate/raw-nbd.xml | 2 +- tests/qemublocktestdata/imagecreate/raw-slice.xml | 2 +- tests/qemublocktestdata/imagecreate/raw.xml | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

The XML does not conform to the RNG schema as we don't yet expose the 'ssh' protocol officially. Mark the XML as invalid by renaming it. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/qemublocktest.c | 2 +- .../{network-ssh-qcow2.json => network-ssh-qcow2-invalid.json} | 0 .../{network-ssh-qcow2.xml => network-ssh-qcow2-invalid.xml} | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename tests/qemublocktestdata/imagecreate/{network-ssh-qcow2.json => network-ssh-qcow2-invalid.json} (100%) rename tests/qemublocktestdata/imagecreate/{network-ssh-qcow2.xml => network-ssh-qcow2-invalid.xml} (100%) diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 1c1013d4d9..010b52f4b3 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -1211,7 +1211,7 @@ mymain(void) TEST_IMAGE_CREATE("network-gluster-qcow2", NULL); TEST_IMAGE_CREATE("network-rbd-qcow2", NULL); - TEST_IMAGE_CREATE("network-ssh-qcow2", NULL); + TEST_IMAGE_CREATE("network-ssh-qcow2-invalid", NULL); #define TEST_BITMAP_DETECT(testname) \ do { \ diff --git a/tests/qemublocktestdata/imagecreate/network-ssh-qcow2.json b/tests/qemublocktestdata/imagecreate/network-ssh-qcow2-invalid.json similarity index 100% rename from tests/qemublocktestdata/imagecreate/network-ssh-qcow2.json rename to tests/qemublocktestdata/imagecreate/network-ssh-qcow2-invalid.json diff --git a/tests/qemublocktestdata/imagecreate/network-ssh-qcow2.xml b/tests/qemublocktestdata/imagecreate/network-ssh-qcow2-invalid.xml similarity index 100% rename from tests/qemublocktestdata/imagecreate/network-ssh-qcow2.xml rename to tests/qemublocktestdata/imagecreate/network-ssh-qcow2-invalid.xml -- 2.38.1

On a Tuesday in 2022, Peter Krempa wrote:
The XML does not conform to the RNG schema as we don't yet expose the 'ssh' protocol officially. Mark the XML as invalid by renaming it.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/qemublocktest.c | 2 +- .../{network-ssh-qcow2.json => network-ssh-qcow2-invalid.json} | 0 .../{network-ssh-qcow2.xml => network-ssh-qcow2-invalid.xml} | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename tests/qemublocktestdata/imagecreate/{network-ssh-qcow2.json => network-ssh-qcow2-invalid.json} (100%) rename tests/qemublocktestdata/imagecreate/{network-ssh-qcow2.xml => network-ssh-qcow2-invalid.xml} (100%)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Rename 'diskTarget' to 'diskTargetDev' and then 'target' to 'diskTarget'. This will make it less confusing when overriding the definition. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/schemas/domainbackup.rng | 4 ++-- src/conf/schemas/domaincheckpoint.rng | 2 +- src/conf/schemas/domaincommon.rng | 9 +++++---- src/conf/schemas/domainsnapshot.rng | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/conf/schemas/domainbackup.rng b/src/conf/schemas/domainbackup.rng index 1ac9da62c1..bfc29a6c06 100644 --- a/src/conf/schemas/domainbackup.rng +++ b/src/conf/schemas/domainbackup.rng @@ -157,7 +157,7 @@ <oneOrMore> <element name="disk"> <attribute name="name"> - <ref name="diskTarget"/> + <ref name="diskTargetDev"/> </attribute> <ref name="backupDiskMode"/> <choice> @@ -227,7 +227,7 @@ <oneOrMore> <element name="disk"> <attribute name="name"> - <ref name="diskTarget"/> + <ref name="diskTargetDev"/> </attribute> <ref name="backupDiskMode"/> <optional> diff --git a/src/conf/schemas/domaincheckpoint.rng b/src/conf/schemas/domaincheckpoint.rng index a1c8b0bb9c..72c4186235 100644 --- a/src/conf/schemas/domaincheckpoint.rng +++ b/src/conf/schemas/domaincheckpoint.rng @@ -55,7 +55,7 @@ <element name="disk"> <attribute name="name"> <choice> - <ref name="diskTarget"/> + <ref name="diskTargetDev"/> <ref name="absFilePath"/> </choice> </attribute> diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng index 85e2e0c57b..ebb39de3ef 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -1512,7 +1512,7 @@ <optional> <ref name="diskAuth"/> </optional> - <ref name="target"/> + <ref name="diskTarget"/> <optional> <ref name="deviceBoot"/> </optional> @@ -2351,15 +2351,16 @@ </element> </define> - <define name="diskTarget"> + <define name="diskTargetDev"> <data type="string"> <param name="pattern">(ioemu:)?(fd|hd|sd|vd|xvd|ubd)[a-zA-Z0-9_]+</param> </data> </define> - <define name="target"> + + <define name="diskTarget"> <element name="target"> <attribute name="dev"> - <ref name="diskTarget"/> + <ref name="diskTargetDev"/> </attribute> <optional> <attribute name="bus"> diff --git a/src/conf/schemas/domainsnapshot.rng b/src/conf/schemas/domainsnapshot.rng index 3db9f458ba..4048266f1d 100644 --- a/src/conf/schemas/domainsnapshot.rng +++ b/src/conf/schemas/domainsnapshot.rng @@ -127,7 +127,7 @@ <element name="disk"> <attribute name="name"> <choice> - <ref name="diskTarget"/> + <ref name="diskTargetDev"/> <ref name="absFilePath"/> </choice> </attribute> -- 2.38.1

On a Tuesday in 2022, Peter Krempa wrote:
Rename 'diskTarget' to 'diskTargetDev' and then 'target' to 'diskTarget'.
This will make it less confusing when overriding the definition.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/schemas/domainbackup.rng | 4 ++-- src/conf/schemas/domaincheckpoint.rng | 2 +- src/conf/schemas/domaincommon.rng | 9 +++++---- src/conf/schemas/domainsnapshot.rng | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Introduce an internal schema for a single device and use it to test the various files in tests/qemuhotplugtestdevices and tests/qemublocktestdata directories. This also requires us to implement schema for (some) privateData bits for the disk source. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/schemas/device.rng.in | 51 ++++++++++++++++++++++++ tests/schemas/meson.build | 2 + tests/schemas/privatedata.rng.in | 68 ++++++++++++++++++++++++++++++++ tests/virschematest.c | 7 ++++ 4 files changed, 128 insertions(+) create mode 100644 tests/schemas/device.rng.in create mode 100644 tests/schemas/privatedata.rng.in diff --git a/tests/schemas/device.rng.in b/tests/schemas/device.rng.in new file mode 100644 index 0000000000..b322b5275e --- /dev/null +++ b/tests/schemas/device.rng.in @@ -0,0 +1,51 @@ +<?xml version="1.0"?> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + <include href="privatedata.rng"/> + <include href="@SCHEMADIR@/domainoverrides.rng"/> + + <!-- This schema file describes a singular device. --> + + <!-- allow also disk definitions without 'target' as they are used in some tests --> + <define name="diskTarget" combine="choice"> + <optional> + <element name="target"> + <empty/> + </element> + </optional> + </define> + + <start> + <choice> + <ref name="disk"/> + <ref name="controller"/> + <ref name="lease"/> + <ref name="filesystem"/> + <ref name="interface"/> + <ref name="input"/> + <ref name="sound"/> + <ref name="audio"/> + <ref name="hostdev"/> + <ref name="graphic"/> + <ref name="video"/> + <ref name="console"/> + <ref name="parallel"/> + <ref name="serial"/> + <ref name="channel"/> + <ref name="smartcard"/> + <ref name="hub"/> + <ref name="redirdev"/> + <ref name="redirfilter"/> + <ref name="rng"/> + <ref name="tpm"/> + <ref name="shmem"/> + <ref name="memorydev"/> + <ref name="watchdog"/> + <ref name="memballoon"/> + <ref name="nvram"/> + <ref name="panic"/> + <ref name="iommu"/> + <ref name="vsock"/> + </choice> + </start> + +</grammar> diff --git a/tests/schemas/meson.build b/tests/schemas/meson.build index 33c16bb2fb..851355d4e9 100644 --- a/tests/schemas/meson.build +++ b/tests/schemas/meson.build @@ -5,6 +5,8 @@ virschematest_test_schemas_conf = configuration_data({ virschematest_schemas = [ 'cpu-baseline.rng.in', + 'device.rng.in', + 'privatedata.rng.in', ] foreach file : virschematest_schemas diff --git a/tests/schemas/privatedata.rng.in b/tests/schemas/privatedata.rng.in new file mode 100644 index 0000000000..945f7a06b3 --- /dev/null +++ b/tests/schemas/privatedata.rng.in @@ -0,0 +1,68 @@ +<?xml version="1.0"?> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + + <define name="privateDataStorageSource" combine="choice"> + <optional> + <element name="privateData"> + <interleave> + <optional> + <ref name="privateDataStorageSourceNodenames"/> + </optional> + <optional> + <ref name="privateDataStorageSourceReservations"/> + </optional> + <optional> + <ref name="privateDataStorageSourceObjects"/> + </optional> + </interleave> + </element> + </optional> + </define> + + <define name="privateDataDeviceDisk" combine="choice"> + <optional> + <element name="privateData"> + <notAllowed/> + </element> + </optional> + </define> + + <define name="privateDataStorageSourceNodenames"> + <element name="nodenames"> + <oneOrMore> + <ref name="nodename"/> + </oneOrMore> + </element> + </define> + + <define name="nodename"> + <element name="nodename"> + <attribute name="type"> + <choice> + <value>storage</value> + <value>format</value> + </choice> + </attribute> + <attribute name="name"/> + </element> + </define> + + <define name="privateDataStorageSourceReservations"> + <element name="reservations"> + <attribute name="mgralias"/> + </element> + </define> + + <define name="privateDataStorageSourceObjects"> + <element name="objects"> + <interleave> + <optional> + <element name="TLSx509"> + <attribute name="alias"/> + </element> + </optional> + </interleave> + </element> + </define> + +</grammar> diff --git a/tests/virschematest.c b/tests/virschematest.c index 29a1d59134..fcf3838630 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -322,6 +322,12 @@ static const struct testSchemaEntry testsCpuBaseline[] = { { . dir = "tests/cputestdata" }, }; +static const struct testSchemaEntry testDevice[] = { + { .dir = "tests/qemuhotplugtestdevices" }, + { .dir = "tests/qemublocktestdata/imagecreate" }, + { .dir = "tests/qemublocktestdata/xml2json" }, +}; + static int mymain(void) { @@ -352,6 +358,7 @@ mymain(void) DO_TEST(SCHEMAS_PATH "storagevol.rng", schemaStorageVol); DO_TEST(INTERNAL_SCHEMAS_PATH "cpu-baseline.rng", testsCpuBaseline); + DO_TEST(INTERNAL_SCHEMAS_PATH "device.rng", testDevice); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -- 2.38.1

On a Tuesday in 2022, Peter Krempa wrote:
Introduce an internal schema for a single device and use it to test the various files in tests/qemuhotplugtestdevices and tests/qemublocktestdata directories.
This also requires us to implement schema for (some) privateData bits for the disk source.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/schemas/device.rng.in | 51 ++++++++++++++++++++++++ tests/schemas/meson.build | 2 + tests/schemas/privatedata.rng.in | 68 ++++++++++++++++++++++++++++++++ tests/virschematest.c | 7 ++++ 4 files changed, 128 insertions(+) create mode 100644 tests/schemas/device.rng.in create mode 100644 tests/schemas/privatedata.rng.in
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (4)
-
Daniel P. Berrangé
-
Jonathon Jongsma
-
Ján Tomko
-
Peter Krempa