virshtest: Adapt 'virsh-snapshot' test

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 <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2024-03-21 13:49:07 +01:00
parent eb82c632e3
commit c8d5703150
8 changed files with 337 additions and 234 deletions

View File

@ -695,7 +695,6 @@ if conf.has('WITH_LIBVIRTD')
'virsh-read-bufsiz', 'virsh-read-bufsiz',
'virsh-read-non-seekable', 'virsh-read-non-seekable',
'virsh-self-test', 'virsh-self-test',
'virsh-snapshot',
'virsh-uriprecedence', 'virsh-uriprecedence',
'virt-admin-self-test', 'virt-admin-self-test',
] ]

View File

@ -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
# <http://www.gnu.org/licenses/>.
. "$(dirname $0)/test-lib.sh"
test_expensive
if test "$VERBOSE" = yes; then
set -x
$abs_top_builddir/tools/virsh --version
fi
fail=0
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 filtering
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 "<!--MarkerA-->"
snapshot-dumpxml test s3
echo "<!--MarkerB-->"
snapshot-dumpxml test s2
echo "<!--MarkerC-->"
# All done
' || fail=1
# 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=1
# Second part holds domain snapshot XMLs
sed -n '/MarkerA/,/MarkerB/p' < out > s3.xml || fail=1
sed -n '/MarkerB/,/MarkerC/p' < out > s2.xml || fail=1
cat <<\EOF > exp || fail=1
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=1
cat <<EOF > exp || fail=1
error: operation failed: domain moment s1 already exists
error: marker
error: Operation not supported: cannot create checkpoint while snapshot exists
error: marker
error: marker
error: domain 'test' has no current snapshot
error: marker
EOF
compare exp err || fail=1
# 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=1
cat <<\EOF > exp || fail=1
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=1
cat <<EOF > exp || fail=1
error: invalid argument: parent s3 for moment s2 not found
error: marker
EOF
compare exp err || fail=1
(exit $fail); exit $fail

View File

@ -218,6 +218,16 @@ mymain(void)
DO_TEST_FULL("domain-id-overflow", NULL, VIRSH_CUSTOM, "-q", "domname", "4294967298"); DO_TEST_FULL("domain-id-overflow", NULL, VIRSH_CUSTOM, "-q", "domname", "4294967298");
DO_TEST_FULL("schedinfo-invalid-argument", NULL, VIRSH_DEFAULT, "schedinfo", "1", "--set", "j=k"); DO_TEST_FULL("schedinfo-invalid-argument", NULL, VIRSH_DEFAULT, "schedinfo", "1", "--set", "j=k");
DO_TEST_SCRIPT("snapshot", "<creationTime", VIRSH_DEFAULT);
DO_TEST_FULL("snapshot-redefine", NULL, VIRSH_DEFAULT,
"cd " abs_srcdir "/virshtestdata ;"
"echo 'Redefine must be in topological order; this will fail' ;"
"snapshot-create test --redefine snapshot-s2.xml --validate ;"
"echo 'correct order' ;"
"snapshot-create test --redefine snapshot-s3.xml --validate ;"
"snapshot-create test --redefine snapshot-s2.xml --current --validate ;"
"snapshot-info test --current");
VIR_FREE(custom_uri); VIR_FREE(custom_uri);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }

View File

@ -0,0 +1,17 @@
Redefine must be in topological order; this will fail
error: invalid argument: parent s3 for moment s2 not found
correct order
Domain snapshot s3 created from 'snapshot-s3.xml'
Domain snapshot s2 created from 'snapshot-s2.xml'
Name: s2
Domain: test
Current: yes
State: running
Location: internal
Parent: s3
Children: 0
Descendants: 0
Metadata: yes

View File

@ -0,0 +1,43 @@
<domainsnapshot>
<name>s2</name>
<state>running</state>
<parent>
<name>s3</name>
</parent>
<creationTime>1234</creationTime>
<memory snapshot='internal'/>
<disks>
<disk name='vda' snapshot='internal'/>
</disks>
<domain type='test'>
<name>test</name>
<uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid>
<memory unit='KiB'>8388608</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='i686'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<source file='/guest/diskimage1'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</disk>
<interface type='network'>
<mac address='aa:bb:cc:dd:ee:ff'/>
<source network='default'/>
<target dev='testnet0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
</interface>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</memballoon>
</devices>
</domain>
</domainsnapshot>

View File

@ -0,0 +1,40 @@
<domainsnapshot>
<name>s3</name>
<state>running</state>
<creationTime>5678</creationTime>
<memory snapshot='internal'/>
<disks>
<disk name='vda' snapshot='internal'/>
</disks>
<domain type='test'>
<name>test</name>
<uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid>
<memory unit='KiB'>8388608</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='i686'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<source file='/guest/diskimage1'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</disk>
<interface type='network'>
<mac address='aa:bb:cc:dd:ee:ff'/>
<source network='default'/>
<target dev='testnet0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
</interface>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</memballoon>
</devices>
</domain>
</domainsnapshot>

54
tests/virshtestdata/snapshot.in Executable file
View File

@ -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 filtering
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

View File

@ -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 exists
Checking tree view (siblings sorted alphabetically)
s1
|
+- s3
| |
| +- s2
| +- s6
| |
| +- s4
| +- s5
|
+- s7
|
+- s8
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
<domainsnapshot>
<name>s3</name>
<state>running</state>
<memory snapshot='internal'/>
<disks>
<disk name='vda' snapshot='internal'/>
</disks>
<domain type='test'>
<name>test</name>
<uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid>
<memory unit='KiB'>8388608</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='i686'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<source file='/guest/diskimage1'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</disk>
<interface type='network'>
<mac address='aa:bb:cc:dd:ee:ff'/>
<source network='default'/>
<target dev='testnet0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
</interface>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</memballoon>
</devices>
</domain>
</domainsnapshot>
<domainsnapshot>
<name>s2</name>
<state>running</state>
<parent>
<name>s3</name>
</parent>
<memory snapshot='internal'/>
<disks>
<disk name='vda' snapshot='internal'/>
</disks>
<domain type='test'>
<name>test</name>
<uuid>6695eb01-f6a4-8304-79aa-97f2502e193f</uuid>
<memory unit='KiB'>8388608</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='i686'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<source file='/guest/diskimage1'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</disk>
<interface type='network'>
<mac address='aa:bb:cc:dd:ee:ff'/>
<source network='default'/>
<target dev='testnet0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
</interface>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</memballoon>
</devices>
</domain>
</domainsnapshot>