-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit testing for ip_neighbor module added (#225)
- Loading branch information
Showing
2 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
tests/unit/modules/network/sonic/fixtures/sonic_ip_neighbor.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
--- | ||
merged_01: | ||
module_args: | ||
config: | ||
ipv4_arp_timeout: 1200 | ||
ipv4_drop_neighbor_aging_time: 600 | ||
ipv6_drop_neighbor_aging_time: 600 | ||
ipv6_nd_cache_expiry: 1200 | ||
num_local_neigh: 1000 | ||
existing_ip_neighbor_config: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config" | ||
response: | ||
code: 200 | ||
value: | ||
openconfig-neighbor:config: | ||
ipv4-arp-timeout: 1800 | ||
ipv6-nd-cache-expiry: 1800 | ||
name: Values | ||
expected_config_requests: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config" | ||
method: "patch" | ||
data: | ||
config: | ||
ipv4-arp-timeout: 1200 | ||
ipv4-drop-neighbor-aging-time: 600 | ||
ipv6-drop-neighbor-aging-time: 600 | ||
ipv6-nd-cache-expiry: 1200 | ||
num-local-neigh: 1000 | ||
|
||
deleted_01: | ||
module_args: | ||
state: deleted | ||
existing_ip_neighbor_config: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config" | ||
response: | ||
code: 200 | ||
value: | ||
openconfig-neighbor:config: | ||
ipv4-arp-timeout: 1200 | ||
ipv6-nd-cache-expiry: 1200 | ||
ipv4-drop-neighbor-aging-time: 600 | ||
ipv6-drop-neighbor-aging-time: 600 | ||
num-local-neigh: 1000 | ||
name: Values | ||
expected_config_requests: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values" | ||
method: "delete" | ||
data: | ||
|
||
deleted_02: | ||
module_args: | ||
state: deleted | ||
config: | ||
ipv4_arp_timeout: 1200 | ||
ipv4_drop_neighbor_aging_time: 600 | ||
ipv6_drop_neighbor_aging_time: 600 | ||
ipv6_nd_cache_expiry: 1200 | ||
num_local_neigh: 1000 | ||
existing_ip_neighbor_config: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config" | ||
response: | ||
code: 200 | ||
value: | ||
openconfig-neighbor:config: | ||
ipv4-arp-timeout: 1200 | ||
ipv6-nd-cache-expiry: 1200 | ||
ipv4-drop-neighbor-aging-time: 600 | ||
ipv6-drop-neighbor-aging-time: 600 | ||
num-local-neigh: 1000 | ||
name: Values | ||
expected_config_requests: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config/ipv4-arp-timeout" | ||
method: "delete" | ||
data: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config/ipv4-drop-neighbor-aging-time" | ||
method: "delete" | ||
data: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config/ipv6-drop-neighbor-aging-time" | ||
method: "delete" | ||
data: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config/ipv6-nd-cache-expiry" | ||
method: "delete" | ||
data: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config/num-local-neigh" | ||
method: "delete" | ||
data: | ||
|
||
replaced_01: | ||
module_args: | ||
state: replaced | ||
config: | ||
ipv4_arp_timeout: 1201 | ||
ipv4_drop_neighbor_aging_time: 601 | ||
ipv6_nd_cache_expiry: 1201 | ||
num_local_neigh: 1001 | ||
existing_ip_neighbor_config: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config" | ||
response: | ||
code: 200 | ||
value: | ||
openconfig-neighbor:config: | ||
ipv4-arp-timeout: 1200 | ||
ipv6-nd-cache-expiry: 1200 | ||
ipv4-drop-neighbor-aging-time: 600 | ||
ipv6-drop-neighbor-aging-time: 600 | ||
num-local-neigh: 1000 | ||
name: Values | ||
expected_config_requests: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config" | ||
method: "patch" | ||
data: | ||
config: | ||
ipv4-arp-timeout: 1201 | ||
ipv4-drop-neighbor-aging-time: 601 | ||
ipv6-nd-cache-expiry: 1201 | ||
num-local-neigh: 1001 | ||
|
||
overridden_01: | ||
module_args: | ||
state: overridden | ||
config: | ||
ipv4_drop_neighbor_aging_time: 602 | ||
ipv6_drop_neighbor_aging_time: 602 | ||
num_local_neigh: 1002 | ||
existing_ip_neighbor_config: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config" | ||
response: | ||
code: 200 | ||
value: | ||
openconfig-neighbor:config: | ||
ipv4-arp-timeout: 1200 | ||
ipv6-nd-cache-expiry: 1200 | ||
ipv4-drop-neighbor-aging-time: 600 | ||
ipv6-drop-neighbor-aging-time: 600 | ||
num-local-neigh: 1000 | ||
name: Values | ||
expected_config_requests: | ||
- path: "data/openconfig-neighbor:neighbor-globals/neighbor-global=Values/config" | ||
method: "patch" | ||
data: | ||
config: | ||
ipv4-arp-timeout: 180 | ||
ipv4-drop-neighbor-aging-time: 602 | ||
ipv6-drop-neighbor-aging-time: 602 | ||
ipv6-nd-cache-expiry: 180 | ||
num-local-neigh: 1002 |
87 changes: 87 additions & 0 deletions
87
tests/unit/modules/network/sonic/test_sonic_ip_neighbor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
__metaclass__ = type | ||
|
||
from ansible_collections.dellemc.enterprise_sonic.tests.unit.compat.mock import ( | ||
patch, | ||
) | ||
from ansible_collections.dellemc.enterprise_sonic.plugins.modules import ( | ||
sonic_ip_neighbor, | ||
) | ||
from ansible_collections.dellemc.enterprise_sonic.tests.unit.modules.utils import ( | ||
set_module_args, | ||
) | ||
from .sonic_module import TestSonicModule | ||
|
||
|
||
class TestSonicInterfacesModule(TestSonicModule): | ||
module = sonic_ip_neighbor | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.mock_facts_edit_config = patch( | ||
"ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.facts.ip_neighbor.ip_neighbor.edit_config" | ||
) | ||
cls.mock_config_edit_config = patch( | ||
"ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.ip_neighbor.ip_neighbor.edit_config" | ||
) | ||
cls.mock_utils_edit_config = patch( | ||
"ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.bgp_utils.edit_config" | ||
) | ||
cls.mock_get_interface_naming_mode = patch( | ||
"ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.utils.utils.get_device_interface_naming_mode" | ||
) | ||
cls.fixture_data = cls.load_fixtures('sonic_ip_neighbor.yaml') | ||
|
||
def setUp(self): | ||
super(TestSonicInterfacesModule, self).setUp() | ||
self.facts_edit_config = self.mock_facts_edit_config.start() | ||
self.config_edit_config = self.mock_config_edit_config.start() | ||
self.facts_edit_config.side_effect = self.facts_side_effect | ||
self.config_edit_config.side_effect = self.config_side_effect | ||
self.get_interface_naming_mode = self.mock_get_interface_naming_mode.start() | ||
self.get_interface_naming_mode.return_value = 'standard' | ||
self.utils_edit_config = self.mock_utils_edit_config.start() | ||
self.utils_edit_config.side_effect = self.facts_side_effect | ||
|
||
def tearDown(self): | ||
super(TestSonicInterfacesModule, self).tearDown() | ||
self.mock_facts_edit_config.stop() | ||
self.mock_config_edit_config.stop() | ||
self.mock_get_interface_naming_mode.stop() | ||
self.mock_utils_edit_config.stop() | ||
|
||
def test_sonic_ip_neighbor_merged_01(self): | ||
set_module_args(self.fixture_data['merged_01']['module_args']) | ||
self.initialize_facts_get_requests(self.fixture_data['merged_01']['existing_ip_neighbor_config']) | ||
self.initialize_config_requests(self.fixture_data['merged_01']['expected_config_requests']) | ||
result = self.execute_module(changed=True) | ||
self.validate_config_requests() | ||
|
||
def test_sonic_ip_neighbor_deleted_01(self): | ||
set_module_args(self.fixture_data['deleted_01']['module_args']) | ||
self.initialize_facts_get_requests(self.fixture_data['deleted_01']['existing_ip_neighbor_config']) | ||
self.initialize_config_requests(self.fixture_data['deleted_01']['expected_config_requests']) | ||
result = self.execute_module(changed=True) | ||
self.validate_config_requests() | ||
|
||
def test_sonic_ip_neighbor_deleted_02(self): | ||
set_module_args(self.fixture_data['deleted_02']['module_args']) | ||
self.initialize_facts_get_requests(self.fixture_data['deleted_02']['existing_ip_neighbor_config']) | ||
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_ip_neighbor_replaced_01(self): | ||
set_module_args(self.fixture_data['replaced_01']['module_args']) | ||
self.initialize_facts_get_requests(self.fixture_data['replaced_01']['existing_ip_neighbor_config']) | ||
self.initialize_config_requests(self.fixture_data['replaced_01']['expected_config_requests']) | ||
result = self.execute_module(changed=True) | ||
self.validate_config_requests() | ||
|
||
def test_sonic_ip_neighbor_overridden_01(self): | ||
set_module_args(self.fixture_data['overridden_01']['module_args']) | ||
self.initialize_facts_get_requests(self.fixture_data['overridden_01']['existing_ip_neighbor_config']) | ||
self.initialize_config_requests(self.fixture_data['overridden_01']['expected_config_requests']) | ||
result = self.execute_module(changed=True) | ||
self.validate_config_requests() |