Skip to content

Commit 4c4907c

Browse files
committed
Implement changes for compatibility with ansible-core 2.19
1 parent 0c82a12 commit 4c4907c

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ description: Ansible Network Collection for Enterprise SONiC Distribution by Del
2121
license_file: LICENSE
2222
tags: [dellemc, dell, networking, nos, sonic]
2323
dependencies:
24-
"ansible.netcommon": ">5.0.0"
24+
"ansible.netcommon": ">=8.1.0"
2525
repository: https://github.com/ansible-collections/dellemc.enterprise_sonic
2626
issues: https://github.com/ansible-collections/dellemc.enterprise_sonic/issues

tests/unit/modules/utils.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,38 @@
99
from ansible_collections.dellemc.enterprise_sonic.tests.unit.compat import unittest
1010
from ansible_collections.dellemc.enterprise_sonic.tests.unit.compat.mock import patch
1111

12+
cur_context = None
1213

1314
def set_module_args(args):
15+
16+
global cur_context
17+
1418
if '_ansible_remote_tmp' not in args:
1519
args['_ansible_remote_tmp'] = '/tmp'
1620
if '_ansible_keep_remote_files' not in args:
1721
args['_ansible_keep_remote_files'] = False
1822

19-
args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
20-
basic._ANSIBLE_ARGS = to_bytes(args)
21-
23+
# Quiesce and clear any previously existing context for
24+
# patch_module_args invocation.
25+
if cur_context is not None:
26+
try:
27+
cur_context.__exit__(None, None, None)
28+
except Exception:
29+
pass
30+
cur_context = None
31+
32+
# Use patch_module_args if it's available (used in
33+
# ansible-core 2.19+)
34+
try:
35+
from ansible.module_utils.testing import patch_module_args
36+
37+
cur_context = patch_module_args(args)
38+
cur_context.__enter__()
39+
except ImportError:
40+
# Fall back to "manual" setting of module args for older
41+
# Ansible versions.
42+
serialized_args = json.dumps({"ANSIBLE_MODULE_ARGS": args})
43+
basic._ANSIBLE_ARGS = to_bytes(serialized_args)
2244

2345
class AnsibleExitJson(Exception):
2446
pass

0 commit comments

Comments
 (0)