From nobody Mon Feb 9 17:24:15 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 171119531404089.70520368490816; Sat, 23 Mar 2024 05:01:54 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EB1DE2175; Sat, 23 Mar 2024 08:01:52 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5BD7A2188; Sat, 23 Mar 2024 07:38:28 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E00041C8A; Sat, 23 Mar 2024 07:38:21 -0400 (EDT) Received: from mx1.osci.io (polly.osci.io [8.43.85.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A7CB21CFF for ; Sat, 23 Mar 2024 07:32:54 -0400 (EDT) Received: by mx1.osci.io (Postfix, from userid 994) id 9E92E223F1; Fri, 22 Mar 2024 13:56:49 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by mx1.osci.io (Postfix) with ESMTPS id ACD09223EC for ; Fri, 22 Mar 2024 13:56:48 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-569-jA9qCY4jMZ6T3oeGoWHASw-1; Fri, 22 Mar 2024 13:56:46 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 38DFF80027C for ; Fri, 22 Mar 2024 17:56:46 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1F0F492BDA for ; Fri, 22 Mar 2024 17:56:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: jA9qCY4jMZ6T3oeGoWHASw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 28/35] virshtest: Adapt 'virsh-snapshot' test Date: Fri, 22 Mar 2024 18:56:06 +0100 Message-ID: <704fe925a5493aa1d279df466ec0ffdb8da138f9.1711129973.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: YCPG6TEVZ6PXQOTLJTL75QEGNQ6PCRCK X-Message-ID-Hash: YCPG6TEVZ6PXQOTLJTL75QEGNQ6PCRCK X-MailFrom: SRS0=Xa5W=K4=redhat.com=pkrempa@osci.io X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1711195314507100001 Invoke the majority of the command via DO_TEST_SCRIPT in 'virshtest'. Some adaptation was needed to avoid printing of tables with volatile data such as snapshot creation time, which were converted to list names-only. To proprely test redefinition we store XMLs rather than taking them from the defined snapshots and use them separately to test redefinition of snapshot XMLs. This makes use of the 'cd' command in non-interactive mode. Signed-off-by: Peter Krempa --- tests/meson.build | 1 - tests/virsh-snapshot | 233 ---------------------- tests/virshtest.c | 10 + tests/virshtestdata/snapshot-redefine.out | 17 ++ tests/virshtestdata/snapshot-s2.xml | 43 ++++ tests/virshtestdata/snapshot-s3.xml | 40 ++++ tests/virshtestdata/snapshot.in | 54 +++++ tests/virshtestdata/snapshot.out | 173 ++++++++++++++++ 8 files changed, 337 insertions(+), 234 deletions(-) delete mode 100755 tests/virsh-snapshot create mode 100644 tests/virshtestdata/snapshot-redefine.out create mode 100644 tests/virshtestdata/snapshot-s2.xml create mode 100644 tests/virshtestdata/snapshot-s3.xml create mode 100755 tests/virshtestdata/snapshot.in create mode 100644 tests/virshtestdata/snapshot.out diff --git a/tests/meson.build b/tests/meson.build index 5a2a499461..efbe99f55e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -695,7 +695,6 @@ if conf.has('WITH_LIBVIRTD') 'virsh-read-bufsiz', 'virsh-read-non-seekable', 'virsh-self-test', - 'virsh-snapshot', 'virsh-uriprecedence', 'virt-admin-self-test', ] diff --git a/tests/virsh-snapshot b/tests/virsh-snapshot deleted file mode 100755 index b09273917b..0000000000 --- a/tests/virsh-snapshot +++ /dev/null @@ -1,233 +0,0 @@ -#!/bin/sh -# simple testing of snapshot APIs on test driver - -# Copyright (C) 2019 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# . - -. "$(dirname $0)/test-lib.sh" - -test_expensive - -if test "$VERBOSE" =3D yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=3D0 - -mock_xdg_ || framework_failure - -# The test driver loses states between restarts, so we perform a script -# with some convenient markers for later post-processing of output. -$abs_top_builddir/tools/virsh --connect test:///default >out 2>err ' - # Create a series of snapshots, with names that intentionally sort - # differently by topology than by name. Use revert to create fanout. - snapshot-create-as test s1 - snapshot-create-as test s1 - snapshot-create-as test s3 - snapshot-create-as test s2 - snapshot-revert test s3 - snapshot-create-as test s6 - snapshot-create-as test s5 - snapshot-revert test s6 - snapshot-create-as test s4 - snapshot-revert test s1 - snapshot-create-as test s7 - snapshot-create-as test s8 - # checkpoints cannot be created while snapshots exist - echo --err marker - checkpoint-create-as test c1 - echo --err marker - # Checking tree view (siblings sorted alphabetically) - snapshot-list test --tree - # Current was last one created, but we can change that - snapshot-current test --name - snapshot-current test s1 - snapshot-current test --name - # Deleting current root leads to multiple roots, demonstrate list filter= ing - snapshot-delete test --current - echo --err marker - snapshot-current test --name - echo --err marker - snapshot-list test --roots - snapshot-list test --leaves - snapshot-list test --parent --no-leaves - snapshot-list test --from s3 - snapshot-list test --from s3 --descendants --name - # More fun with delete flags, current node moves up to remaining parent - snapshot-current test s4 - snapshot-delete test --children-only s6 - snapshot-current test --name - snapshot-delete test --children s7 - snapshot-current test --name - snapshot-delete test s6 - snapshot-current test --name - # Now the tree is linear, so we have an unambiguous topological order - snapshot-list test --name - snapshot-list test --name --topological - # Capture some XML for later redefine - echo "" - snapshot-dumpxml test s3 - echo "" - snapshot-dumpxml test s2 - echo "" - # All done -' || fail=3D1 - -# First part is expected output, --tree results in trailing spaces, -# and snapshot-list produces timestamps -sed 's/ *$//; s/[0-9-]\{10\} [0-9:.]* .[0-9]\{4\}/TIMESTAMP/; - /MarkerA/,/MarkerC/d' < out > out.cooked || fail=3D1 -# Second part holds domain snapshot XMLs -sed -n '/MarkerA/,/MarkerB/p' < out > s3.xml || fail=3D1 -sed -n '/MarkerB/,/MarkerC/p' < out > s2.xml || fail=3D1 - -cat <<\EOF > exp || fail=3D1 -Domain snapshot s1 created - -Domain snapshot s3 created -Domain snapshot s2 created -Domain snapshot s3 reverted - -Domain snapshot s6 created -Domain snapshot s5 created -Domain snapshot s6 reverted - -Domain snapshot s4 created -Domain snapshot s1 reverted - -Domain snapshot s7 created -Domain snapshot s8 created - - - -s1 - | - +- s3 - | | - | +- s2 - | +- s6 - | | - | +- s4 - | +- s5 - | - +- s7 - | - +- s8 - - -s8 -Snapshot s1 set as current -s1 -Domain snapshot s1 deleted - - - - - Name Creation Time State ---------------------------------------------- - s3 TIMESTAMP running - s7 TIMESTAMP running - - Name Creation Time State ---------------------------------------------- - s2 TIMESTAMP running - s4 TIMESTAMP running - s5 TIMESTAMP running - s8 TIMESTAMP running - - Name Creation Time State Parent ------------------------------------------------------- - s3 TIMESTAMP running - s6 TIMESTAMP running s3 - s7 TIMESTAMP running - - Name Creation Time State ---------------------------------------------- - s2 TIMESTAMP running - s6 TIMESTAMP running - -s2 -s4 -s5 -s6 - -Snapshot s4 set as current -Domain snapshot s6 children deleted - -s6 -Domain snapshot s7 deleted - -s6 -Domain snapshot s6 deleted - -s3 -s2 -s3 - -s3 -s2 - -EOF -compare exp out.cooked || fail=3D1 - -cat < exp || fail=3D1 -error: operation failed: domain moment s1 already exists -error: marker -error: Operation not supported: cannot create checkpoint while snapshot ex= ists -error: marker -error: marker -error: domain 'test' has no current snapshot -error: marker -EOF -compare exp err || fail=3D1 - -# Restore state with redefine -$abs_top_builddir/tools/virsh -c test:///default >out 2>err ' - # Redefine must be in topological order; this will fail - snapshot-create test --redefine s2.xml --validate - echo --err marker - # This is the right order - snapshot-create test --redefine s3.xml --validate - snapshot-create test --redefine s2.xml --current --validate - snapshot-info test --current -' || fail=3D1 - -cat <<\EOF > exp || fail=3D1 - - -Domain snapshot s3 created from 's3.xml' -Domain snapshot s2 created from 's2.xml' -Name: s2 -Domain: test -Current: yes -State: running -Location: internal -Parent: s3 -Children: 0 -Descendants: 0 -Metadata: yes - -EOF -compare exp out || fail=3D1 - -cat < exp || fail=3D1 -error: invalid argument: parent s3 for moment s2 not found -error: marker -EOF -compare exp err || fail=3D1 - -(exit $fail); exit $fail diff --git a/tests/virshtest.c b/tests/virshtest.c index 9cad18cf58..83baac8c43 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -218,6 +218,16 @@ mymain(void) DO_TEST_FULL("domain-id-overflow", NULL, VIRSH_CUSTOM, "-q", "domname"= , "4294967298"); DO_TEST_FULL("schedinfo-invalid-argument", NULL, VIRSH_DEFAULT, "sched= info", "1", "--set", "j=3Dk"); + DO_TEST_SCRIPT("snapshot", " + s2 + running + + s3 + + 1234 + + + + + + test + 6695eb01-f6a4-8304-79aa-97f2502e193f + 8388608 + 2097152 + 2 + + hvm + + + + destroy + restart + destroy + + + + +
+ + + + + +
+ + +
+ + + + diff --git a/tests/virshtestdata/snapshot-s3.xml b/tests/virshtestdata/snap= shot-s3.xml new file mode 100644 index 0000000000..80d65074e1 --- /dev/null +++ b/tests/virshtestdata/snapshot-s3.xml @@ -0,0 +1,40 @@ + + s3 + running + 5678 + + + + + + test + 6695eb01-f6a4-8304-79aa-97f2502e193f + 8388608 + 2097152 + 2 + + hvm + + + + destroy + restart + destroy + + + + +
+ + + + + +
+ + +
+ + + + diff --git a/tests/virshtestdata/snapshot.in b/tests/virshtestdata/snapshot= .in new file mode 100755 index 0000000000..9e73db7ba7 --- /dev/null +++ b/tests/virshtestdata/snapshot.in @@ -0,0 +1,54 @@ +echo Create a series of snapshots, with names that intentionally sort +echo differently by topology than by name. Use revert to create fanout. +snapshot-create-as test s1 +snapshot-create-as test s1 +snapshot-create-as test s3 +snapshot-create-as test s2 +snapshot-revert test s3 +snapshot-create-as test s6 +snapshot-create-as test s5 +snapshot-revert test s6 +snapshot-create-as test s4 +snapshot-revert test s1 +snapshot-create-as test s7 +snapshot-create-as test s8 + +echo checkpoints cannot be created while snapshots exist +checkpoint-create-as test c1 + +echo Checking tree view (siblings sorted alphabetically) +snapshot-list test --tree + +echo Current was last one created, but we can change that +snapshot-current test --name +snapshot-current test s1 +snapshot-current test --name + +echo Deleting current root leads to multiple roots, demonstrate list filte= ring +snapshot-delete test --current +snapshot-current test --name + +echo list roots +snapshot-list test --roots --name +echo list leaves +snapshot-list test --leaves --name +echo list no-leaves +snapshot-list test --parent --no-leaves --name +echo list from +snapshot-list test --from s3 --name +snapshot-list test --from s3 --descendants --name + +echo More fun with delete flags, current node moves up to remaining parent +snapshot-current test s4 +snapshot-delete test --children-only s6 +snapshot-current test --name +snapshot-delete test --children s7 +snapshot-current test --name +snapshot-delete test s6 +snapshot-current test --name + +echo Now the tree is linear, so we have an unambiguous topological order +snapshot-list test --name +snapshot-list test --name --topological +snapshot-dumpxml test s3 +snapshot-dumpxml test s2 diff --git a/tests/virshtestdata/snapshot.out b/tests/virshtestdata/snapsho= t.out new file mode 100644 index 0000000000..03268415d7 --- /dev/null +++ b/tests/virshtestdata/snapshot.out @@ -0,0 +1,173 @@ +Create a series of snapshots, with names that intentionally sort +differently by topology than by name. Use revert to create fanout. +Domain snapshot s1 created +error: operation failed: domain moment s1 already exists + +Domain snapshot s3 created +Domain snapshot s2 created +Domain snapshot s3 reverted + +Domain snapshot s6 created +Domain snapshot s5 created +Domain snapshot s6 reverted + +Domain snapshot s4 created +Domain snapshot s1 reverted + +Domain snapshot s7 created +Domain snapshot s8 created +checkpoints cannot be created while snapshots exist +error: Operation not supported: cannot create checkpoint while snapshot ex= ists + +Checking tree view (siblings sorted alphabetically) +s1 + | + +- s3 + | | + | +- s2 + | +- s6 + | | + | +- s4 + | +- s5 + | =20 + +- s7 + | + +- s8 + =20 + +Current was last one created, but we can change that +s8 +Snapshot s1 set as current +s1 +Deleting current root leads to multiple roots, demonstrate list filtering +Domain snapshot s1 deleted + +error: domain 'test' has no current snapshot + +list roots +s3 +s7 + +list leaves +s2 +s4 +s5 +s8 + +list no-leaves +s3 +s6 s3 +s7 + +list from +s2 +s6 + +s2 +s4 +s5 +s6 + +More fun with delete flags, current node moves up to remaining parent +Snapshot s4 set as current +Domain snapshot s6 children deleted + +s6 +Domain snapshot s7 deleted + +s6 +Domain snapshot s6 deleted + +s3 +Now the tree is linear, so we have an unambiguous topological order +s2 +s3 + +s3 +s2 + + + s3 + running + =20 + + + + + + test + 6695eb01-f6a4-8304-79aa-97f2502e193f + 8388608 + 2097152 + 2 + + hvm + + + + destroy + restart + destroy + + + + +
+ + + + + +
+ + +
+ + + + + + + s2 + running + + s3 + + =20 + + + + + + test + 6695eb01-f6a4-8304-79aa-97f2502e193f + 8388608 + 2097152 + 2 + + hvm + + + + destroy + restart + destroy + + + + +
+ + + + + +
+ + +
+ + + + + --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org