From b6d3df4012c65b367df011f77d1a73b9fe06300d Mon Sep 17 00:00:00 2001 From: George Shuklin Date: Thu, 29 Feb 2024 16:02:35 +0200 Subject: [PATCH] wip: for patch --- integration_tests/test3.yaml | 3 ++- plugins/strategy/patching.py | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/integration_tests/test3.yaml b/integration_tests/test3.yaml index 0d181b8..e2af9d4 100644 --- a/integration_tests/test3.yaml +++ b/integration_tests/test3.yaml @@ -3,7 +3,8 @@ hosts: test gather_facts: false tasks: - - name: "known bug to cause trace for mitogen with ansible 2.16" + # https://github.com/mitogen-hq/mitogen/issues/1034 + - name: "bug 1034, known bug to cause trace for mitogen with ansible 2.16" check_mode: true ansible.builtin.package: name: "vim" diff --git a/plugins/strategy/patching.py b/plugins/strategy/patching.py index f25a04d..22b313d 100644 --- a/plugins/strategy/patching.py +++ b/plugins/strategy/patching.py @@ -19,6 +19,39 @@ import os +# Written by @AKrumov +# https://github.com/mitogen-hq/mitogen/issues/1034#issuecomment-1851557386 +patch_1034_v1 = """ +--- core.old 2024-02-29 14:53:29.478417261 +0200 ++++ core.py 2024-02-29 14:53:48.846102667 +0200 +@@ -842,11 +842,15 @@ + s, n = LATIN1_CODEC.encode(s) + return s + ++ def _unpickle_ansible_unsafe_text(self, serialized_obj): ++ return serialized_obj ++ + def _find_global(self, module, func): + \""" + Return the class implementing `module_name.class_name` or raise + `StreamError` if the module is not whitelisted. + \""" ++ print(module, __name__) + if module == __name__: + if func == '_unpickle_call_error' or func == 'CallError': + return _unpickle_call_error +@@ -860,6 +864,8 @@ + return Secret + elif func == 'Kwargs': + return Kwargs ++ elif module == 'ansible.utils.unsafe_proxy' and func == 'AnsibleUnsafeText': ++ return self._unpickle_ansible_unsafe_text + elif module == '_codecs' and func == 'encode': + return self._unpickle_bytes + elif module == '__builtin__' and func == 'bytes': +""" + + def loaders_path(): import ansible_mitogen @@ -26,6 +59,11 @@ def loaders_path(): return loaders_path +def core_path(): + from mitogen import core + return core.__file__ + + class patch_version(ContextDecorator): ORIG_LINE = "ANSIBLE_VERSION_MAX = (2, 13)\n" PATCH_LINE = "ANSIBLE_VERSION_MAX = (2, 16)\n"