Skip to content

Commit d57177a

Browse files
committed
qemu-iotests: Test commit with top-node/base-node
This adds some tests for block-commit with the new options top-node and base-node (taking node names) instead of top and base (taking file names). Signed-off-by: Kevin Wolf <[email protected]>
1 parent 3c605f4 commit d57177a

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

tests/qemu-iotests/040

+50-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ class ImageCommitTestCase(iotests.QMPTestCase):
5757
self.assert_no_active_block_jobs()
5858
self.vm.shutdown()
5959

60-
def run_commit_test(self, top, base, need_ready=False):
60+
def run_commit_test(self, top, base, need_ready=False, node_names=False):
6161
self.assert_no_active_block_jobs()
62-
result = self.vm.qmp('block-commit', device='drive0', top=top, base=base)
62+
if node_names:
63+
result = self.vm.qmp('block-commit', device='drive0', top_node=top, base_node=base)
64+
else:
65+
result = self.vm.qmp('block-commit', device='drive0', top=top, base=base)
6366
self.assert_qmp(result, 'return', {})
6467
self.wait_for_complete(need_ready)
6568

@@ -101,6 +104,11 @@ class TestSingleDrive(ImageCommitTestCase):
101104
self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed"))
102105
self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed"))
103106

107+
def test_commit_node(self):
108+
self.run_commit_test("mid", "base", node_names=True)
109+
self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed"))
110+
self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed"))
111+
104112
def test_device_not_found(self):
105113
result = self.vm.qmp('block-commit', device='nonexistent', top='%s' % mid_img)
106114
self.assert_qmp(result, 'error/class', 'DeviceNotFound')
@@ -123,6 +131,30 @@ class TestSingleDrive(ImageCommitTestCase):
123131
self.assert_qmp(result, 'error/class', 'GenericError')
124132
self.assert_qmp(result, 'error/desc', 'Base \'badfile\' not found')
125133

134+
def test_top_node_invalid(self):
135+
self.assert_no_active_block_jobs()
136+
result = self.vm.qmp('block-commit', device='drive0', top_node='badfile', base_node='base')
137+
self.assert_qmp(result, 'error/class', 'GenericError')
138+
self.assert_qmp(result, 'error/desc', "Cannot find device= nor node_name=badfile")
139+
140+
def test_base_node_invalid(self):
141+
self.assert_no_active_block_jobs()
142+
result = self.vm.qmp('block-commit', device='drive0', top_node='mid', base_node='badfile')
143+
self.assert_qmp(result, 'error/class', 'GenericError')
144+
self.assert_qmp(result, 'error/desc', "Cannot find device= nor node_name=badfile")
145+
146+
def test_top_path_and_node(self):
147+
self.assert_no_active_block_jobs()
148+
result = self.vm.qmp('block-commit', device='drive0', top_node='mid', base_node='base', top='%s' % mid_img)
149+
self.assert_qmp(result, 'error/class', 'GenericError')
150+
self.assert_qmp(result, 'error/desc', "'top-node' and 'top' are mutually exclusive")
151+
152+
def test_base_path_and_node(self):
153+
self.assert_no_active_block_jobs()
154+
result = self.vm.qmp('block-commit', device='drive0', top_node='mid', base_node='base', base='%s' % backing_img)
155+
self.assert_qmp(result, 'error/class', 'GenericError')
156+
self.assert_qmp(result, 'error/desc', "'base-node' and 'base' are mutually exclusive")
157+
126158
def test_top_is_active(self):
127159
self.run_commit_test(test_img, backing_img, need_ready=True)
128160
self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed"))
@@ -139,6 +171,22 @@ class TestSingleDrive(ImageCommitTestCase):
139171
self.assert_qmp(result, 'error/class', 'GenericError')
140172
self.assert_qmp(result, 'error/desc', 'Base \'%s\' not found' % mid_img)
141173

174+
def test_top_and_base_node_reversed(self):
175+
self.assert_no_active_block_jobs()
176+
result = self.vm.qmp('block-commit', device='drive0', top_node='base', base_node='top')
177+
self.assert_qmp(result, 'error/class', 'GenericError')
178+
self.assert_qmp(result, 'error/desc', "'top' is not in this backing file chain")
179+
180+
def test_top_node_in_wrong_chain(self):
181+
self.assert_no_active_block_jobs()
182+
183+
result = self.vm.qmp('blockdev-add', driver='null-co', node_name='null')
184+
self.assert_qmp(result, 'return', {})
185+
186+
result = self.vm.qmp('block-commit', device='drive0', top_node='null', base_node='base')
187+
self.assert_qmp(result, 'error/class', 'GenericError')
188+
self.assert_qmp(result, 'error/desc', "'null' is not in this backing file chain")
189+
142190
# When the job is running on a BB that is automatically deleted on hot
143191
# unplug, the job is cancelled when the device disappears
144192
def test_hot_unplug(self):

tests/qemu-iotests/040.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
.............................
1+
...........................................
22
----------------------------------------------------------------------
3-
Ran 29 tests
3+
Ran 43 tests
44

55
OK

0 commit comments

Comments
 (0)