From nobody Sat Apr 27 22:23:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1555422860; cv=none; d=zoho.com; s=zohoarc; b=dDwhVYeoBJVUcCToSYua6eQlAbVXp4Y7KHcY+PWHGKw9OHeBFoMIt65wdjbIaAIEgEqDxCKLpZ6uZI7xVADcInivQ6Ba1TMEBXLkQXR6FYE9OXIaPZeGHKZQ0rEDk7EwdMMwOL03zJuAnrAqIKXUJhwJM/sWAOF2m7EdU5sPdek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555422860; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=otboh53usxODY+cRP+jhBkoYysXhomnm7irVA5sQxvg=; b=idJ0Od3Asnj0KJU3UsbbPxXcbAZcxRVxZfWB+Lpaf4lr+bks9PKZAwzeTiipeKcVwtYXwoWx2Z0CEVnjYRSaVbUghIysMZduSP+xyN917++DUR/x6fqbRNbWdll8JmfnpqCbDAgDFBwh3TCOTZKNQqNmFmxchHCnLPLqReXW0DY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1555422860606627.3066608489744; Tue, 16 Apr 2019 06:54:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BAB673001C62; Tue, 16 Apr 2019 13:54:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 958FB5D9D3; Tue, 16 Apr 2019 13:54:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 561E8181AC47; Tue, 16 Apr 2019 13:54:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3GDrSkn019232 for ; Tue, 16 Apr 2019 09:53:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id AEF611001E75; Tue, 16 Apr 2019 13:53:28 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-146.phx2.redhat.com [10.3.116.146]) by smtp.corp.redhat.com (Postfix) with ESMTP id 704431001DF1 for ; Tue, 16 Apr 2019 13:53:28 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Tue, 16 Apr 2019 08:53:20 -0500 Message-Id: <20190416135324.18173-2-eblake@redhat.com> In-Reply-To: <20190416135324.18173-1-eblake@redhat.com> References: <20190416135324.18173-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/5] snapshot: Refactor snapshotxml2xml test X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 16 Apr 2019 13:54:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Upcoming changes want to separate out a post-parse massaging of snapshots separate from parsing the XML, so as not to be dependent on filtering out an ever-changing timestamp from the testsuite. Along the way, this means we will want to add yet another conditional to the snapshot xml2xml tests on whether to perform post-processing steps to canned values. This will be easier to read if we consolidate all the decisions into a flags variable, instead of adding yet another boolean. While at it, drop the redundant inout test of "noparent" (once is enough). Signed-off-by: Eric Blake --- tests/domainsnapshotxml2xmltest.c | 63 +++++++++++++++++-------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xm= ltest.c index 9f7f98585f..c329f15a54 100644 --- a/tests/domainsnapshotxml2xmltest.c +++ b/tests/domainsnapshotxml2xmltest.c @@ -33,6 +33,11 @@ static const char *testSnapshotXMLVariableLineRegexStr = =3D regex_t *testSnapshotXMLVariableLineRegex =3D NULL; +enum { + TEST_INTERNAL =3D 1 << 0, + TEST_REDEFINE =3D 1 << 1, +}; + static char * testFilterXML(char *xml) { @@ -70,8 +75,7 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml, const char *uuid, - bool internal, - bool redefine) + unsigned int flags) { char *inXmlData =3D NULL; char *outXmlData =3D NULL; @@ -82,12 +86,12 @@ testCompareXMLToXMLFiles(const char *inxml, unsigned int formatflags =3D VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE; bool cur; - if (internal) { + if (flags & TEST_INTERNAL) { parseflags |=3D VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL; formatflags |=3D VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL; } - if (redefine) + if (flags & TEST_REDEFINE) parseflags |=3D VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE; if (virTestLoadFile(inxml, &inXmlData) < 0) @@ -108,7 +112,7 @@ testCompareXMLToXMLFiles(const char *inxml, formatflags))) goto cleanup; - if (!redefine) { + if (!(flags & TEST_REDEFINE)) { if (!(actual =3D testFilterXML(actual))) goto cleanup; @@ -135,8 +139,7 @@ struct testInfo { const char *inxml; const char *outxml; const char *uuid; - bool internal; - bool redefine; + unsigned int flags; }; @@ -146,7 +149,7 @@ testCompareXMLToXMLHelper(const void *data) const struct testInfo *info =3D data; return testCompareXMLToXMLFiles(info->inxml, info->outxml, info->uuid, - info->internal, info->redefine); + info->flags); } @@ -170,11 +173,11 @@ mymain(void) } -# define DO_TEST(prefix, name, inpath, outpath, uuid, internal, redefine) \ +# define DO_TEST(prefix, name, inpath, outpath, uuid, flags) \ do { \ const struct testInfo info =3D {abs_srcdir "/" inpath "/" name ".x= ml", \ abs_srcdir "/" outpath "/" name ".xm= l", \ - uuid, internal, redefine}; \ + uuid, flags}; \ if (virTestRun("SNAPSHOT XML-2-XML " prefix " " name, \ testCompareXMLToXMLHelper, &info) < 0) \ ret =3D -1; \ @@ -183,39 +186,43 @@ mymain(void) # define DO_TEST_IN(name, uuid) DO_TEST("in->in", name,\ "domainsnapshotxml2xmlin",\ "domainsnapshotxml2xmlin",\ - uuid, false, false) + uuid, 0) # define DO_TEST_OUT(name, uuid, internal) DO_TEST("out->out", name,\ "domainsnapshotxml2xmlo= ut",\ "domainsnapshotxml2xmlo= ut",\ - uuid, internal, true) + uuid, \ + internal | TEST_REDEFIN= E) -# define DO_TEST_INOUT(name, uuid, internal, redefine) \ +# define DO_TEST_INOUT(name, uuid, flags) \ DO_TEST("in->out", name,\ "domainsnapshotxml2xmlin",\ "domainsnapshotxml2xmlout",\ - uuid, internal, redefine) + uuid, flags) /* Unset or set all envvars here that are copied in qemudBuildCommandL= ine * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected * values for these envvars */ setenv("PATH", "/bin", 1); - DO_TEST_OUT("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", = true); - DO_TEST_OUT("disk_snapshot_redefine", "c7a5fdbd-edaf-9455-926a-d65c16d= b1809", true); - DO_TEST_OUT("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809", tru= e); - DO_TEST_OUT("noparent_nodescription_noactive", NULL, false); - DO_TEST_OUT("noparent_nodescription", NULL, true); - DO_TEST_OUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", false); - DO_TEST_OUT("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", false); - DO_TEST_OUT("external_vm_redefine", "c7a5fdbd-edaf-9455-926a-d65c16db1= 809", false); + DO_TEST_OUT("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", + TEST_INTERNAL); + DO_TEST_OUT("disk_snapshot_redefine", "c7a5fdbd-edaf-9455-926a-d65c16d= b1809", + TEST_INTERNAL); + DO_TEST_OUT("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809", + TEST_INTERNAL); + DO_TEST_OUT("noparent_nodescription_noactive", NULL, 0); + DO_TEST_OUT("noparent_nodescription", NULL, TEST_INTERNAL); + DO_TEST_OUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0); + DO_TEST_OUT("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0); + DO_TEST_OUT("external_vm_redefine", "c7a5fdbd-edaf-9455-926a-d65c16db1= 809", + 0); - DO_TEST_INOUT("empty", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", false, = false); - DO_TEST_INOUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", fals= e, false); - DO_TEST_INOUT("external_vm", NULL, false, false); - DO_TEST_INOUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", fals= e, false); - DO_TEST_INOUT("disk_snapshot", NULL, false, false); - DO_TEST_INOUT("disk_driver_name_null", NULL, false, false); + DO_TEST_INOUT("empty", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0); + DO_TEST_INOUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0); + DO_TEST_INOUT("external_vm", NULL, 0); + DO_TEST_INOUT("disk_snapshot", NULL, 0); + DO_TEST_INOUT("disk_driver_name_null", NULL, 0); DO_TEST_IN("name_and_description", NULL); DO_TEST_IN("description_only", NULL); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 22:23:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1555422864; cv=none; d=zoho.com; s=zohoarc; b=bedGFWTs3J/wKmlc9fWhjA3WXWyZKbNPs1RNtuRfbRpCsj8VrGNFePdvXMWaiqFZLylkJiaCS9mUcL40FCav9uXOrO3W3PL5vfFvye16EC/3UFjta8/nno1TkR6bTTMLEMfsvvVv8f9WeXVVaSAVEc8l4iybzGGjQhhnJo6y6cg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555422864; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Bu3c6xb4fuEcWwG+qwF61WRZel7Eof5NIF50JXk8Zwo=; b=V2wOyp5cCsjQLdTgn/P28PGUY2KPE8hmeOmXAIRHZvE/8YSu67bvQv7AZulemei0+/R5iB13uJQPLM9Uw3b3wIBO45RuW+9YmmK9HAAWds8/USyIX6vtpvycq2sRtJafHf5jX6jropBBGUbofS/IzMcevLsejSWFbgJwVSHX3eA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1555422864297881.2862342651384; Tue, 16 Apr 2019 06:54:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 88D343087BBE; Tue, 16 Apr 2019 13:54:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 53EEC608C2; Tue, 16 Apr 2019 13:54:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0476A181AC90; Tue, 16 Apr 2019 13:54:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3GDrTVp019237 for ; Tue, 16 Apr 2019 09:53:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1B62A1001E8D; Tue, 16 Apr 2019 13:53:29 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-146.phx2.redhat.com [10.3.116.146]) by smtp.corp.redhat.com (Postfix) with ESMTP id D28C51001E75 for ; Tue, 16 Apr 2019 13:53:28 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Tue, 16 Apr 2019 08:53:21 -0500 Message-Id: <20190416135324.18173-3-eblake@redhat.com> In-Reply-To: <20190416135324.18173-1-eblake@redhat.com> References: <20190416135324.18173-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] snapshot: Don't expose testsuite-only state in snapshot XML X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 16 Apr 2019 13:54:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" None of the existing drivers actually use the 0-valued 'nostate' snapshot state; rather, it was a fluke of implementation. In fact, some drivers, like qemu, actively reject 'nostate' as invalid during a snapshot redefine. Normally, a driver computes the state post-parse from the current domain, and thus virDomainSnapshotGetXMLDesc() will never expose the state. However, since the testsuite lacks any associated domain to copy state from, and lackes post-parse processing that normal drivers have, the testsuite output had several spots with the state, coupled with a regex filter to ignore the oddity. It is better to follow the lead of other XML defaults, by not outputting anything during format if post-parse defaults have not been applied, and rejecting the default value during parsing. The testsuite needs a bit of an update, by adding another flag for when to simulate a post-parse action of setting a snapshot state, but none of the drivers are impacted other than rejecting XML that was previously already suspicious in nature. Similarly, don't expose creation time 0 (for now, only possible if a user redefined a snapshot to claim creation at the Epoch, but also happens once setting the creation time is deferred to a post-parse handler). This is also a step towards cleaning up snapshot_conf.c to separate its existing post-parse work (namely, setting the creationTime and default snapshot name) from the pure parsing work, so that we can get rid of the testsuite hack of regex filtering of the XML and instead have more accurate testing of our parser/formatter code. Signed-off-by: Eric Blake --- docs/schemas/domainsnapshot.rng | 1 - src/conf/snapshot_conf.c | 12 +++++++----- tests/domainsnapshotxml2xmlout/empty.xml | 1 - .../name_and_description.xml | 1 - tests/domainsnapshotxml2xmlout/noparent.xml | 2 +- tests/domainsnapshotxml2xmltest.c | 15 ++++++++++----- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/docs/schemas/domainsnapshot.rng b/docs/schemas/domainsnapshot.= rng index 2680887095..8863d99578 100644 --- a/docs/schemas/domainsnapshot.rng +++ b/docs/schemas/domainsnapshot.rng @@ -103,7 +103,6 @@ - nostate running blocked paused diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index ce543cbaf7..08f335646c 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -245,7 +245,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, goto cleanup; } def->state =3D virDomainSnapshotStateTypeFromString(state); - if (def->state < 0) { + if (def->state <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid state '%s' in domain snapshot XML"), state); @@ -810,8 +810,9 @@ virDomainSnapshotDefFormatInternal(virBufferPtr buf, if (def->common.description) virBufferEscapeString(buf, "%s\n", def->common.description); - virBufferAsprintf(buf, "%s\n", - virDomainSnapshotStateTypeToString(def->state)); + if (def->state) + virBufferAsprintf(buf, "%s\n", + virDomainSnapshotStateTypeToString(def->state)); if (def->common.parent) { virBufferAddLit(buf, "\n"); @@ -821,8 +822,9 @@ virDomainSnapshotDefFormatInternal(virBufferPtr buf, virBufferAddLit(buf, "\n"); } - virBufferAsprintf(buf, "%lld\n", - def->common.creationTime); + if (def->common.creationTime) + virBufferAsprintf(buf, "%lld\n", + def->common.creationTime); if (def->memory) { virBufferAsprintf(buf, " 1386166249 - nostate 1386166249 9d37b878-a7cc-9f9a-b78f-49b3abad25a8 diff --git a/tests/domainsnapshotxml2xmlout/name_and_description.xml b/test= s/domainsnapshotxml2xmlout/name_and_description.xml index 435ab79aa9..90ce774741 100644 --- a/tests/domainsnapshotxml2xmlout/name_and_description.xml +++ b/tests/domainsnapshotxml2xmlout/name_and_description.xml @@ -1,5 +1,4 @@ snap1 A longer description! - nostate diff --git a/tests/domainsnapshotxml2xmlout/noparent.xml b/tests/domainsnap= shotxml2xmlout/noparent.xml index d4360f0dc1..0cbbb658d8 100644 --- a/tests/domainsnapshotxml2xmlout/noparent.xml +++ b/tests/domainsnapshotxml2xmlout/noparent.xml @@ -1,7 +1,7 @@ my snap name !@#$%^ - nostate + running 1272917631 diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xm= ltest.c index c329f15a54..a35edf18fb 100644 --- a/tests/domainsnapshotxml2xmltest.c +++ b/tests/domainsnapshotxml2xmltest.c @@ -24,18 +24,17 @@ static virQEMUDriver driver; /* This regex will skip the following XML constructs in test files * that are dynamically generated and thus problematic to test: * 1234352345 if the snapshot has no name, - * 23523452345, - * nostate as the backend code doesn't fill this + * 23523452345 */ static const char *testSnapshotXMLVariableLineRegexStr =3D - "(<(name|creationTime)>[0-9]+|" - "nostate)"; + "<(name|creationTime)>[0-9]+"; regex_t *testSnapshotXMLVariableLineRegex =3D NULL; enum { TEST_INTERNAL =3D 1 << 0, TEST_REDEFINE =3D 1 << 1, + TEST_RUNNING =3D 1 << 2, }; static char * @@ -106,6 +105,11 @@ testCompareXMLToXMLFiles(const char *inxml, goto cleanup; if (cur) formatflags |=3D VIR_DOMAIN_SNAPSHOT_FORMAT_CURRENT; + if (flags & TEST_RUNNING) { + if (def->state) + goto cleanup; + def->state =3D VIR_DOMAIN_RUNNING; + } if (!(actual =3D virDomainSnapshotDefFormat(uuid, def, driver.caps, driver.xmlopt, @@ -219,7 +223,8 @@ mymain(void) 0); DO_TEST_INOUT("empty", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0); - DO_TEST_INOUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0); + DO_TEST_INOUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", + TEST_RUNNING); DO_TEST_INOUT("external_vm", NULL, 0); DO_TEST_INOUT("disk_snapshot", NULL, 0); DO_TEST_INOUT("disk_driver_name_null", NULL, 0); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 22:23:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1555422835; cv=none; d=zoho.com; s=zohoarc; b=TeGN3qq7LaUcPRAYKynzXvSHfHFc05vBOaezJXsSHYf5yDtZahUWZ8wfs6+1ti3OmjGTsoDXrdR1ixke5cjyVpGBNIUldvRKkDBDgipd6RsDSJO2QTePmKEfz8/JE1qstUq0vWcZvYVNkcPyPfPhWztTrh/rQJEUXSJqMhfzsn4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555422835; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=gMthUpvD0DsbFupOgzcMMEU+CJa7wtYhoN6fq3/u6IU=; b=WgVDTUKsYcKX4RTtW3BSDOVU6Sr/KbBw5BRQ3rxlIbYlvGJqIaPhzgSO5Fc6FfImmIIYpjYdMGvhKBtso+Pgk1TjAsK/sl5/ja4v6JmxFwVWlff7oJ4DhW1tCSbUVVu/X5EESKOrq40d3ydKCGkrMjuiv+Kg/ElbiaDYaUatB7Y= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155542283585459.81479074202514; Tue, 16 Apr 2019 06:53:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E3A5033025E; Tue, 16 Apr 2019 13:53:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7ABD4608C2; Tue, 16 Apr 2019 13:53:48 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6E78F3FB12; Tue, 16 Apr 2019 13:53:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3GDrTN5019245 for ; Tue, 16 Apr 2019 09:53:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7E0B01001E75; Tue, 16 Apr 2019 13:53:29 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-146.phx2.redhat.com [10.3.116.146]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F95F1001DF1 for ; Tue, 16 Apr 2019 13:53:29 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Tue, 16 Apr 2019 08:53:22 -0500 Message-Id: <20190416135324.18173-4-eblake@redhat.com> In-Reply-To: <20190416135324.18173-1-eblake@redhat.com> References: <20190416135324.18173-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/5] snapshot: Factor out post-parse code X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 16 Apr 2019 13:53:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Move the non-deterministic code that sets snapshot properties independently of what the incoming XML described to instead live in a post-parse function common to virDomainMoment (as checkpoints will also reuse it in later patches). This patch is just code motion, with no difference to any callers; but the next patch will further refactor things to call the post-process code from each driver, while the testsuite performs its own deterministic actions, for better testsuite coverage of parser/formatter code. Signed-off-by: Eric Blake --- src/conf/moment_conf.h | 2 ++ src/conf/moment_conf.c | 19 +++++++++++++++++++ src/conf/snapshot_conf.c | 10 ++-------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/conf/moment_conf.h b/src/conf/moment_conf.h index 8af3fbc6ac..e06a4a7b3c 100644 --- a/src/conf/moment_conf.h +++ b/src/conf/moment_conf.h @@ -39,4 +39,6 @@ struct _virDomainMomentDef { void virDomainMomentDefClear(virDomainMomentDefPtr def); +int virDomainMomentDefPostParse(virDomainMomentDefPtr def); + #endif /* LIBVIRT_MOMENT_CONF_H */ diff --git a/src/conf/moment_conf.c b/src/conf/moment_conf.c index 886f3a44b4..0eb32eeb52 100644 --- a/src/conf/moment_conf.c +++ b/src/conf/moment_conf.c @@ -21,11 +21,14 @@ #include +#include + #include "internal.h" #include "moment_conf.h" #include "domain_conf.h" #include "virlog.h" #include "viralloc.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN @@ -38,3 +41,19 @@ void virDomainMomentDefClear(virDomainMomentDefPtr def) VIR_FREE(def->parent); virDomainDefFree(def->dom); } + +/* Provide defaults for creation time and moment name after parsing XML */ +int +virDomainMomentDefPostParse(virDomainMomentDefPtr def) +{ + struct timeval tv; + + gettimeofday(&tv, NULL); + + if (!def->name && + virAsprintf(&def->name, "%lld", (long long)tv.tv_sec) < 0) + return -1; + + def->creationTime =3D tv.tv_sec; + return 0; +} diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 08f335646c..ef6eae3a51 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -23,7 +23,6 @@ #include #include -#include #include #include "internal.h" @@ -199,7 +198,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, size_t i; int n; char *creation =3D NULL, *state =3D NULL; - struct timeval tv; int active; char *tmp; char *memorySnapshot =3D NULL; @@ -210,8 +208,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, if (VIR_ALLOC(def) < 0) goto cleanup; - gettimeofday(&tv, NULL); - def->common.name =3D virXPathString("string(./name)", ctxt); if (def->common.name =3D=3D NULL) { if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) { @@ -219,8 +215,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, _("a redefined snapshot must have a name")); goto cleanup; } - if (virAsprintf(&def->common.name, "%lld", (long long)tv.tv_sec) <= 0) - goto cleanup; } def->common.description =3D virXPathString("string(./description)", ct= xt); @@ -276,8 +270,8 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, } else { VIR_WARN("parsing older snapshot that lacks domain"); } - } else { - def->common.creationTime =3D tv.tv_sec; + } else if (virDomainMomentDefPostParse(&def->common) < 0) { + goto cleanup; } memorySnapshot =3D virXPathString("string(./memory/@snapshot)", ctxt); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 22:23:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1555422836; cv=none; d=zoho.com; s=zohoarc; b=Ipek7yQcBTuRABsfNDRbg1ZwkS0mUSmxLiZ2x5dvsqL8hks3UhSa1AN4YZ7w4NfDuwdwIioS4wE0ZsOUGGeUcObhifpqw3rD9NpvJhPSL0Gl55yNC334OZAdzFUCV8b8cR/I3IN9fEtIr/t6B+QCOifc2vSyQ5CdFhKqXuSLfJA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555422836; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=BR4EfnYJI4mb4C0Zitn9Zzak1dm82Dw+NB7FURPD97s=; b=dBD45IPNz9qStlhXvoasUfOewDVAciVOTXCyfiSBs0ms5wVshWhcbTQncY4/S7QFlvyPaiHQ45Jlx128wm4hK2vmO6CCDKmv6LS4OgH7jHvxx8cOMhy6+5DAFXTQhHVZSW6RQvt+h2HMHJM+hRVfNSloYf8t3CK5aHtP11uKS+M= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1555422836021918.5348076141781; Tue, 16 Apr 2019 06:53:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AABC3002727; Tue, 16 Apr 2019 13:53:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED88A5D71C; Tue, 16 Apr 2019 13:53:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0C4651819AFA; Tue, 16 Apr 2019 13:53:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3GDrTjZ019250 for ; Tue, 16 Apr 2019 09:53:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id DDCD31001E8D; Tue, 16 Apr 2019 13:53:29 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-146.phx2.redhat.com [10.3.116.146]) by smtp.corp.redhat.com (Postfix) with ESMTP id A26A91001E75 for ; Tue, 16 Apr 2019 13:53:29 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Tue, 16 Apr 2019 08:53:23 -0500 Message-Id: <20190416135324.18173-5-eblake@redhat.com> In-Reply-To: <20190416135324.18173-1-eblake@redhat.com> References: <20190416135324.18173-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/5] snapshot: Allow for post-parse override X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 16 Apr 2019 13:53:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Wire up the accessor functions necessary for the testsuite to install an alternative post-parse handler from normal drivers. I could have modified the signature for virDomainXMLOptionNew() to take another parameter, but thought it was easier to add a new set function rather than chase down all existing callers. Until code actually sets the override, there is no change in behavior. Signed-off-by: Eric Blake Reviewed-by: Cole Robinson --- src/conf/domain_conf.h | 9 +++++++++ src/conf/domain_conf.c | 24 ++++++++++++++++++++++++ src/conf/snapshot_conf.c | 2 +- src/libvirt_private.syms | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 988ef90f11..be3b8bedf2 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2693,6 +2693,15 @@ virDomainXMLOptionPtr virDomainXMLOptionNew(virDomai= nDefParserConfigPtr config, virSaveCookieCallbacksPtr virDomainXMLOptionGetSaveCookie(virDomainXMLOptionPtr xmlopt); +typedef int (*virDomainMomentPostParseCallback)(virDomainMomentDefPtr def, + void *opaque); + +void virDomainXMLOptionSetMomentPostParse(virDomainXMLOptionPtr xmlopt, + virDomainMomentPostParseCallback= cb, + void *opaque); +int virDomainXMLOptionRunMomentPostParse(virDomainXMLOptionPtr xmlopt, + virDomainMomentDefPtr def); + void virDomainNetGenerateMAC(virDomainXMLOptionPtr xmlopt, virMacAddrPtr m= ac); virDomainXMLNamespacePtr diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 17e8975be3..32d4539f69 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -82,6 +82,10 @@ struct _virDomainXMLOption { /* Private data for save image stored in snapshot XML */ virSaveCookieCallbacks saveCookie; + + /* Snapshot postparse callbacks */ + virDomainMomentPostParseCallback moment; + void *moment_opaque; }; #define VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS \ @@ -1451,6 +1455,26 @@ virDomainXMLOptionGetSaveCookie(virDomainXMLOptionPt= r xmlopt) } +void +virDomainXMLOptionSetMomentPostParse(virDomainXMLOptionPtr xmlopt, + virDomainMomentPostParseCallback cb, + void *opaque) +{ + xmlopt->moment =3D cb; + xmlopt->moment_opaque =3D opaque; +} + + +int +virDomainXMLOptionRunMomentPostParse(virDomainXMLOptionPtr xmlopt, + virDomainMomentDefPtr def) +{ + if (!xmlopt->moment) + return virDomainMomentDefPostParse(def); + return xmlopt->moment(def, xmlopt->moment_opaque); +} + + void virBlkioDeviceArrayClear(virBlkioDevicePtr devices, int ndevices) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index ef6eae3a51..36c328f692 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -270,7 +270,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, } else { VIR_WARN("parsing older snapshot that lacks domain"); } - } else if (virDomainMomentDefPostParse(&def->common) < 0) { + } else if (virDomainXMLOptionRunMomentPostParse(xmlopt, &def->common) = < 0) { goto cleanup; } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b2be2d0fb9..8cd82c4416 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -604,6 +604,7 @@ virDomainWatchdogModelTypeToString; virDomainXMLOptionGetNamespace; virDomainXMLOptionGetSaveCookie; virDomainXMLOptionNew; +virDomainXMLOptionSetMomentPostParse; # conf/domain_event.h --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 22:23:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1555422859; cv=none; d=zoho.com; s=zohoarc; b=RXnF/iRNJJkh885lFIzG6NKvbLOX+8rXL6eanIZ109BynIipYg93rACfT35ltX9NAHQvNdH7e3iKUhsJBTUvPCQeUe1niSKOvo85BZSVM5sppBRzsryz+hrBDFd3ZXaznrMeUzH84FmDPb+lAr1wpsueiS0Lgt/Pkrxyg11h7Mg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555422859; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=94U+BaH9OxOROkIF1NckzMKAe20FyKxb8KraXX2MVfA=; b=Rr6f5K5KncCm2++8slLDTPvvdMUt3ErcPlR0Zg2RIZsbLduf9Nuih/0eshH4usGDFKUNJurmaCydwaaifp8JjX1ff8/P/IRY99Aix0gM/an2oCk0DKRpxfIP+oK9MRXLv8TS4G8aicBo9iCvqc5NnayVrz01xob5uCoEysZ+bsE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1555422859076231.62528638253707; Tue, 16 Apr 2019 06:54:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7694E37E88; Tue, 16 Apr 2019 13:54:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 500AC5D720; Tue, 16 Apr 2019 13:54:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C2D663FB14; Tue, 16 Apr 2019 13:54:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3GDrUsV019260 for ; Tue, 16 Apr 2019 09:53:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5469B1001DF1; Tue, 16 Apr 2019 13:53:30 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-146.phx2.redhat.com [10.3.116.146]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E9331001E75 for ; Tue, 16 Apr 2019 13:53:29 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Tue, 16 Apr 2019 08:53:24 -0500 Message-Id: <20190416135324.18173-6-eblake@redhat.com> In-Reply-To: <20190416135324.18173-1-eblake@redhat.com> References: <20190416135324.18173-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/5] snapshot: Use post-parse instead of regex in testsuite X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 16 Apr 2019 13:54:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Now that we can override the post-parse handling, let's update the testsuite to provide the desired timestamp/name rather than ignoring the non-deterministic one that was previously being generated. A few output files need timestamps added now that they are no longer ignored. Signed-off-by: Eric Blake --- .../disk_driver_name_null.xml | 1 + .../disk_snapshot.xml | 1 + .../domainsnapshotxml2xmlout/external_vm.xml | 1 + tests/domainsnapshotxml2xmltest.c | 142 ++++++------------ 4 files changed, 52 insertions(+), 93 deletions(-) diff --git a/tests/domainsnapshotxml2xmlout/disk_driver_name_null.xml b/tes= ts/domainsnapshotxml2xmlout/disk_driver_name_null.xml index ddd350de65..b0b27fd7e0 100644 --- a/tests/domainsnapshotxml2xmlout/disk_driver_name_null.xml +++ b/tests/domainsnapshotxml2xmlout/disk_driver_name_null.xml @@ -1,6 +1,7 @@ asdf adsf + 1555419243 diff --git a/tests/domainsnapshotxml2xmlout/disk_snapshot.xml b/tests/domai= nsnapshotxml2xmlout/disk_snapshot.xml index 0e81f35c69..76c543d25c 100644 --- a/tests/domainsnapshotxml2xmlout/disk_snapshot.xml +++ b/tests/domainsnapshotxml2xmlout/disk_snapshot.xml @@ -1,6 +1,7 @@ my snap name !@#$%^ + 1555419243 diff --git a/tests/domainsnapshotxml2xmlout/external_vm.xml b/tests/domains= napshotxml2xmlout/external_vm.xml index 9da369b1e5..03c2e703b5 100644 --- a/tests/domainsnapshotxml2xmlout/external_vm.xml +++ b/tests/domainsnapshotxml2xmlout/external_vm.xml @@ -1,5 +1,6 @@ my snap name !@#$%^ + 1555419243 diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xm= ltest.c index a35edf18fb..daceac34e6 100644 --- a/tests/domainsnapshotxml2xmltest.c +++ b/tests/domainsnapshotxml2xmltest.c @@ -21,55 +21,12 @@ static virQEMUDriver driver; -/* This regex will skip the following XML constructs in test files - * that are dynamically generated and thus problematic to test: - * 1234352345 if the snapshot has no name, - * 23523452345 - */ -static const char *testSnapshotXMLVariableLineRegexStr =3D - "<(name|creationTime)>[0-9]+"; - -regex_t *testSnapshotXMLVariableLineRegex =3D NULL; - enum { TEST_INTERNAL =3D 1 << 0, TEST_REDEFINE =3D 1 << 1, TEST_RUNNING =3D 1 << 2, }; -static char * -testFilterXML(char *xml) -{ - virBuffer buf =3D VIR_BUFFER_INITIALIZER; - char **xmlLines =3D NULL; - char **xmlLine; - char *ret =3D NULL; - - if (!(xmlLines =3D virStringSplit(xml, "\n", 0))) { - VIR_FREE(xml); - goto cleanup; - } - VIR_FREE(xml); - - for (xmlLine =3D xmlLines; *xmlLine; xmlLine++) { - if (regexec(testSnapshotXMLVariableLineRegex, - *xmlLine, 0, NULL, 0) =3D=3D 0) - continue; - - virBufferStrcat(&buf, *xmlLine, "\n", NULL); - } - - if (virBufferCheckError(&buf) < 0) - goto cleanup; - - ret =3D virBufferContentAndReset(&buf); - - cleanup: - virBufferFreeAndReset(&buf); - virStringListFree(xmlLines); - return ret; -} - static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml, @@ -116,14 +73,6 @@ testCompareXMLToXMLFiles(const char *inxml, formatflags))) goto cleanup; - if (!(flags & TEST_REDEFINE)) { - if (!(actual =3D testFilterXML(actual))) - goto cleanup; - - if (!(outXmlData =3D testFilterXML(outXmlData))) - goto cleanup; - } - if (STRNEQ(outXmlData, actual)) { virTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml); goto cleanup; @@ -143,15 +92,33 @@ struct testInfo { const char *inxml; const char *outxml; const char *uuid; + long long creationTime; unsigned int flags; }; +static long long timeptr; +static int +testSnapshotPostParse(virDomainMomentDefPtr def, void *opaque) +{ + long long *ptr =3D opaque; + + if (!*ptr) + return 0; + if (def->creationTime) + return -1; + def->creationTime =3D *ptr; + if (!def->name && + virAsprintf(&def->name, "%lld", def->creationTime) < 0) + return -1; + return 0; +} static int testCompareXMLToXMLHelper(const void *data) { const struct testInfo *info =3D data; + timeptr =3D info->creationTime; return testCompareXMLToXMLFiles(info->inxml, info->outxml, info->uuid, info->flags); } @@ -165,44 +132,34 @@ mymain(void) if (qemuTestDriverInit(&driver) < 0) return EXIT_FAILURE; - if (VIR_ALLOC(testSnapshotXMLVariableLineRegex) < 0) - goto cleanup; + virDomainXMLOptionSetMomentPostParse(driver.xmlopt, + testSnapshotPostParse, + &timeptr); - if (regcomp(testSnapshotXMLVariableLineRegex, - testSnapshotXMLVariableLineRegexStr, - REG_EXTENDED | REG_NOSUB) !=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - "failed to compile test regex"); - goto cleanup; - } - - -# define DO_TEST(prefix, name, inpath, outpath, uuid, flags) \ +# define DO_TEST(prefix, name, inpath, outpath, uuid, time, flags) \ do { \ const struct testInfo info =3D {abs_srcdir "/" inpath "/" name ".x= ml", \ abs_srcdir "/" outpath "/" name ".xm= l", \ - uuid, flags}; \ + uuid, time, flags}; \ if (virTestRun("SNAPSHOT XML-2-XML " prefix " " name, \ testCompareXMLToXMLHelper, &info) < 0) \ ret =3D -1; \ } while (0) -# define DO_TEST_IN(name, uuid) DO_TEST("in->in", name,\ - "domainsnapshotxml2xmlin",\ - "domainsnapshotxml2xmlin",\ - uuid, 0) +# define DO_TEST_IN(name, uuid) DO_TEST("in->in", name, \ + "domainsnapshotxml2xmlin", \ + "domainsnapshotxml2xmlin", \ + uuid, 0, 0) -# define DO_TEST_OUT(name, uuid, internal) DO_TEST("out->out", name,\ - "domainsnapshotxml2xmlo= ut",\ - "domainsnapshotxml2xmlo= ut",\ - uuid, \ - internal | TEST_REDEFIN= E) +# define DO_TEST_OUT(name, uuid, time, internal) \ + DO_TEST("out->out", name, "domainsnapshotxml2xmlout", \ + "domainsnapshotxml2xmlout", uuid, time, internal | TEST_REDEFI= NE) -# define DO_TEST_INOUT(name, uuid, flags) \ - DO_TEST("in->out", name,\ +# define DO_TEST_INOUT(name, uuid, time, flags) \ + DO_TEST("in->out", name, \ "domainsnapshotxml2xmlin",\ "domainsnapshotxml2xmlout",\ - uuid, flags) + uuid, time, flags) /* Unset or set all envvars here that are copied in qemudBuildCommandL= ine * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected @@ -210,33 +167,32 @@ mymain(void) setenv("PATH", "/bin", 1); DO_TEST_OUT("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", - TEST_INTERNAL); + 1272917631, TEST_INTERNAL); DO_TEST_OUT("disk_snapshot_redefine", "c7a5fdbd-edaf-9455-926a-d65c16d= b1809", - TEST_INTERNAL); + 1272917631, TEST_INTERNAL); DO_TEST_OUT("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809", - TEST_INTERNAL); - DO_TEST_OUT("noparent_nodescription_noactive", NULL, 0); - DO_TEST_OUT("noparent_nodescription", NULL, TEST_INTERNAL); - DO_TEST_OUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0); - DO_TEST_OUT("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0); + 1272917631, TEST_INTERNAL); + DO_TEST_OUT("noparent_nodescription_noactive", NULL, 1272917631, 0); + DO_TEST_OUT("noparent_nodescription", NULL, 1272917631, TEST_INTERNAL); + DO_TEST_OUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", + 1272917631, 0); + DO_TEST_OUT("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", + 1272917631, 0); DO_TEST_OUT("external_vm_redefine", "c7a5fdbd-edaf-9455-926a-d65c16db1= 809", - 0); + 1272917631, 0); - DO_TEST_INOUT("empty", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0); + DO_TEST_INOUT("empty", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", + 1386166249, 0); DO_TEST_INOUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", - TEST_RUNNING); - DO_TEST_INOUT("external_vm", NULL, 0); - DO_TEST_INOUT("disk_snapshot", NULL, 0); - DO_TEST_INOUT("disk_driver_name_null", NULL, 0); + 1272917631, TEST_RUNNING); + DO_TEST_INOUT("external_vm", NULL, 1555419243, 0); + DO_TEST_INOUT("disk_snapshot", NULL, 1555419243, 0); + DO_TEST_INOUT("disk_driver_name_null", NULL, 1555419243, 0); DO_TEST_IN("name_and_description", NULL); DO_TEST_IN("description_only", NULL); DO_TEST_IN("name_only", NULL); - cleanup: - if (testSnapshotXMLVariableLineRegex) - regfree(testSnapshotXMLVariableLineRegex); - VIR_FREE(testSnapshotXMLVariableLineRegex); qemuTestDriverFree(&driver); return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list