summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2025-09-23 13:12:44 +0100
committerGitHub <noreply@github.com>2025-09-23 13:12:44 +0100
commit5bb78168ee43bad1ad93b3353b4753ae94aa3bd5 (patch)
treeb32f205c498ca23bd155af26869b006bbb7598a5 /src
parentc035c4d627ed53c9744d956b7a4d9878e36020cb (diff)
parent805b90a636c50d63f68dd2746738030de966565a (diff)
downloadvyos-1x-5bb78168ee43bad1ad93b3353b4753ae94aa3bd5.tar.gz
vyos-1x-5bb78168ee43bad1ad93b3353b4753ae94aa3bd5.zip
Merge pull request #4742 from c-po/add-image
image: T7818: avoid error when skipping config migration
Diffstat (limited to 'src')
-rwxr-xr-xsrc/op_mode/image_installer.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/op_mode/image_installer.py b/src/op_mode/image_installer.py
index e42d5b856..6dc2dc490 100755
--- a/src/op_mode/image_installer.py
+++ b/src/op_mode/image_installer.py
@@ -37,6 +37,8 @@ from psutil import disk_partitions
from vyos.base import Warning
from vyos.configtree import ConfigTree
+from vyos.defaults import base_dir
+from vyos.defaults import directories
from vyos.remote import download
from vyos.system import disk
from vyos.system import grub
@@ -116,6 +118,7 @@ CONST_MIN_ROOT_SIZE: int = 1610612736 # 1.5 GB
CONST_RESERVED_SPACE: int = (2 + 1 + 256) * 1024**2
# define directories and paths
+DIR_CONFIG: str = directories['config']
DIR_INSTALLATION: str = '/mnt/installation'
DIR_ROOTFS_SRC: str = f'{DIR_INSTALLATION}/root_src'
DIR_ROOTFS_DST: str = f'{DIR_INSTALLATION}/root_dst'
@@ -125,8 +128,8 @@ DIR_KERNEL_SRC: str = '/boot/'
FILE_ROOTFS_SRC: str = '/usr/lib/live/mount/medium/live/filesystem.squashfs'
ISO_DOWNLOAD_PATH: str = ''
-external_download_script = '/usr/libexec/vyos/simple-download.py'
-external_latest_image_url_script = '/usr/libexec/vyos/latest-image-url.py'
+external_download_script: str = f'{base_dir}/simple-download.py'
+external_latest_image_url_script: str = f'{base_dir}/latest-image-url.py'
# default boot variables
DEFAULT_BOOT_VARS: dict[str, str] = {
@@ -344,7 +347,7 @@ def copy_preserve_owner(src: str, dst: str, *, follow_symlinks=True):
def copy_previous_installation_data(target_dir: str) -> None:
if Path('/mnt/config').exists():
- copytree('/mnt/config', f'{target_dir}/opt/vyatta/etc/config',
+ copytree('/mnt/config', f'{target_dir}{DIR_CONFIG}',
dirs_exist_ok=True)
if Path('/mnt/ssh').exists():
copytree('/mnt/ssh', f'{target_dir}/etc/ssh',
@@ -697,7 +700,7 @@ def migrate_config() -> bool:
Returns:
bool: user's decision
"""
- active_config_path: Path = Path('/opt/vyatta/etc/config/config.boot')
+ active_config_path: Path = Path(f'{DIR_CONFIG}/config.boot')
if active_config_path.exists():
if ask_yes_no(MSG_INPUT_CONFIG_FOUND, default=True):
return True
@@ -882,7 +885,7 @@ def install_image() -> None:
valid_responses=['K', 'S'])
console_dict: dict[str, str] = {'K': 'tty', 'S': 'ttyS'}
- config_boot_list = ['/opt/vyatta/etc/config/config.boot',
+ config_boot_list = [f'{DIR_CONFIG}/config.boot',
'/opt/vyatta/etc/config.boot.default']
default_config = config_boot_list[0]
@@ -918,7 +921,7 @@ def install_image() -> None:
# a config dir. It is the deepest one, so the comand will
# create all the rest in a single step
print('Creating a configuration file')
- target_config_dir: str = f'{DIR_DST_ROOT}/boot/{image_name}/rw/opt/vyatta/etc/config/'
+ target_config_dir: str = f'{DIR_DST_ROOT}/boot/{image_name}/rw{DIR_CONFIG}/'
Path(target_config_dir).mkdir(parents=True)
chown(target_config_dir, group='vyattacfg')
chmod_2775(target_config_dir)
@@ -1085,7 +1088,7 @@ def add_image(image_path: str, vrf: str = None, username: str = '',
# a config dir. It is the deepest one, so the comand will
# create all the rest in a single step
- target_config_dir: str = f'{root_dir}/boot/{image_name}/rw/opt/vyatta/etc/config/'
+ target_config_dir: str = f'{root_dir}/boot/{image_name}/rw{DIR_CONFIG}/'
# copy config
if no_prompt or migrate_config():
print('Copying configuration directory')
@@ -1093,7 +1096,7 @@ def add_image(image_path: str, vrf: str = None, username: str = '',
Path(target_config_dir).mkdir(parents=True)
chown(target_config_dir, group='vyattacfg')
chmod_2775(target_config_dir)
- copytree('/opt/vyatta/etc/config/', target_config_dir, symlinks=True,
+ copytree(f'{DIR_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.
@@ -1132,11 +1135,12 @@ def add_image(image_path: str, vrf: str = None, username: str = '',
if set_as_default:
grub.set_default(image_name, root_dir)
- cmdline_options = get_cli_kernel_options(
- f'{target_config_dir}/config.boot')
- grub_util.update_kernel_cmdline_options(' '.join(cmdline_options),
- root_dir=root_dir,
- version=image_name)
+ if Path(f'{target_config_dir}/config.boot').exists():
+ cmdline_options = get_cli_kernel_options(
+ f'{target_config_dir}/config.boot')
+ grub_util.update_kernel_cmdline_options(' '.join(cmdline_options),
+ root_dir=root_dir,
+ version=image_name)
except OSError as e:
# if no space error, remove image dir and cleanup