mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
storage: Skip tests that involve loopback device in a container
- Insider a container, it is not possible to use loopback devices without additional permissions. Skips tests that need loopback devices. This will results in fewer errors when running './container run-tests'. Tests: - Run './container run-tests --pytest-args plinth/modules/stroage/test_storage.py'. Notice that all tests are either skipped or succeed. - Run the tests on host machine and they all run without skipping. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
parent
bd03969d95
commit
ebe6ad7556
@ -18,8 +18,23 @@ from plinth.diagnostic_check import DiagnosticCheck, Result
|
|||||||
from plinth.modules import storage
|
from plinth.modules import storage
|
||||||
from plinth.modules.storage import privileged
|
from plinth.modules.storage import privileged
|
||||||
|
|
||||||
|
|
||||||
|
def _is_container():
|
||||||
|
"""Return if we are running inside a container."""
|
||||||
|
try:
|
||||||
|
process = subprocess.run(['systemd-detect-virt', '--container'],
|
||||||
|
check=False)
|
||||||
|
except FileNotFoundError:
|
||||||
|
# systemd is not installed on the machine. Likely a container.
|
||||||
|
return True # Skip just in case.
|
||||||
|
|
||||||
|
return process.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures('mock_privileged')
|
pytestmark = pytest.mark.usefixtures('mock_privileged')
|
||||||
privileged_modules_to_mock = ['plinth.modules.storage.privileged']
|
privileged_modules_to_mock = ['plinth.modules.storage.privileged']
|
||||||
|
skip_if_container = pytest.mark.skipif(_is_container(),
|
||||||
|
reason='running inside a container')
|
||||||
|
|
||||||
|
|
||||||
class Disk():
|
class Disk():
|
||||||
@ -163,6 +178,7 @@ def disk_space_available():
|
|||||||
@pytest.mark.usefixtures('needs_root')
|
@pytest.mark.usefixtures('needs_root')
|
||||||
@pytest.mark.skipif(disk_space_available() < 1024,
|
@pytest.mark.skipif(disk_space_available() < 1024,
|
||||||
reason='Needs 1024MiB of space')
|
reason='Needs 1024MiB of space')
|
||||||
|
@skip_if_container
|
||||||
def test_simple_case():
|
def test_simple_case():
|
||||||
"""Test a simple with no complications"""
|
"""Test a simple with no complications"""
|
||||||
disk_info = [
|
disk_info = [
|
||||||
@ -188,6 +204,7 @@ def test_simple_case():
|
|||||||
@pytest.mark.usefixtures('needs_root')
|
@pytest.mark.usefixtures('needs_root')
|
||||||
@pytest.mark.skipif(disk_space_available() < 512,
|
@pytest.mark.skipif(disk_space_available() < 512,
|
||||||
reason='Needs 512MiB of space')
|
reason='Needs 512MiB of space')
|
||||||
|
@skip_if_container
|
||||||
def test_extended_partition_free_space():
|
def test_extended_partition_free_space():
|
||||||
"""Test that free space does not show up when outside extended."""
|
"""Test that free space does not show up when outside extended."""
|
||||||
disk_info = [
|
disk_info = [
|
||||||
@ -202,6 +219,7 @@ def test_extended_partition_free_space():
|
|||||||
@pytest.mark.usefixtures('needs_root')
|
@pytest.mark.usefixtures('needs_root')
|
||||||
@pytest.mark.skipif(disk_space_available() < 512,
|
@pytest.mark.skipif(disk_space_available() < 512,
|
||||||
reason='Needs 512MiB of space')
|
reason='Needs 512MiB of space')
|
||||||
|
@skip_if_container
|
||||||
def test_gpt_partition_free_space():
|
def test_gpt_partition_free_space():
|
||||||
"""Test that GPT partitions can be expanded."""
|
"""Test that GPT partitions can be expanded."""
|
||||||
# Specifically check for partition number > 4
|
# Specifically check for partition number > 4
|
||||||
@ -225,6 +243,7 @@ def test_gpt_partition_free_space():
|
|||||||
@pytest.mark.usefixtures('needs_root')
|
@pytest.mark.usefixtures('needs_root')
|
||||||
@pytest.mark.parametrize('partition_table_type', ['gpt', 'msdos'])
|
@pytest.mark.parametrize('partition_table_type', ['gpt', 'msdos'])
|
||||||
@pytest.mark.skipif(disk_space_available() < 32, reason='Needs 32MiB of space')
|
@pytest.mark.skipif(disk_space_available() < 32, reason='Needs 32MiB of space')
|
||||||
|
@skip_if_container
|
||||||
def test_unsupported_file_system(partition_table_type):
|
def test_unsupported_file_system(partition_table_type):
|
||||||
"""Test that free space after unknown file system does not count."""
|
"""Test that free space after unknown file system does not count."""
|
||||||
disk_info = [f'mktable {partition_table_type}', 'mkpart primary 1 8']
|
disk_info = [f'mktable {partition_table_type}', 'mkpart primary 1 8']
|
||||||
@ -237,6 +256,7 @@ def test_unsupported_file_system(partition_table_type):
|
|||||||
@pytest.mark.parametrize('partition_table_type', ['gpt', 'msdos'])
|
@pytest.mark.parametrize('partition_table_type', ['gpt', 'msdos'])
|
||||||
@pytest.mark.skipif(disk_space_available() < 512,
|
@pytest.mark.skipif(disk_space_available() < 512,
|
||||||
reason='Needs 512MiB of space')
|
reason='Needs 512MiB of space')
|
||||||
|
@skip_if_container
|
||||||
def test_btrfs_expansion(partition_table_type):
|
def test_btrfs_expansion(partition_table_type):
|
||||||
"""Test that btrfs file system can be expanded."""
|
"""Test that btrfs file system can be expanded."""
|
||||||
disk_info = [
|
disk_info = [
|
||||||
@ -252,6 +272,7 @@ def test_btrfs_expansion(partition_table_type):
|
|||||||
@pytest.mark.parametrize('partition_table_type', ['gpt', 'msdos'])
|
@pytest.mark.parametrize('partition_table_type', ['gpt', 'msdos'])
|
||||||
@pytest.mark.skipif(disk_space_available() < 128,
|
@pytest.mark.skipif(disk_space_available() < 128,
|
||||||
reason='Needs 128MiB of space')
|
reason='Needs 128MiB of space')
|
||||||
|
@skip_if_container
|
||||||
def test_ext4_expansion(partition_table_type):
|
def test_ext4_expansion(partition_table_type):
|
||||||
"""Test that ext4 file system can be expanded."""
|
"""Test that ext4 file system can be expanded."""
|
||||||
disk_info = [f'mktable {partition_table_type}', 'mkpart primary ext4 1 64']
|
disk_info = [f'mktable {partition_table_type}', 'mkpart primary ext4 1 64']
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user