diff options
author | Christian Breunig <christian@breunig.cc> | 2025-04-15 21:29:34 +0200 |
---|---|---|
committer | Christian Breunig <christian@breunig.cc> | 2025-05-17 14:30:45 +0200 |
commit | 74d848a981e25a5a3f563e355ba658ce70acf626 (patch) | |
tree | 3472c9dec02ab05883d315248e47ee1bfeb983de /src | |
parent | 1268ebb05e909027ecf1b9b4af4a6282d944efa7 (diff) | |
download | vyos-1x-74d848a981e25a5a3f563e355ba658ce70acf626.tar.gz vyos-1x-74d848a981e25a5a3f563e355ba658ce70acf626.zip |
image: T1771: save previous image name to upgraded image persistent storage
When performing an image upgrade we will create a file named /config/first_boot
with JSON data inside the new images persistent storage. The content of the file
will look like: {"previous_image": "1.5-stream-2025-Q3"}
The previous image name can be easily queried using "jq -r '.previous_image'".
This is the base work required for an adjusted version of the vyos-router init
script to support an automatic rollback to a previous image if things go
sideways.
Diffstat (limited to 'src')
-rwxr-xr-x | src/op_mode/image_installer.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/op_mode/image_installer.py b/src/op_mode/image_installer.py index ac5a84419..27371a18f 100755 --- a/src/op_mode/image_installer.py +++ b/src/op_mode/image_installer.py @@ -27,6 +27,7 @@ from os import readlink from os import getpid from os import getppid from json import loads +from json import dumps from typing import Union from urllib.parse import urlparse from passlib.hosts import linux_context @@ -54,6 +55,7 @@ from vyos.utils.dict import dict_search from vyos.utils.io import ask_input, ask_yes_no, select_entry from vyos.utils.file import chmod_2775 from vyos.utils.file import read_file +from vyos.utils.file import write_file from vyos.utils.process import cmd, run, rc_cmd from vyos.version import get_version_data @@ -1040,6 +1042,12 @@ def add_image(image_path: str, vrf: str = None, username: str = '', chmod_2775(target_config_dir) copytree('/opt/vyatta/etc/config/', target_config_dir, symlinks=True, copy_function=copy_preserve_owner, dirs_exist_ok=True) + + # Record information from which image we upgraded to the new one. + # This can be used for a future automatic rollback into the old image. + tmp = {'previous_image' : image.get_running_image()} + write_file(f'{target_config_dir}/first_boot', dumps(tmp)) + else: Path(target_config_dir).mkdir(parents=True) chown(target_config_dir, group='vyattacfg') |