summaryrefslogtreecommitdiff
path: root/src/op_mode
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-04-22 13:18:17 -0500
committerJohn Estabrook <jestabro@vyos.io>2024-04-22 20:11:08 -0500
commitc2fc2dba32ba861684f5e34635f810c56d551d51 (patch)
tree6174dae9f0dd072c6a750816506506bfbab73743 /src/op_mode
parent5ebcbddb0842c570284cd17553395fcc2e2edad0 (diff)
downloadvyos-1x-c2fc2dba32ba861684f5e34635f810c56d551d51.tar.gz
vyos-1x-c2fc2dba32ba861684f5e34635f810c56d551d51.zip
image-tools: T6260: remove persistence image directory if no space error
Diffstat (limited to 'src/op_mode')
-rwxr-xr-xsrc/op_mode/image_installer.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/op_mode/image_installer.py b/src/op_mode/image_installer.py
index b1311b6f9..ba0e3b6db 100755
--- a/src/op_mode/image_installer.py
+++ b/src/op_mode/image_installer.py
@@ -26,6 +26,7 @@ from os import environ
from typing import Union
from urllib.parse import urlparse
from passlib.hosts import linux_context
+from errno import ENOSPC
from psutil import disk_partitions
@@ -939,6 +940,16 @@ def add_image(image_path: str, vrf: str = None, username: str = '',
if set_as_default:
grub.set_default(image_name, root_dir)
+ except OSError as e:
+ # if no space error, remove image dir and cleanup
+ if e.errno == ENOSPC:
+ cleanup(mounts=[str(iso_path)],
+ remove_items=[f'{root_dir}/boot/{image_name}'])
+ else:
+ # unmount an ISO and cleanup
+ cleanup([str(iso_path)])
+ exit(f'Error: {e}')
+
except Exception as err:
# unmount an ISO and cleanup
cleanup([str(iso_path)])