[PATCH 28/35] virshtest: Adapt 'virsh-snapshot' test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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
-# <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
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, "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);
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/virshtestdata/snapshot-redefine.out b/tests/virshtestdata/snapshot-redefine.out
new file mode 100644
index 0000000000..cc68b5cad4
--- /dev/null
+++ b/tests/virshtestdata/snapshot-redefine.out
@@ -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
+
diff --git a/tests/virshtestdata/snapshot-s2.xml b/tests/virshtestdata/snapshot-s2.xml
new file mode 100644
index 0000000000..63d13dc4bb
--- /dev/null
+++ b/tests/virshtestdata/snapshot-s2.xml
@@ -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>
diff --git a/tests/virshtestdata/snapshot-s3.xml b/tests/virshtestdata/snapshot-s3.xml
new file mode 100644
index 0000000000..80d65074e1
--- /dev/null
+++ b/tests/virshtestdata/snapshot-s3.xml
@@ -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>
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 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
diff --git a/tests/virshtestdata/snapshot.out b/tests/virshtestdata/snapshot.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 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>
+
-- 
2.44.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux