mirror of
https://github.com/qemu/qemu.git
synced 2024-11-28 14:24:02 +08:00
iotests: 205: support luks format
Support default luks options in VM.add_drive and in new library function qemu_img_create. Use it in 205 iotests. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20180206182507.21753-1-vsementsov@virtuozzo.com> Reviewed-by: Daniel P. Berrange <berrange@redhat.com> Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
c7b02d7d03
commit
85a353a024
@ -22,7 +22,7 @@ import os
|
||||
import sys
|
||||
import iotests
|
||||
import time
|
||||
from iotests import qemu_img, qemu_io, filter_qemu_io, QemuIoInteractive
|
||||
from iotests import qemu_img_create, qemu_io, filter_qemu_io, QemuIoInteractive
|
||||
|
||||
nbd_sock = 'nbd_sock'
|
||||
nbd_uri = 'nbd+unix:///exp?socket=' + nbd_sock
|
||||
@ -31,7 +31,7 @@ disk = os.path.join(iotests.test_dir, 'disk')
|
||||
|
||||
class TestNbdServerRemove(iotests.QMPTestCase):
|
||||
def setUp(self):
|
||||
qemu_img('create', '-f', iotests.imgfmt, disk, '1M')
|
||||
qemu_img_create('-f', iotests.imgfmt, disk, '1M')
|
||||
|
||||
self.vm = iotests.VM().add_drive(disk)
|
||||
self.vm.launch()
|
||||
|
@ -58,6 +58,11 @@ qemu_default_machine = os.environ.get('QEMU_DEFAULT_MACHINE')
|
||||
socket_scm_helper = os.environ.get('SOCKET_SCM_HELPER', 'socket_scm_helper')
|
||||
debug = False
|
||||
|
||||
luks_default_secret_object = 'secret,id=keysec0,data=' + \
|
||||
os.environ['IMGKEYSECRET']
|
||||
luks_default_key_secret_opt = 'key-secret=keysec0'
|
||||
|
||||
|
||||
def qemu_img(*args):
|
||||
'''Run qemu-img and return the exit code'''
|
||||
devnull = open('/dev/null', 'r+')
|
||||
@ -66,6 +71,25 @@ def qemu_img(*args):
|
||||
sys.stderr.write('qemu-img received signal %i: %s\n' % (-exitcode, ' '.join(qemu_img_args + list(args))))
|
||||
return exitcode
|
||||
|
||||
def qemu_img_create(*args):
|
||||
args = list(args)
|
||||
|
||||
# default luks support
|
||||
if '-f' in args and args[args.index('-f') + 1] == 'luks':
|
||||
if '-o' in args:
|
||||
i = args.index('-o')
|
||||
if 'key-secret' not in args[i + 1]:
|
||||
args[i + 1].append(luks_default_key_secret_opt)
|
||||
args.insert(i + 2, '--object')
|
||||
args.insert(i + 3, luks_default_secret_object)
|
||||
else:
|
||||
args = ['-o', luks_default_key_secret_opt,
|
||||
'--object', luks_default_secret_object] + args
|
||||
|
||||
args.insert(0, 'create')
|
||||
|
||||
return qemu_img(*args)
|
||||
|
||||
def qemu_img_verbose(*args):
|
||||
'''Run qemu-img without suppressing its output and return the exit code'''
|
||||
exitcode = subprocess.call(qemu_img_args + list(args))
|
||||
@ -263,6 +287,13 @@ class VM(qtest.QEMUQtestMachine):
|
||||
if opts:
|
||||
options.append(opts)
|
||||
|
||||
if format == 'luks' and 'key-secret' not in opts:
|
||||
# default luks support
|
||||
if luks_default_secret_object not in self._args:
|
||||
self.add_object(luks_default_secret_object)
|
||||
|
||||
options.append(luks_default_key_secret_opt)
|
||||
|
||||
self._args.append('-drive')
|
||||
self._args.append(','.join(options))
|
||||
self._num_drives += 1
|
||||
|
Loading…
Reference in New Issue
Block a user