[PATCH 29/35] virshtest: Adapt 'virsh-checkpoint' 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 checkpoint creation time, which were converted to list
names-only.

To proprely test redefinition we store XMLs rather than taking them from
the defined checkpoints and use them separately to test redefinition of
checkpoint 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-checkpoint                      | 178 --------------------
 tests/virshtest.c                           |  10 ++
 tests/virshtestdata/checkpoint-c2.xml       |  41 +++++
 tests/virshtestdata/checkpoint-c3.xml       |  38 +++++
 tests/virshtestdata/checkpoint-redefine.out |  13 ++
 tests/virshtestdata/checkpoint.in           |  35 ++++
 tests/virshtestdata/checkpoint.out          | 133 +++++++++++++++
 8 files changed, 270 insertions(+), 179 deletions(-)
 delete mode 100755 tests/virsh-checkpoint
 create mode 100644 tests/virshtestdata/checkpoint-c2.xml
 create mode 100644 tests/virshtestdata/checkpoint-c3.xml
 create mode 100644 tests/virshtestdata/checkpoint-redefine.out
 create mode 100755 tests/virshtestdata/checkpoint.in
 create mode 100644 tests/virshtestdata/checkpoint.out

diff --git a/tests/meson.build b/tests/meson.build
index efbe99f55e..46e1679ad7 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -691,7 +691,6 @@ if conf.has('WITH_LIBVIRTD')
     'libvirtd-fail',
     'libvirtd-pool',
     'virsh-auth',
-    'virsh-checkpoint',
     'virsh-read-bufsiz',
     'virsh-read-non-seekable',
     'virsh-self-test',
diff --git a/tests/virsh-checkpoint b/tests/virsh-checkpoint
deleted file mode 100755
index 2492d29f53..0000000000
--- a/tests/virsh-checkpoint
+++ /dev/null
@@ -1,178 +0,0 @@
-#!/bin/sh
-# simple testing of checkpoint 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 checkpoints, with names that intentionally sort
-  # differently by topology than by name. For now, it is not possible
-  # to create fanout without hacking through redefines.
-  checkpoint-create-as test c1
-  checkpoint-create-as test c1
-  checkpoint-create-as test c3
-  checkpoint-create-as test c2
-  # snapshots cannot be created while checkpoints exist
-  echo --err marker
-  snapshot-create-as test s1
-  echo --err marker
-  # Checking tree view (siblings sorted alphabetically)
-  checkpoint-list test --tree
-  # Demonstrate list filtering
-  checkpoint-list test --roots
-  checkpoint-list test --leaves
-  checkpoint-list test --parent --no-leaves
-  checkpoint-list test --from c3
-  checkpoint-list test --from c1 --descendants --name
-  # Now the tree is linear, so we have an unambiguous topological order
-  checkpoint-list test --name
-  checkpoint-list test --name --topological
-  # Capture some XML for later redefine
-  checkpoint-delete test c1
-  echo "<!--MarkerA-->"
-  checkpoint-dumpxml test c3
-  echo "<!--MarkerB-->"
-  checkpoint-dumpxml test c2
-  echo "<!--MarkerC-->"
-  # Deleting current checkpoint moves current up to remaining parent
-  checkpoint-delete test --children-only c3
-  checkpoint-list test --leaves --name
-  checkpoint-delete test --children c3
-  checkpoint-list test --leaves --name
-  # All done
-' || fail=1
-
-# First part is expected output, --tree results in trailing spaces,
-# and checkpoint-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 checkpoint XMLs
-sed -n '/MarkerA/,/MarkerB/p' < out > c3.xml || fail=1
-sed -n '/MarkerB/,/MarkerC/p' < out > c2.xml || fail=1
-
-cat <<\EOF > exp || fail=1
-Domain checkpoint c1 created
-
-Domain checkpoint c3 created
-Domain checkpoint c2 created
-
-
-
-c1
-  |
-  +- c3
-      |
-      +- c2
-
-
- Name   Creation Time
------------------------------------
- c1     TIMESTAMP
-
- Name   Creation Time
------------------------------------
- c2     TIMESTAMP
-
- Name   Creation Time               Parent
---------------------------------------------
- c1     TIMESTAMP
- c3     TIMESTAMP   c1
-
- Name   Creation Time
------------------------------------
- c2     TIMESTAMP
-
-c2
-c3
-
-c1
-c2
-c3
-
-c1
-c3
-c2
-
-Domain checkpoint c1 deleted
-
-Domain checkpoint c3 children deleted
-
-c3
-
-Domain checkpoint c3 deleted
-
-
-EOF
-compare exp out.cooked || fail=1
-
-cat <<EOF > exp || fail=1
-error: operation failed: domain moment c1 already exists
-error: marker
-error: Operation not supported: cannot create snapshot while checkpoint exists
-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
-  checkpoint-create test --redefine c2.xml
-  echo --err marker
-  # This is the right order
-  checkpoint-create test --redefine c3.xml
-  checkpoint-create test --redefine c2.xml
-  checkpoint-list test --leaves --name
-  checkpoint-info test c2
-' || fail=1
-
-cat <<\EOF > exp || fail=1
-
-
-Domain checkpoint c3 created from 'c3.xml'
-Domain checkpoint c2 created from 'c2.xml'
-c2
-
-Name:           c2
-Domain:         test
-Parent:         c3
-Children:       0
-Descendants:    0
-
-EOF
-compare exp out || fail=1
-
-cat <<EOF > exp || fail=1
-error: invalid argument: parent c3 for moment c2 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 83baac8c43..8bb94b7693 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -228,6 +228,16 @@ mymain(void)
                  "snapshot-create test --redefine snapshot-s2.xml --current --validate ;"
                  "snapshot-info test --current");

