-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtest_vmimage.py
More file actions
48 lines (38 loc) · 1.99 KB
/
test_vmimage.py
File metadata and controls
48 lines (38 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# ScanCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/extractcode for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
import os
from pathlib import Path
import pytest
from commoncode.system import on_linux
from commoncode.system import on_ubuntu_22
from extractcode_assert_utils import BaseArchiveTestCase
from extractcode_assert_utils import check_files
from extractcode import vmimage
@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')
def test_can_listfs_from_qcow2_image(self):
test_file = self.extract_test_tar('vmimage/foobar.qcow2.tar.gz')
test_file = str(Path(test_file) / 'foobar.qcow2')
vmi = vmimage.VmImage.from_file(test_file)
assert [('/dev/sda', 'ext2')] == vmi.listfs()
def test_can_extract_qcow2_vm_image_as_tarball(self):
test_file = self.extract_test_tar('vmimage/foobar.qcow2.tar.gz')
test_file = str(Path(test_file) / 'foobar.qcow2')
target_dir = self.get_temp_dir('vmimage')
vmimage.extract(location=test_file, target_dir=target_dir, as_tarballs=True)
expected = ['foobar.qcow2.tar.gz']
check_files(target_dir, expected)
def test_can_extract_qcow2_vm_image_not_as_tarball(self):
test_file = self.extract_test_tar('vmimage/bios-tables-test.x86_64.iso.qcow2.tar.gz')
test_file = str(Path(test_file) / 'bios-tables-test.x86_64.iso.qcow2')
target_dir = self.get_temp_dir('vmimage')
vmimage.extract(location=test_file, target_dir=target_dir, as_tarballs=False)
expected = ['bios_tab.fat', 'boot.cat']
check_files(target_dir, expected)