From 74d848a981e25a5a3f563e355ba658ce70acf626 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Tue, 15 Apr 2025 21:29:34 +0200 Subject: 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. --- src/op_mode/image_installer.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') 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') -- cgit v1.2.3