[PATCH v2 5/6] iotests.py: add unarchive_sample_image() helper

Vladimir Sementsov-Ogievskiy posted 6 patches 4 years, 8 months ago
Maintainers: John Snow <jsnow@redhat.com>, Eric Blake <eblake@redhat.com>, Max Reitz <mreitz@redhat.com>, Kevin Wolf <kwolf@redhat.com>, "Denis V. Lunev" <den@openvz.org>, Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>, Stefan Hajnoczi <stefanha@redhat.com>
[PATCH v2 5/6] iotests.py: add unarchive_sample_image() helper
Posted by Vladimir Sementsov-Ogievskiy 4 years, 8 months ago
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 tests/qemu-iotests/iotests.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 4e758308f2..90d0b62523 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -17,6 +17,7 @@
 #
 
 import atexit
+import bz2
 from collections import OrderedDict
 import faulthandler
 import io
@@ -24,6 +25,7 @@
 import logging
 import os
 import re
+import shutil
 import signal
 import struct
 import subprocess
@@ -96,6 +98,14 @@
                              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]:
-- 
2.29.2


Re: [PATCH v2 5/6] iotests.py: add unarchive_sample_image() helper
Posted by Denis V. Lunev 4 years, 8 months ago
On 2/24/21 1:47 PM, Vladimir Sementsov-Ogievskiy wrote:
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  tests/qemu-iotests/iotests.py | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index 4e758308f2..90d0b62523 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -17,6 +17,7 @@
>  #
>  
>  import atexit
> +import bz2
>  from collections import OrderedDict
>  import faulthandler
>  import io
> @@ -24,6 +25,7 @@
>  import logging
>  import os
>  import re
> +import shutil
>  import signal
>  import struct
>  import subprocess
> @@ -96,6 +98,14 @@
>                               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]:
Reviewed-by: Denis V. Lunev <den@openvz.org>