diff --git a/scripts/wk/os/linux.py b/scripts/wk/os/linux.py index 49fedcec..4ee690c3 100644 --- a/scripts/wk/os/linux.py +++ b/scripts/wk/os/linux.py @@ -183,6 +183,12 @@ def mount_volumes(device_path=None, read_write=False, scan_corestorage=False): NOTE: If device_path is specified then only volumes under that path will be mounted. """ + def _get_volumes(dev) -> list: + """Convert lsblk JSON tree to a flat list of items, returns list.""" + volumes = [dev] + for child in dev.get('children', []): + volumes.extend(_get_volumes(child)) + return volumes json_data = {} volumes = [] containers = [] @@ -199,12 +205,10 @@ def mount_volumes(device_path=None, read_write=False, scan_corestorage=False): json_data = get_json_from_command(cmd) # Build list of volumes - for dev in json_data.get('blockdevices', []): + for dev in _get_volumes(json_data.get('blockdevices', [])): volumes.append(dev) - for child in dev.get('children', []): - volumes.append(child) - if child['parttype'] == UUID_CORESTORAGE: - containers.append(child['name']) + if dev.get('parttype', '') == UUID_CORESTORAGE: + containers.append(dev['name']) # Scan CoreStorage containers if scan_corestorage: