diff --git a/octane/tests/test_docker.py b/octane/tests/test_docker.py index b58719fd..d0a89729 100644 --- a/octane/tests/test_docker.py +++ b/octane/tests/test_docker.py @@ -168,7 +168,7 @@ def test_applied_patches(mocker, container, prefix, patches, error): pass assert [ 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 diff --git a/octane/tests/test_util_patch.py b/octane/tests/test_util_patch.py index c4c4109a..cd0392e1 100644 --- a/octane/tests/test_util_patch.py +++ b/octane/tests/test_util_patch.py @@ -36,7 +36,7 @@ def test_applied_context_manager(mocker, patches, cwd, is_exception): pass assert [ mock.call(cwd, patches), - mock.call(cwd, patches, revert=True) + mock.call(cwd, patches[::-1], revert=True) ] == patch_mock.call_args_list diff --git a/octane/tests/test_util_ssh.py b/octane/tests/test_util_ssh.py index 25ec982b..18eb6cef 100644 --- a/octane/tests/test_util_ssh.py +++ b/octane/tests/test_util_ssh.py @@ -42,7 +42,11 @@ def test_applied_patches(mocker, node, mock_open, error_idx = error_idx or len(patches) + 1 mock_shutil_side_effect = [] + revert_patches = [] + for idx, path in enumerate(patches): + if idx < error_idx: + revert_patches.append(path) if idx <= error_idx: mock_open_calls.append(mock.call(path, "rb")) mock_patch_calls.append(mock.call( @@ -57,17 +61,17 @@ def test_applied_patches(mocker, node, mock_open, else: mock_shutil_side_effect.append(None) - for idx, path in enumerate(patches): - if idx < error_idx: - mock_shutil_side_effect.append(None) - mock_patch_calls.append(mock.call( - ["patch", "-R", "-p1", "-d", cwd], node=node, stdin=ssh.PIPE - )) - mock_open_calls.append(mock.call(path, "rb")) - mock_shutil_calls.append(mock.call( - mock_open.return_value, - mock_popen.return_value.__enter__.return_value.stdin - )) + revert_patches.reverse() + for path in revert_patches: + mock_shutil_side_effect.append(None) + mock_patch_calls.append(mock.call( + ["patch", "-R", "-p1", "-d", cwd], node=node, stdin=ssh.PIPE + )) + mock_open_calls.append(mock.call(path, "rb")) + mock_shutil_calls.append(mock.call( + mock_open.return_value, + mock_popen.return_value.__enter__.return_value.stdin + )) mock_shutil = mocker.patch( "shutil.copyfileobj", side_effect=mock_shutil_side_effect) diff --git a/octane/util/docker.py b/octane/util/docker.py index 47d0645c..72c1f382 100644 --- a/octane/util/docker.py +++ b/octane/util/docker.py @@ -239,7 +239,7 @@ def applied_patches(container, prefix, *patches): try: yield finally: - apply_patches(container, prefix, *patches, revert=True) + apply_patches(container, prefix, *patches[::-1], revert=True) @contextlib.contextmanager diff --git a/octane/util/patch.py b/octane/util/patch.py index 87c46c92..21f2aeee 100644 --- a/octane/util/patch.py +++ b/octane/util/patch.py @@ -36,7 +36,7 @@ def applied_patch(cwd, *patches): try: yield finally: - patch_apply(cwd, patches, revert=True) + patch_apply(cwd, patches[::-1], revert=True) def get_filenames_from_single_patch(patch): diff --git a/octane/util/ssh.py b/octane/util/ssh.py index 0da76d21..2fe929f9 100644 --- a/octane/util/ssh.py +++ b/octane/util/ssh.py @@ -245,6 +245,7 @@ def applied_patches(cwd, node, *patches): patched_files.append(path) yield finally: + patched_files.reverse() for path in patched_files: with open(path, "rb") as patch: with popen(