qemu-iotests/118: Test media change with qdev name
We just added the option to use qdev device names in all device related block QMP commands. This patch converts some of the test cases in 118 to use qdev device names instead of BlockBackend names to cover the new way. It converts cases for each of the media change commands, but only for CD-ROM and not everywhere, so that the old way is still tested, too. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
7a9877a026
commit
486b88bdc8
@ -62,6 +62,9 @@ class ChangeBaseClass(iotests.QMPTestCase):
|
||||
self.fail('Timeout while waiting for the tray to close')
|
||||
|
||||
class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||
|
||||
device_name = None
|
||||
|
||||
def test_change(self):
|
||||
result = self.vm.qmp('change', device='drive0', target=new_img,
|
||||
arg=iotests.imgfmt)
|
||||
@ -76,9 +79,15 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
|
||||
|
||||
def test_blockdev_change_medium(self):
|
||||
result = self.vm.qmp('blockdev-change-medium', device='drive0',
|
||||
filename=new_img,
|
||||
format=iotests.imgfmt)
|
||||
if self.device_name is not None:
|
||||
result = self.vm.qmp('blockdev-change-medium',
|
||||
id=self.device_name, filename=new_img,
|
||||
format=iotests.imgfmt)
|
||||
else:
|
||||
result = self.vm.qmp('blockdev-change-medium',
|
||||
device='drive0', filename=new_img,
|
||||
format=iotests.imgfmt)
|
||||
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
self.wait_for_open()
|
||||
@ -90,7 +99,10 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
|
||||
|
||||
def test_eject(self):
|
||||
result = self.vm.qmp('eject', device='drive0', force=True)
|
||||
if self.device_name is not None:
|
||||
result = self.vm.qmp('eject', id=self.device_name, force=True)
|
||||
else:
|
||||
result = self.vm.qmp('eject', device='drive0', force=True)
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
self.wait_for_open()
|
||||
@ -101,7 +113,10 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||
self.assert_qmp_absent(result, 'return[0]/inserted')
|
||||
|
||||
def test_tray_eject_change(self):
|
||||
result = self.vm.qmp('eject', device='drive0', force=True)
|
||||
if self.device_name is not None:
|
||||
result = self.vm.qmp('eject', id=self.device_name, force=True)
|
||||
else:
|
||||
result = self.vm.qmp('eject', device='drive0', force=True)
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
self.wait_for_open()
|
||||
@ -111,9 +126,12 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||
self.assert_qmp(result, 'return[0]/tray_open', True)
|
||||
self.assert_qmp_absent(result, 'return[0]/inserted')
|
||||
|
||||
result = self.vm.qmp('blockdev-change-medium', device='drive0',
|
||||
filename=new_img,
|
||||
format=iotests.imgfmt)
|
||||
if self.device_name is not None:
|
||||
result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
|
||||
filename=new_img, format=iotests.imgfmt)
|
||||
else:
|
||||
result = self.vm.qmp('blockdev-change-medium', device='drive0',
|
||||
filename=new_img, format=iotests.imgfmt)
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
self.wait_for_close()
|
||||
@ -124,7 +142,12 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
|
||||
|
||||
def test_tray_open_close(self):
|
||||
result = self.vm.qmp('blockdev-open-tray', device='drive0', force=True)
|
||||
if self.device_name is not None:
|
||||
result = self.vm.qmp('blockdev-open-tray',
|
||||
id=self.device_name, force=True)
|
||||
else:
|
||||
result = self.vm.qmp('blockdev-open-tray',
|
||||
device='drive0', force=True)
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
self.wait_for_open()
|
||||
@ -137,7 +160,10 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||
else:
|
||||
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
|
||||
|
||||
result = self.vm.qmp('blockdev-close-tray', device='drive0')
|
||||
if self.device_name is not None:
|
||||
result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
|
||||
else:
|
||||
result = self.vm.qmp('blockdev-close-tray', device='drive0')
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
if self.has_real_tray or not self.was_empty:
|
||||
@ -162,7 +188,10 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||
self.assert_qmp(result, 'return[0]/tray_open', True)
|
||||
self.assert_qmp_absent(result, 'return[0]/inserted')
|
||||
|
||||
result = self.vm.qmp('blockdev-close-tray', device='drive0')
|
||||
if self.device_name is not None:
|
||||
result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
|
||||
else:
|
||||
result = self.vm.qmp('blockdev-close-tray', device='drive0')
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
self.wait_for_close()
|
||||
@ -206,7 +235,12 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||
'driver': 'file'}})
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
result = self.vm.qmp('blockdev-open-tray', device='drive0', force=True)
|
||||
if self.device_name is not None:
|
||||
result = self.vm.qmp('blockdev-open-tray',
|
||||
id=self.device_name, force=True)
|
||||
else:
|
||||
result = self.vm.qmp('blockdev-open-tray',
|
||||
device='drive0', force=True)
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
self.wait_for_open()
|
||||
@ -219,7 +253,11 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||
else:
|
||||
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
|
||||
|
||||
result = self.vm.qmp('x-blockdev-remove-medium', device='drive0')
|
||||
if self.device_name is not None:
|
||||
result = self.vm.qmp('x-blockdev-remove-medium',
|
||||
id=self.device_name)
|
||||
else:
|
||||
result = self.vm.qmp('x-blockdev-remove-medium', device='drive0')
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
result = self.vm.qmp('query-block')
|
||||
@ -227,8 +265,12 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||
self.assert_qmp(result, 'return[0]/tray_open', True)
|
||||
self.assert_qmp_absent(result, 'return[0]/inserted')
|
||||
|
||||
result = self.vm.qmp('x-blockdev-insert-medium', device='drive0',
|
||||
node_name='new')
|
||||
if self.device_name is not None:
|
||||
result = self.vm.qmp('x-blockdev-insert-medium',
|
||||
id=self.device_name, node_name='new')
|
||||
else:
|
||||
result = self.vm.qmp('x-blockdev-insert-medium',
|
||||
device='drive0', node_name='new')
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
result = self.vm.qmp('query-block')
|
||||
@ -236,7 +278,10 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||
self.assert_qmp(result, 'return[0]/tray_open', True)
|
||||
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
|
||||
|
||||
result = self.vm.qmp('blockdev-close-tray', device='drive0')
|
||||
if self.device_name is not None:
|
||||
result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
|
||||
else:
|
||||
result = self.vm.qmp('blockdev-close-tray', device='drive0')
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
self.wait_for_close()
|
||||
@ -280,7 +325,13 @@ class TestInitiallyFilled(GeneralChangeTestsBaseClass):
|
||||
def setUp(self, media, interface):
|
||||
qemu_img('create', '-f', iotests.imgfmt, old_img, '1440k')
|
||||
qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k')
|
||||
self.vm = iotests.VM().add_drive(old_img, 'media=%s' % media, interface)
|
||||
self.vm = iotests.VM()
|
||||
if interface == 'ide':
|
||||
self.device_name = 'qdev0'
|
||||
self.vm.add_drive(old_img, 'media=%s' % media, 'none')
|
||||
self.vm.add_device('ide-cd,drive=drive0,id=%s' % self.device_name)
|
||||
else:
|
||||
self.vm.add_drive(old_img, 'media=%s' % media, interface)
|
||||
self.vm.launch()
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -139,6 +139,11 @@ class VM(qtest.QEMUQtestMachine):
|
||||
self._debug = True
|
||||
self._num_drives = 0
|
||||
|
||||
def add_device(self, opts):
|
||||
self._args.append('-device')
|
||||
self._args.append(opts)
|
||||
return self
|
||||
|
||||
def add_drive_raw(self, opts):
|
||||
self._args.append('-drive')
|
||||
self._args.append(opts)
|
||||
|
Loading…
Reference in New Issue
Block a user