+    DO_TEST_SCRIPT("checkpoint", "<creationTime", VIRSH_DEFAULT);
+    DO_TEST_FULL("checkpoint-redefine", NULL, VIRSH_DEFAULT,
+                 "cd " abs_srcdir "/virshtestdata ;"
+                 "echo 'Redefine must be in topological order; this will fail' ;"
+                 "checkpoint-create test --redefine checkpoint-c2.xml ;"
+                 "echo 'correct order' ;"
+                 "checkpoint-create test --redefine checkpoint-c3.xml ;"
+                 "checkpoint-create test --redefine checkpoint-c2.xml ;"
+                 "checkpoint-info test c2");
+
     VIR_FREE(custom_uri);
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/virshtestdata/checkpoint-c2.xml b/tests/virshtestdata/checkpoint-c2.xml
new file mode 100644
index 0000000000..6879eb992f
--- /dev/null
+++ b/tests/virshtestdata/checkpoint-c2.xml
@@ -0,0 +1,41 @@
+<domaincheckpoint>
+  <name>c2</name>
+  <parent>
+    <name>c3</name>
+  </parent>
+  <creationTime>1234</creationTime>
+  <disks>
+    <disk name='vda' checkpoint='bitmap' bitmap='c2'/>
+  </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>
+</domaincheckpoint>
diff --git a/tests/virshtestdata/checkpoint-c3.xml b/tests/virshtestdata/checkpoint-c3.xml
new file mode 100644
index 0000000000..c960a8553b
--- /dev/null
+++ b/tests/virshtestdata/checkpoint-c3.xml
@@ -0,0 +1,38 @@
+<domaincheckpoint>
+  <name>c3</name>
+  <creationTime>5678</creationTime>
+  <disks>
+    <disk name='vda' checkpoint='bitmap' bitmap='c3'/>
+  </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>
+</domaincheckpoint>
diff --git a/tests/virshtestdata/checkpoint-redefine.out b/tests/virshtestdata/checkpoint-redefine.out
new file mode 100644
index 0000000000..83fccbc799
--- /dev/null
+++ b/tests/virshtestdata/checkpoint-redefine.out
@@ -0,0 +1,13 @@
+
+Redefine must be in topological order; this will fail
+error: invalid argument: parent c3 for moment c2 not found
+
+correct order
+Domain checkpoint c3 created from 'checkpoint-c3.xml'
+Domain checkpoint c2 created from 'checkpoint-c2.xml'
+Name:           c2
+Domain:         test
+Parent:         c3
+Children:       0
+Descendants:    0
+
diff --git a/tests/virshtestdata/checkpoint.in b/tests/virshtestdata/checkpoint.in
new file mode 100755
index 0000000000..760f1fb648
--- /dev/null
+++ b/tests/virshtestdata/checkpoint.in
@@ -0,0 +1,35 @@
+echo Create a series of checkpoints, with names that intentionally sort
+echo differently by topology than by name. For now, it is not possible
+echo to create fanout without hacking through redefines.
+checkpoint-create-as test c1
+checkpoint-create-as test c1
+checkpoint-create-as test c3
+checkpoint-create-as test c2
+
+echo snapshots cannot be created while checkpoints exist
+snapshot-create-as test s1
+
+echo Checking tree view (siblings sorted alphabetically)
+checkpoint-list test --tree
+
+echo Demonstrate list filtering
+checkpoint-list test --roots --name
+checkpoint-list test --leaves --name
+checkpoint-list test --parent --no-leaves --name
+checkpoint-list test --from c3 --name
+checkpoint-list test --from c1 --descendants --name
+
+echo Now the tree is linear, so we have an unambiguous topological order
+checkpoint-list test --name
+checkpoint-list test --name --topological
+
+echo validate XML
+checkpoint-delete test c1
+checkpoint-dumpxml test c3
+checkpoint-dumpxml test c2
+
+echo Deleting current checkpoint moves current up to remaining parent
+checkpoint-delete test --children-only c3
+checkpoint-list test --leaves --name
+checkpoint-delete test --children c3
+checkpoint-list test --leaves --name
diff --git a/tests/virshtestdata/checkpoint.out b/tests/virshtestdata/checkpoint.out
new file mode 100644
index 0000000000..285bb0648f
--- /dev/null
+++ b/tests/virshtestdata/checkpoint.out
@@ -0,0 +1,133 @@
+Create a series of checkpoints, with names that intentionally sort
+differently by topology than by name. For now, it is not possible
+to create fanout without hacking through redefines.
+Domain checkpoint c1 created
+error: operation failed: domain moment c1 already exists
+
+Domain checkpoint c3 created
+Domain checkpoint c2 created
+snapshots cannot be created while checkpoints exist
+error: Operation not supported: cannot create snapshot while checkpoint exists
+
+Checking tree view (siblings sorted alphabetically)
+c1
+  |
+  +- c3
+      |
+      +- c2
+        
+
+Demonstrate list filtering
+c1
+
+c2
+
+c1
+c3	c1
+
+c2
+
+c2
+c3
+
+Now the tree is linear, so we have an unambiguous topological order
+c1
+c2
+c3
+
+c1
+c3
+c2
+
+validate XML
+Domain checkpoint c1 deleted
+
+<domaincheckpoint>
+  <name>c3</name>
+  
+  <disks>
+    <disk name='vda' checkpoint='bitmap' bitmap='c3'/>
+  </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>
+</domaincheckpoint>
+
+<domaincheckpoint>
+  <name>c2</name>
+  <parent>
+    <name>c3</name>
+  </parent>
+  
+  <disks>
+    <disk name='vda' checkpoint='bitmap' bitmap='c2'/>
+  </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>
+</domaincheckpoint>
+
+Deleting current checkpoint moves current up to remaining parent
+Domain checkpoint c3 children deleted
+
+c3
+
+Domain checkpoint c3 deleted
+
+
-- 
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