mirror of
https://github.com/kubevirt/kubevirt.core.git
synced 2026-05-07 22:02:38 +00:00
fix: Ensure compatibility with ansible-core >= 2.19
ansible-core 2.19 changes the way templates are trusted and provides a new way of patching module args in unit tests. With this commit the following changes are made to ensure compatibility with ansible-core >= 2.19: - Mark inputs to composable as trusted to align with the new template trust model. - Utilize the updated method for patching module arguments in unit tests if available. - Replace direct access to the self._cache attribute with the inventory's cache property. Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
This commit is contained in:
@@ -10,16 +10,24 @@ from __future__ import absolute_import, division, print_function
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
from contextlib import contextmanager
|
||||
from json import dumps
|
||||
from typing import (
|
||||
Any,
|
||||
Dict,
|
||||
)
|
||||
from unittest import mock
|
||||
|
||||
from ansible.module_utils import basic
|
||||
from ansible.module_utils.common.text.converters import to_bytes
|
||||
|
||||
|
||||
def set_module_args(args):
|
||||
@contextmanager
|
||||
def patch_module_args(args: Dict[str, Any] | None = None):
|
||||
"""prepare arguments so that they will be picked up during module creation"""
|
||||
args = json.dumps({"ANSIBLE_MODULE_ARGS": args})
|
||||
basic._ANSIBLE_ARGS = to_bytes(args)
|
||||
args = dumps({"ANSIBLE_MODULE_ARGS": args})
|
||||
with mock.patch.object(basic, "_ANSIBLE_ARGS", to_bytes(args)):
|
||||
yield
|
||||
|
||||
|
||||
class AnsibleExitJson(Exception):
|
||||
|
||||
Reference in New Issue
Block a user