1*7b14f231SMax Reitz#!/usr/bin/env python 2*7b14f231SMax Reitz# 3*7b14f231SMax Reitz# Test json:{} filenames with qemu-internal BDSs 4*7b14f231SMax Reitz# (the one of commit, to be precise) 5*7b14f231SMax Reitz# 6*7b14f231SMax Reitz# Copyright (C) 2018 Red Hat, Inc. 7*7b14f231SMax Reitz# 8*7b14f231SMax Reitz# This program is free software; you can redistribute it and/or modify 9*7b14f231SMax Reitz# it under the terms of the GNU General Public License as published by 10*7b14f231SMax Reitz# the Free Software Foundation; either version 2 of the License, or 11*7b14f231SMax Reitz# (at your option) any later version. 12*7b14f231SMax Reitz# 13*7b14f231SMax Reitz# This program is distributed in the hope that it will be useful, 14*7b14f231SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 15*7b14f231SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*7b14f231SMax Reitz# GNU General Public License for more details. 17*7b14f231SMax Reitz# 18*7b14f231SMax Reitz# You should have received a copy of the GNU General Public License 19*7b14f231SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 20*7b14f231SMax Reitz# 21*7b14f231SMax Reitz# Creator/Owner: Max Reitz <mreitz@redhat.com> 22*7b14f231SMax Reitz 23*7b14f231SMax Reitzimport iotests 24*7b14f231SMax Reitzfrom iotests import log, qemu_img, qemu_io_silent, filter_qmp_testfiles, \ 25*7b14f231SMax Reitz filter_qmp_imgfmt 26*7b14f231SMax Reitzimport json 27*7b14f231SMax Reitz 28*7b14f231SMax Reitz# Need backing file support (for arbitrary backing formats) 29*7b14f231SMax Reitziotests.verify_image_format(supported_fmts=['qcow2', 'qcow', 'qed']) 30*7b14f231SMax Reitziotests.verify_platform(['linux']) 31*7b14f231SMax Reitz 32*7b14f231SMax Reitz 33*7b14f231SMax Reitz# There are two variations of this test: 34*7b14f231SMax Reitz# (1) We do not set filter_node_name. In that case, the commit_top 35*7b14f231SMax Reitz# driver should not appear anywhere. 36*7b14f231SMax Reitz# (2) We do set filter_node_name. In that case, it should appear. 37*7b14f231SMax Reitz# 38*7b14f231SMax Reitz# This for loop executes both. 39*7b14f231SMax Reitzfor filter_node_name in False, True: 40*7b14f231SMax Reitz log('') 41*7b14f231SMax Reitz log('--- filter_node_name: %s ---' % filter_node_name) 42*7b14f231SMax Reitz log('') 43*7b14f231SMax Reitz 44*7b14f231SMax Reitz with iotests.FilePath('base.img') as base_img_path, \ 45*7b14f231SMax Reitz iotests.FilePath('mid.img') as mid_img_path, \ 46*7b14f231SMax Reitz iotests.FilePath('top.img') as top_img_path, \ 47*7b14f231SMax Reitz iotests.VM() as vm: 48*7b14f231SMax Reitz 49*7b14f231SMax Reitz assert qemu_img('create', '-f', iotests.imgfmt, 50*7b14f231SMax Reitz base_img_path, '64M') == 0 51*7b14f231SMax Reitz assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, 52*7b14f231SMax Reitz mid_img_path) == 0 53*7b14f231SMax Reitz assert qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path, 54*7b14f231SMax Reitz top_img_path) == 0 55*7b14f231SMax Reitz 56*7b14f231SMax Reitz # Something to commit 57*7b14f231SMax Reitz assert qemu_io_silent(mid_img_path, '-c', 'write -P 1 0 1M') == 0 58*7b14f231SMax Reitz 59*7b14f231SMax Reitz vm.launch() 60*7b14f231SMax Reitz 61*7b14f231SMax Reitz # Change the bottom-most image's backing file (to null-co://) 62*7b14f231SMax Reitz # to enforce json:{} filenames 63*7b14f231SMax Reitz vm.qmp_log('blockdev-add', 64*7b14f231SMax Reitz node_name='top', 65*7b14f231SMax Reitz driver=iotests.imgfmt, 66*7b14f231SMax Reitz file={ 67*7b14f231SMax Reitz 'driver': 'file', 68*7b14f231SMax Reitz 'filename': top_img_path 69*7b14f231SMax Reitz }, 70*7b14f231SMax Reitz backing={ 71*7b14f231SMax Reitz 'node-name': 'mid', 72*7b14f231SMax Reitz 'driver': iotests.imgfmt, 73*7b14f231SMax Reitz 'file': { 74*7b14f231SMax Reitz 'driver': 'file', 75*7b14f231SMax Reitz 'filename': mid_img_path 76*7b14f231SMax Reitz }, 77*7b14f231SMax Reitz 'backing': { 78*7b14f231SMax Reitz 'node-name': 'base', 79*7b14f231SMax Reitz 'driver': iotests.imgfmt, 80*7b14f231SMax Reitz 'file': { 81*7b14f231SMax Reitz 'driver': 'file', 82*7b14f231SMax Reitz 'filename': base_img_path 83*7b14f231SMax Reitz }, 84*7b14f231SMax Reitz 'backing': { 85*7b14f231SMax Reitz 'driver': 'null-co' 86*7b14f231SMax Reitz } 87*7b14f231SMax Reitz } 88*7b14f231SMax Reitz }, 89*7b14f231SMax Reitz filters=[filter_qmp_testfiles, filter_qmp_imgfmt]) 90*7b14f231SMax Reitz 91*7b14f231SMax Reitz # As long as block-commit does not accept node names, we have to 92*7b14f231SMax Reitz # get our mid/base filenames here 93*7b14f231SMax Reitz mid_name = vm.node_info('mid')['image']['filename'] 94*7b14f231SMax Reitz base_name = vm.node_info('base')['image']['filename'] 95*7b14f231SMax Reitz 96*7b14f231SMax Reitz assert mid_name[:5] == 'json:' 97*7b14f231SMax Reitz assert base_name[:5] == 'json:' 98*7b14f231SMax Reitz 99*7b14f231SMax Reitz # Start the block job 100*7b14f231SMax Reitz if filter_node_name: 101*7b14f231SMax Reitz vm.qmp_log('block-commit', 102*7b14f231SMax Reitz job_id='commit', 103*7b14f231SMax Reitz device='top', 104*7b14f231SMax Reitz filter_node_name='filter_node', 105*7b14f231SMax Reitz top=mid_name, 106*7b14f231SMax Reitz base=base_name, 107*7b14f231SMax Reitz speed=1, 108*7b14f231SMax Reitz filters=[filter_qmp_testfiles, filter_qmp_imgfmt]) 109*7b14f231SMax Reitz else: 110*7b14f231SMax Reitz vm.qmp_log('block-commit', 111*7b14f231SMax Reitz job_id='commit', 112*7b14f231SMax Reitz device='top', 113*7b14f231SMax Reitz top=mid_name, 114*7b14f231SMax Reitz base=base_name, 115*7b14f231SMax Reitz speed=1, 116*7b14f231SMax Reitz filters=[filter_qmp_testfiles, filter_qmp_imgfmt]) 117*7b14f231SMax Reitz 118*7b14f231SMax Reitz vm.qmp_log('job-pause', id='commit') 119*7b14f231SMax Reitz 120*7b14f231SMax Reitz # Get and parse top's json:{} filename 121*7b14f231SMax Reitz top_name = vm.node_info('top')['image']['filename'] 122*7b14f231SMax Reitz 123*7b14f231SMax Reitz vm.shutdown() 124*7b14f231SMax Reitz 125*7b14f231SMax Reitz assert top_name[:5] == 'json:' 126*7b14f231SMax Reitz top_options = json.loads(top_name[5:]) 127*7b14f231SMax Reitz 128*7b14f231SMax Reitz if filter_node_name: 129*7b14f231SMax Reitz # This should be present and set 130*7b14f231SMax Reitz assert top_options['backing']['driver'] == 'commit_top' 131*7b14f231SMax Reitz # And the mid image is commit_top's backing image 132*7b14f231SMax Reitz mid_options = top_options['backing']['backing'] 133*7b14f231SMax Reitz else: 134*7b14f231SMax Reitz # The mid image should appear as the immediate backing BDS 135*7b14f231SMax Reitz # of top 136*7b14f231SMax Reitz mid_options = top_options['backing'] 137*7b14f231SMax Reitz 138*7b14f231SMax Reitz assert mid_options['driver'] == iotests.imgfmt 139*7b14f231SMax Reitz assert mid_options['file']['filename'] == mid_img_path 140