From 93f30bbfcb073fd8213c18c2e7eb7f857234fc8a Mon Sep 17 00:00:00 2001 From: James Falcon Date: Thu, 29 Aug 2024 18:22:23 -0400 Subject: [PATCH] fix: properly handle blank lines in fstab (#5643) --- cloudinit/config/cc_mounts.py | 5 +++-- tests/unittests/config/test_cc_mounts.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cloudinit/config/cc_mounts.py b/cloudinit/config/cc_mounts.py index 1d9f821bbd0..20e23296a4f 100644 --- a/cloudinit/config/cc_mounts.py +++ b/cloudinit/config/cc_mounts.py @@ -374,8 +374,9 @@ def parse_fstab() -> Tuple[List[str], Dict[str, str], List[str]]: fstab_removed.append(line) continue toks = line.split() - fstab_devs[toks[0]] = line - fstab_lines.append(line) + if toks: + fstab_devs[toks[0]] = line + fstab_lines.append(line) return fstab_lines, fstab_devs, fstab_removed diff --git a/tests/unittests/config/test_cc_mounts.py b/tests/unittests/config/test_cc_mounts.py index 7e85987b744..0e6d8379379 100644 --- a/tests/unittests/config/test_cc_mounts.py +++ b/tests/unittests/config/test_cc_mounts.py @@ -533,6 +533,7 @@ def test_fstab_mounts_combinations(self): "LABEL=keepme none ext4 defaults 0 0\n" "/dev/sda1 /a auto defaults,comment=cloudconfig 0 2\n" "LABEL=UEFI\n" + "\n" "/dev/sda2 /b auto defaults,comment=cloudconfig 0 2\n" ) with open(cc_mounts.FSTAB_PATH, "w") as fd: