]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
iotests.py: add unarchive_sample_image() helper
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Wed, 24 Feb 2021 10:47:06 +0000 (13:47 +0300)
committerKevin Wolf <kwolf@redhat.com>
Mon, 8 Mar 2021 13:56:55 +0000 (14:56 +0100)
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210224104707.88430-6-vsementsov@virtuozzo.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
tests/qemu-iotests/iotests.py

index 4e758308f24710fe32141692fc7dfd0fae728056..90d0b6252368578a610a0b15557f8cee7dfe932b 100644 (file)
@@ -17,6 +17,7 @@
 #
 
 import atexit
+import bz2
 from collections import OrderedDict
 import faulthandler
 import io
@@ -24,6 +25,7 @@ import json
 import logging
 import os
 import re
+import shutil
 import signal
 import struct
 import subprocess
@@ -96,6 +98,14 @@ luks_default_secret_object = 'secret,id=keysec0,data=' + \
                              os.environ.get('IMGKEYSECRET', '')
 luks_default_key_secret_opt = 'key-secret=keysec0'
 
+sample_img_dir = os.environ['SAMPLE_IMG_DIR']
+
+
+def unarchive_sample_image(sample, fname):
+    sample_fname = os.path.join(sample_img_dir, sample + '.bz2')
+    with bz2.open(sample_fname) as f_in, open(fname, 'wb') as f_out:
+        shutil.copyfileobj(f_in, f_out)
+
 
 def qemu_tool_pipe_and_status(tool: str, args: Sequence[str],
                               connect_stderr: bool = True) -> Tuple[str, int]: