Skip to content

Commit 5bb7816

Browse files
authored
Merge pull request #4742 from c-po/add-image
image: T7818: avoid error when skipping config migration
2 parents c035c4d + 805b90a commit 5bb7816

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/op_mode/image_installer.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
from vyos.base import Warning
3939
from vyos.configtree import ConfigTree
40+
from vyos.defaults import base_dir
41+
from vyos.defaults import directories
4042
from vyos.remote import download
4143
from vyos.system import disk
4244
from vyos.system import grub
@@ -116,6 +118,7 @@
116118
CONST_RESERVED_SPACE: int = (2 + 1 + 256) * 1024**2
117119

118120
# define directories and paths
121+
DIR_CONFIG: str = directories['config']
119122
DIR_INSTALLATION: str = '/mnt/installation'
120123
DIR_ROOTFS_SRC: str = f'{DIR_INSTALLATION}/root_src'
121124
DIR_ROOTFS_DST: str = f'{DIR_INSTALLATION}/root_dst'
@@ -125,8 +128,8 @@
125128
FILE_ROOTFS_SRC: str = '/usr/lib/live/mount/medium/live/filesystem.squashfs'
126129
ISO_DOWNLOAD_PATH: str = ''
127130

128-
external_download_script = '/usr/libexec/vyos/simple-download.py'
129-
external_latest_image_url_script = '/usr/libexec/vyos/latest-image-url.py'
131+
external_download_script: str = f'{base_dir}/simple-download.py'
132+
external_latest_image_url_script: str = f'{base_dir}/latest-image-url.py'
130133

131134
# default boot variables
132135
DEFAULT_BOOT_VARS: dict[str, str] = {
@@ -344,7 +347,7 @@ def copy_preserve_owner(src: str, dst: str, *, follow_symlinks=True):
344347

345348
def copy_previous_installation_data(target_dir: str) -> None:
346349
if Path('/mnt/config').exists():
347-
copytree('/mnt/config', f'{target_dir}/opt/vyatta/etc/config',
350+
copytree('/mnt/config', f'{target_dir}{DIR_CONFIG}',
348351
dirs_exist_ok=True)
349352
if Path('/mnt/ssh').exists():
350353
copytree('/mnt/ssh', f'{target_dir}/etc/ssh',
@@ -697,7 +700,7 @@ def migrate_config() -> bool:
697700
Returns:
698701
bool: user's decision
699702
"""
700-
active_config_path: Path = Path('/opt/vyatta/etc/config/config.boot')
703+
active_config_path: Path = Path(f'{DIR_CONFIG}/config.boot')
701704
if active_config_path.exists():
702705
if ask_yes_no(MSG_INPUT_CONFIG_FOUND, default=True):
703706
return True
@@ -882,7 +885,7 @@ def install_image() -> None:
882885
valid_responses=['K', 'S'])
883886
console_dict: dict[str, str] = {'K': 'tty', 'S': 'ttyS'}
884887

885-
config_boot_list = ['/opt/vyatta/etc/config/config.boot',
888+
config_boot_list = [f'{DIR_CONFIG}/config.boot',
886889
'/opt/vyatta/etc/config.boot.default']
887890
default_config = config_boot_list[0]
888891

@@ -918,7 +921,7 @@ def install_image() -> None:
918921
# a config dir. It is the deepest one, so the comand will
919922
# create all the rest in a single step
920923
print('Creating a configuration file')
921-
target_config_dir: str = f'{DIR_DST_ROOT}/boot/{image_name}/rw/opt/vyatta/etc/config/'
924+
target_config_dir: str = f'{DIR_DST_ROOT}/boot/{image_name}/rw{DIR_CONFIG}/'
922925
Path(target_config_dir).mkdir(parents=True)
923926
chown(target_config_dir, group='vyattacfg')
924927
chmod_2775(target_config_dir)
@@ -1085,15 +1088,15 @@ def add_image(image_path: str, vrf: str = None, username: str = '',
10851088

10861089
# a config dir. It is the deepest one, so the comand will
10871090
# create all the rest in a single step
1088-
target_config_dir: str = f'{root_dir}/boot/{image_name}/rw/opt/vyatta/etc/config/'
1091+
target_config_dir: str = f'{root_dir}/boot/{image_name}/rw{DIR_CONFIG}/'
10891092
# copy config
10901093
if no_prompt or migrate_config():
10911094
print('Copying configuration directory')
10921095
# copytree preserves perms but not ownership:
10931096
Path(target_config_dir).mkdir(parents=True)
10941097
chown(target_config_dir, group='vyattacfg')
10951098
chmod_2775(target_config_dir)
1096-
copytree('/opt/vyatta/etc/config/', target_config_dir, symlinks=True,
1099+
copytree(f'{DIR_CONFIG}/', target_config_dir, symlinks=True,
10971100
copy_function=copy_preserve_owner, dirs_exist_ok=True)
10981101

10991102
# 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 = '',
11321135
if set_as_default:
11331136
grub.set_default(image_name, root_dir)
11341137

1135-
cmdline_options = get_cli_kernel_options(
1136-
f'{target_config_dir}/config.boot')
1137-
grub_util.update_kernel_cmdline_options(' '.join(cmdline_options),
1138-
root_dir=root_dir,
1139-
version=image_name)
1138+
if Path(f'{target_config_dir}/config.boot').exists():
1139+
cmdline_options = get_cli_kernel_options(
1140+
f'{target_config_dir}/config.boot')
1141+
grub_util.update_kernel_cmdline_options(' '.join(cmdline_options),
1142+
root_dir=root_dir,
1143+
version=image_name)
11401144

11411145
except OSError as e:
11421146
# if no space error, remove image dir and cleanup

0 commit comments

Comments
 (0)