Skip to content

Commit

Permalink
add UT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aida-shumburo committed Oct 4, 2024
1 parent 9f29b5a commit d054a2f
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 0 deletions.
136 changes: 136 additions & 0 deletions tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/modules/network/sonic/test_sonic_vxlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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.
Expand Down

0 comments on commit d054a2f

Please sign in to comment.