[libvirt] [PATCH v2 0/4] Add schema validation for news

v2: - rename DO_TEST to DO_TEST_DIR along with changes in the first patch - add 'abs_srcdir' to the tested XML path so that vpath builds work - fix wording of the rules for adding news entries - fix commit messages Peter Krempa (4): tests: schema: Add possibility to validate individual files news: Introduce rules for the schema file and fix offending lines schema: Introduce schema for the news.xml file news: Add template for a <release> section docs/news.xml | 62 ++++++++++++++++++++++++++++++++--------- docs/schemas/news.rng | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/virschematest.c | 77 ++++++++++++++++++++++++++++++++------------------- 3 files changed, 171 insertions(+), 41 deletions(-) create mode 100644 docs/schemas/news.rng -- 2.12.1

Sometimes it may be desired to validate individual files against a schema. Refactor the data structures to unify them and introduce a new macro DO_TEST_FILE(schema, xmlfile) which will test the XML file against the given schema file. --- tests/virschematest.c | 75 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/tests/virschematest.c b/tests/virschematest.c index faf66d642..b73555da8 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -35,6 +35,7 @@ VIR_LOG_INIT("tests.schematest"); struct testSchemaData { virXMLValidatorPtr validator; + const char *schema; const char *xml_path; }; @@ -140,15 +141,10 @@ testSchemaDirs(const char *schema, virXMLValidatorPtr validator, ...) } -struct testSchemaFileData { - virXMLValidatorPtr validator; - const char *schema; -}; - static int testSchemaGrammar(const void *opaque) { - struct testSchemaFileData *data = (struct testSchemaFileData *) opaque; + struct testSchemaData *data = (struct testSchemaData *) opaque; char *schema_path; int ret = -1; @@ -171,11 +167,11 @@ static int mymain(void) { int ret = 0; - struct testSchemaFileData data; + struct testSchemaData data; memset(&data, 0, sizeof(data)); -#define DO_TEST(sch, ...) \ +#define DO_TEST_DIR(sch, ...) \ do { \ data.schema = sch; \ if (virTestRun("test schema grammar file: " sch, \ @@ -196,26 +192,49 @@ mymain(void) } \ } while (0) - DO_TEST("capability.rng", "capabilityschemadata", "xencapsdata"); - DO_TEST("domain.rng", "domainschemadata", "qemuargv2xmldata", - "qemuxml2argvdata", "sexpr2xmldata", "xmconfigdata", - "xml2sexprdata", "qemuxml2xmloutdata", "lxcxml2xmldata", - "lxcxml2xmloutdata", "bhyvexml2argvdata", "genericxml2xmlindata", - "genericxml2xmloutdata", "xlconfigdata", - "qemuhotplugtestdomains"); - DO_TEST("domaincaps.rng", "domaincapsschemadata"); - DO_TEST("domainsnapshot.rng", "domainsnapshotxml2xmlin", - "domainsnapshotxml2xmlout"); - DO_TEST("interface.rng", "interfaceschemadata"); - DO_TEST("network.rng", "../src/network", "networkxml2xmlin", - "networkxml2xmlout", "networkxml2confdata"); - DO_TEST("nodedev.rng", "nodedevschemadata"); - DO_TEST("nwfilter.rng", "nwfilterxml2xmlout"); - DO_TEST("secret.rng", "secretxml2xmlin"); - DO_TEST("storagepool.rng", "storagepoolxml2xmlin", "storagepoolxml2xmlout", - "storagepoolschemadata"); - DO_TEST("storagevol.rng", "storagevolxml2xmlin", "storagevolxml2xmlout", - "storagevolschemadata"); +#define DO_TEST_FILE(sch, xmlfile) \ + do { \ + data.schema = sch; \ + data.xml_path = abs_srcdir "/" xmlfile; \ + if (virTestRun("test schema grammar file: " sch, \ + testSchemaGrammar, &data) == 0) { \ + /* initialize the validator even if the schema test \ + * was skipped because of VIR_TEST_RANGE */ \ + if (!data.validator && testSchemaGrammar(&data) < 0) { \ + ret = -1; \ + break; \ + } \ + if (virTestRun("Checking " xmlfile " against " sch, \ + testSchemaFile, &data) < 0) \ + ret = -1; \ + \ + virXMLValidatorFree(data.validator); \ + data.validator = NULL; \ + } else { \ + ret = -1; \ + } \ + } while (0) + + DO_TEST_DIR("capability.rng", "capabilityschemadata", "xencapsdata"); + DO_TEST_DIR("domain.rng", "domainschemadata", "qemuargv2xmldata", + "qemuxml2argvdata", "sexpr2xmldata", "xmconfigdata", + "xml2sexprdata", "qemuxml2xmloutdata", "lxcxml2xmldata", + "lxcxml2xmloutdata", "bhyvexml2argvdata", "genericxml2xmlindata", + "genericxml2xmloutdata", "xlconfigdata", + "qemuhotplugtestdomains"); + DO_TEST_DIR("domaincaps.rng", "domaincapsschemadata"); + DO_TEST_DIR("domainsnapshot.rng", "domainsnapshotxml2xmlin", + "domainsnapshotxml2xmlout"); + DO_TEST_DIR("interface.rng", "interfaceschemadata"); + DO_TEST_DIR("network.rng", "../src/network", "networkxml2xmlin", + "networkxml2xmlout", "networkxml2confdata"); + DO_TEST_DIR("nodedev.rng", "nodedevschemadata"); + DO_TEST_DIR("nwfilter.rng", "nwfilterxml2xmlout"); + DO_TEST_DIR("secret.rng", "secretxml2xmlin"); + DO_TEST_DIR("storagepool.rng", "storagepoolxml2xmlin", "storagepoolxml2xmlout", + "storagepoolschemadata"); + DO_TEST_DIR("storagevol.rng", "storagevolxml2xmlin", "storagevolxml2xmlout", + "storagevolschemadata"); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -- 2.12.1

Add stricter rules for the news file and fix offending entries. --- docs/news.xml | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/docs/news.xml b/docs/news.xml index b2e21efca..5115cb1ab 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -5,9 +5,18 @@ This file will be processed to produce both HTML and plain text versions of the release notes. - Keep the style consistent with existing entries as much as possible: - each change should be documented by a short, one-sentence summary - and optionally a description where it's explained in more detail --> + Keep the style consistent with existing entries as much as possible. + + Each change should be documented by a short, one-sentence summary, which + should fit in a single line and should not contain any formatting tags. + + You can optionally add a description if you feel like the summary alone is + not enough to document the change accurately. The description may contain + a <code> tag for switching to non-proportional font. No other tags are + allowed. + + Lines should be kept under 80 columns, and should not exceed 100 columns. + --> <libvirt> <release version="v3.2.0" date="unreleased"> @@ -380,7 +389,7 @@ </change> <change> <summary> - nss: Introduce <code>libvirt_guest</code> + nss: Introduce libvirt_guest </summary> <description> New <code>libvirt_guest</code> nss module that translates libvirt @@ -640,7 +649,7 @@ <description> The new libssh transport allows one to connect to a running libvirtd via SSH, using the libssh library; for example: - <tt>qemu+libssh://<i>server</i>/system</tt>. + <code>qemu+libssh://server/system</code>. </description> </change> <change> @@ -654,17 +663,22 @@ </change> <change> <summary> - qemu: Users can now enable debug logging for native gluster - volumes in qemu using the "gluster_debug_level" option in qemu.conf + Allow debugging of gluster volumes in qemu </summary> + <description> + Users can now enable debug logging for native gluster + volumes in qemu using the "gluster_debug_level" option in qemu.conf + </description> </change> <change> <summary> - memory hotplug: Slot numbers for memory devices are now - automatically allocated and thus persistent. In addition slot numbers - can be specified without providing a base address, which simplifies - user configuration + Pre-allocate memory slots for memory hotplug </summary> + <description> + Slot numbers for memory devices are now automatically allocated and + thus persistent. In addition slot numbers can be specified without + providing a base address, which simplifies user configuration + </description> </change> <change> <summary> @@ -694,8 +708,7 @@ </change> <change> <summary> - virsh: Add support for passing an alternative persistent XML - to migrate command + virsh: Add support for passing an alternative persistent XML to migrate command </summary> </change> <change> -- 2.12.1

Since this file gets changed (and broken) rather often, introduce a schema file so that the test suite can validate it. --- docs/news.xml | 2 ++ docs/schemas/news.rng | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/virschematest.c | 2 ++ 3 files changed, 77 insertions(+) create mode 100644 docs/schemas/news.rng diff --git a/docs/news.xml b/docs/news.xml index 5115cb1ab..d9c39d026 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -16,6 +16,8 @@ allowed. Lines should be kept under 80 columns, and should not exceed 100 columns. + + This file is validated against docs/schemas/news.rng schema. --> <libvirt> diff --git a/docs/schemas/news.rng b/docs/schemas/news.rng new file mode 100644 index 000000000..94a6870c1 --- /dev/null +++ b/docs/schemas/news.rng @@ -0,0 +1,73 @@ +<?xml version="1.0"?> +<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> + <start> + <ref name="libvirt"/> + </start> + + <define name="libvirt"> + <element name="libvirt"> + <oneOrMore> + <ref name="release"/> + </oneOrMore> + </element> + </define> + + <define name="release"> + <element name="release"> + <attribute name="version"> + <data type="string"> + <param name="pattern">v[0-9]+\.[0-9]+\.[0-9]+</param> + </data> + </attribute> + <attribute name="date"> + <data type="string"> + <param name="pattern">[0-9]{4}-[0-9]{2}-[0-9]{2}|unreleased</param> + </data> + </attribute> + <oneOrMore> + <ref name="section"/> + </oneOrMore> + </element> + </define> + + <define name="section"> + <element name="section"> + <attribute name="title"> + <data type="string"/> + </attribute> + <oneOrMore> + <ref name="change"/> + </oneOrMore> + </element> + </define> + + <define name="change"> + <element name="change"> + <element name="summary"> + <choice> + <data type="string"> + <param name="pattern">\n[^\n]+\n +</param> + </data> + <empty/> + </choice> + </element> + <optional> + <element name="description"> + <ref name="description"/> + </element> + </optional> + </element> + </define> + + <define name="description"> + <oneOrMore> + <choice> + <text/> + <element name="code"> + <text/> + </element> + </choice> + </oneOrMore> + </define> + +</grammar> diff --git a/tests/virschematest.c b/tests/virschematest.c index b73555da8..4f194804a 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -236,6 +236,8 @@ mymain(void) DO_TEST_DIR("storagevol.rng", "storagevolxml2xmlin", "storagevolxml2xmlout", "storagevolschemadata"); + DO_TEST_FILE("news.rng", "../docs/news.xml"); + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -- 2.12.1

After the release it's necessary to add a new <release> section for the upcoming release. Add a template so that it does not have to be compiled over and over again. --- docs/news.xml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/news.xml b/docs/news.xml index d9c39d026..9f3538394 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -18,6 +18,27 @@ Lines should be kept under 80 columns, and should not exceed 100 columns. This file is validated against docs/schemas/news.rng schema. + + Use the following template to add a new release section: + + <release version="FIXME" date="unreleased"> + <section title="New features"> + <change> + <summary/> + </change> + </section> + <section title="Improvements"> + <change> + <summary/> + </change> + </section> + <section title="Bug fixes"> + <change> + <summary/> + </change> + </section> + </release> + --> <libvirt> -- 2.12.1

On Wed, Mar 29, 2017 at 09:28:16AM +0200, Peter Krempa wrote:
After the release it's necessary to add a new <release> section for the upcoming release. Add a template so that it does not have to be compiled over and over again.
s/compiled/copied/? Jan

On Wed, Mar 29, 2017 at 16:30:41 +0200, Ján Tomko wrote:
On Wed, Mar 29, 2017 at 09:28:16AM +0200, Peter Krempa wrote:
After the release it's necessary to add a new <release> section for the upcoming release. Add a template so that it does not have to be compiled over and over again.
s/compiled/copied/?
No, you have to compile it from the existing entries. I've rebased this one patch on top of the current master and pushed it since the release is near.

On Wed, Mar 29, 2017 at 09:28:12AM +0200, Peter Krempa wrote:
v2: - rename DO_TEST to DO_TEST_DIR along with changes in the first patch - add 'abs_srcdir' to the tested XML path so that vpath builds work - fix wording of the rules for adding news entries - fix commit messages
Peter Krempa (4): tests: schema: Add possibility to validate individual files news: Introduce rules for the schema file and fix offending lines schema: Introduce schema for the news.xml file news: Add template for a <release> section
docs/news.xml | 62 ++++++++++++++++++++++++++++++++--------- docs/schemas/news.rng | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/virschematest.c | 77 ++++++++++++++++++++++++++++++++------------------- 3 files changed, 171 insertions(+), 41 deletions(-) create mode 100644 docs/schemas/news.rng
ACK series Jan
participants (2)
-
Ján Tomko
-
Peter Krempa