yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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