Skip to content

Commit

Permalink
fix key collision in zpool.status
Browse files Browse the repository at this point in the history
  • Loading branch information
yocalebo committed Nov 26, 2024
1 parent 3b878a6 commit 3f59cec
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/middlewared/middlewared/plugins/disk_/availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def details_impl(self, data):
in_use_disks_imported = {}
for in_use_disk, info in (
await self.middleware.call('zpool.status', {'real_paths': True})
)['disks'].items():
)['.disks'].items():
in_use_disks_imported[in_use_disk] = info['pool_name']

in_use_disks_exported = {}
Expand Down
2 changes: 1 addition & 1 deletion src/middlewared/middlewared/plugins/webui/enclosure.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def dashboard_impl(self):
# work with UI to remove unnecessary ones
self.map_disk_details(slot_info, disk_deets)

if pool_info := disks_to_pools['disks'].get(slot_info['dev']):
if pool_info := disks_to_pools['.disks'].get(slot_info['dev']):
# now map zpool info
self.map_zpool_info(enc['id'], disk_slot, slot_info['dev'], pool_info)

Expand Down
9 changes: 6 additions & 3 deletions src/middlewared/middlewared/plugins/zfs_/pool_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def status(self, data):
An example of what this returns looks like the following:
{
"disks": {
".disks": {
"/dev/disk/by-partuuid/d9cfa346-8623-402f-9bfe-a8256de902ec": {
"pool_name": "evo",
"disk_status": "ONLINE",
Expand Down Expand Up @@ -120,7 +120,10 @@ def status(self, data):
"""
pools = get_zpool_status(data.get('name'))

final = {'disks': dict()}
# Yes, the key is prefixed with a period and is not
# a mistake. A user can name their zpool "disks"
# which would cause a key collision
final = {'.disks': dict()}
for pool_name, pool_info in pools.items():
final[pool_name] = dict()
# We need some normalization for data vdev here
Expand All @@ -136,6 +139,6 @@ def status(self, data):
# this was designed, primarily, for the
# `webui.enclosure.dashboard` endpoint
final[pool_name][vdev_type] = info
final['disks'].update(info)
final['.disks'].update(info)

return final
2 changes: 1 addition & 1 deletion tests/api2/test_zpool_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_disk_uuid_mapping(unused_disks):
def get_pool_status(unused_disks, real_paths=False, replaced=False):
disk_uuid_mapping = get_disk_uuid_mapping(unused_disks)
return {
'disks': {
'.disks': {
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 'ONLINE',
Expand Down

0 comments on commit 3f59cec

Please sign in to comment.