Skip to content

Commit 6de4d74

Browse files
committed
installer: T7036: handle missing version data in images gracefully
1 parent 3f26685 commit 6de4d74

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

src/op_mode/image_installer.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@
4646
MSG_ERR_LIVE: str = 'The system is in live-boot mode. Please use "install image" instead.'
4747
MSG_ERR_NO_DISK: str = 'No suitable disk was found. There must be at least one disk of 2GB or greater size.'
4848
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.'
49-
MSG_ERR_ARCHITECTURE_MISMATCH: str = 'Upgrading to a different image architecture will break your system.'
49+
MSG_ERR_INCOMPATIBLE_IMAGE: str = 'Image compatibility check failed, aborting installation.'
50+
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.'
5051
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.'
52+
MSG_ERR_MISSING_ARCHITECTURE: str = 'The new image version data does not specify architecture, cannot check compatibility (is it a legacy release image?)'
53+
MSG_ERR_MISSING_FLAVOR: str = 'The new image version data does not specify flavor, cannot check compatibility (is it a legacy release image?)'
54+
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.'
5155
MSG_INFO_INSTALL_WELCOME: str = 'Welcome to VyOS installation!\nThis command will install VyOS to your permanent storage.'
5256
MSG_INFO_INSTALL_EXIT: str = 'Exiting from VyOS installation'
5357
MSG_INFO_INSTALL_SUCCESS: str = 'The image installed successfully; please reboot now.'
@@ -707,25 +711,42 @@ def validate_compatibility(iso_path: str) -> None:
707711
Args:
708712
iso_path (str): a path to the mounted ISO image
709713
"""
710-
old_data = get_version_data()
711-
old_flavor = old_data.get('flavor', '')
712-
old_architecture = old_data.get('architecture') or cmd('dpkg --print-architecture')
714+
current_data = get_version_data()
715+
current_flavor = current_data.get('flavor')
716+
current_architecture = current_data.get('architecture') or cmd('dpkg --print-architecture')
713717

714718
new_data = get_version_data(f'{iso_path}/version.json')
715-
new_flavor = new_data.get('flavor', '')
716-
new_architecture = new_data.get('architecture', '')
719+
new_flavor = new_data.get('flavor')
720+
new_architecture = new_data.get('architecture')
717721

718-
if not old_architecture == new_architecture:
719-
print(MSG_ERR_ARCHITECTURE_MISMATCH)
722+
if not current_flavor or not current_architecture:
723+
# This may only happen if someone modified the version file.
724+
# Unlikely but not impossible.
725+
print(MSG_ERR_CORRUPT_CURRENT_IMAGE)
720726
cleanup()
721727
exit(MSG_INFO_INSTALL_EXIT)
722728

723-
if not old_flavor == new_flavor:
724-
print(MSG_ERR_FLAVOR_MISMATCH.format(old_flavor, new_flavor))
729+
success = True
730+
731+
if current_architecture != new_architecture:
732+
success = False
733+
if not new_architecture:
734+
print(MSG_ERR_MISSING_ARCHITECTURE)
735+
else:
736+
print(MSG_ERR_ARCHITECTURE_MISMATCH.format(current_architecture, new_architecture))
737+
738+
if current_flavor != new_flavor:
739+
success = False
740+
if not new_flavor:
741+
print(MSG_ERR_MISSING_FLAVOR)
742+
else:
743+
print(MSG_ERR_FLAVOR_MISMATCH.format(current_flavor, new_flavor))
744+
745+
if not success:
746+
print(MSG_ERR_INCOMPATIBLE_IMAGE)
725747
cleanup()
726748
exit(MSG_INFO_INSTALL_EXIT)
727749

728-
729750
def install_image() -> None:
730751
"""Install an image to a disk
731752
"""

0 commit comments

Comments
 (0)