Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion product.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ class SettingsNotAvailable(Exception):
XENSERVER_7_0_0 = Version([2, 1, 0]) # Platform version
XENSERVER_MIN_VERSION = XENSERVER_7_0_0

def is_rootfs_uefi(mount_point):
try:
with open(os.path.join(mount_point, 'etc', 'fstab'), 'r') as fstab:
for line in fstab:
m = re.search(r'^\s*[^#]+\s/boot/efi\s', line)
if m:
return True
except FileNotFoundError:
pass

return False

class ExistingInstallation:
def __init__(self, primary_disk, boot_device, state_device):
self.primary_disk = primary_disk
Expand Down Expand Up @@ -63,6 +75,15 @@ def isUpgradeable(self):
self.mount_state()
result = True
try:
# Don't propose to upgrade a BIOS installation with a UEFI installer and conversely
existing_is_uefi = is_rootfs_uefi(self.join_state_path())
if existing_is_uefi != constants.UEFI_INSTALLER:
logger.log("Cannot upgrade %s, installer mode (%s) does not match existing boot mode (%s)" %
(self.primary_disk,
"uefi" if constants.UEFI_INSTALLER else "legacy",
"uefi" if existing_is_uefi else "legacy"))
return False

# CA-38459: handle missing firstboot directory e.g. Rio
if os.path.exists(self.join_state_path('etc/firstboot.d/state')):
firstboot_files = [ f for f in os.listdir(self.join_state_path('etc/firstboot.d')) \
Expand Down Expand Up @@ -564,7 +585,12 @@ def findXenSourceBackups():
if os.path.exists(os.path.join(b.mount_point, '.xen-backup-partition')):
backup = XenServerBackup(p, b.mount_point)
logger.log("Found a backup: %s" % (repr(backup),))
if backup.version >= XENSERVER_MIN_VERSION and \
# Don't restore a BIOS backup with a UEFI installer and conversely
backup_is_uefi = is_rootfs_uefi(b.mount_point)
if backup_is_uefi != constants.UEFI_INSTALLER:
logger.log("Ignoring backup, installer mode (%s) does not match backup boot mode (%s)" %
("uefi" if constants.UEFI_INSTALLER else "legacy", "uefi" if backup_is_uefi else "legacy" ))
elif backup.version >= XENSERVER_MIN_VERSION and \
backup.version <= THIS_PLATFORM_VERSION:
backups.append(backup)
except:
Expand Down