Skip to content

Commit

Permalink
address review (#15043)
Browse files Browse the repository at this point in the history
  • Loading branch information
yocalebo authored Nov 26, 2024
1 parent fc3a785 commit 011177b
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 138 deletions.
53 changes: 26 additions & 27 deletions src/middlewared/middlewared/plugins/zfs_/pool_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,47 +95,46 @@ def status(self, data):
]
}
},
"evo": {
"spares": {},
"logs": {},
"dedup": {},
"special": {},
"l2cache": {},
"data": {
"/dev/disk/by-partuuid/d9cfa346-8623-402f-9bfe-a8256de902ec": {
"pool_name": "evo",
"disk_status": "ONLINE",
"disk_read_errors": 0,
"disk_write_errors": 0,
"disk_checksum_errors": 0,
"vdev_name": "stripe",
"vdev_type": "data",
"vdev_disks": [
"/dev/disk/by-partuuid/d9cfa346-8623-402f-9bfe-a8256de902ec"
]
}
"pools": {
"evo": {
"spares": {},
"logs": {},
"dedup": {},
"special": {},
"l2cache": {},
"data": {
"/dev/disk/by-partuuid/d9cfa346-8623-402f-9bfe-a8256de902ec": {
"pool_name": "evo",
"disk_status": "ONLINE",
"disk_read_errors": 0,
"disk_write_errors": 0,
"disk_checksum_errors": 0,
"vdev_name": "stripe",
"vdev_type": "data",
"vdev_disks": [
"/dev/disk/by-partuuid/d9cfa346-8623-402f-9bfe-a8256de902ec"
]
}
}
}
}
}
"""
pools = get_zpool_status(data.get('name'))

final = {'disks': dict()}
for pool_name, pool_info in pools.items():
final[pool_name] = dict()
final = {'disks': dict(), 'pools': dict()}
for pool_name, pool_info in get_zpool_status(data.get('name')).items():
final['pools'][pool_name] = dict()
# We need some normalization for data vdev here
pool_info['data'] = pool_info.get('vdevs', {}).get(pool_name, {}).get('vdevs', {})
for vdev_type in ('spares', 'logs', 'dedup', 'special', 'l2cache', 'data'):
vdev_members = pool_info.get(vdev_type, {})
if not vdev_members:
final[pool_name][vdev_type] = dict()
final['pools'][pool_name][vdev_type] = dict()
continue

info = self.status_impl(pool_name, vdev_type, vdev_members, **data)
# we key on pool name and disk id because
# this was designed, primarily, for the
# `webui.enclosure.dashboard` endpoint
final[pool_name][vdev_type] = info
final['pools'][pool_name][vdev_type] = info
final['disks'].update(info)

return final
4 changes: 2 additions & 2 deletions tests/api2/test_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def alert_id(degraded_pool_gptid):

def test_verify_the_pool_is_degraded(degraded_pool_gptid):
status = call("zpool.status", {"name": pool_name})
disk_status = status[pool_name]["data"][ID_PATH + degraded_pool_gptid]["disk_status"]
disk_status = status["pools"][pool_name]["data"][ID_PATH + degraded_pool_gptid]["disk_status"]
assert disk_status == "DEGRADED"


Expand All @@ -63,7 +63,7 @@ def test_restore_alert(alert_id):
def test_clear_the_pool_degradation(degraded_pool_gptid):
ssh(f"zpool clear {pool_name}")
status = call("zpool.status", {"name": pool_name})
disk_status = status[pool_name]["data"][ID_PATH + degraded_pool_gptid]["disk_status"]
disk_status = status["pools"][pool_name]["data"][ID_PATH + degraded_pool_gptid]["disk_status"]
assert disk_status != "DEGRADED"


Expand Down
220 changes: 111 additions & 109 deletions tests/api2/test_zpool_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,117 +104,119 @@ def get_pool_status(unused_disks, real_paths=False, replaced=False):
]
}
},
POOL_NAME: {
'spares': {
f'{disk_uuid_mapping[unused_disks[4]] if not real_paths else unused_disks[4]}': {
'pool_name': POOL_NAME,
'disk_status': 'AVAIL' if not replaced else 'INUSE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'stripe',
'vdev_type': 'spares',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[4]] if not real_paths else unused_disks[4]}'
]
}
},
'logs': {
f'{disk_uuid_mapping[unused_disks[3]] if not real_paths else unused_disks[3]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'stripe',
'vdev_type': 'logs',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[3]] if not real_paths else unused_disks[3]}'
]
}
},
'dedup': {
f'{disk_uuid_mapping[unused_disks[2]] if not real_paths else unused_disks[2]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'stripe',
'vdev_type': 'dedup',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[2]] if not real_paths else unused_disks[2]}'
]
}
},
'special': {
f'{disk_uuid_mapping[unused_disks[5]] if not real_paths else unused_disks[5]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'stripe',
'vdev_type': 'special',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[5]] if not real_paths else unused_disks[5]}'
]
}
},
'l2cache': {
f'{disk_uuid_mapping[unused_disks[0]] if not real_paths else unused_disks[0]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'stripe',
'vdev_type': 'l2cache',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[0]] if not real_paths else unused_disks[0]}'
]
}
},
'data': {
f'{disk_uuid_mapping[unused_disks[1]] if not real_paths else unused_disks[1]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'stripe',
'vdev_type': 'data',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[1]] if not real_paths else unused_disks[1]}'
]
}
} if not replaced else {
f'{disk_uuid_mapping[unused_disks[1]] if not real_paths else unused_disks[1]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'spare-0',
'vdev_type': 'data',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[1]] if not real_paths else unused_disks[1]}',
f'{disk_uuid_mapping[unused_disks[4]] if not real_paths else unused_disks[4]}'
]
'pools': {
POOL_NAME: {
'spares': {
f'{disk_uuid_mapping[unused_disks[4]] if not real_paths else unused_disks[4]}': {
'pool_name': POOL_NAME,
'disk_status': 'AVAIL' if not replaced else 'INUSE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'stripe',
'vdev_type': 'spares',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[4]] if not real_paths else unused_disks[4]}'
]
}
},
'logs': {
f'{disk_uuid_mapping[unused_disks[3]] if not real_paths else unused_disks[3]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'stripe',
'vdev_type': 'logs',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[3]] if not real_paths else unused_disks[3]}'
]
}
},
f'{disk_uuid_mapping[unused_disks[4]] if not real_paths else unused_disks[4]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'spare-0',
'vdev_type': 'data',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[1]] if not real_paths else unused_disks[1]}',
f'{disk_uuid_mapping[unused_disks[4]] if not real_paths else unused_disks[4]}'
]
'dedup': {
f'{disk_uuid_mapping[unused_disks[2]] if not real_paths else unused_disks[2]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'stripe',
'vdev_type': 'dedup',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[2]] if not real_paths else unused_disks[2]}'
]
}
},
'special': {
f'{disk_uuid_mapping[unused_disks[5]] if not real_paths else unused_disks[5]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'stripe',
'vdev_type': 'special',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[5]] if not real_paths else unused_disks[5]}'
]
}
},
'l2cache': {
f'{disk_uuid_mapping[unused_disks[0]] if not real_paths else unused_disks[0]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'stripe',
'vdev_type': 'l2cache',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[0]] if not real_paths else unused_disks[0]}'
]
}
},
'data': {
f'{disk_uuid_mapping[unused_disks[1]] if not real_paths else unused_disks[1]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'stripe',
'vdev_type': 'data',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[1]] if not real_paths else unused_disks[1]}'
]
}
} if not replaced else {
f'{disk_uuid_mapping[unused_disks[1]] if not real_paths else unused_disks[1]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'spare-0',
'vdev_type': 'data',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[1]] if not real_paths else unused_disks[1]}',
f'{disk_uuid_mapping[unused_disks[4]] if not real_paths else unused_disks[4]}'
]
},
f'{disk_uuid_mapping[unused_disks[4]] if not real_paths else unused_disks[4]}': {
'pool_name': POOL_NAME,
'disk_status': 'ONLINE',
'disk_read_errors': 0,
'disk_write_errors': 0,
'disk_checksum_errors': 0,
'vdev_name': 'spare-0',
'vdev_type': 'data',
'vdev_disks': [
f'{disk_uuid_mapping[unused_disks[1]] if not real_paths else unused_disks[1]}',
f'{disk_uuid_mapping[unused_disks[4]] if not real_paths else unused_disks[4]}'
]
},
}
}
}
}
Expand Down

0 comments on commit 011177b

Please sign in to comment.