From e6f093fc1a01ffaf37f20353b9abe9c82f950d1a Mon Sep 17 00:00:00 2001 From: Lili Deng Date: Sun, 25 Sep 2022 16:15:22 +0800 Subject: [PATCH] add sync after making partitions disk and throw exception if no partitions found --- lisa/tools/fdisk.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lisa/tools/fdisk.py b/lisa/tools/fdisk.py index e4fcb87a3..6e13203ed 100644 --- a/lisa/tools/fdisk.py +++ b/lisa/tools/fdisk.py @@ -5,7 +5,7 @@ from typing import List, cast from lisa.executable import Tool from lisa.operating_system import Posix -from lisa.util import find_patterns_in_lines +from lisa.util import LisaException, find_patterns_in_lines from .mkfs import FileSystem, Mkfs @@ -63,6 +63,10 @@ class Fdisk(Tool): ) # get the partition, e.g. /dev/sdc1 or /dev/nvme0n1p1 partition_disk = self._get_partitions(disk_name) + if not partition_disk: + raise LisaException( + f"fail to find partition(s) after formatting disk {disk_name}" + ) if format: mkfs.format_disk(partition_disk[0], file_system) return partition_disk[0] @@ -91,7 +95,7 @@ class Fdisk(Tool): def _get_partitions(self, disk_name: str) -> List[str]: partition_pattern = re.compile(rf"({disk_name}p[0-9]|{disk_name}[0-9])+") cmd_result = self.node.execute( - "ls -lt /dev/sd*; ls -lt /dev/nvme*; ls -lt /dev/xvd*", + "sync; ls -lt /dev/sd*; ls -lt /dev/nvme*; ls -lt /dev/xvd*", shell=True, sudo=True, )