Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix l3_interfaces regression failures due to IPv6 default "dad" configuration #428

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/428-l3-interfaces-default-dad-fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- sonic_l3_interfaces - Fix IPv6 default dad configuration handling (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/428).
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,21 @@ def execute_module(self):
existing_l3_intf_facts = remove_empties_from_list(existing_l3_interfaces_facts)
cmmnds = remove_empties_from_list(commands)

old_config = self.remove_default_entries(existing_l3_intf_facts)
cmds = self.remove_default_entries(cmmnds)
old_config = self.remove_default_entries(existing_l3_intf_facts, False)
cmds = self.remove_default_entries(cmmnds, True)

new_config = get_new_config(cmds, old_config,
TEST_KEYS_formatted_diff)
new_config = remove_empties_from_list(new_config)
new_config = self.remove_default_entries(new_config)
new_config = self.remove_default_entries(new_config, False)
result['after(generated)'] = new_config

if self._module._diff:
old_conf = remove_empties_from_list(old_config)
old_conf = self.remove_default_entries(old_conf)
old_conf = self.remove_default_entries(old_conf, False)

new_conf = remove_empties_from_list(new_config)
new_conf = self.remove_default_entries(new_conf)
new_conf = self.remove_default_entries(new_conf, False)

self.sort_lists_in_config(old_conf)
self.sort_lists_in_config(new_conf)
Expand Down Expand Up @@ -184,7 +184,7 @@ def _state_replaced(self, want, have):
ret_requests = list()
commands = list()
new_want = self.update_object(want)
new_have = self.remove_default_entries(have)
new_have = self.remove_default_entries(have, False)
get_replace_interfaces_list = self.get_interface_object_for_replaced(new_have, want)

diff = get_diff(get_replace_interfaces_list, new_want, TEST_KEYS)
Expand All @@ -210,9 +210,9 @@ def _state_overridden(self, want, have):
commands = list()
new_want = self.update_object(want)
new_want = remove_empties_from_list(new_want)
new_want = self.remove_default_entries(new_want)
new_want = self.remove_default_entries(new_want, True)
new_have = remove_empties_from_list(have)
new_have = self.remove_default_entries(new_have)
new_have = self.remove_default_entries(new_have, False)
get_override_interfaces = self.get_interface_object_for_overridden(new_have)
diff = get_diff(get_override_interfaces, new_want, TEST_KEYS)
diff2 = get_diff(new_want, get_override_interfaces, TEST_KEYS)
Expand Down Expand Up @@ -264,8 +264,9 @@ def _state_deleted(self, want, have):
commands = update_states(commands, "deleted")
return commands, requests

def remove_default_entries(self, config):
def remove_default_entries(self, config, input_cmds):
new_config = list()
state = self._module.params['state']
for obj in config:
new_obj = dict()
if obj.get('ipv4', None) and \
Expand All @@ -278,6 +279,34 @@ def remove_default_entries(self, config):
obj['ipv6'].get('autoconf', None) is not None or
obj['ipv6'].get('enabled', None) is not None):
new_obj['ipv6'] = obj['ipv6']
if new_obj['ipv6'].get('dad', None) == "DISABLE":

# Because 'dad' is shown in the device IPv6 config as "DISABLE" when
# 'dad' configuration has been deleted, enable correct handling
# for all states by filtering out 'dad' == "DISABLE" unless one of the
# following conditions is true:
#
# (1) The 'config' parameter to this function represents input commands
# (from the executing user playbook) and the specified target state is a
# value other than 'deleted' ("positive" configuration). This is to
# enable idempotent handling for 'deleted' state when 'deleting' a 'dad'
# value of 'DISABLE' (a no-op that should not generate a request), while
# preserving the ability to 'merge' a 'dad' value of 'DISABLE'
# when that is requested by a playbook state of 'merged', 'overridden',
# or 'replaced'.
#
# or
#
# (2) The 'config' parameter to this function does not represent input
# commands (because it is from the current device configuration) and the
# specified target state is 'merged'. (This exclusion is to enable
# idempotent handling for 'merged' state when 'merging' a 'dad' value of
# 'DISABLE'.)
if ((input_cmds and state == "deleted") or
((not input_cmds) and state != "merged")):
del new_obj['ipv6']['dad']
if new_obj['ipv6'] == {}:
del new_obj['ipv6']

if new_obj:
key_set = set(obj.keys())
Expand Down Expand Up @@ -397,7 +426,8 @@ def get_delete_l3_interfaces_requests(self, want, have):
have_ipv6_enabled = have_obj['ipv6']['enabled']
if have_obj.get('ipv6') and 'autoconf' in have_obj['ipv6']:
have_ipv6_autoconf = have_obj['ipv6']['autoconf']
if have_obj.get('ipv6') and 'dad' in have_obj['ipv6']:
if (have_obj.get('ipv6') and 'dad' in have_obj['ipv6'] and
have_obj['ipv6']['dad'] is not None and have_obj['ipv6']['dad'] != "DISABLE"):
have_ipv6_dad = have_obj['ipv6']['dad']

ipv4 = l3.get('ipv4', None)
Expand Down Expand Up @@ -548,7 +578,7 @@ def get_delete_all_requests(self, configs):
ipv6_enabled = l3['ipv6']['enabled']
if 'autoconf' in l3['ipv6']:
ipv6_autoconf = l3['ipv6']['autoconf']
if 'dad' in l3['ipv6']:
if 'dad' in l3['ipv6'] and l3['ipv6']['dad'] is not None and l3['ipv6']['dad'] != "DISABLE":
ipv6_dad = l3['ipv6']['dad']

sub_intf = self.get_sub_interface_name(name)
Expand Down
Loading