From 8c80d34c589a723253c3fb1301d3f454467d4ab3 Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Wed, 11 Sep 2024 17:57:02 -0400 Subject: [PATCH 01/14] add new 'suppress_vlan_neigh' option --- .../network/sonic/argspec/vxlans/vxlans.py | 7 ++ .../network/sonic/config/vxlans/vxlans.py | 94 ++++++++++++++++++- .../network/sonic/facts/vxlans/vxlans.py | 26 +++++ plugins/modules/sonic_vxlans.py | 18 ++++ .../roles/sonic_vxlan/defaults/main.yml | 7 ++ 5 files changed, 150 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/network/sonic/argspec/vxlans/vxlans.py b/plugins/module_utils/network/sonic/argspec/vxlans/vxlans.py index e18450f18..fea9190ca 100644 --- a/plugins/module_utils/network/sonic/argspec/vxlans/vxlans.py +++ b/plugins/module_utils/network/sonic/argspec/vxlans/vxlans.py @@ -61,6 +61,13 @@ def __init__(self, **kwargs): 'vrf': {'type': 'str'} }, 'type': 'list' + }, + 'suppress_vlan_neigh': { + 'elements': 'dict', + 'options': { + 'vlan_name': {'type': 'str'}, + }, + 'type': 'list' } }, 'type': 'list' diff --git a/plugins/module_utils/network/sonic/config/vxlans/vxlans.py b/plugins/module_utils/network/sonic/config/vxlans/vxlans.py index accab6fae..15ab8279c 100644 --- a/plugins/module_utils/network/sonic/config/vxlans/vxlans.py +++ b/plugins/module_utils/network/sonic/config/vxlans/vxlans.py @@ -37,17 +37,20 @@ get_formatted_config_diff ) from ansible.module_utils.connection import ConnectionError +import re PATCH = 'patch' DELETE = 'delete' test_keys = [ {'vlan_map': {'vlan': '', 'vni': ''}}, {'vrf_map': {'vni': '', 'vrf': ''}}, + {'suppress_vlan_neigh': {'vlan_name': ''}}, ] test_keys_generate_config = [ {'config': {'name': '', '__delete_op': __DELETE_CONFIG_IF_NO_SUBCONFIG}}, {'vlan_map': {'vlan': '', 'vni': '', '__delete_op': __DELETE_CONFIG_IF_NO_SUBCONFIG}}, {'vrf_map': {'vni': '', 'vrf': '', '__delete_op': __DELETE_CONFIG_IF_NO_SUBCONFIG}}, + ['suppress_vlan_neigh', {'vlan_name': '', '__delete_op': __DELETE_CONFIG_IF_NO_SUBCONFIG}], ] @@ -288,6 +291,7 @@ def get_create_vxlans_request(self, configs, have): tunnel_requests = self.get_create_tunnel_request(configs, have) vlan_map_requests = self.get_create_vlan_map_request(configs, have) vrf_map_requests = self.get_create_vrf_map_request(configs, have) + suppress_vlan_neigh_requests = self.get_create_suppress_vlan_neigh_request(configs, have) if tunnel_requests: requests.extend(tunnel_requests) @@ -295,12 +299,15 @@ def get_create_vxlans_request(self, configs, have): requests.extend(vlan_map_requests) if vrf_map_requests: requests.extend(vrf_map_requests) + if suppress_vlan_neigh_requests: + requests.extend(suppress_vlan_neigh_requests) return requests def get_delete_all_vxlan_request(self, have): requests = [] + suppress_vlan_neigh_requests = [] vrf_map_requests = [] vlan_map_requests = [] src_ip_requests = [] @@ -314,6 +321,7 @@ def get_delete_all_vxlan_request(self, have): # vlan_map needs to be cleared before tunnel(source-ip) for conf in have: name = conf['name'] + suppress_vlan_neigh_list = conf.get('suppress_vlan_neigh', []) vlan_map_list = conf.get('vlan_map', []) vrf_map_list = conf.get('vrf_map', []) src_ip = conf.get('source_ip', None) @@ -321,6 +329,8 @@ def get_delete_all_vxlan_request(self, have): external_ip = conf.get('external_ip', None) evpn_nvo = conf.get('evpn_nvo', None) + if suppress_vlan_neigh_list: + suppress_vlan_neigh_requests.extend(self.get_delete_suppress_vlan_neigh_request(conf, conf, name, suppress_vlan_neigh_list)) if vrf_map_list: vrf_map_requests.extend(self.get_delete_vrf_map_request(conf, conf, name, vrf_map_list)) if vlan_map_list: @@ -335,6 +345,8 @@ def get_delete_all_vxlan_request(self, have): evpn_nvo_requests.extend(self.get_delete_evpn_request(conf, conf, evpn_nvo)) tunnel_requests.extend(self.get_delete_tunnel_request(conf, conf, name)) + if suppress_vlan_neigh_requests: + requests.extend(suppress_vlan_neigh_requests) if vrf_map_requests: requests.extend(vrf_map_requests) if vlan_map_requests: @@ -358,6 +370,7 @@ def get_delete_vxlan_request(self, configs, have): if not configs: return requests + suppress_vlan_neigh_requests = [] vrf_map_requests = [] vlan_map_requests = [] src_ip_requests = [] @@ -378,30 +391,38 @@ def get_delete_vxlan_request(self, configs, have): external_ip = conf.get('external_ip', None) vlan_map_list = conf.get('vlan_map', None) vrf_map_list = conf.get('vrf_map', None) + suppress_vlan_neigh_list = conf.get('suppress_vlan_neigh', None) + have_suppress_vlan_neigh_count = 0 have_vlan_map_count = 0 have_vrf_map_count = 0 matched = next((each_vxlan for each_vxlan in have if each_vxlan['name'] == name), None) if matched: have_vlan_map = matched.get('vlan_map', []) have_vrf_map = matched.get('vrf_map', []) + have_suppress_vlan_neigh = matched.get('suppress_vlan_neigh', []) if have_vlan_map: have_vlan_map_count = len(have_vlan_map) if have_vrf_map: have_vrf_map_count = len(have_vrf_map) + if have_suppress_vlan_neigh: + have_suppress_vlan_neigh_count = len(have_suppress_vlan_neigh) is_delete_full = False if (name and vlan_map_list is None and vrf_map_list is None and src_ip is None and evpn_nvo is None and primary_ip is None and - external_ip is None): + external_ip is None and suppress_vlan_neigh_list is None): is_delete_full = True vrf_map_list = matched.get("vrf_map", []) vlan_map_list = matched.get("vlan_map", []) + suppress_vlan_neigh_list = matched.get("suppress_vlan_neigh", []) if vlan_map_list is not None and len(vlan_map_list) == 0 and matched: vlan_map_list = matched.get("vlan_map", []) if vrf_map_list is not None and len(vrf_map_list) == 0 and matched: vrf_map_list = matched.get("vrf_map", []) + if suppress_vlan_neigh_list is not None and len(suppress_vlan_neigh_list) == 0 and matched: + suppress_vlan_neigh_list = matched.get("suppress_vlan_neigh", []) if vrf_map_list: temp_vrf_map_requests = self.get_delete_vrf_map_request(conf, matched, name, vrf_map_list) @@ -413,6 +434,11 @@ def get_delete_vxlan_request(self, configs, have): if temp_vlan_map_requests: vlan_map_requests.extend(temp_vlan_map_requests) have_vlan_map_count -= len(temp_vlan_map_requests) + if suppress_vlan_neigh_list: + temp_suppress_vlan_neigh_requests = self.get_delete_suppress_vlan_neigh_request(conf, matched, name, suppress_vlan_neigh_list) + if temp_suppress_vlan_neigh_requests: + suppress_vlan_neigh_requests.extend(temp_suppress_vlan_neigh_requests) + have_suppress_vlan_neigh_count -= len(temp_suppress_vlan_neigh_requests) if src_ip: src_ip_requests.extend(self.get_delete_src_ip_request(conf, matched, name, src_ip)) if evpn_nvo: @@ -424,6 +450,8 @@ def get_delete_vxlan_request(self, configs, have): if is_delete_full: tunnel_requests.extend(self.get_delete_tunnel_request(conf, matched, name)) + if suppress_vlan_neigh_requests: + requests.extend(suppress_vlan_neigh_requests) if vrf_map_requests: requests.extend(vrf_map_requests) if vlan_map_requests: @@ -562,6 +590,43 @@ def build_create_vrf_map_payload(self, conf, vrf_map): payload_url = dict({"sonic-vrf:vni": vrf_map['vni']}) return payload_url + def get_create_suppress_vlan_neigh_request(self, configs, have): + # Create URL and payload + requests = [] + payload = dict() + vlan_list = [] + is_change_needed = False + + for conf in configs: + name = conf['name'] + new_suppress_vlan_neigh_list = conf.get('suppress_vlan_neigh', []) + if new_suppress_vlan_neigh_list: + is_change_needed = True + for each_suppress_vlan_neigh in new_suppress_vlan_neigh_list: + vlan_name = each_suppress_vlan_neigh.get('vlan_name') + vlan_list.append(vlan_name) + + payload.update(self.build_create_suppress_vlan_neigh_payload(vlan_list)) + url = "data/sonic-vxlan:sonic-vxlan/SUPPRESS_VLAN_NEIGH" + #url = "sonic-vxlan:sonic-vxlan%2fSUPPRESS_VLAN_NEIGH" + request = {"path": url, "method": PATCH, "data": payload} + requests.append(request) + + + return requests + + def build_create_suppress_vlan_neigh_payload(self, vlan_list): + payload_url = dict() + + vlans = [] + for vlan in vlan_list: + suppress_vlan_neigh_dict = dict() + suppress_vlan_neigh_dict['name'] = vlan + suppress_vlan_neigh_dict['suppress'] = 'on' + vlans.append(suppress_vlan_neigh_dict) + payload_url['sonic-vxlan:SUPPRESS_VLAN_NEIGH'] = {'SUPPRESS_VLAN_NEIGH_LIST': vlans} + return payload_url + def get_delete_evpn_request(self, conf, matched, del_evpn_nvo): # Create URL and payload requests = [] @@ -686,6 +751,28 @@ def get_delete_vrf_map_request(self, conf, matched, name, del_vrf_map_list): return requests + def get_delete_suppress_vlan_neigh_request(self, conf, matched, name, del_suppress_vlan_neigh_list): + # Create URL and payload + requests = [] + + for each_suppress_vlan_neigh in del_suppress_vlan_neigh_list: + vlan_name = each_suppress_vlan_neigh.get('vlan_name') + + is_change_needed = False + if matched: + matched_suppress_vlan_neigh_list = matched.get('suppress_vlan_neigh', None) + if matched_suppress_vlan_neigh_list: + matched_suppress_vlan_neigh = next((e_suppress_vlan_neigh for e_suppress_vlan_neigh in matched_suppress_vlan_neigh_list if e_suppress_vlan_neigh['vlan_name'] == vlan_name), None) + if matched_suppress_vlan_neigh: + is_change_needed = True + + if is_change_needed: + url = "data/sonic-vxlan:sonic-vxlan/SUPPRESS_VLAN_NEIGH" + request = {"path": url, "method": DELETE} + requests.append(request) + + return requests + def sort_lists_in_config(self, config): if config: config.sort(key=lambda x: x['name']) @@ -694,6 +781,8 @@ def sort_lists_in_config(self, config): cfg['vlan_map'].sort(key=lambda x: x['vni']) if 'vrf_map' in cfg and cfg['vrf_map']: cfg['vrf_map'].sort(key=lambda x: x['vni']) + if 'suppress_vlan_neigh' in cfg and cfg['suppress_vlan_neigh']: + cfg['suppress_vlan_neigh'].sort(key=lambda x: x['vlan_name']) def post_process_generated_config(self, configs): confs = remove_empties_from_list(configs) @@ -701,6 +790,7 @@ def post_process_generated_config(self, configs): for conf in confs[:]: vlan_map = conf.get('vlan_map', None) vrf_map = conf.get('vrf_map', None) - if not vlan_map and not vrf_map: + suppress_vlan_neigh = conf.get('suppress_vlan_neigh', None) + if not vlan_map and not vrf_map and not suppress_vlan_neigh: confs.remove(conf) return confs diff --git a/plugins/module_utils/network/sonic/facts/vxlans/vxlans.py b/plugins/module_utils/network/sonic/facts/vxlans/vxlans.py index 73252c083..b9c8e11c5 100644 --- a/plugins/module_utils/network/sonic/facts/vxlans/vxlans.py +++ b/plugins/module_utils/network/sonic/facts/vxlans/vxlans.py @@ -97,6 +97,7 @@ def get_all_vxlans(self): vxlans = [] vxlan_tunnels = [] vxlan_vlan_map = [] + suppress_vlans = [] vxlans_tunnels_vlan_map = self.get_all_vxlans_tunnels_vlan_map() vxlans_evpn_nvo_list = self.get_all_vxlans_evpn_nvo_list() @@ -109,12 +110,18 @@ def get_all_vxlans(self): if vxlans_tunnels_vlan_map['VXLAN_TUNNEL_MAP'].get('VXLAN_TUNNEL_MAP_LIST'): vxlan_vlan_map.extend(vxlans_tunnels_vlan_map['VXLAN_TUNNEL_MAP']['VXLAN_TUNNEL_MAP_LIST']) + if vxlans_tunnels_vlan_map.get('SUPPRESS_VLAN_NEIGH'): + if vxlans_tunnels_vlan_map['SUPPRESS_VLAN_NEIGH'].get('SUPPRESS_VLAN_NEIGH_LIST'): + suppress_vlans.extend(vxlans_tunnels_vlan_map['SUPPRESS_VLAN_NEIGH']['SUPPRESS_VLAN_NEIGH_LIST']) + self.fill_tunnel_source_ip(vxlans, vxlan_tunnels, vxlans_evpn_nvo_list) self.fill_vlan_map(vxlans, vxlan_vlan_map) vxlan_vrf_list = self.get_all_vxlans_vrf_list() self.fill_vrf_map(vxlans, vxlan_vrf_list) + self.fill_suppress_vlan_neigh(vxlans, suppress_vlans) + return vxlans def get_all_vxlans_vrf_list(self): @@ -204,3 +211,22 @@ def fill_vrf_map(self, vxlans, vxlan_vrf_list): vrf_map.append(dict({'vni': vni, 'vrf': vrf})) else: matched_vtep['vrf_map'] = [dict({'vni': vni, 'vrf': vrf})] + + def fill_suppress_vlan_neigh(self, vxlans, suppress_vlans): + suppress_vlan_neigh = dict() + suppress_vlan_neigh_list = [] + for each_suppress_vlan_neigh in suppress_vlans: + name = each_suppress_vlan_neigh.get('name', None) + if name is None: + continue + matched_suppres_vn = None + if vxlans: + matched_suppres_vn = vxlans[0] + + if matched_suppres_vn: + suppress_vlan_neigh = matched_suppres_vn.get('suppress_vlan_neigh') + if suppress_vlan_neigh: + suppress_vlan_neigh.append(dict({'vlan_name': name})) + else: + matched_suppres_vn['suppress_vlan_neigh'] = [dict({'vlan_name': name})] + diff --git a/plugins/modules/sonic_vxlans.py b/plugins/modules/sonic_vxlans.py index 335753e81..ea06cedde 100644 --- a/plugins/modules/sonic_vxlans.py +++ b/plugins/modules/sonic_vxlans.py @@ -87,6 +87,14 @@ vrf: type: str description: 'VRF name for VNI VRF map.' + suppress_vlan_neigh: + description: 'list map of vlan names with suppress on' + type: list + elements: dict + suboptions: + vlan_name: + type: str + description: 'name of VLAN' state: description: 'The state of the configuration after module completion.' type: str @@ -112,6 +120,8 @@ # map vni 102 vlan 12 # map vni 101 vrf Vrfcheck1 # map vni 102 vrf Vrfcheck2 +# suppress vlan-neigh vlan_name Vlan11 +# suppress vlan-neigh vlan_name Vlan12 #! # - name: "Test vxlans deleted state 01" @@ -125,6 +135,9 @@ vrf_map: - vni: 101 vrf: Vrfcheck1 + suppress_vlan_neigh: + - vlan_name: Vlan11 + - vlan_name: Vlan12 state: deleted # # After state: @@ -189,6 +202,9 @@ vrf: Vrfcheck1 - vni: 102 vrf: Vrfcheck2 + suppress_vlan_neigh: + - vlan_name: Vlan11 + - vlan_name: Vlan12 state: merged # # After state: @@ -203,6 +219,8 @@ # map vni 102 vlan 12 # map vni 101 vrf Vrfcheck1 # map vni 102 vrf Vrfcheck2 +# suppress vlan-neigh vlan-name Vlan11 +# suppress vlan-neigh vlan-name Vlan12 #! # # Using overridden diff --git a/tests/regression/roles/sonic_vxlan/defaults/main.yml b/tests/regression/roles/sonic_vxlan/defaults/main.yml index db1f0559b..50f903bf5 100644 --- a/tests/regression/roles/sonic_vxlan/defaults/main.yml +++ b/tests/regression/roles/sonic_vxlan/defaults/main.yml @@ -104,6 +104,8 @@ tests: vrf_map: - vni: 101 vrf: "{{vrf1}}" + suppress_vlan_neigh: + - vlan_name: Vlan7 - name: test_case_07 description: Replace VXLAN properties state: replaced @@ -123,6 +125,8 @@ tests: vrf: "{{vrf2}}" - vni: 102 vrf: "{{vrf1}}" + suppress_vlan_neigh: + - vlan_name: Vlan8 - name: test_case_08 description: Delete VRF properties state: deleted @@ -142,6 +146,9 @@ tests: vrf: "{{vrf2}}" - vni: 102 vrf: "{{vrf1}}" + suppress_vlan_neigh: + - vlan_name: Vlan5 + - vlan_name: Vlan6 - name: test_case_09 description: Delete VRF properties state: deleted From 3aee04b759bba15e7acccffa906b13cde09dd876 Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Thu, 12 Sep 2024 11:50:00 -0400 Subject: [PATCH 02/14] fix syntax pylint errors --- .../fragments/448-set-suppress-vlan-neigh-option.yaml | 2 ++ .../module_utils/network/sonic/config/vxlans/vxlans.py | 9 ++++----- .../module_utils/network/sonic/facts/vxlans/vxlans.py | 3 +-- 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/448-set-suppress-vlan-neigh-option.yaml diff --git a/changelogs/fragments/448-set-suppress-vlan-neigh-option.yaml b/changelogs/fragments/448-set-suppress-vlan-neigh-option.yaml new file mode 100644 index 000000000..64fb7daaf --- /dev/null +++ b/changelogs/fragments/448-set-suppress-vlan-neigh-option.yaml @@ -0,0 +1,2 @@ +minor_changes: + - sonic-vxlan - add 'suppress_vlan_neigh' option (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/448) \ No newline at end of file diff --git a/plugins/module_utils/network/sonic/config/vxlans/vxlans.py b/plugins/module_utils/network/sonic/config/vxlans/vxlans.py index 15ab8279c..52e7ac8c2 100644 --- a/plugins/module_utils/network/sonic/config/vxlans/vxlans.py +++ b/plugins/module_utils/network/sonic/config/vxlans/vxlans.py @@ -37,7 +37,6 @@ get_formatted_config_diff ) from ansible.module_utils.connection import ConnectionError -import re PATCH = 'patch' DELETE = 'delete' @@ -608,11 +607,9 @@ def get_create_suppress_vlan_neigh_request(self, configs, have): payload.update(self.build_create_suppress_vlan_neigh_payload(vlan_list)) url = "data/sonic-vxlan:sonic-vxlan/SUPPRESS_VLAN_NEIGH" - #url = "sonic-vxlan:sonic-vxlan%2fSUPPRESS_VLAN_NEIGH" request = {"path": url, "method": PATCH, "data": payload} - requests.append(request) + requests.append(request) - return requests def build_create_suppress_vlan_neigh_payload(self, vlan_list): @@ -762,7 +759,9 @@ def get_delete_suppress_vlan_neigh_request(self, conf, matched, name, del_suppre if matched: matched_suppress_vlan_neigh_list = matched.get('suppress_vlan_neigh', None) if matched_suppress_vlan_neigh_list: - matched_suppress_vlan_neigh = next((e_suppress_vlan_neigh for e_suppress_vlan_neigh in matched_suppress_vlan_neigh_list if e_suppress_vlan_neigh['vlan_name'] == vlan_name), None) + matched_suppress_vlan_neigh = next( + (e_suppress_vlan_neigh for e_suppress_vlan_neigh in matched_suppress_vlan_neigh_list if e_suppress_vlan_neigh['vlan_name'] == vlan_name), + None) if matched_suppress_vlan_neigh: is_change_needed = True diff --git a/plugins/module_utils/network/sonic/facts/vxlans/vxlans.py b/plugins/module_utils/network/sonic/facts/vxlans/vxlans.py index b9c8e11c5..1905d36e7 100644 --- a/plugins/module_utils/network/sonic/facts/vxlans/vxlans.py +++ b/plugins/module_utils/network/sonic/facts/vxlans/vxlans.py @@ -222,11 +222,10 @@ def fill_suppress_vlan_neigh(self, vxlans, suppress_vlans): matched_suppres_vn = None if vxlans: matched_suppres_vn = vxlans[0] - + if matched_suppres_vn: suppress_vlan_neigh = matched_suppres_vn.get('suppress_vlan_neigh') if suppress_vlan_neigh: suppress_vlan_neigh.append(dict({'vlan_name': name})) else: matched_suppres_vn['suppress_vlan_neigh'] = [dict({'vlan_name': name})] - From e7997f1483057de71cb2156d7dfd61ad2685f668 Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Thu, 12 Sep 2024 11:56:04 -0400 Subject: [PATCH 03/14] fix line length --- plugins/module_utils/network/sonic/config/vxlans/vxlans.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/module_utils/network/sonic/config/vxlans/vxlans.py b/plugins/module_utils/network/sonic/config/vxlans/vxlans.py index 52e7ac8c2..61ff52869 100644 --- a/plugins/module_utils/network/sonic/config/vxlans/vxlans.py +++ b/plugins/module_utils/network/sonic/config/vxlans/vxlans.py @@ -760,8 +760,7 @@ def get_delete_suppress_vlan_neigh_request(self, conf, matched, name, del_suppre matched_suppress_vlan_neigh_list = matched.get('suppress_vlan_neigh', None) if matched_suppress_vlan_neigh_list: matched_suppress_vlan_neigh = next( - (e_suppress_vlan_neigh for e_suppress_vlan_neigh in matched_suppress_vlan_neigh_list if e_suppress_vlan_neigh['vlan_name'] == vlan_name), - None) + (e_svn for e_svn in matched_suppress_vlan_neigh_list if e_svn['vlan_name'] == vlan_name), None) if matched_suppress_vlan_neigh: is_change_needed = True From e75554acfebc9ea206d5933054ccc9585793f3e5 Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Thu, 12 Sep 2024 16:31:33 -0400 Subject: [PATCH 04/14] update regression test and write UT tests --- .../roles/sonic_vxlan/defaults/main.yml | 2 + .../network/sonic/fixtures/sonic_vxlans.yaml | 86 +++++++++++++++++++ .../network/sonic/test_sonic_vxlans.py | 14 +++ 3 files changed, 102 insertions(+) diff --git a/tests/regression/roles/sonic_vxlan/defaults/main.yml b/tests/regression/roles/sonic_vxlan/defaults/main.yml index 50f903bf5..c62fbd67f 100644 --- a/tests/regression/roles/sonic_vxlan/defaults/main.yml +++ b/tests/regression/roles/sonic_vxlan/defaults/main.yml @@ -127,6 +127,8 @@ tests: vrf: "{{vrf1}}" suppress_vlan_neigh: - vlan_name: Vlan8 + - vlan_name: Vlan5 + - vlan_name: Vlan6 - name: test_case_08 description: Delete VRF properties state: deleted diff --git a/tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml b/tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml index 3e7eed9eb..47e25560c 100644 --- a/tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml +++ b/tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml @@ -73,6 +73,43 @@ merged_01: vlan: Vlan12 vni: 102 +merged_02: + module_args: + config: + - name: vteptest1 + suppress_vlan_neigh: + - vlan_name: Vlan5 + - vlan_name: Vlan6 + existing_vxlans_config: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST" + response: + code: 200 + value: + sonic-vrf:VRF_LIST: + - vrf_name: default + - path: "data/sonic-vxlan:sonic-vxlan" + response: + code: 200 + - path: "data/sonic-vxlan:sonic-vxlan/EVPN_NVO/EVPN_NVO_LIST" + response: + code: 200 + expected_config_requests: + - path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL" + method: "patch" + data: + sonic-vxlan:VXLAN_TUNNEL: + VXLAN_TUNNEL_LIST: + - name: vteptest1 + - path: "data/sonic-vxlan:sonic-vxlan/SUPPRESS_VLAN_NEIGH" + method: "patch" + data: + sonic-vxlan:SUPPRESS_VLAN_NEIGH: + SUPPRESS_VLAN_NEIGH_LIST: + - name: Vlan5 + suppress: "on" + - name: Vlan6 + suppress: "on" + deleted_01: module_args: state: deleted @@ -228,6 +265,55 @@ deleted_02: method: "delete" data: +deleted_03: + module_args: + state: deleted + config: + - name: vteptest1 + evpn_nvo: nvo1 + vrf_map: + - vni: 101 + vrf: Vrfcheck1 + suppress_vlan_neigh: + - vlan_name: Vlan5 + - vlan_name: Vlan6 + existing_vxlans_config: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST" + response: + code: 200 + value: + sonic-vrf:VRF_LIST: + - vrf_name: Vrfcheck1 + vni: 101 + - path: "data/sonic-vxlan:sonic-vxlan/EVPN_NVO/EVPN_NVO_LIST" + response: + code: 200 + value: + sonic-vxlan:EVPN_NVO_LIST: + - name: nvo1 + source_vtep: vteptest1 + - path: "data/sonic-vxlan:sonic-vxlan" + response: + code: 200 + value: + sonic-vxlan:sonic-vxlan: + VXLAN_TUNNEL: + VXLAN_TUNNEL_LIST: + - name: vteptest1 + sonic-vxlan:SUPPRESS_VLAN_NEIGH: + SUPPRESS_VLAN_NEIGH_LIST: + - name: Vlan5 + suppress: "on" + - name: Vlan6 + suppress: "on" + expected_config_requests: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST=Vrfcheck1/vni" + method: "delete" + data: + - path: "data/sonic-vxlan:sonic-vxlan/EVPN_NVO/EVPN_NVO_LIST=nvo1" + method: "delete" + data: + replaced_02: module_args: state: replaced diff --git a/tests/unit/modules/network/sonic/test_sonic_vxlans.py b/tests/unit/modules/network/sonic/test_sonic_vxlans.py index 16f7566c6..9dd829eb3 100644 --- a/tests/unit/modules/network/sonic/test_sonic_vxlans.py +++ b/tests/unit/modules/network/sonic/test_sonic_vxlans.py @@ -64,6 +64,13 @@ def test_sonic_vxlans_merged_01(self): result = self.execute_module(changed=True) self.validate_config_requests() + def test_sonic_vxlans_merged_02(self): + set_module_args(self.fixture_data['merged_02']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['merged_02']['existing_vxlans_config']) + self.initialize_config_requests(self.fixture_data['merged_02']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + def test_sonic_vxlans_deleted_01(self): set_module_args(self.fixture_data['deleted_01']['module_args']) self.initialize_facts_get_requests(self.fixture_data['deleted_01']['existing_vxlans_config']) @@ -77,6 +84,13 @@ def test_sonic_vxlans_deleted_02(self): self.initialize_config_requests(self.fixture_data['deleted_02']['expected_config_requests']) result = self.execute_module(changed=True) self.validate_config_requests() + + def test_sonic_vxlans_deleted_03(self): + set_module_args(self.fixture_data['deleted_03']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['deleted_03']['existing_vxlans_config']) + self.initialize_config_requests(self.fixture_data['deleted_03']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() # When replace is executed, it first deletes the existing config and then patches the new config. # As part of UT, sonic_module.py does a SORTING before comparison and hence the sequence of the actual configs sent to device varies from the sequence. From 0fcfe78a5f1abbce26c2b9fda1f76fd36b30262d Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Thu, 12 Sep 2024 16:41:23 -0400 Subject: [PATCH 05/14] fix linting error --- tests/unit/modules/network/sonic/test_sonic_vxlans.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/modules/network/sonic/test_sonic_vxlans.py b/tests/unit/modules/network/sonic/test_sonic_vxlans.py index 9dd829eb3..b13b526bc 100644 --- a/tests/unit/modules/network/sonic/test_sonic_vxlans.py +++ b/tests/unit/modules/network/sonic/test_sonic_vxlans.py @@ -84,7 +84,7 @@ def test_sonic_vxlans_deleted_02(self): self.initialize_config_requests(self.fixture_data['deleted_02']['expected_config_requests']) result = self.execute_module(changed=True) self.validate_config_requests() - + def test_sonic_vxlans_deleted_03(self): set_module_args(self.fixture_data['deleted_03']['module_args']) self.initialize_facts_get_requests(self.fixture_data['deleted_03']['existing_vxlans_config']) From 65d08a311ebe5d9ba1c7cba6f26eb1c65238add9 Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Tue, 1 Oct 2024 12:22:58 -0400 Subject: [PATCH 06/14] update code and tests --- .../448-set-suppress-vlan-neigh-option.yaml | 2 +- .../network/sonic/argspec/vxlans/vxlans.py | 2 +- .../network/sonic/config/vxlans/vxlans.py | 4 +- .../network/sonic/facts/vxlans/vxlans.py | 12 +- plugins/modules/sonic_vxlans.py | 2 +- .../roles/sonic_vxlan/defaults/main.yml | 3 + .../network/sonic/fixtures/sonic_vxlans.yaml | 132 +++++++++++++++++- .../network/sonic/test_sonic_vxlans.py | 14 ++ 8 files changed, 158 insertions(+), 13 deletions(-) diff --git a/changelogs/fragments/448-set-suppress-vlan-neigh-option.yaml b/changelogs/fragments/448-set-suppress-vlan-neigh-option.yaml index 64fb7daaf..44da916f8 100644 --- a/changelogs/fragments/448-set-suppress-vlan-neigh-option.yaml +++ b/changelogs/fragments/448-set-suppress-vlan-neigh-option.yaml @@ -1,2 +1,2 @@ minor_changes: - - sonic-vxlan - add 'suppress_vlan_neigh' option (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/448) \ No newline at end of file + - sonic-vxlan - Add 'suppress_vlan_neigh' option (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/448) \ No newline at end of file diff --git a/plugins/module_utils/network/sonic/argspec/vxlans/vxlans.py b/plugins/module_utils/network/sonic/argspec/vxlans/vxlans.py index fea9190ca..a96eede51 100644 --- a/plugins/module_utils/network/sonic/argspec/vxlans/vxlans.py +++ b/plugins/module_utils/network/sonic/argspec/vxlans/vxlans.py @@ -1,6 +1,6 @@ # # -*- coding: utf-8 -*- -# © Copyright 2020 Dell Inc. or its subsidiaries. All Rights Reserved +# © Copyright 2024 Dell Inc. or its subsidiaries. All Rights Reserved # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) diff --git a/plugins/module_utils/network/sonic/config/vxlans/vxlans.py b/plugins/module_utils/network/sonic/config/vxlans/vxlans.py index 61ff52869..b117e2092 100644 --- a/plugins/module_utils/network/sonic/config/vxlans/vxlans.py +++ b/plugins/module_utils/network/sonic/config/vxlans/vxlans.py @@ -1,6 +1,6 @@ # # -*- coding: utf-8 -*- -# © Copyright 2020 Dell Inc. or its subsidiaries. All Rights Reserved +# © Copyright 20204 Dell Inc. or its subsidiaries. All Rights Reserved # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """ @@ -765,7 +765,7 @@ def get_delete_suppress_vlan_neigh_request(self, conf, matched, name, del_suppre is_change_needed = True if is_change_needed: - url = "data/sonic-vxlan:sonic-vxlan/SUPPRESS_VLAN_NEIGH" + url = "data/sonic-vxlan:sonic-vxlan/SUPPRESS_VLAN_NEIGH/SUPPRESS_VLAN_NEIGH_LIST={vlan_name}".format(vlan_name=vlan_name) request = {"path": url, "method": DELETE} requests.append(request) diff --git a/plugins/module_utils/network/sonic/facts/vxlans/vxlans.py b/plugins/module_utils/network/sonic/facts/vxlans/vxlans.py index 1905d36e7..f079e0917 100644 --- a/plugins/module_utils/network/sonic/facts/vxlans/vxlans.py +++ b/plugins/module_utils/network/sonic/facts/vxlans/vxlans.py @@ -1,6 +1,6 @@ # # -*- coding: utf-8 -*- -# © Copyright 2020 Dell Inc. or its subsidiaries. All Rights Reserved +# © Copyright 2024 Dell Inc. or its subsidiaries. All Rights Reserved # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """ @@ -219,13 +219,13 @@ def fill_suppress_vlan_neigh(self, vxlans, suppress_vlans): name = each_suppress_vlan_neigh.get('name', None) if name is None: continue - matched_suppres_vn = None + matched_suppress_vn = None if vxlans: - matched_suppres_vn = vxlans[0] + matched_suppress_vn = vxlans[0] - if matched_suppres_vn: - suppress_vlan_neigh = matched_suppres_vn.get('suppress_vlan_neigh') + if matched_suppress_vn: + suppress_vlan_neigh = matched_suppress_vn.get('suppress_vlan_neigh') if suppress_vlan_neigh: suppress_vlan_neigh.append(dict({'vlan_name': name})) else: - matched_suppres_vn['suppress_vlan_neigh'] = [dict({'vlan_name': name})] + matched_suppress_vn['suppress_vlan_neigh'] = [dict({'vlan_name': name})] diff --git a/plugins/modules/sonic_vxlans.py b/plugins/modules/sonic_vxlans.py index ea06cedde..86eefc68f 100644 --- a/plugins/modules/sonic_vxlans.py +++ b/plugins/modules/sonic_vxlans.py @@ -88,7 +88,7 @@ type: str description: 'VRF name for VNI VRF map.' suppress_vlan_neigh: - description: 'list map of vlan names with suppress on' + description: 'list map of VLAN names with suppress on' type: list elements: dict suboptions: diff --git a/tests/regression/roles/sonic_vxlan/defaults/main.yml b/tests/regression/roles/sonic_vxlan/defaults/main.yml index c62fbd67f..65ef23062 100644 --- a/tests/regression/roles/sonic_vxlan/defaults/main.yml +++ b/tests/regression/roles/sonic_vxlan/defaults/main.yml @@ -75,6 +75,9 @@ tests: vrf_map: - vni: 101 vrf: "{{vrf1}}" + suppress_vlan_neigh: + - vlan_name: Vlan6 + - vlan_name: Vlan7 - name: test_case_05 description: Update VRF properties state: merged diff --git a/tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml b/tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml index 47e25560c..93ac15b35 100644 --- a/tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml +++ b/tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml @@ -417,6 +417,70 @@ replaced_02: vlan: Vlan22 vni: 102 +replaced_03: + module_args: + state: replaced + config: + - name: vteptest1 + suppress_vlan_neigh: + - vlan_name: Vlan7 + - vlan_name: Vlan8 + existing_vxlans_config: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST" + response: + code: 200 + value: + sonic-vrf:VRF_LIST: + - vrf_name: Vrfcheck1 + vni: 101 + - vrf_name: Vrfcheck2 + vni: 102 + - vrf_name: default + - path: "data/sonic-vxlan:sonic-vxlan/EVPN_NVO/EVPN_NVO_LIST" + response: + code: 200 + value: + sonic-vxlan:EVPN_NVO_LIST: + - name: nvo1 + source_vtep: vteptest1 + - path: "data/sonic-vxlan:sonic-vxlan" + response: + code: 200 + value: + sonic-vxlan:sonic-vxlan: + VXLAN_TUNNEL: + VXLAN_TUNNEL_LIST: + - name: vteptest1 + src_ip: 1.1.1.1 + primary_ip: 2.2.2.2 + external_ip: 3.3.3.3 + VXLAN_TUNNEL_MAP: + VXLAN_TUNNEL_MAP_LIST: + - name: vteptest1 + mapname: map_101_Vlan11 + vni: 101 + vlan: Vlan11 + - name: vteptest1 + mapname: map_102_Vlan12 + vni: 102 + vlan: Vlan12 + expected_config_requests: + - path: "data/sonic-vxlan:sonic-vxlan/SUPPRESS_VLAN_NEIGH" + method: "patch" + data: + sonic-vxlan:SUPPRESS_VLAN_NEIGH: + SUPPRESS_VLAN_NEIGH_LIST: + - name: Vlan7 + suppress: "on" + - name: Vlan8 + suppress: "on" + - path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL" + method: "patch" + data: + sonic-vxlan:VXLAN_TUNNEL: + VXLAN_TUNNEL_LIST: + - name: vteptest1 + overridden_02: module_args: state: overridden @@ -447,8 +511,6 @@ overridden_02: - vrf_name: Vrfcheck2 vni: 102 - vrf_name: default - - vrf_name: Vrfcheck3 - - vrf_name: Vrfcheck4 - path: "data/sonic-vxlan:sonic-vxlan/EVPN_NVO/EVPN_NVO_LIST" response: code: 200 @@ -519,3 +581,69 @@ overridden_02: mapname: map_102_Vlan22 vlan: Vlan22 vni: 102 + +overridden_03: + module_args: + state: replaced + config: + - name: vteptest1 + suppress_vlan_neigh: + - vlan_name: Vlan7 + - vlan_name: Vlan8 + existing_vxlans_config: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST" + response: + code: 200 + value: + sonic-vrf:VRF_LIST: + - vrf_name: Vrfcheck1 + vni: 101 + - vrf_name: Vrfcheck2 + vni: 102 + - vrf_name: default + - vrf_name: Vrfcheck3 + - vrf_name: Vrfcheck4 + - path: "data/sonic-vxlan:sonic-vxlan/EVPN_NVO/EVPN_NVO_LIST" + response: + code: 200 + value: + sonic-vxlan:EVPN_NVO_LIST: + - name: nvo1 + source_vtep: vteptest1 + - path: "data/sonic-vxlan:sonic-vxlan" + response: + code: 200 + value: + sonic-vxlan:sonic-vxlan: + VXLAN_TUNNEL: + VXLAN_TUNNEL_LIST: + - name: vteptest1 + src_ip: 1.1.1.1 + primary_ip: 2.2.2.2 + external_ip: 3.3.3.3 + VXLAN_TUNNEL_MAP: + VXLAN_TUNNEL_MAP_LIST: + - name: vteptest1 + mapname: map_101_Vlan11 + vni: 101 + vlan: Vlan11 + - name: vteptest1 + mapname: map_102_Vlan12 + vni: 102 + vlan: Vlan12 + expected_config_requests: + - path: "data/sonic-vxlan:sonic-vxlan/SUPPRESS_VLAN_NEIGH" + method: "patch" + data: + sonic-vxlan:SUPPRESS_VLAN_NEIGH: + SUPPRESS_VLAN_NEIGH_LIST: + - name: Vlan7 + suppress: "on" + - name: Vlan8 + suppress: "on" + - path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL" + method: "patch" + data: + sonic-vxlan:VXLAN_TUNNEL: + VXLAN_TUNNEL_LIST: + - name: vteptest1 \ No newline at end of file diff --git a/tests/unit/modules/network/sonic/test_sonic_vxlans.py b/tests/unit/modules/network/sonic/test_sonic_vxlans.py index b13b526bc..7bc462316 100644 --- a/tests/unit/modules/network/sonic/test_sonic_vxlans.py +++ b/tests/unit/modules/network/sonic/test_sonic_vxlans.py @@ -102,9 +102,23 @@ def test_sonic_vxlans_replaced_02(self): result = self.execute_module(changed=True) self.validate_config_requests() + def test_sonic_vxlans_replaced_03(self): + set_module_args(self.fixture_data['replaced_03']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['replaced_03']['existing_vxlans_config']) + self.initialize_config_requests(self.fixture_data['replaced_03']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + def test_sonic_vxlans_overridden_02(self): set_module_args(self.fixture_data['overridden_02']['module_args']) self.initialize_facts_get_requests(self.fixture_data['overridden_02']['existing_vxlans_config']) self.initialize_config_requests(self.fixture_data['overridden_02']['expected_config_requests']) result = self.execute_module(changed=True) self.validate_config_requests() + + def test_sonic_vxlans_overridden_03(self): + set_module_args(self.fixture_data['overridden_03']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['overridden_03']['existing_vxlans_config']) + self.initialize_config_requests(self.fixture_data['overridden_03']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() \ No newline at end of file From c7dda73747e08482e6d2bb40bedcb335766e9bec Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Tue, 1 Oct 2024 12:29:05 -0400 Subject: [PATCH 07/14] add missing new line --- tests/unit/modules/network/sonic/test_sonic_vxlans.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/modules/network/sonic/test_sonic_vxlans.py b/tests/unit/modules/network/sonic/test_sonic_vxlans.py index 7bc462316..85884c02c 100644 --- a/tests/unit/modules/network/sonic/test_sonic_vxlans.py +++ b/tests/unit/modules/network/sonic/test_sonic_vxlans.py @@ -121,4 +121,4 @@ def test_sonic_vxlans_overridden_03(self): self.initialize_facts_get_requests(self.fixture_data['overridden_03']['existing_vxlans_config']) self.initialize_config_requests(self.fixture_data['overridden_03']['expected_config_requests']) result = self.execute_module(changed=True) - self.validate_config_requests() \ No newline at end of file + self.validate_config_requests() From 5b170129127af2aff7c053e4defe33fa9448bba7 Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Tue, 1 Oct 2024 13:52:05 -0400 Subject: [PATCH 08/14] add 'version_added' field to 'suppress_vlan_neigh' --- plugins/modules/sonic_vxlans.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/sonic_vxlans.py b/plugins/modules/sonic_vxlans.py index 86eefc68f..b37f64fbd 100644 --- a/plugins/modules/sonic_vxlans.py +++ b/plugins/modules/sonic_vxlans.py @@ -89,6 +89,7 @@ description: 'VRF name for VNI VRF map.' suppress_vlan_neigh: description: 'list map of VLAN names with suppress on' + version_added: 3.1.0 type: list elements: dict suboptions: From 2ab9ef24c640cc414652c64ed3bd0d21317cec94 Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Thu, 3 Oct 2024 10:32:55 -0400 Subject: [PATCH 09/14] clean up unused variables and update tests --- .../448-set-suppress-vlan-neigh-option.yaml | 2 +- .../network/sonic/config/vxlans/vxlans.py | 16 +++------------- .../roles/sonic_vxlan/defaults/main.yml | 4 +++- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/changelogs/fragments/448-set-suppress-vlan-neigh-option.yaml b/changelogs/fragments/448-set-suppress-vlan-neigh-option.yaml index 44da916f8..f1941fca3 100644 --- a/changelogs/fragments/448-set-suppress-vlan-neigh-option.yaml +++ b/changelogs/fragments/448-set-suppress-vlan-neigh-option.yaml @@ -1,2 +1,2 @@ minor_changes: - - sonic-vxlan - Add 'suppress_vlan_neigh' option (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/448) \ No newline at end of file + - sonic-vxlan - Add 'suppress_vlan_neigh' vlan list option (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/448). \ No newline at end of file diff --git a/plugins/module_utils/network/sonic/config/vxlans/vxlans.py b/plugins/module_utils/network/sonic/config/vxlans/vxlans.py index b117e2092..377f7b835 100644 --- a/plugins/module_utils/network/sonic/config/vxlans/vxlans.py +++ b/plugins/module_utils/network/sonic/config/vxlans/vxlans.py @@ -1,6 +1,6 @@ # # -*- coding: utf-8 -*- -# © Copyright 20204 Dell Inc. or its subsidiaries. All Rights Reserved +# © Copyright 2024 Dell Inc. or its subsidiaries. All Rights Reserved # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """ @@ -392,20 +392,13 @@ def get_delete_vxlan_request(self, configs, have): vrf_map_list = conf.get('vrf_map', None) suppress_vlan_neigh_list = conf.get('suppress_vlan_neigh', None) - have_suppress_vlan_neigh_count = 0 - have_vlan_map_count = 0 - have_vrf_map_count = 0 + + matched = next((each_vxlan for each_vxlan in have if each_vxlan['name'] == name), None) if matched: have_vlan_map = matched.get('vlan_map', []) have_vrf_map = matched.get('vrf_map', []) have_suppress_vlan_neigh = matched.get('suppress_vlan_neigh', []) - if have_vlan_map: - have_vlan_map_count = len(have_vlan_map) - if have_vrf_map: - have_vrf_map_count = len(have_vrf_map) - if have_suppress_vlan_neigh: - have_suppress_vlan_neigh_count = len(have_suppress_vlan_neigh) is_delete_full = False if (name and vlan_map_list is None and vrf_map_list is None and @@ -427,17 +420,14 @@ def get_delete_vxlan_request(self, configs, have): temp_vrf_map_requests = self.get_delete_vrf_map_request(conf, matched, name, vrf_map_list) if temp_vrf_map_requests: vrf_map_requests.extend(temp_vrf_map_requests) - have_vrf_map_count -= len(temp_vrf_map_requests) if vlan_map_list: temp_vlan_map_requests = self.get_delete_vlan_map_request(conf, matched, name, vlan_map_list) if temp_vlan_map_requests: vlan_map_requests.extend(temp_vlan_map_requests) - have_vlan_map_count -= len(temp_vlan_map_requests) if suppress_vlan_neigh_list: temp_suppress_vlan_neigh_requests = self.get_delete_suppress_vlan_neigh_request(conf, matched, name, suppress_vlan_neigh_list) if temp_suppress_vlan_neigh_requests: suppress_vlan_neigh_requests.extend(temp_suppress_vlan_neigh_requests) - have_suppress_vlan_neigh_count -= len(temp_suppress_vlan_neigh_requests) if src_ip: src_ip_requests.extend(self.get_delete_src_ip_request(conf, matched, name, src_ip)) if evpn_nvo: diff --git a/tests/regression/roles/sonic_vxlan/defaults/main.yml b/tests/regression/roles/sonic_vxlan/defaults/main.yml index 65ef23062..24a3b2403 100644 --- a/tests/regression/roles/sonic_vxlan/defaults/main.yml +++ b/tests/regression/roles/sonic_vxlan/defaults/main.yml @@ -92,6 +92,8 @@ tests: vrf_map: - vni: 102 vrf: "{{vrf2}}" + suppress_vlan_neigh: + - vlan_name: Vlan6 - name: test_case_06 description: Override VXLAN properties state: overridden @@ -152,8 +154,8 @@ tests: - vni: 102 vrf: "{{vrf1}}" suppress_vlan_neigh: - - vlan_name: Vlan5 - vlan_name: Vlan6 + - vlan_name: Vlan7 - name: test_case_09 description: Delete VRF properties state: deleted From 9f29b5af4a554f861d61ffe242b78b12fb390f3b Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Thu, 3 Oct 2024 10:38:41 -0400 Subject: [PATCH 10/14] remove extra blank lines --- plugins/module_utils/network/sonic/config/vxlans/vxlans.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/module_utils/network/sonic/config/vxlans/vxlans.py b/plugins/module_utils/network/sonic/config/vxlans/vxlans.py index 377f7b835..f27f528a2 100644 --- a/plugins/module_utils/network/sonic/config/vxlans/vxlans.py +++ b/plugins/module_utils/network/sonic/config/vxlans/vxlans.py @@ -392,8 +392,6 @@ def get_delete_vxlan_request(self, configs, have): vrf_map_list = conf.get('vrf_map', None) suppress_vlan_neigh_list = conf.get('suppress_vlan_neigh', None) - - matched = next((each_vxlan for each_vxlan in have if each_vxlan['name'] == name), None) if matched: have_vlan_map = matched.get('vlan_map', []) From d054a2f2a6767263b702a75dfd955357fa7ca9fe Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Fri, 4 Oct 2024 11:11:05 -0400 Subject: [PATCH 11/14] add UT tests --- .../network/sonic/fixtures/sonic_vxlans.yaml | 136 ++++++++++++++++++ .../network/sonic/test_sonic_vxlans.py | 22 +++ 2 files changed, 158 insertions(+) diff --git a/tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml b/tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml index 93ac15b35..3f5eea1ae 100644 --- a/tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml +++ b/tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml @@ -110,6 +110,46 @@ merged_02: - name: Vlan6 suppress: "on" +merged_03: + module_args: + config: + - name: vteptest1 + suppress_vlan_neigh: + - vlan_name: Vlan7 + existing_vxlans_config: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST" + response: + code: 200 + value: + sonic-vrf:VRF_LIST: + - vrf_name: default + - path: "data/sonic-vxlan:sonic-vxlan" + response: + code: 200 + - path: "data/sonic-vxlan:sonic-vxlan/EVPN_NVO/EVPN_NVO_LIST" + response: + code: 200 + - path: "data/sonic-vxlan:sonic-vxlan/SUPPRESS_VLAN_NEIGH" + response: + sonic-vxlan:SUPPRESS_VLAN_NEIGH: + SUPPRESS_VLAN_NEIGH_LIST: + - name: Vlan5 + - name: Vlan6 + expected_config_requests: + - path: "data/sonic-vxlan:sonic-vxlan/SUPPRESS_VLAN_NEIGH" + method: "patch" + data: + sonic-vxlan:SUPPRESS_VLAN_NEIGH: + SUPPRESS_VLAN_NEIGH_LIST: + - name: Vlan7 + suppress: "on" + - path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL" + method: "patch" + data: + sonic-vxlan:VXLAN_TUNNEL: + VXLAN_TUNNEL_LIST: + - name: vteptest1 + deleted_01: module_args: state: deleted @@ -314,6 +354,102 @@ deleted_03: method: "delete" data: +deleted_04: + module_args: + state: deleted + config: + - name: vteptest1 + evpn_nvo: nvo1 + vrf_map: + - vni: 101 + vrf: Vrfcheck1 + suppress_vlan_neigh: + existing_vxlans_config: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST" + response: + code: 200 + value: + sonic-vrf:VRF_LIST: + - vrf_name: Vrfcheck1 + vni: 101 + - path: "data/sonic-vxlan:sonic-vxlan/EVPN_NVO/EVPN_NVO_LIST" + response: + code: 200 + value: + sonic-vxlan:EVPN_NVO_LIST: + - name: nvo1 + source_vtep: vteptest1 + - path: "data/sonic-vxlan:sonic-vxlan" + response: + code: 200 + value: + sonic-vxlan:sonic-vxlan: + VXLAN_TUNNEL: + VXLAN_TUNNEL_LIST: + - name: vteptest1 + sonic-vxlan:SUPPRESS_VLAN_NEIGH: + SUPPRESS_VLAN_NEIGH_LIST: + - name: Vlan5 + suppress: "on" + - name: Vlan6 + suppress: "on" + expected_config_requests: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST=Vrfcheck1/vni" + method: "delete" + data: + - path: "data/sonic-vxlan:sonic-vxlan/EVPN_NVO/EVPN_NVO_LIST=nvo1" + method: "delete" + data: + +deleted_05: + module_args: + state: deleted + existing_vxlans_config: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST" + response: + code: 200 + value: + sonic-vrf:VRF_LIST: + - vrf_name: Vrfcheck1 + vni: 101 + - vrf_name: Vrfcheck2 + vni: 102 + - vrf_name: default + - path: "data/sonic-vxlan:sonic-vxlan/EVPN_NVO/EVPN_NVO_LIST" + response: + code: 200 + value: + sonic-vxlan:EVPN_NVO_LIST: + - name: nvo1 + source_vtep: vteptest1 + - path: "data/sonic-vxlan:sonic-vxlan" + response: + code: 200 + value: + sonic-vxlan:sonic-vxlan: + VXLAN_TUNNEL: + VXLAN_TUNNEL_LIST: + - name: vteptest1 + sonic-vxlan:SUPPRESS_VLAN_NEIGH: + SUPPRESS_VLAN_NEIGH_LIST: + - name: Vlan5 + suppress: "on" + - name: Vlan6 + suppress: "on" + expected_config_requests: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST=Vrfcheck1/vni" + method: "delete" + data: + - path: "data/sonic-vrf:sonic-vrf/VRF/VRF_LIST=Vrfcheck2/vni" + method: "delete" + data: + - path: "data/sonic-vxlan:sonic-vxlan/EVPN_NVO/EVPN_NVO_LIST=nvo1" + method: "delete" + data: + - path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL/VXLAN_TUNNEL_LIST=vteptest1" + method: "delete" + data: + replaced_02: module_args: state: replaced diff --git a/tests/unit/modules/network/sonic/test_sonic_vxlans.py b/tests/unit/modules/network/sonic/test_sonic_vxlans.py index 85884c02c..faed9bc4a 100644 --- a/tests/unit/modules/network/sonic/test_sonic_vxlans.py +++ b/tests/unit/modules/network/sonic/test_sonic_vxlans.py @@ -71,6 +71,13 @@ def test_sonic_vxlans_merged_02(self): result = self.execute_module(changed=True) self.validate_config_requests() + def test_sonic_vxlans_merged_03(self): + set_module_args(self.fixture_data['merged_03']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['merged_03']['existing_vxlans_config']) + self.initialize_config_requests(self.fixture_data['merged_03']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + def test_sonic_vxlans_deleted_01(self): set_module_args(self.fixture_data['deleted_01']['module_args']) self.initialize_facts_get_requests(self.fixture_data['deleted_01']['existing_vxlans_config']) @@ -92,6 +99,21 @@ def test_sonic_vxlans_deleted_03(self): result = self.execute_module(changed=True) self.validate_config_requests() + def test_sonic_vxlans_deleted_04(self): + set_module_args(self.fixture_data['deleted_04']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['deleted_04']['existing_vxlans_config']) + self.initialize_config_requests(self.fixture_data['deleted_04']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + + def test_sonic_vxlans_deleted_05(self): + set_module_args(self.fixture_data['deleted_05']['module_args']) + self.initialize_facts_get_requests(self.fixture_data['deleted_05']['existing_vxlans_config']) + self.initialize_config_requests(self.fixture_data['deleted_05']['expected_config_requests']) + result = self.execute_module(changed=True) + self.validate_config_requests() + + # When replace is executed, it first deletes the existing config and then patches the new config. # As part of UT, sonic_module.py does a SORTING before comparison and hence the sequence of the actual configs sent to device varies from the sequence. # in which the UT test case compares with expected results. The actual sequence in which the requests are sent to device should be working fine. From 9a838b0a833a502e97a2c283bd0e212be5ffcfa7 Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Fri, 4 Oct 2024 11:17:56 -0400 Subject: [PATCH 12/14] update line spacing --- tests/unit/modules/network/sonic/test_sonic_vxlans.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/modules/network/sonic/test_sonic_vxlans.py b/tests/unit/modules/network/sonic/test_sonic_vxlans.py index faed9bc4a..e44bc1a7a 100644 --- a/tests/unit/modules/network/sonic/test_sonic_vxlans.py +++ b/tests/unit/modules/network/sonic/test_sonic_vxlans.py @@ -113,10 +113,10 @@ def test_sonic_vxlans_deleted_05(self): result = self.execute_module(changed=True) self.validate_config_requests() - # When replace is executed, it first deletes the existing config and then patches the new config. # As part of UT, sonic_module.py does a SORTING before comparison and hence the sequence of the actual configs sent to device varies from the sequence. # in which the UT test case compares with expected results. The actual sequence in which the requests are sent to device should be working fine. + def test_sonic_vxlans_replaced_02(self): set_module_args(self.fixture_data['replaced_02']['module_args']) self.initialize_facts_get_requests(self.fixture_data['replaced_02']['existing_vxlans_config']) From 9dc2c0a5eb5de15cfb77cc0cf1c3d55bdc44bee2 Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Fri, 4 Oct 2024 11:22:07 -0400 Subject: [PATCH 13/14] get rid of extra spaces --- tests/unit/modules/network/sonic/test_sonic_vxlans.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/modules/network/sonic/test_sonic_vxlans.py b/tests/unit/modules/network/sonic/test_sonic_vxlans.py index e44bc1a7a..2aeb127e7 100644 --- a/tests/unit/modules/network/sonic/test_sonic_vxlans.py +++ b/tests/unit/modules/network/sonic/test_sonic_vxlans.py @@ -116,7 +116,7 @@ def test_sonic_vxlans_deleted_05(self): # When replace is executed, it first deletes the existing config and then patches the new config. # As part of UT, sonic_module.py does a SORTING before comparison and hence the sequence of the actual configs sent to device varies from the sequence. # in which the UT test case compares with expected results. The actual sequence in which the requests are sent to device should be working fine. - + def test_sonic_vxlans_replaced_02(self): set_module_args(self.fixture_data['replaced_02']['module_args']) self.initialize_facts_get_requests(self.fixture_data['replaced_02']['existing_vxlans_config']) From a9db5c1a505c4d495b830ac1ab715d718f80734a Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Fri, 4 Oct 2024 12:52:10 -0400 Subject: [PATCH 14/14] update regression test --- tests/regression/roles/sonic_vxlan/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/regression/roles/sonic_vxlan/defaults/main.yml b/tests/regression/roles/sonic_vxlan/defaults/main.yml index 24a3b2403..0950eb2a1 100644 --- a/tests/regression/roles/sonic_vxlan/defaults/main.yml +++ b/tests/regression/roles/sonic_vxlan/defaults/main.yml @@ -93,7 +93,7 @@ tests: - vni: 102 vrf: "{{vrf2}}" suppress_vlan_neigh: - - vlan_name: Vlan6 + - vlan_name: Vlan5 - name: test_case_06 description: Override VXLAN properties state: overridden