summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-02-06 18:15:01 +0100
committerGitHub <noreply@github.com>2024-02-06 18:15:01 +0100
commita0a18c4fa02c9d8aae30950720362d599a8ba6cd (patch)
tree57d270d1ad084a5bfcc52d2b0c72a252dc92c9f6 /python
parent5f61a51c8f5a647ff0eac4563a77cc58bf549c15 (diff)
parent1eb17f79bf3ebf29c4caf7e09734cd3a6346cdd2 (diff)
downloadvyos-1x-a0a18c4fa02c9d8aae30950720362d599a8ba6cd.tar.gz
vyos-1x-a0a18c4fa02c9d8aae30950720362d599a8ba6cd.zip
Merge pull request #2948 from vyos/mergify/bp/sagitta/pr-2941
image-tools: T6016: wait for umount in cleanup function (backport #2941)
Diffstat (limited to 'python')
-rw-r--r--python/vyos/system/disk.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/python/vyos/system/disk.py b/python/vyos/system/disk.py
index 7860d719f..c8908cd5c 100644
--- a/python/vyos/system/disk.py
+++ b/python/vyos/system/disk.py
@@ -16,6 +16,7 @@
from json import loads as json_loads
from os import sync
from dataclasses import dataclass
+from time import sleep
from psutil import disk_partitions
@@ -207,13 +208,25 @@ def find_device(mountpoint: str) -> str:
Returns:
str: Path to device, Empty if not found
"""
- mounted_partitions = disk_partitions()
+ mounted_partitions = disk_partitions(all=True)
for partition in mounted_partitions:
if partition.mountpoint == mountpoint:
return partition.mountpoint
return ''
+def wait_for_umount(mountpoint: str = '') -> None:
+ """Wait (within reason) for umount to complete
+ """
+ i = 0
+ while find_device(mountpoint):
+ i += 1
+ if i == 5:
+ print(f'Warning: {mountpoint} still mounted')
+ break
+ sleep(1)
+
+
def disks_size() -> dict[str, int]:
"""Get a dictionary with physical disks and their sizes