2019-03-22 22:23:09 +00:00
|
|
|
#!/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"
|
|
|
|
|
|
|
|
if test "$VERBOSE" = yes; then
|
|
|
|
set -x
|
|
|
|
$abs_top_builddir/tools/virsh --version
|
|
|
|
fi
|
|
|
|
|
|
|
|
fail=0
|
|
|
|
|
2019-03-27 18:42:45 +00:00
|
|
|
mock_xdg_ || framework_failure
|
|
|
|
|
2019-03-22 22:23:09 +00:00
|
|
|
# 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
|
2019-07-24 05:03:24 +00:00
|
|
|
snapshot-create-as test s1
|
2019-03-22 22:23:09 +00:00
|
|
|
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
|
2019-07-24 05:17:23 +00:00
|
|
|
# checkpoints cannot be created while snapshots exist
|
|
|
|
echo --err marker
|
|
|
|
checkpoint-create-as test c1
|
|
|
|
echo --err marker
|
2019-03-22 22:23:09 +00:00
|
|
|
# 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
|
2019-07-12 20:43:01 +00:00
|
|
|
# Second part holds domain snapshot XMLs
|
2019-03-22 22:23:09 +00:00
|
|
|
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
|
2019-07-24 05:03:24 +00:00
|
|
|
|
2019-03-22 22:23:09 +00:00
|
|
|
Domain snapshot s3 created
|
|
|
|
Domain snapshot s2 created
|
|
|
|
|
|
|
|
Domain snapshot s6 created
|
|
|
|
Domain snapshot s5 created
|
|
|
|
|
|
|
|
Domain snapshot s4 created
|
|
|
|
|
|
|
|
Domain snapshot s7 created
|
|
|
|
Domain snapshot s8 created
|
2019-07-24 05:17:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-03-22 22:23:09 +00:00
|
|
|
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 paused
|
|
|
|
|
|
|
|
Name Creation Time State
|
|
|
|
---------------------------------------------
|
|
|
|
s2 TIMESTAMP running
|
|
|
|
s4 TIMESTAMP paused
|
|
|
|
s5 TIMESTAMP paused
|
|
|
|
s8 TIMESTAMP paused
|
|
|
|
|
|
|
|
Name Creation Time State Parent
|
|
|
|
------------------------------------------------------
|
|
|
|
s3 TIMESTAMP running
|
|
|
|
s6 TIMESTAMP paused s3
|
|
|
|
s7 TIMESTAMP paused
|
|
|
|
|
|
|
|
Name Creation Time State
|
|
|
|
---------------------------------------------
|
|
|
|
s2 TIMESTAMP running
|
|
|
|
s6 TIMESTAMP paused
|
|
|
|
|
|
|
|
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
|
2019-07-24 05:03:24 +00:00
|
|
|
error: operation failed: domain moment s1 already exists
|
2019-03-22 22:23:09 +00:00
|
|
|
error: marker
|
2019-07-24 05:17:23 +00:00
|
|
|
error: Operation not supported: cannot create checkpoint while snapshot exists
|
|
|
|
error: marker
|
|
|
|
error: marker
|
2019-03-22 22:23:09 +00:00
|
|
|
error: domain 'test' has no current snapshot
|
|
|
|
error: marker
|
|
|
|
EOF
|
|
|
|
compare exp err || fail=1
|
|
|
|
|
|
|
|
# Restore state with redefine
|
2019-08-02 13:20:08 +00:00
|
|
|
$abs_top_builddir/tools/virsh -c test:///default >out 2>err '
|
2019-03-22 22:23:09 +00:00
|
|
|
# Redefine must be in topological order; this will fail
|
snapshot: Add VIR_DOMAIN_SNAPSHOT_CREATE_VALIDATE flag
We've been doing a terrible job of performing XML validation in our
various API that parse XML with a corresponding schema (we started
with domains back in commit dd69a14f, v1.2.12, but didn't catch all
domain-related APIs, didn't document the use of the flag, and didn't
cover other XML). New APIs (like checkpoints) should do the validation
unconditionally, but it doesn't hurt to continue retrofitting existing
APIs to at least allow the option.
While there are many APIs that could be improved, this patch focuses
on wiring up a new snapshot XML creation flag through all the
hypervisors that support snapshots, as well as exposing it in 'virsh
snapshot-create'. For 'virsh snapshot-create-as', we blindly set the
flag without a command-line option, since the XML we create from the
command line should generally always comply (note that validation
might cause failures where it used to succeed, such as if we tighten
the RNG to reject a name of '../\n'); but blindly passing the flag
means we also have to add in fallback code to disable validation if
the server is too old to understand the flag.
Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
2019-07-06 03:05:37 +00:00
|
|
|
snapshot-create test --redefine s2.xml --validate
|
2019-03-22 22:23:09 +00:00
|
|
|
echo --err marker
|
|
|
|
# This is the right order
|
snapshot: Add VIR_DOMAIN_SNAPSHOT_CREATE_VALIDATE flag
We've been doing a terrible job of performing XML validation in our
various API that parse XML with a corresponding schema (we started
with domains back in commit dd69a14f, v1.2.12, but didn't catch all
domain-related APIs, didn't document the use of the flag, and didn't
cover other XML). New APIs (like checkpoints) should do the validation
unconditionally, but it doesn't hurt to continue retrofitting existing
APIs to at least allow the option.
While there are many APIs that could be improved, this patch focuses
on wiring up a new snapshot XML creation flag through all the
hypervisors that support snapshots, as well as exposing it in 'virsh
snapshot-create'. For 'virsh snapshot-create-as', we blindly set the
flag without a command-line option, since the XML we create from the
command line should generally always comply (note that validation
might cause failures where it used to succeed, such as if we tighten
the RNG to reject a name of '../\n'); but blindly passing the flag
means we also have to add in fallback code to disable validation if
the server is too old to understand the flag.
Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
2019-07-06 03:05:37 +00:00
|
|
|
snapshot-create test --redefine s3.xml --validate
|
|
|
|
snapshot-create test --redefine s2.xml --current --validate
|
2019-03-22 22:23:09 +00:00
|
|
|
snapshot-info test --current
|
2019-08-02 13:20:08 +00:00
|
|
|
' || fail=1
|
2019-03-22 22:23:09 +00:00
|
|
|
|
|
|
|
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
|
2019-08-02 13:20:08 +00:00
|
|
|
compare exp out || fail=1
|
2019-03-22 22:23:09 +00:00
|
|
|
|
|
|
|
cat <<EOF > exp || fail=1
|
2019-07-06 02:07:43 +00:00
|
|
|
error: invalid argument: parent s3 for moment s2 not found
|
2019-03-22 22:23:09 +00:00
|
|
|
error: marker
|
|
|
|
EOF
|
|
|
|
compare exp err || fail=1
|
|
|
|
|
|
|
|
(exit $fail); exit $fail
|