From d054a2f2a6767263b702a75dfd955357fa7ca9fe Mon Sep 17 00:00:00 2001 From: aida-shumburo Date: Fri, 4 Oct 2024 11:11:05 -0400 Subject: [PATCH] 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.