Blame SOURCES/kvm-iotests-Add-test-for-cancelling-a-mirror-job.patch

383d26
From 2476593dd4bc78bbf9183e873f2ca641ce15fddf Mon Sep 17 00:00:00 2001
383d26
From: Max Reitz <mreitz@redhat.com>
383d26
Date: Mon, 18 Jun 2018 14:47:36 +0200
383d26
Subject: [PATCH 26/54] iotests: Add test for cancelling a mirror job
383d26
383d26
RH-Author: Max Reitz <mreitz@redhat.com>
383d26
Message-id: <20180618144736.29873-4-mreitz@redhat.com>
383d26
Patchwork-id: 80745
383d26
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 3/3] iotests: Add test for cancelling a mirror job
383d26
Bugzilla: 1572856
383d26
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
383d26
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
383d26
RH-Acked-by: John Snow <jsnow@redhat.com>
383d26
383d26
We already have an extensive mirror test (041) which does cover
383d26
cancelling a mirror job, especially after it has emitted the READY
383d26
event.  However, it does not check what exact events are emitted after
383d26
block-job-cancel is executed.  More importantly, it does not use
383d26
throttling to ensure that it covers the case of block-job-cancel before
383d26
READY.
383d26
383d26
It would be possible to add this case to 041, but considering it is
383d26
already our largest test file, it makes sense to create a new file for
383d26
these cases.
383d26
383d26
Signed-off-by: Max Reitz <mreitz@redhat.com>
383d26
Message-id: 20180501220509.14152-3-mreitz@redhat.com
383d26
Signed-off-by: Jeff Cody <jcody@redhat.com>
383d26
(cherry picked from commit dc885fff972c447f51572afc4c921a26b880731b)
383d26
Signed-off-by: Max Reitz <mreitz@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 tests/qemu-iotests/218     | 138 +++++++++++++++++++++++++++++++++++++++++++++
383d26
 tests/qemu-iotests/218.out |  30 ++++++++++
383d26
 tests/qemu-iotests/group   |   1 +
383d26
 3 files changed, 169 insertions(+)
383d26
 create mode 100644 tests/qemu-iotests/218
383d26
 create mode 100644 tests/qemu-iotests/218.out
