Revert patches in reverse order
Change-Id: I8f3431691d93043fb49570f68417cf3011b5d806
This commit is contained in:
parent
fdafa2666d
commit
60386fe00c
|
@ -168,7 +168,7 @@ def test_applied_patches(mocker, container, prefix, patches, error):
|
||||||
pass
|
pass
|
||||||
assert [
|
assert [
|
||||||
mock.call(container, prefix, *patches),
|
mock.call(container, prefix, *patches),
|
||||||
mock.call(container, prefix, *patches, revert=True)
|
mock.call(container, prefix, *patches[::-1], revert=True)
|
||||||
] == apply_patches.call_args_list
|
] == apply_patches.call_args_list
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ def test_applied_context_manager(mocker, patches, cwd, is_exception):
|
||||||
pass
|
pass
|
||||||
assert [
|
assert [
|
||||||
mock.call(cwd, patches),
|
mock.call(cwd, patches),
|
||||||
mock.call(cwd, patches, revert=True)
|
mock.call(cwd, patches[::-1], revert=True)
|
||||||
] == patch_mock.call_args_list
|
] == patch_mock.call_args_list
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,11 @@ def test_applied_patches(mocker, node, mock_open,
|
||||||
error_idx = error_idx or len(patches) + 1
|
error_idx = error_idx or len(patches) + 1
|
||||||
mock_shutil_side_effect = []
|
mock_shutil_side_effect = []
|
||||||
|
|
||||||
|
revert_patches = []
|
||||||
|
|
||||||
for idx, path in enumerate(patches):
|
for idx, path in enumerate(patches):
|
||||||
|
if idx < error_idx:
|
||||||
|
revert_patches.append(path)
|
||||||
if idx <= error_idx:
|
if idx <= error_idx:
|
||||||
mock_open_calls.append(mock.call(path, "rb"))
|
mock_open_calls.append(mock.call(path, "rb"))
|
||||||
mock_patch_calls.append(mock.call(
|
mock_patch_calls.append(mock.call(
|
||||||
|
@ -57,17 +61,17 @@ def test_applied_patches(mocker, node, mock_open,
|
||||||
else:
|
else:
|
||||||
mock_shutil_side_effect.append(None)
|
mock_shutil_side_effect.append(None)
|
||||||
|
|
||||||
for idx, path in enumerate(patches):
|
revert_patches.reverse()
|
||||||
if idx < error_idx:
|
for path in revert_patches:
|
||||||
mock_shutil_side_effect.append(None)
|
mock_shutil_side_effect.append(None)
|
||||||
mock_patch_calls.append(mock.call(
|
mock_patch_calls.append(mock.call(
|
||||||
["patch", "-R", "-p1", "-d", cwd], node=node, stdin=ssh.PIPE
|
["patch", "-R", "-p1", "-d", cwd], node=node, stdin=ssh.PIPE
|
||||||
))
|
))
|
||||||
mock_open_calls.append(mock.call(path, "rb"))
|
mock_open_calls.append(mock.call(path, "rb"))
|
||||||
mock_shutil_calls.append(mock.call(
|
mock_shutil_calls.append(mock.call(
|
||||||
mock_open.return_value,
|
mock_open.return_value,
|
||||||
mock_popen.return_value.__enter__.return_value.stdin
|
mock_popen.return_value.__enter__.return_value.stdin
|
||||||
))
|
))
|
||||||
|
|
||||||
mock_shutil = mocker.patch(
|
mock_shutil = mocker.patch(
|
||||||
"shutil.copyfileobj", side_effect=mock_shutil_side_effect)
|
"shutil.copyfileobj", side_effect=mock_shutil_side_effect)
|
||||||
|
|
|
@ -239,7 +239,7 @@ def applied_patches(container, prefix, *patches):
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
apply_patches(container, prefix, *patches, revert=True)
|
apply_patches(container, prefix, *patches[::-1], revert=True)
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
|
|
|
@ -36,7 +36,7 @@ def applied_patch(cwd, *patches):
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
patch_apply(cwd, patches, revert=True)
|
patch_apply(cwd, patches[::-1], revert=True)
|
||||||
|
|
||||||
|
|
||||||
def get_filenames_from_single_patch(patch):
|
def get_filenames_from_single_patch(patch):
|
||||||
|
|
|
@ -245,6 +245,7 @@ def applied_patches(cwd, node, *patches):
|
||||||
patched_files.append(path)
|
patched_files.append(path)
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
|
patched_files.reverse()
|
||||||
for path in patched_files:
|
for path in patched_files:
|
||||||
with open(path, "rb") as patch:
|
with open(path, "rb") as patch:
|
||||||
with popen(
|
with popen(
|
||||||
|
|
Loading…
Reference in New Issue