Fix error for patching

If MOS picked some fix from upstream, the patches may be not
needed any more. We need avoid error for this case. The fix
is to make it to skip patching fix which has already existed.

Change-Id: I2b2a2cf1a01d24701b94fd00e2e815869f078cdd
Closes-Bug: #1683288
This commit is contained in:
jianghua wang 2017-04-15 17:27:46 +01:00 committed by Jianghua Wang
parent fea2e5d9a5
commit e50e18ab2a
1 changed files with 18 additions and 3 deletions

View File

@ -90,12 +90,27 @@ def patch(directory, patch_file, level):
patched = (patch_file) in patches
if not patched:
execute('patch', '-d', directory, '-p%s' % level, '-i',
os.path.join(patchset_dir, patch_file))
# use '--forward' to ignore patches that seem to be reversed or
# already applied.
ret_code, out, err = detailed_execute(
'patch', '--forward', '-d', directory, '-p%s' % level,
'-i', os.path.join(patchset_dir, patch_file),
allowed_return_codes=[0, 1])
if ret_code == 1:
skip_reason = 'Reversed (or previously applied) patch detected!'
if skip_reason in out or skip_reason in err:
LOG.info('Skipping patching %s: not needed anymore.'
% patch_file)
else:
raise ExecutionError('Failed patching %s' % patch_file)
else:
LOG.info('%s is applied successfully.' % patch_file)
with open(patches_applied, "a") as f:
f.write(patch_file + "\n")
else:
logging.info(patch_file + " is already applied - skipping")
LOG.info("%s is already applied - skipping" % patch_file)
def ssh(host, username, *cmd, **kwargs):