383d26
383d26
diff --git a/tests/qemu-iotests/218 b/tests/qemu-iotests/218
383d26
new file mode 100644
383d26
index 0000000..92c331b
383d26
--- /dev/null
383d26
+++ b/tests/qemu-iotests/218
383d26
@@ -0,0 +1,138 @@
383d26
+#!/usr/bin/env python
383d26
+#
383d26
+# This test covers what happens when a mirror block job is cancelled
383d26
+# in various phases of its existence.
383d26
+#
383d26
+# Note that this test only checks the emitted events (i.e.
383d26
+# BLOCK_JOB_COMPLETED vs. BLOCK_JOB_CANCELLED), it does not compare
383d26
+# whether the target is in sync with the source when the
383d26
+# BLOCK_JOB_COMPLETED event occurs.  This is covered by other tests
383d26
+# (such as 041).
383d26
+#
383d26
+# Copyright (C) 2018 Red Hat, Inc.
383d26
+#
383d26
+# This program is free software; you can redistribute it and/or modify
383d26
+# it under the terms of the GNU General Public License as published by
383d26
+# the Free Software Foundation; either version 2 of the License, or
383d26
+# (at your option) any later version.
383d26
+#
383d26
+# This program is distributed in the hope that it will be useful,
383d26
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
383d26
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
383d26
+# GNU General Public License for more details.
383d26
+#
383d26
+# You should have received a copy of the GNU General Public License
383d26
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
383d26
+#
383d26
+# Creator/Owner: Max Reitz <mreitz@redhat.com>
383d26
+
383d26
+import iotests
383d26
+from iotests import log
383d26
+
383d26
+iotests.verify_platform(['linux'])
383d26
+
383d26
+
383d26
+# Launches the VM, adds two null-co nodes (source and target), and
383d26
+# starts a blockdev-mirror job on them.
383d26
+#
383d26
+# Either both or none of speed and buf_size must be given.
383d26
+
383d26
+def start_mirror(vm, speed=None, buf_size=None):
383d26
+    vm.launch()
383d26
+
383d26
+    ret = vm.qmp('blockdev-add',
383d26
+                     node_name='source',
383d26
+                     driver='null-co',
383d26
+                     size=1048576)
383d26
+    assert ret['return'] == {}
383d26
+
383d26
+    ret = vm.qmp('blockdev-add',
383d26
+                     node_name='target',
383d26
+                     driver='null-co',
383d26
+                     size=1048576)
383d26
+    assert ret['return'] == {}
383d26
+
383d26
+    if speed is not None:
383d26
+        ret = vm.qmp('blockdev-mirror',
383d26
+                         job_id='mirror',
383d26
+                         device='source',
383d26
+                         target='target',
383d26
+                         sync='full',
383d26
+                         speed=speed,
383d26
+                         buf_size=buf_size)
383d26
+    else:
383d26
+        ret = vm.qmp('blockdev-mirror',
383d26
+                         job_id='mirror',
383d26
+                         device='source',
383d26
+                         target='target',
383d26
+                         sync='full')
383d26
+
383d26
+    assert ret['return'] == {}
383d26
+
383d26
+
383d26
+log('')
383d26
+log('=== Cancel mirror job before convergence ===')
383d26
+log('')
383d26
+
383d26
+log('--- force=false ---')
383d26
+log('')
383d26
+
383d26
+with iotests.VM() as vm:
383d26
+    # Low speed so it does not converge
383d26
+    start_mirror(vm, 65536, 65536)
383d26
+
383d26
+    log('Cancelling job')
383d26
+    log(vm.qmp('block-job-cancel', device='mirror', force=False))
383d26
+
383d26
+    log(vm.event_wait('BLOCK_JOB_CANCELLED'),
383d26
+        filters=[iotests.filter_qmp_event])
383d26
+
383d26
+log('')
383d26
+log('--- force=true ---')
383d26
+log('')
383d26
+
383d26
+with iotests.VM() as vm:
383d26
+    # Low speed so it does not converge
383d26
+    start_mirror(vm, 65536, 65536)
383d26
+
383d26
+    log('Cancelling job')
383d26
+    log(vm.qmp('block-job-cancel', device='mirror', force=True))
383d26
+
383d26
+    log(vm.event_wait('BLOCK_JOB_CANCELLED'),
383d26
+        filters=[iotests.filter_qmp_event])
383d26
+
383d26
+
383d26
+log('')
383d26
+log('=== Cancel mirror job after convergence ===')
383d26
+log('')
383d26
+
383d26
+log('--- force=false ---')
383d26
+log('')
383d26
+
383d26
+with iotests.VM() as vm:
383d26
+    start_mirror(vm)
383d26
+
383d26
+    log(vm.event_wait('BLOCK_JOB_READY'),
383d26
+        filters=[iotests.filter_qmp_event])
383d26
+
383d26
+    log('Cancelling job')
383d26
+    log(vm.qmp('block-job-cancel', device='mirror', force=False))
383d26
+
383d26
+    log(vm.event_wait('BLOCK_JOB_COMPLETED'),
383d26
+        filters=[iotests.filter_qmp_event])
383d26
+
383d26
+log('')
383d26
+log('--- force=true ---')
383d26
+log('')
383d26
+
383d26
+with iotests.VM() as vm:
383d26
+    start_mirror(vm)
383d26
+
383d26
+    log(vm.event_wait('BLOCK_JOB_READY'),
383d26
+        filters=[iotests.filter_qmp_event])
383d26
+
383d26
+    log('Cancelling job')
383d26
+    log(vm.qmp('block-job-cancel', device='mirror', force=True))
383d26
+
383d26
+    log(vm.event_wait('BLOCK_JOB_CANCELLED'),
383d26
+        filters=[iotests.filter_qmp_event])
383d26
diff --git a/tests/qemu-iotests/218.out b/tests/qemu-iotests/218.out
383d26
new file mode 100644
383d26
index 0000000..7dbf78e
383d26
--- /dev/null
383d26
+++ b/tests/qemu-iotests/218.out
383d26
@@ -0,0 +1,30 @@
383d26
+
383d26
+=== Cancel mirror job before convergence ===
383d26
+
383d26
+--- force=false ---
383d26
+
383d26
+Cancelling job
383d26
+{u'return': {}}
383d26
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror', u'type': u'mirror', u'speed': 65536, u'len': 1048576, u'offset': 65536}, u'event': u'BLOCK_JOB_CANCELLED'}
383d26
+
383d26
+--- force=true ---
383d26
+
383d26
+Cancelling job
383d26
+{u'return': {}}
383d26
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror', u'type': u'mirror', u'speed': 65536, u'len': 1048576, u'offset': 65536}, u'event': u'BLOCK_JOB_CANCELLED'}
383d26
+
383d26
+=== Cancel mirror job after convergence ===
383d26
+
383d26
+--- force=false ---
383d26
+
383d26
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror', u'type': u'mirror', u'speed': 0, u'len': 1048576, u'offset': 1048576}, u'event': u'BLOCK_JOB_READY'}
383d26
+Cancelling job
383d26
+{u'return': {}}
383d26
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror', u'type': u'mirror', u'speed': 0, u'len': 1048576, u'offset': 1048576}, u'event': u'BLOCK_JOB_COMPLETED'}
383d26
+
383d26
+--- force=true ---
383d26
+
383d26
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror', u'type': u'mirror', u'speed': 0, u'len': 1048576, u'offset': 1048576}, u'event': u'BLOCK_JOB_READY'}
383d26
+Cancelling job
383d26
+{u'return': {}}
383d26
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror', u'type': u'mirror', u'speed': 0, u'len': 1048576, u'offset': 1048576}, u'event': u'BLOCK_JOB_CANCELLED'}
383d26
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
383d26
index 99777ec..3a89aed 100644
383d26
--- a/tests/qemu-iotests/group
383d26
+++ b/tests/qemu-iotests/group
383d26
@@ -212,3 +212,4 @@
383d26
 211 rw auto quick
383d26
 212 rw auto quick
383d26
 213 rw auto quick
383d26
+218 rw auto quick
383d26
-- 
383d26
1.8.3.1
383d26