mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 12:21:26 -07:00
Provide kubernetes definition diffs in check_mode (#41471)
Move dict_merge from azure_rm_resource module to module_utils.common.dict_transformations and add tests. Use dict_merge to provide a fairly realistic, reliable diff output when k8s-based modules are run in check_mode. Rename unit tests so that they actually run and reflect the module_utils they're based on.
This commit is contained in:
parent
cf7a42b4f4
commit
42eaa00371
4 changed files with 78 additions and 25 deletions
|
@ -114,7 +114,7 @@ response:
|
|||
|
||||
from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
||||
from ansible.module_utils.azure_rm_common_rest import GenericRestClient
|
||||
from copy import deepcopy
|
||||
from ansible.module_utils.common.dict_transformations import dict_merge
|
||||
|
||||
try:
|
||||
from msrestazure.azure_exceptions import CloudError
|
||||
|
@ -265,21 +265,6 @@ class AzureRMResource(AzureRMModuleBase):
|
|||
return self.results
|
||||
|
||||
|
||||
def dict_merge(a, b):
|
||||
'''recursively merges dict's. not just simple a['key'] = b['key'], if
|
||||
both a and bhave a key who's value is a dict then dict_merge is called
|
||||
on both values and the result stored in the returned dictionary.'''
|
||||
if not isinstance(b, dict):
|
||||
return b
|
||||
result = deepcopy(a)
|
||||
for k, v in b.items():
|
||||
if k in result and isinstance(result[k], dict):
|
||||
result[k] = dict_merge(result[k], v)
|
||||
else:
|
||||
result[k] = deepcopy(v)
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
AzureRMResource()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue