Skip to content

Commit 2b7b38c

Browse files
committed
check the xapi version in the installer
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 9a903f2 commit 2b7b38c

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

backend.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
import tempfile
1212

13+
import rpm
1314
import repository
1415
import generalui
1516
import xelogging
@@ -161,7 +162,7 @@ def getPrepSequence(ans, interactive):
161162

162163
def getMainRepoSequence(ans, repos):
163164
seq = []
164-
seq.append(Task(repository.installFromRepos, lambda a: [repos] + [a.get('mounts'), a.get('kernel-alt'), a.get('linstor-version')], [],
165+
seq.append(Task(repository.installFromRepos, lambda a: [repos] + [a.get('mounts'), a.get('kernel-alt'), a.get('linstor-version'), a.get('xapi-version')], [],
165166
progress_scale=100,
166167
pass_progress_callback=True,
167168
progress_text="Installing %s..." % (", ".join([repo.name() for repo in repos]))))
@@ -440,6 +441,19 @@ def performInstallation(answers, ui_package, interactive):
440441
"latest dedicated ISO." %
441442
(answers['linstor-version'], ', '.join(available_linstor_versions)))
442443

444+
# if upgrading a host with xapi, check we can upgrade it first
445+
if answers['install-type'] == INSTALL_TYPE_REINSTALL and answers['xapi-version']:
446+
available_xapi_versions = repository.listPackagesFromRepos(
447+
main_repositories, 'xapi-core', '%{evr}', latest_only=True)
448+
if not available_xapi_versions:
449+
raise RuntimeError("No XAPI package found in package source")
450+
assert len(available_xapi_versions) == 1
451+
if rpm.labelCompare(('pkg', 'arch', available_xapi_versions[0]), ('pkg', 'arch', answers['xapi-version'])) < 0:
452+
raise RuntimeError("Cannot upgrade the host: the XAPI version on the host (%s) "
453+
"is newer than the XAPI version to install (%s). "
454+
"Please refer to the XCP-ng upgrade documentation." %
455+
(answers['xapi-version'], available_xapi_versions[0]))
456+
443457
# perform installation:
444458
prep_seq = getPrepSequence(answers, interactive)
445459
executeSequence(prep_seq, "Preparing for installation...", answers, ui_package, False)

product.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ def getLinstorVersion(rootfs_mount):
4848
return None
4949
return out
5050

51+
def getXapiVersion(rootfs_mount):
52+
""" Returns the package version of the xapi packages"""
53+
command = ['rpm', '--root', rootfs_mount, '-q', '--qf', '%{evr}', 'xapi-core']
54+
rc, out = util.runCmd2(command, with_stdout=True)
55+
if rc != 0:
56+
return None
57+
return out
58+
5159
class ExistingInstallation:
5260
def __init__(self, primary_disk, boot_device, state_device):
5361
self.primary_disk = primary_disk
@@ -388,6 +396,9 @@ def fetchIfaceInfoFromNetworkdbAsDict(bridge, iface=None):
388396
results['linstor-version'] = getLinstorVersion(self.state_fs.mount_point) or None
389397
logger.info("LINSTOR version detected: %s" % (results['linstor-version'],))
390398

399+
results['xapi-version'] = getXapiVersion(self.state_fs.mount_point) or None
400+
logger.info("xapi version detected: %s" % (results['xapi-version'],))
401+
391402
finally:
392403
self.unmount_state()
393404

upgrade.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def replace_config(config_file, destination):
608608
primary_fs.unmount()
609609

610610
prepUpgradeArgs = []
611-
prepStateChanges = ['installation-uuid', 'control-domain-uuid', 'management-address-type', 'linstor-version']
611+
prepStateChanges = ['installation-uuid', 'control-domain-uuid', 'management-address-type', 'linstor-version', 'xapi-version']
612612
def prepareUpgrade(self, progress_callback):
613613
""" Try to preserve the installation and control-domain UUIDs from
614614
xensource-inventory."""
@@ -619,7 +619,7 @@ def prepareUpgrade(self, progress_callback):
619619
except KeyError:
620620
raise RuntimeError("Required information (INSTALLATION_UUID, CONTROL_DOMAIN_UUID, MANAGEMENT_ADDRESS_TYPE) was missing from your xensource-inventory file. Aborting installation; please replace these keys and try again.")
621621

622-
return installID, controlID, mgmtAddrType, self.source.settings['linstor-version']
622+
return installID, controlID, mgmtAddrType, self.source.settings['linstor-version'], self.source.settings['xapi-version']
623623

624624
def buildRestoreList(self, src_base):
625625
restore_list = []

0 commit comments

Comments
 (0)