diff --git a/plugin_source/deployment_scripts/compute_post_deployment.py b/plugin_source/deployment_scripts/compute_post_deployment.py index 92f4125..e71b49f 100755 --- a/plugin_source/deployment_scripts/compute_post_deployment.py +++ b/plugin_source/deployment_scripts/compute_post_deployment.py @@ -129,6 +129,15 @@ def route_to_compute(endpoints, himn_xs, himn_local, username): '> /etc/udev/rules.d/90-reroute.rules')) +def parse_uuid(output): + uuid = None + index = output.strip().find('uuid:') + if index >= 0: + start = index + len('uuid:') + uuid = output[start:].strip() + return uuid + + def install_suppack(himn, username, package, xcp_version): """Install xapi driver supplemental pack. """ tmp = utils.ssh(himn, username, 'mktemp', '-d') @@ -136,8 +145,30 @@ def install_suppack(himn, username, package, xcp_version): if not os.path.exists(real_pack): utils.reportError('Package folder %s not exist' % real_pack) utils.scp(himn, username, tmp, real_pack) - utils.ssh(himn, username, 'xe-install-supplemental-pack', - tmp + '/' + package, prompt='Y\n') + if LooseVersion(xcp_version) < LooseVersion('2.2.0'): + utils.ssh(himn, username, 'xe-install-supplemental-pack', + tmp + '/' + package, prompt='Y\n') + else: + errcode, uuid, errmsg = \ + utils.ssh_detailed(himn, username, 'xe', 'update-upload', + 'file-name=' + tmp + '/' + package, + allowed_return_codes=[0, 1]) + if errcode == 0: + utils.ssh(himn, username, 'xe', 'update-apply', + 'uuid=' + uuid.strip()) + else: + LOG.debug("Install supplemental pack failed, err: %s", errmsg) + if "The uploaded update already exists" in errmsg: + uuid = parse_uuid(errmsg) + if uuid is None: + raise utils.ExecutionError(errmsg) + # Check current update is applied already + out = utils.ssh(himn, username, 'xe', 'update-list', + 'uuid=' + uuid, '--minimal') + # Apply this update if cannot find it with uuid + if not out: + utils.ssh(himn, username, 'xe', 'update-apply', + 'uuid=' + uuid) utils.ssh(himn, username, 'rm', tmp, '-rf') diff --git a/plugin_source/deployment_scripts/utils.py b/plugin_source/deployment_scripts/utils.py index 073eaaf..fe511c9 100644 --- a/plugin_source/deployment_scripts/utils.py +++ b/plugin_source/deployment_scripts/utils.py @@ -103,8 +103,15 @@ def ssh(host, username, *cmd, **kwargs): return execute('ssh', '-i', XS_RSA, '-o', 'StrictHostKeyChecking=no', - '%s@%s' % (username, host), *cmd, - prompt=kwargs.get('prompt')) + '%s@%s' % (username, host), *cmd, **kwargs) + + +def ssh_detailed(host, username, *cmd, **kwargs): + cmd = map(str, cmd) + + return detailed_execute('ssh', '-i', XS_RSA, + '-o', 'StrictHostKeyChecking=no', + '%s@%s' % (username, host), *cmd, **kwargs) def scp(host, username, target_path, filename):