From e50e18ab2a04148506e33ed671714adf6c522044 Mon Sep 17 00:00:00 2001 From: jianghua wang Date: Sat, 15 Apr 2017 17:27:46 +0100 Subject: [PATCH] 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 --- plugin_source/deployment_scripts/utils.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/plugin_source/deployment_scripts/utils.py b/plugin_source/deployment_scripts/utils.py index fe511c9..a75c3a7 100644 --- a/plugin_source/deployment_scripts/utils.py +++ b/plugin_source/deployment_scripts/utils.py @@ -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):