summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-04-23 08:19:25 +0200
committerGitHub <noreply@github.com>2024-04-23 08:19:25 +0200
commit48461a9693568b1ca7ca4422130504cceed4ea28 (patch)
tree3e170665a83fc33c70171172cad1c049d0a0d2e2 /src
parentb734d1f277dc85a48e6c9b305e315cfc3e7a89d5 (diff)
parent8349d3e6a8cad1c282beb6a0552edf30cd8d2788 (diff)
downloadvyos-1x-48461a9693568b1ca7ca4422130504cceed4ea28.tar.gz
vyos-1x-48461a9693568b1ca7ca4422130504cceed4ea28.zip
Merge pull request #3350 from vyos/mergify/bp/sagitta/pr-3346
image-tools: T6260: remove persistence image directory if no space error (backport #3346)
Diffstat (limited to 'src')
-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 c401a8c20..185d12c49 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
@@ -886,6 +887,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)])