From 5429e9cac20bdb5d2d4bca3dccfca2a0c65a74e5 Mon Sep 17 00:00:00 2001 From: Jono Yang Date: Wed, 15 May 2024 16:01:03 -0700 Subject: [PATCH] Update pytest mark on TestExtractVmImage Signed-off-by: Jono Yang --- tests/test_vmimage.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/test_vmimage.py b/tests/test_vmimage.py index 6653cdd..2f667b9 100644 --- a/tests/test_vmimage.py +++ b/tests/test_vmimage.py @@ -20,7 +20,31 @@ from extractcode import vmimage -@pytest.mark.skipif(not on_linux, reason='Only linux supports image extraction') +def get_etc_os_release_info(os_release_path='/etc/os-release'): + cfg_kv = {} + with open(os_release_path) as f: + for line in f: + split_line = line.split('=') + if not split_line: + continue + k = split_line[0].strip() + v = split_line[-1].strip() + cfg_kv[k] = v + return cfg_kv + + +def is_on_ubuntu_22(): + if not on_linux: + return False + os_release_info = get_etc_os_release_info() + return os_release_info['ID'] == 'ubuntu' and '22' in os_release_info['VERSION_ID'] + +on_ubuntu_22 = is_on_ubuntu_22() + +del is_on_ubuntu_22 + + +@pytest.mark.skipif(not on_linux or on_ubuntu_22, reason='Only linux supports image extraction, kernel is unreadable on Ubuntu 22.04') class TestExtractVmImage(BaseArchiveTestCase): test_data_dir = os.path.join(os.path.dirname(__file__), 'data')