Browse Source

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
jianghua wang 2 years ago
parent
commit
e50e18ab2a
1 changed files with 18 additions and 3 deletions
  1. 18
    3
      plugin_source/deployment_scripts/utils.py

+ 18
- 3
plugin_source/deployment_scripts/utils.py View File

@@ -90,12 +90,27 @@ def patch(directory, patch_file, level):
90 90
         patched = (patch_file) in patches
91 91
 
92 92
     if not patched:
93
-        execute('patch', '-d', directory, '-p%s' % level, '-i',
94
-                os.path.join(patchset_dir, patch_file))
93
+        # use '--forward' to ignore patches that seem to be reversed or
94
+        # already applied.
95
+        ret_code, out, err = detailed_execute(
96
+            'patch', '--forward', '-d', directory, '-p%s' % level,
97
+            '-i', os.path.join(patchset_dir, patch_file),
98
+            allowed_return_codes=[0, 1])
99
+
100
+        if ret_code == 1:
101
+            skip_reason = 'Reversed (or previously applied) patch detected!'
102
+            if skip_reason in out or skip_reason in err:
103
+                LOG.info('Skipping patching %s: not needed anymore.'
104
+                         % patch_file)
105
+            else:
106
+                raise ExecutionError('Failed patching %s' % patch_file)
107
+        else:
108
+            LOG.info('%s is applied successfully.' % patch_file)
109
+
95 110
         with open(patches_applied, "a") as f:
96 111
             f.write(patch_file + "\n")
97 112
     else:
98
-        logging.info(patch_file + " is already applied - skipping")
113
+        LOG.info("%s is already applied - skipping" % patch_file)
99 114
 
100 115
 
101 116
 def ssh(host, username, *cmd, **kwargs):

Loading…
Cancel
Save