Skip to content

Commit

Permalink
Key fixes
Browse files Browse the repository at this point in the history
(cherry picked from commit 7a8f040)
  • Loading branch information
Qubad786 authored and bugclerk committed Sep 6, 2024
1 parent 13f5403 commit dbfc5db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/middlewared/middlewared/plugins/zfs_/pool_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def resolve_block_paths(self, paths, should_resolve):
def status_impl(self, pool_name, vdev_type, members, **kwargs):
real_paths = kwargs.setdefault('real_paths', False)
final = dict()
for member in filter(lambda x: x['vdev_type'] != 'file', members.values()):
for member in filter(lambda x: x.get('vdev_type') != 'file', members.values()):
vdev_disks = self.resolve_block_paths(get_zfs_vdev_disks(member), real_paths)
if member['vdev_type'] == 'disk':
if member.get('vdev_type') in ('disk', 'dspare'):
disk = self.resolve_block_path(member['path'], real_paths)
final[disk] = get_normalized_disk_info(pool_name, member, 'stripe', vdev_type, vdev_disks)
else:
Expand Down
8 changes: 5 additions & 3 deletions src/middlewared/middlewared/plugins/zfs_/status_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ def get_normalized_disk_info(pool_name: str, disk: dict, vdev_name: str, vdev_ty


def get_zfs_vdev_disks(vdev) -> list:
if vdev['state'] in ('UNAVAIL', 'OFFLINE'):
# We get this safely because of draid based vdevs
if vdev.get('state') in ('UNAVAIL', 'OFFLINE'):
return []

if vdev['vdev_type'] == 'disk':
vdev_type = vdev.get('vdev_type')
if vdev_type == 'disk':
return [vdev['path']]
elif vdev['vdev_type'] == 'file':
elif vdev_type == 'file':
return []
else:
result = []
Expand Down
12 changes: 8 additions & 4 deletions tests/api2/test_zpool_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
from middlewared.test.integration.assets.pool import another_pool
from middlewared.test.integration.utils import call, ssh


POOL_NAME = 'test_format_pool'
ZFS_PART_UUID = '6a898cc3-1dd2-11b2-99a6-080020736631'


def get_disk_uuid_mapping(unused_disks):
disk_uuid = {}
for disk_path in call('filesystem.listdir', '/dev/disk/by-partuuid'):
resolved_path = call('zpool.resolve_block_path', disk_path['path'], True)
if resolved_path in unused_disks:
disk_uuid[resolved_path] = disk_path['path']
for disk in filter(
lambda n: n['name'] in unused_disks and n['parts'], call('device.get_disks', True, False).values()
):
if partition := next((part for part in disk['parts'] if part['partition_type'] == ZFS_PART_UUID), None):
disk_uuid[disk['name']] = os.path.join('/dev/disk/by-partuuid', partition['partition_uuid'])

return disk_uuid


Expand Down

0 comments on commit dbfc5db

Please sign in to comment.