Skip to content

Commit

Permalink
Change config diff utility function (#318)
Browse files Browse the repository at this point in the history
* Change config util

* Fix sanity error

* Add fragment file

* Fix sanity error

* Address review comment

* Address more review comments
  • Loading branch information
mingjunzhang2019 authored Dec 22, 2023
1 parent a745f08 commit 9572088
Show file tree
Hide file tree
Showing 24 changed files with 208 additions and 87 deletions.
19 changes: 19 additions & 0 deletions changelogs/fragments/318-playbook-diff-mode-enhancement.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
minor_changes:
- sonic_aaa - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_acl_interfaces - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_interfaces - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_ip_neighbor - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_l2_acls - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_l2_interfaces - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_l3_acls - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_lag_interfaces - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_logging - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_ntp - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_port_group - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_radius_server - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_static_routes - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_system - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_tacacs_server - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_users - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_vlans - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
- sonic_vrfs - Enhance config diff generation function (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/318).
5 changes: 3 additions & 2 deletions plugins/module_utils/network/sonic/config/aaa/aaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ def execute_module(self):
new_config = get_new_config(commands, existing_aaa_facts)
result['after(generated)'] = new_config
if self._module._diff:
result['config_diff'] = get_formatted_config_diff(old_config,
new_config)
result['diff'] = get_formatted_config_diff(old_config,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ def execute_module(self):
if self._module._diff:
self.sort_config(new_config)
self.sort_config(old_config)
result['config_diff'] = get_formatted_config_diff(old_config,
new_config)
result['diff'] = get_formatted_config_diff(old_config,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ def execute_module(self):
old_config.sort(key=lambda x: x['name'])

if self._module._diff:
result['config_diff'] = get_formatted_config_diff(old_config,
new_config)
result['diff'] = get_formatted_config_diff(old_config,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __derive_ip_neighbor_config_delete_op(key_set, command, exist_conf):


TEST_KEYS_formatted_diff = [
{'__delete_op_default': {'__delete_op': __derive_ip_neighbor_config_delete_op}},
{'__default_ops': {'__delete_op': __derive_ip_neighbor_config_delete_op}},
]


Expand Down Expand Up @@ -170,8 +170,9 @@ def execute_module(self):
result['after(generated)'] = new_config

if self._module._diff:
result['config_diff'] = get_formatted_config_diff(existing_ip_neighbor_facts,
new_config)
result['diff'] = get_formatted_config_diff(existing_ip_neighbor_facts,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
5 changes: 3 additions & 2 deletions plugins/module_utils/network/sonic/config/l2_acls/l2_acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ def execute_module(self):
if self._module._diff:
self.sort_config(new_config)
self.sort_config(old_config)
result['config_diff'] = get_formatted_config_diff(old_config,
new_config)
result['diff'] = get_formatted_config_diff(old_config,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ def execute_module(self):
if self._module._diff:
self.sort_config(new_config)
self.sort_config(old_config)
result['config_diff'] = get_formatted_config_diff(old_config,
new_config)
result['diff'] = get_formatted_config_diff(old_config,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
5 changes: 3 additions & 2 deletions plugins/module_utils/network/sonic/config/l3_acls/l3_acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ def execute_module(self):
if self._module._diff:
self.sort_config(new_config)
self.sort_config(old_config)
result['config_diff'] = get_formatted_config_diff(old_config,
new_config)
result['diff'] = get_formatted_config_diff(old_config,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ def execute_module(self):
if self._module._diff:
self.sort_config(new_config)
self.sort_config(old_config)
result['config_diff'] = get_formatted_config_diff(old_config,
new_config)
result['diff'] = get_formatted_config_diff(old_config,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
5 changes: 3 additions & 2 deletions plugins/module_utils/network/sonic/config/logging/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ def execute_module(self):
result['after(generated)'] = new_config

if self._module._diff:
result['config_diff'] = get_formatted_config_diff(existing_logging_facts,
new_config)
result['diff'] = get_formatted_config_diff(existing_logging_facts,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
8 changes: 4 additions & 4 deletions plugins/module_utils/network/sonic/config/ntp/ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{"ntp_keys": {"key_id": ""}}
]
TEST_KEYS_formatted_diff = [
{'__delete_op_default': {'__delete_op': __DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF}},
{'__default_ops': {'__delete_op': __DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF}},
{"servers": {"address": "", '__delete_op': __DELETE_CONFIG_IF_NO_SUBCONFIG}},
{"ntp_keys": {"key_id": "", '__delete_op': __DELETE_CONFIG_IF_NO_SUBCONFIG}}
]
Expand Down Expand Up @@ -122,9 +122,9 @@ def execute_module(self):
result['after(generated)'] = new_config

if self._module._diff:
result['config_diff'] = get_formatted_config_diff(existing_ntp_facts,
new_config)

result['diff'] = get_formatted_config_diff(existing_ntp_facts,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ def execute_module(self):
result['after(generated)'] = new_config

if self._module._diff:
result['config_diff'] = get_formatted_config_diff(existing_port_group_facts,
new_config)
result['diff'] = get_formatted_config_diff(existing_port_group_facts,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{'host': {'name': ''}},
]
TEST_KEYS_formatted_diff = [
{'__delete_op_default': {'__delete_op': __DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF}},
{'__default_ops': {'__delete_op': __DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF}},
{'host': {'name': '', '__delete_op': __DELETE_CONFIG_IF_NO_SUBCONFIG}},
]

Expand Down Expand Up @@ -110,8 +110,9 @@ def execute_module(self):
result['after(generated)'] = new_config

if self._module._diff:
result['config_diff'] = get_formatted_config_diff(existing_radius_server_facts,
new_config)
result['diff'] = get_formatted_config_diff(existing_radius_server_facts,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ def execute_module(self):
if self._module._diff:
self.sort_lists_in_config(new_config)
self.sort_lists_in_config(old_config)
result['config_diff'] = get_formatted_config_diff(old_config,
new_config)
result['diff'] = get_formatted_config_diff(old_config,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
7 changes: 4 additions & 3 deletions plugins/module_utils/network/sonic/config/system/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __derive_system_config_delete_op(key_set, command, exist_conf):


TEST_KEYS_formatted_diff = [
{'__delete_op_default': {'__delete_op': __derive_system_config_delete_op}},
{'__default_ops': {'__delete_op': __derive_system_config_delete_op}},
]


Expand Down Expand Up @@ -126,8 +126,9 @@ def execute_module(self):
result['after(generated)'] = new_config

if self._module._diff:
result['config_diff'] = get_formatted_config_diff(existing_system_facts,
new_config)
result['diff'] = get_formatted_config_diff(existing_system_facts,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{'host': {'name': ''}},
]
TEST_KEYS_formatted_diff = [
{'__delete_op_default': {'__delete_op': __DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF}},
{'__default_ops': {'__delete_op': __DELETE_LEAFS_OR_CONFIG_IF_NO_NON_KEY_LEAF}},
{'host': {'name': '', '__delete_op': __DELETE_CONFIG_IF_NO_SUBCONFIG}},
]

Expand Down Expand Up @@ -110,8 +110,9 @@ def execute_module(self):
result['after(generated)'] = new_config

if self._module._diff:
result['config_diff'] = get_formatted_config_diff(existing_tacacs_server_facts,
new_config)
result['diff'] = get_formatted_config_diff(existing_tacacs_server_facts,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
5 changes: 3 additions & 2 deletions plugins/module_utils/network/sonic/config/users/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ def execute_module(self):
if self._module._diff:
self.sort_lists_in_config(new_config)
self.sort_lists_in_config(old_config)
result['config_diff'] = get_formatted_config_diff(old_config,
new_config)
result['diff'] = get_formatted_config_diff(old_config,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
5 changes: 3 additions & 2 deletions plugins/module_utils/network/sonic/config/vlans/vlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ def execute_module(self):
result['after(generated)'] = new_config

if self._module._diff:
result['config_diff'] = get_formatted_config_diff(existing_vlans_facts,
new_config)
result['diff'] = get_formatted_config_diff(existing_vlans_facts,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
5 changes: 3 additions & 2 deletions plugins/module_utils/network/sonic/config/vrfs/vrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ def execute_module(self):
result['after(generated)'] = new_config

if self._module._diff:
result['config_diff'] = get_formatted_config_diff(existing_vrf_interfaces_facts,
new_config)
result['diff'] = get_formatted_config_diff(existing_vrf_interfaces_facts,
new_config,
self._module._verbosity)
result['warnings'] = warnings
return result

Expand Down
Loading

0 comments on commit 9572088

Please sign in to comment.