From nobody Mon Feb 9 14:15:05 2026 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15523586367441022.7530748627825; Mon, 11 Mar 2019 19:43:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37AC73092644; Tue, 12 Mar 2019 02:43:55 +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 143F660C55; Tue, 12 Mar 2019 02:43:55 +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 C85DF3FB12; Tue, 12 Mar 2019 02:43:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2C2cken014271 for ; Mon, 11 Mar 2019 22:38:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0900960C4C; Tue, 12 Mar 2019 02:38:46 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C43F648AB; Tue, 12 Mar 2019 02:38:45 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Mon, 11 Mar 2019 21:38:37 -0500 Message-Id: <20190312023839.11069-7-eblake@redhat.com> In-Reply-To: <20190312023839.11069-1-eblake@redhat.com> References: <20190312023839.11069-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com Subject: [libvirt] [PATCH v4 6/8] test: Implement bulk snapshot operations 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 12 Mar 2019 02:43:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Implement the new API calls for bulk snapshot dump and import. The bulk of the work is already done by the common code. Since each connection to test:///default restarts at the same canned state, this can easily be tested with: $ virsh -c test:///default " snapshot-create-as test s1 snapshot-create-as test s2 echo witness snapshot-dumpxml test --all" | sed '1,/witness/d' > list.xml $ virsh -c test:///default " snapshot-list test snapshot-import test list.xml snapshot-current --name test snapshot-list --parent test " Name Creation Time State Reviewed-by: J=C3=A1n Tomko ------------------------------- Imported 2 snapshots s2 Name Creation Time State Parent ------------------------------------------------------ s1 2019-02-20 22:26:52 -0600 running s2 2019-02-20 22:26:52 -0600 running s1 The test driver also makes it easy to test input validation, by modifying list.xml incorrectly (such as trying to attempt circular dependencies). Proving that that --topological makes a difference is a bit harder (since we randomize the hash seed, it is not 100% reproducible which order you get without it), but I found that creating snapshots s1, s3, s2 in that order tended to be more likely to hash in non-topological order without the flag. Signed-off-by: Eric Blake --- src/test/test_driver.c | 62 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 02cd4f4d07..085e228873 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1,7 +1,7 @@ /* * test_driver.c: A "mock" hypervisor for use by application unit tests * - * Copyright (C) 2006-2015 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -6222,6 +6222,36 @@ testDomainSnapshotGetXMLDesc(virDomainSnapshotPtr sn= apshot, return xml; } +static char * +testDomainGetSnapshotsXMLDesc(virDomainPtr domain, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + char *xml =3D NULL; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + testDriverPtr privconn =3D domain->conn->privateData; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + virCheckFlags(VIR_DOMAIN_GET_SNAPSHOTS_XML_SECURE | + VIR_DOMAIN_GET_SNAPSHOTS_XML_TOPOLOGICAL, NULL); + + if (!(vm =3D testDomObjFromDomain(domain))) + return NULL; + + virUUIDFormat(domain->uuid, uuidstr); + + if (virDomainSnapshotObjListFormat(&buf, uuidstr, vm->snapshots, + vm->current_snapshot, privconn->cap= s, + privconn->xmlopt, flags) < 0) + goto cleanup; + + xml =3D virBufferContentAndReset(&buf); + + cleanup: + virDomainObjEndAPI(&vm); + return xml; +} + static int testDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot, unsigned int flags) @@ -6409,6 +6439,34 @@ testDomainSnapshotCreateXML(virDomainPtr domain, } +static int +testDomainImportSnapshotsXML(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags) +{ + testDriverPtr privconn =3D domain->conn->privateData; + virDomainObjPtr vm =3D NULL; + int ret =3D -1; + unsigned int parse_flags =3D VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE | + VIR_DOMAIN_SNAPSHOT_PARSE_DISKS; + + virCheckFlags(0, -1); + + if (!(vm =3D testDomObjFromDomain(domain))) + return -1; + + ret =3D virDomainSnapshotObjListParse(xmlDesc, + vm->def->uuid, + vm->snapshots, + &vm->current_snapshot, + privconn->caps, + privconn->xmlopt, + parse_flags); + virDomainObjEndAPI(&vm); + return ret; +} + + typedef struct _testSnapRemoveData testSnapRemoveData; typedef testSnapRemoveData *testSnapRemoveDataPtr; struct _testSnapRemoveData { @@ -6840,6 +6898,7 @@ static virHypervisorDriver testHypervisorDriver =3D { .domainSnapshotListNames =3D testDomainSnapshotListNames, /* 1.1.4 */ .domainListAllSnapshots =3D testDomainListAllSnapshots, /* 1.1.4 */ .domainSnapshotGetXMLDesc =3D testDomainSnapshotGetXMLDesc, /* 1.1.4 */ + .domainGetSnapshotsXMLDesc =3D testDomainGetSnapshotsXMLDesc, /* 5.2.0= */ .domainSnapshotNumChildren =3D testDomainSnapshotNumChildren, /* 1.1.4= */ .domainSnapshotListChildrenNames =3D testDomainSnapshotListChildrenNam= es, /* 1.1.4 */ .domainSnapshotListAllChildren =3D testDomainSnapshotListAllChildren, = /* 1.1.4 */ @@ -6850,6 +6909,7 @@ static virHypervisorDriver testHypervisorDriver =3D { .domainSnapshotIsCurrent =3D testDomainSnapshotIsCurrent, /* 1.1.4 */ .domainSnapshotHasMetadata =3D testDomainSnapshotHasMetadata, /* 1.1.4= */ .domainSnapshotCreateXML =3D testDomainSnapshotCreateXML, /* 1.1.4 */ + .domainImportSnapshotsXML =3D testDomainImportSnapshotsXML, /* 5.2.0 */ .domainRevertToSnapshot =3D testDomainRevertToSnapshot, /* 1.1.4 */ .domainSnapshotDelete =3D testDomainSnapshotDelete, /* 1.1.4 */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list