storage: tests: Fix a test failure for psutils >= 7.0

- We are using a private data structure that lead to failure. psutil 7.0 removed
two fields from the partition class. Just update the code to work with 7.0
instead of emulating psutil completely as that is a better test.

- The primary code is unaffected in is_partition_read_only() and
get_filesystem_type() due to not having any changes in the fields we use.

Tests:

- Run unit tests on testing and unstable VMs.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2025-03-24 19:50:54 -07:00
parent df8d41e7fb
commit aa181a564f
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -375,7 +375,16 @@ def test_validate_directory_creatable(path, error):
@patch('psutil.disk_partitions')
def test_is_partition_read_only(disk_partitions):
"""Test whether checking for ro partition works."""
partition = psutil._common.sdiskpart # pylint: disable=protected-access
def partition(*args):
try:
# psutil <= 5.9.8
# pylint: disable=protected-access
return psutil._common.sdiskpart(*args)
except TypeError:
# psutil >= 7.0
return psutil._common.sdiskpart(*args[:-2])
disk_partitions.return_value = [
partition('/dev/root', '/', 'btrfs', 'rw,nosuid', 42, 42),
partition('/dev/root', '/foo', 'btrfs', 'rw', 321, 321),