in selftest/selftest.py [0:0]
def validate_dev_disk_azure_links_local(self) -> None:
"""Validate /dev/disk/azure/local links.
All local disks should have by-serial if azure-vm-utils is installed.
If NVMe id is supported, by-index and by-name will be available as well.
"""
local_disks = sorted(
[
link
for link in self.disk_info.dev_disk_azure_links
if link.startswith("/dev/disk/azure/local")
]
)
for key in ["index", "name", "serial"]:
local_disks_by_key = sorted(
[
link
for link in self.disk_info.dev_disk_azure_links
if link.startswith(f"/dev/disk/azure/local/by-{key}")
]
)
if key == "serial":
expected_count = len(self.disk_info.nvme_local_disks)
else:
expected_count = len(self.disk_info.nvme_local_disks_v2)
assert (
len(local_disks_by_key) == expected_count
), f"unexpected number of local disks by-{key}: {local_disks_by_key} (expected {expected_count})"
assert (
not self.sku_config
or not self.sku_config.nvme_id_enabled_local
or len(local_disks_by_key) == self.sku_config.nvme_local_disk_count
), f"unexpected number of local disks by sku for by-{key}: {local_disks_by_key} (expected {expected_count})"
if key == "name":
for disk in local_disks_by_key:
name = disk.split("/")[-1]
assert name.startswith(
"nvme-"
), f"unexpected local disk name: {name}"
match = re.match(r"nvme-(\d+)G-(\d+)", name)
assert (
match
), f"local disk name does not conform to expected pattern: {name}"
size, index = match.groups()
assert (
size.isdigit() and index.isdigit()
), f"invalid size or index in local disk name: {name}"
# Cross-check by-index links with by-name links.
by_index_path = f"/dev/disk/azure/local/by-index/{index}"
assert os.path.realpath(by_index_path) == os.path.realpath(
disk
), f"mismatch between by-index and by-name links: {by_index_path} != {disk}"
logger.info("validate_dev_disk_azure_links_local OK: %r", local_disks)