Skip to content

Commit

Permalink
installer: T7036: handle missing flavor and architecture data gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
dmbaturin committed Jan 30, 2025
1 parent 608db9e commit fb74bd9
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions src/op_mode/image_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@
MSG_ERR_LIVE: str = 'The system is in live-boot mode. Please use "install image" instead.'
MSG_ERR_NO_DISK: str = 'No suitable disk was found. There must be at least one disk of 2GB or greater size.'
MSG_ERR_IMPROPER_IMAGE: str = 'Missing sha256sum.txt.\nEither this image is corrupted, or of era 1.2.x (md5sum) and would downgrade image tools;\ndisallowed in either case.'
MSG_ERR_ARCHITECTURE_MISMATCH: str = 'Upgrading to a different image architecture will break your system.'
MSG_ERR_INCOMPATIBLE_IMAGE: str = 'Image compatibility check failed, aborting installation.'
MSG_ERR_ARCHITECTURE_MISMATCH: str = 'The current architecture is "{0}", the new image is for "{1}". Upgrading to a different image architecture will break your system.'
MSG_ERR_FLAVOR_MISMATCH: str = 'The current image flavor is "{0}", the new image is "{1}". Upgrading to a non-matching flavor can have unpredictable consequences.'
MSG_ERR_MISSING_ARCHITECTURE: str = 'The new image version data does not specify architecture, cannot check compatibility (is it a legacy release image?)'
MSG_ERR_MISSING_FLAVOR: str = 'The new image version data does not specify flavor, cannot check compatibility (is it a legacy release image?)'
MSG_ERR_CORRUPT_CURRENT_IMAGE: str = 'Version data in the current image is malformed: missing flavor and/or architecture fields. Upgrade compatibility cannot be checked.'
MSG_INFO_INSTALL_WELCOME: str = 'Welcome to VyOS installation!\nThis command will install VyOS to your permanent storage.'
MSG_INFO_INSTALL_EXIT: str = 'Exiting from VyOS installation'
MSG_INFO_INSTALL_SUCCESS: str = 'The image installed successfully; please reboot now.'
Expand Down Expand Up @@ -707,25 +711,42 @@ def validate_compatibility(iso_path: str, force: bool = False) -> None:
Args:
iso_path (str): a path to the mounted ISO image
"""
old_data = get_version_data()
old_flavor = old_data.get('flavor', '')
old_architecture = old_data.get('architecture') or cmd('dpkg --print-architecture')
current_data = get_version_data()
current_flavor = current_data.get('flavor')
current_architecture = current_data.get('architecture') or cmd('dpkg --print-architecture')

new_data = get_version_data(f'{iso_path}/version.json')
new_flavor = new_data.get('flavor', '')
new_architecture = new_data.get('architecture', '')
new_flavor = new_data.get('flavor')
new_architecture = new_data.get('architecture')

if not old_architecture == new_architecture:
print(MSG_ERR_ARCHITECTURE_MISMATCH)
if not current_flavor or not current_architecture:
# This may only happen if someone modified the version file.
# Unlikely but not impossible.
print(MSG_ERR_CORRUPT_CURRENT_IMAGE)
cleanup()
exit(MSG_INFO_INSTALL_EXIT)

if not old_flavor == new_flavor:
print(MSG_ERR_FLAVOR_MISMATCH.format(old_flavor, new_flavor))
success = True

if current_architecture != new_architecture:
success = False
if not new_architecture:
print(MSG_ERR_MISSING_ARCHITECTURE)
else:
print(MSG_ERR_ARCHITECTURE_MISMATCH.format(current_architecture, new_architecture))

if current_flavor != new_flavor:
if not force:
cleanup()
exit(MSG_INFO_INSTALL_EXIT)
success = False
if not new_flavor:
print(MSG_ERR_MISSING_FLAVOR)
else:
print(MSG_ERR_FLAVOR_MISMATCH.format(current_flavor, new_flavor))

if not success:
print(MSG_ERR_INCOMPATIBLE_IMAGE)
cleanup()
exit(MSG_INFO_INSTALL_EXIT)

def install_image() -> None:
"""Install an image to a disk
Expand Down

0 comments on commit fb74bd9

Please sign in to comment.