14089f7c6SJeff Cody#!/bin/bash 24089f7c6SJeff Cody# 34089f7c6SJeff Cody# Live snapshot tests 44089f7c6SJeff Cody# 54089f7c6SJeff Cody# This tests live snapshots of images on a running QEMU instance, using 64089f7c6SJeff Cody# QMP commands. Both single disk snapshots, and transactional group 74089f7c6SJeff Cody# snapshots are performed. 84089f7c6SJeff Cody# 94089f7c6SJeff Cody# Copyright (C) 2014 Red Hat, Inc. 104089f7c6SJeff Cody# 114089f7c6SJeff Cody# This program is free software; you can redistribute it and/or modify 124089f7c6SJeff Cody# it under the terms of the GNU General Public License as published by 134089f7c6SJeff Cody# the Free Software Foundation; either version 2 of the License, or 144089f7c6SJeff Cody# (at your option) any later version. 154089f7c6SJeff Cody# 164089f7c6SJeff Cody# This program is distributed in the hope that it will be useful, 174089f7c6SJeff Cody# but WITHOUT ANY WARRANTY; without even the implied warranty of 184089f7c6SJeff Cody# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 194089f7c6SJeff Cody# GNU General Public License for more details. 204089f7c6SJeff Cody# 214089f7c6SJeff Cody# You should have received a copy of the GNU General Public License 224089f7c6SJeff Cody# along with this program. If not, see <http://www.gnu.org/licenses/>. 234089f7c6SJeff Cody# 244089f7c6SJeff Cody 254089f7c6SJeff Cody# creator 264089f7c6SJeff Codyowner=jcody@redhat.com 274089f7c6SJeff Cody 284089f7c6SJeff Codyseq=`basename $0` 294089f7c6SJeff Codyecho "QA output created by $seq" 304089f7c6SJeff Cody 314089f7c6SJeff Codyhere=`pwd` 324089f7c6SJeff Codystatus=1 # failure is the default! 334089f7c6SJeff Cody 344089f7c6SJeff Codysnapshot_virt0="snapshot-v0.qcow2" 354089f7c6SJeff Codysnapshot_virt1="snapshot-v1.qcow2" 364089f7c6SJeff Cody 374089f7c6SJeff CodyMAX_SNAPSHOTS=10 384089f7c6SJeff Cody 394089f7c6SJeff Cody_cleanup() 404089f7c6SJeff Cody{ 41*e86e8697SJeff Cody _cleanup_qemu 424089f7c6SJeff Cody for i in $(seq 1 ${MAX_SNAPSHOTS}) 434089f7c6SJeff Cody do 444089f7c6SJeff Cody rm -f "${TEST_DIR}/${i}-${snapshot_virt0}" 454089f7c6SJeff Cody rm -f "${TEST_DIR}/${i}-${snapshot_virt1}" 464089f7c6SJeff Cody done 474089f7c6SJeff Cody _cleanup_test_img 484089f7c6SJeff Cody 494089f7c6SJeff Cody} 504089f7c6SJeff Codytrap "_cleanup; exit \$status" 0 1 2 3 15 514089f7c6SJeff Cody 524089f7c6SJeff Cody# get standard environment, filters and checks 534089f7c6SJeff Cody. ./common.rc 544089f7c6SJeff Cody. ./common.filter 55*e86e8697SJeff Cody. ./common.qemu 564089f7c6SJeff Cody 574089f7c6SJeff Cody_supported_fmt qcow2 584089f7c6SJeff Cody_supported_proto file 594089f7c6SJeff Cody_supported_os Linux 604089f7c6SJeff Cody 614089f7c6SJeff Cody 624089f7c6SJeff Cody# ${1}: unique identifier for the snapshot filename 634089f7c6SJeff Codyfunction create_single_snapshot() 644089f7c6SJeff Cody{ 654089f7c6SJeff Cody cmd="{ 'execute': 'blockdev-snapshot-sync', 664089f7c6SJeff Cody 'arguments': { 'device': 'virtio0', 674089f7c6SJeff Cody 'snapshot-file':'"${TEST_DIR}/${1}-${snapshot_virt0}"', 684089f7c6SJeff Cody 'format': 'qcow2' } }" 69*e86e8697SJeff Cody _send_qemu_cmd $h "${cmd}" "return" 704089f7c6SJeff Cody} 714089f7c6SJeff Cody 724089f7c6SJeff Cody# ${1}: unique identifier for the snapshot filename 734089f7c6SJeff Codyfunction create_group_snapshot() 744089f7c6SJeff Cody{ 754089f7c6SJeff Cody cmd="{ 'execute': 'transaction', 'arguments': 764089f7c6SJeff Cody {'actions': [ 774089f7c6SJeff Cody { 'type': 'blockdev-snapshot-sync', 'data' : 784089f7c6SJeff Cody { 'device': 'virtio0', 794089f7c6SJeff Cody 'snapshot-file': '"${TEST_DIR}/${1}-${snapshot_virt0}"' } }, 804089f7c6SJeff Cody { 'type': 'blockdev-snapshot-sync', 'data' : 814089f7c6SJeff Cody { 'device': 'virtio1', 824089f7c6SJeff Cody 'snapshot-file': '"${TEST_DIR}/${1}-${snapshot_virt1}"' } } ] 834089f7c6SJeff Cody } }" 844089f7c6SJeff Cody 85*e86e8697SJeff Cody _send_qemu_cmd $h "${cmd}" "return" 864089f7c6SJeff Cody} 874089f7c6SJeff Cody 884089f7c6SJeff Codysize=128M 894089f7c6SJeff Cody 904089f7c6SJeff Cody_make_test_img $size 914089f7c6SJeff Codymv "${TEST_IMG}" "${TEST_IMG}.orig" 924089f7c6SJeff Cody_make_test_img $size 934089f7c6SJeff Cody 944089f7c6SJeff Codyecho 954089f7c6SJeff Codyecho === Running QEMU === 964089f7c6SJeff Codyecho 974089f7c6SJeff Cody 98*e86e8697SJeff Codyqemu_comm_method="qmp" 99*e86e8697SJeff Cody_launch_qemu -drive file="${TEST_IMG}.orig",if=virtio -drive file="${TEST_IMG}",if=virtio 100*e86e8697SJeff Codyh=$QEMU_HANDLE 1014089f7c6SJeff Cody 1024089f7c6SJeff Codyecho 1034089f7c6SJeff Codyecho === Sending capabilities === 1044089f7c6SJeff Codyecho 1054089f7c6SJeff Cody 106*e86e8697SJeff Cody_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" "return" 1074089f7c6SJeff Cody 1084089f7c6SJeff Codyecho 1094089f7c6SJeff Codyecho === Create a single snapshot on virtio0 === 1104089f7c6SJeff Codyecho 1114089f7c6SJeff Cody 1124089f7c6SJeff Codycreate_single_snapshot 1 1134089f7c6SJeff Cody 1144089f7c6SJeff Cody 1154089f7c6SJeff Codyecho 1164089f7c6SJeff Codyecho === Invalid command - missing device and nodename === 1174089f7c6SJeff Codyecho 1184089f7c6SJeff Cody 119*e86e8697SJeff Cody_send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot-sync', 120*e86e8697SJeff Cody 'arguments': { 'snapshot-file':'"${TEST_DIR}/1-${snapshot_virt0}"', 1214089f7c6SJeff Cody 'format': 'qcow2' } }" "error" 1224089f7c6SJeff Cody 1234089f7c6SJeff Codyecho 1244089f7c6SJeff Codyecho === Invalid command - missing snapshot-file === 1254089f7c6SJeff Codyecho 1264089f7c6SJeff Cody 127*e86e8697SJeff Cody_send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot-sync', 1284089f7c6SJeff Cody 'arguments': { 'device': 'virtio0', 1294089f7c6SJeff Cody 'format': 'qcow2' } }" "error" 1304089f7c6SJeff Codyecho 1314089f7c6SJeff Codyecho 1324089f7c6SJeff Codyecho === Create several transactional group snapshots === 1334089f7c6SJeff Codyecho 1344089f7c6SJeff Cody 1354089f7c6SJeff Codyfor i in $(seq 2 ${MAX_SNAPSHOTS}) 1364089f7c6SJeff Codydo 1374089f7c6SJeff Cody create_group_snapshot ${i} 1384089f7c6SJeff Codydone 1394089f7c6SJeff Cody 1404089f7c6SJeff Cody# success, all done 1414089f7c6SJeff Codyecho "*** done" 1424089f7c6SJeff Codyrm -f $seq.full 1434089f7c6SJeff Codystatus=0 144