-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-127511 / 25.04 / Fix zpool status for reporting used spare disks …
…correctly (#14262) * Use as_dict of ZFSPool when getting output of zpool.status * Do not use py-libzfs for zpool status * Add integration test for zpool status
- Loading branch information
Showing
4 changed files
with
381 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import json | ||
import subprocess | ||
|
||
from middlewared.service import CallError, ValidationError | ||
|
||
|
||
def get_normalized_disk_info(pool_name: str, disk: dict, vdev_name: str, vdev_type: str, vdev_disks: list) -> dict: | ||
return { | ||
'pool_name': pool_name, | ||
'disk_status': disk['state'], | ||
'disk_read_errors': disk.get('read_errors', 0), | ||
'disk_write_errors': disk.get('write_errors', 0), | ||
'disk_checksum_errors': disk.get('checksum_errors', 0), | ||
'vdev_name': vdev_name, | ||
'vdev_type': vdev_type, | ||
'vdev_disks': vdev_disks, | ||
} | ||
|
||
|
||
def get_zfs_vdev_disks(vdev) -> list: | ||
if vdev['state'] in ('UNAVAIL', 'OFFLINE'): | ||
return [] | ||
|
||
if vdev['vdev_type'] == 'disk': | ||
return [vdev['path']] | ||
elif vdev['vdev_type'] == 'file': | ||
return [] | ||
else: | ||
result = [] | ||
for i in vdev.get('vdevs', {}).values(): | ||
result.extend(get_zfs_vdev_disks(i)) | ||
return result | ||
|
||
|
||
def get_zpool_status(pool_name: str | None = None) -> dict: | ||
args = [pool_name] if pool_name else [] | ||
cp = subprocess.run(['zpool', 'status', '-jP', '--json-int'] + args, capture_output=True, check=False) | ||
if cp.returncode: | ||
if b'no such pool' in cp.stderr: | ||
raise ValidationError('zpool.status', f'{pool_name!r} not found') | ||
|
||
raise CallError(f'Failed to get zpool status: {cp.stderr.decode()}') | ||
|
||
return json.loads(cp.stdout)['pools'] |
Oops, something went wrong.