Support install suppack multi times

When add a new VM to current MOS environment, our plugins script
compute_post_deployment.py will be triggered and it will try to
install the supplemental packages and got the exception like:
"This update has already been applied", this patch is to add the
acceptable return code 1 when execute xe-install-supplemental-pack

Change-Id: Ie4e4328ed85938a6f98b272858ce3a39f9d564d4
This commit is contained in:
Huan Xie 2017-03-08 23:28:20 -08:00
parent fdf8795844
commit 3009f637e2
2 changed files with 42 additions and 4 deletions

View File

@ -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')

View File

@ -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):