17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3 2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick 37b14f231SMax Reitz# 47b14f231SMax Reitz# Test json:{} filenames with qemu-internal BDSs 57b14f231SMax Reitz# (the one of commit, to be precise) 67b14f231SMax Reitz# 77b14f231SMax Reitz# Copyright (C) 2018 Red Hat, Inc. 87b14f231SMax Reitz# 97b14f231SMax Reitz# This program is free software; you can redistribute it and/or modify 107b14f231SMax Reitz# it under the terms of the GNU General Public License as published by 117b14f231SMax Reitz# the Free Software Foundation; either version 2 of the License, or 127b14f231SMax Reitz# (at your option) any later version. 137b14f231SMax Reitz# 147b14f231SMax Reitz# This program is distributed in the hope that it will be useful, 157b14f231SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 167b14f231SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 177b14f231SMax Reitz# GNU General Public License for more details. 187b14f231SMax Reitz# 197b14f231SMax Reitz# You should have received a copy of the GNU General Public License 207b14f231SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 217b14f231SMax Reitz# 227b14f231SMax Reitz# Creator/Owner: Max Reitz <mreitz@redhat.com> 237b14f231SMax Reitz 247b14f231SMax Reitzimport iotests 257b14f231SMax Reitzfrom iotests import log, qemu_img, qemu_io_silent, filter_qmp_testfiles, \ 267b14f231SMax Reitz filter_qmp_imgfmt 277b14f231SMax Reitzimport json 287b14f231SMax Reitz 297b14f231SMax Reitz# Need backing file support (for arbitrary backing formats) 307d814059SJohn Snowiotests.script_initialize(supported_fmts=['qcow2', 'qcow', 'qed'], 317d814059SJohn Snow supported_platforms=['linux']) 327b14f231SMax Reitz 337b14f231SMax Reitz 347b14f231SMax Reitz# There are two variations of this test: 357b14f231SMax Reitz# (1) We do not set filter_node_name. In that case, the commit_top 367b14f231SMax Reitz# driver should not appear anywhere. 377b14f231SMax Reitz# (2) We do set filter_node_name. In that case, it should appear. 387b14f231SMax Reitz# 397b14f231SMax Reitz# This for loop executes both. 407b14f231SMax Reitzfor filter_node_name in False, True: 417b14f231SMax Reitz log('') 427b14f231SMax Reitz log('--- filter_node_name: %s ---' % filter_node_name) 437b14f231SMax Reitz log('') 447b14f231SMax Reitz 457b14f231SMax Reitz with iotests.FilePath('base.img') as base_img_path, \ 467b14f231SMax Reitz iotests.FilePath('mid.img') as mid_img_path, \ 477b14f231SMax Reitz iotests.FilePath('top.img') as top_img_path, \ 487b14f231SMax Reitz iotests.VM() as vm: 497b14f231SMax Reitz 507b14f231SMax Reitz assert qemu_img('create', '-f', iotests.imgfmt, 517b14f231SMax Reitz base_img_path, '64M') == 0 527b14f231SMax Reitz assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, 53b66ff2c2SEric Blake '-F', iotests.imgfmt, mid_img_path) == 0 547b14f231SMax Reitz assert qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path, 55b66ff2c2SEric Blake '-F', iotests.imgfmt, top_img_path) == 0 567b14f231SMax Reitz 577b14f231SMax Reitz # Something to commit 587b14f231SMax Reitz assert qemu_io_silent(mid_img_path, '-c', 'write -P 1 0 1M') == 0 597b14f231SMax Reitz 607b14f231SMax Reitz vm.launch() 617b14f231SMax Reitz 627b14f231SMax Reitz # Change the bottom-most image's backing file (to null-co://) 637b14f231SMax Reitz # to enforce json:{} filenames 647b14f231SMax Reitz vm.qmp_log('blockdev-add', 657b14f231SMax Reitz node_name='top', 667b14f231SMax Reitz driver=iotests.imgfmt, 677b14f231SMax Reitz file={ 687b14f231SMax Reitz 'driver': 'file', 697b14f231SMax Reitz 'filename': top_img_path 707b14f231SMax Reitz }, 717b14f231SMax Reitz backing={ 727b14f231SMax Reitz 'node-name': 'mid', 737b14f231SMax Reitz 'driver': iotests.imgfmt, 747b14f231SMax Reitz 'file': { 757b14f231SMax Reitz 'driver': 'file', 767b14f231SMax Reitz 'filename': mid_img_path 777b14f231SMax Reitz }, 787b14f231SMax Reitz 'backing': { 797b14f231SMax Reitz 'node-name': 'base', 807b14f231SMax Reitz 'driver': iotests.imgfmt, 817b14f231SMax Reitz 'file': { 827b14f231SMax Reitz 'driver': 'file', 837b14f231SMax Reitz 'filename': base_img_path 847b14f231SMax Reitz }, 857b14f231SMax Reitz 'backing': { 867b14f231SMax Reitz 'driver': 'null-co' 877b14f231SMax Reitz } 887b14f231SMax Reitz } 897b14f231SMax Reitz }, 907b14f231SMax Reitz filters=[filter_qmp_testfiles, filter_qmp_imgfmt]) 917b14f231SMax Reitz 927b14f231SMax Reitz # As long as block-commit does not accept node names, we have to 937b14f231SMax Reitz # get our mid/base filenames here 947b14f231SMax Reitz mid_name = vm.node_info('mid')['image']['filename'] 957b14f231SMax Reitz base_name = vm.node_info('base')['image']['filename'] 967b14f231SMax Reitz 977b14f231SMax Reitz assert mid_name[:5] == 'json:' 987b14f231SMax Reitz assert base_name[:5] == 'json:' 997b14f231SMax Reitz 1007b14f231SMax Reitz # Start the block job 1017b14f231SMax Reitz if filter_node_name: 1027b14f231SMax Reitz vm.qmp_log('block-commit', 1037b14f231SMax Reitz job_id='commit', 1047b14f231SMax Reitz device='top', 1057b14f231SMax Reitz filter_node_name='filter_node', 1067b14f231SMax Reitz top=mid_name, 1077b14f231SMax Reitz base=base_name, 1087b14f231SMax Reitz speed=1, 1097b14f231SMax Reitz filters=[filter_qmp_testfiles, filter_qmp_imgfmt]) 1107b14f231SMax Reitz else: 1117b14f231SMax Reitz vm.qmp_log('block-commit', 1127b14f231SMax Reitz job_id='commit', 1137b14f231SMax Reitz device='top', 1147b14f231SMax Reitz top=mid_name, 1157b14f231SMax Reitz base=base_name, 1167b14f231SMax Reitz speed=1, 1177b14f231SMax Reitz filters=[filter_qmp_testfiles, filter_qmp_imgfmt]) 1187b14f231SMax Reitz 1197b14f231SMax Reitz vm.qmp_log('job-pause', id='commit') 1207b14f231SMax Reitz 1217b14f231SMax Reitz # Get and parse top's json:{} filename 1227b14f231SMax Reitz top_name = vm.node_info('top')['image']['filename'] 1237b14f231SMax Reitz 1247b14f231SMax Reitz vm.shutdown() 1257b14f231SMax Reitz 1267b14f231SMax Reitz assert top_name[:5] == 'json:' 1277b14f231SMax Reitz top_options = json.loads(top_name[5:]) 1287b14f231SMax Reitz 1297b14f231SMax Reitz if filter_node_name: 1307b14f231SMax Reitz # This should be present and set 1317b14f231SMax Reitz assert top_options['backing']['driver'] == 'commit_top' 1327b14f231SMax Reitz # And the mid image is commit_top's backing image 1337b14f231SMax Reitz mid_options = top_options['backing']['backing'] 1347b14f231SMax Reitz else: 1357b14f231SMax Reitz # The mid image should appear as the immediate backing BDS 1367b14f231SMax Reitz # of top 1377b14f231SMax Reitz mid_options = top_options['backing'] 1387b14f231SMax Reitz 1397b14f231SMax Reitz assert mid_options['driver'] == iotests.imgfmt 1407b14f231SMax Reitz assert mid_options['file']['filename'] == mid_img_path 141