diff --git a/src/simplezfs/validation.py b/src/simplezfs/validation.py index 84a9209..67de088 100644 --- a/src/simplezfs/validation.py +++ b/src/simplezfs/validation.py @@ -158,6 +158,7 @@ def validate_metadata_property_name(name: str) -> None: if not METADATA_PROPERTY_NAME_RE.match(name): raise ValidationError('property name does not match') + def validate_property_value(value: str) -> None: ''' Validates the value of a property. This works for both native properties, where the driver will tell us if the diff --git a/src/simplezfs/zfs_cli.py b/src/simplezfs/zfs_cli.py index d5d89ff..fed53d1 100644 --- a/src/simplezfs/zfs_cli.py +++ b/src/simplezfs/zfs_cli.py @@ -10,7 +10,7 @@ import shutil import subprocess from .exceptions import DatasetNotFound, PropertyNotFound -from .types import Property, Dataset +from .types import Dataset, Property, PropertySource from .validation import ( validate_dataset_path, validate_pool_name, @@ -164,7 +164,9 @@ class ZFSCli(ZFS): if is_metadata: namespace = prop_name.split(':')[0] - return Property(key=prop_name, value=prop_value, source=prop_source, namespace=namespace) + property_source = PropertySource.from_string(prop_source) + + return Property(key=prop_name, value=prop_value, source=property_source, namespace=namespace) def _get_properties(self, dataset: str, include_metadata: bool = False) -> List[Property]: ''' @@ -182,11 +184,12 @@ class ZFSCli(ZFS): for line in proc.stdout.split('\n'): if line: _, prop_name, prop_value, prop_source = line.strip().split('\t') + property_source = PropertySource.from_string(prop_source) if ':' in prop_name: if include_metadata: namespace = prop_name.split(':')[0] prop_name = prop_name.lstrip(f'{namespace}:') - res.append(Property(key=prop_name, value=prop_value, source=prop_source, namespace=namespace)) + res.append(Property(key=prop_name, value=prop_value, source=property_source, namespace=namespace)) else: - res.append(Property(key=prop_name, value=prop_value, source=prop_source, namespace=None)) + res.append(Property(key=prop_name, value=prop_value, source=property_source, namespace=None)) return res diff --git a/src/simplezfs/zpool_cli.py b/src/simplezfs/zpool_cli.py index 5c5d416..61a5e3e 100644 --- a/src/simplezfs/zpool_cli.py +++ b/src/simplezfs/zpool_cli.py @@ -6,7 +6,7 @@ CLI-based implementation of ZPOOL. import logging import shutil -from typing import Any, Dict, NamedTuple, Optional +from typing import Any, Dict, Optional from .types import ZPoolHealth from .zpool import ZPool @@ -14,7 +14,7 @@ log = logging.getLogger('zfs.zpool_cli') class ZPoolCli(ZPool): - + def __init__(self, *, metadata_namespace: Optional[str] = None, zpool_exe: Optional[str] = None, **kwargs) -> None: super().__init__(metadata_namespace=metadata_namespace) self.find_executable(path=zpool_exe) @@ -104,7 +104,7 @@ class ZPoolCli(ZPool): # Append the pending elements to the current pool and state and clear them. if vdev_drives: plog.debug(f'have {len(vdev_drives)} vdev_drives, save data') - vdevs['members']= vdev_drives + vdevs['members'] = vdev_drives output[pool_name][state].append(vdevs) vdevs = dict(type='none') diff --git a/tests/test_enums.py b/tests/test_enums.py index 2d4310d..42e62c8 100644 --- a/tests/test_enums.py +++ b/tests/test_enums.py @@ -32,6 +32,7 @@ class TestDatasetType: DatasetType.from_string(None) assert 'only string' in str(excinfo.value) + class TestPropertySource: @pytest.mark.parametrize('string,value', [('default', PropertySource.DEFAULT), ('DeFAULT', PropertySource.DEFAULT), ('inheriteD', PropertySource.INHERITED), ('inherited', PropertySource.INHERITED), ('TEMPORARY', PropertySource.TEMPORARY), ('temporary', PropertySource.TEMPORARY), ('rEcEiVeD', PropertySource.RECEIVED), ('received', PropertySource.RECEIVED), ('None', PropertySource.NONE), ('none', PropertySource.NONE)]) diff --git a/tests/test_validation.py b/tests/test_validation.py index 9d5c46d..7dae5a8 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -238,6 +238,7 @@ class TestMetadataPropertyName: validate_metadata_property_name('a' * 1024) assert 'length >' in str(excinfo.value) + class TestPropertyValue: ''' Tests the function ``validate_property_value``.