Fix nxos_pim_interface dr-priority handling (#28472)

* Fix nxos_pim_interface dr-priority handling

* Prefer execute_show over `| json`

* Mock get_config

* Fix sparse-mode detection
This commit is contained in:
Nathaniel Case 2017-08-29 14:42:09 -04:00 committed by GitHub
parent e3b66a8016
commit 64dac346c9
4 changed files with 35 additions and 22 deletions

View file

@ -0,0 +1,11 @@
!Command: show running-config interface Ethernet2/1
!Time: Mon Aug 21 17:22:02 2017
version 7.3(0)D1(1)
interface Ethernet2/1
description Configured by Ansible - Layer3
no switchport
mac-address fa16.3e00.0006
ip address 10.0.0.69/30
no shutdown

View file

@ -8,19 +8,17 @@
"if-status": "protocol-up/link-up/admin-up",
"if-addr-summary": "IP address: 10.0.0.45, IP subnet: 10.0.0.44/30",
"pim-dr-address": "10.0.0.45",
"dr-priority": 1,
"dr-priority": 2,
"nbr-cnt": 0,
"hello-interval-sec": 30,
"hello-interval-sec": 35,
"hello-timer": "PT3S",
"holdtime-sec": 105,
"if-conf-dr-priority": 1,
"if-conf-delay": 3,
"is-border": "false",
"is-border": "true",
"genid": "38c4b959",
"isauth-config": "false",
"nbr-policy-name": "none configured",
"jp-in-policy-name": "JPIN",
"jp-out-policy-name": "JPOUT",
"jp-interval": 1,
"jp-next-send": 1,
"pim-bfd-enabled": "no",

View file

@ -29,6 +29,9 @@ class TestNxosIPInterfaceModule(TestNxosModule):
module = nxos_pim_interface
def setUp(self):
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_pim_interface.get_config')
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_pim_interface.load_config')
self.load_config = self.mock_load_config.start()
@ -36,6 +39,7 @@ class TestNxosIPInterfaceModule(TestNxosModule):
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_run_commands.stop()
@ -53,15 +57,17 @@ class TestNxosIPInterfaceModule(TestNxosModule):
output.append(load_fixture(module_name, filename))
return output
self.get_config.return_value = load_fixture(module_name, 'config.cfg')
self.load_config.return_value = None
self.run_commands.side_effect = load_from_file
def test_nxos_pim_interface_present(self):
set_module_args(dict(interface='eth2/1', dr_prio=10, hello_interval=40))
set_module_args(dict(interface='eth2/1', dr_prio=10, hello_interval=40, sparse=True, border=True))
self.execute_module(
changed=True,
commands=['interface eth2/1', 'ip pim dr-priority 10',
'ip pim hello-interval 40000', 'ip pim sparse-mode']
commands=[
'interface eth2/1', 'ip pim dr-priority 10', 'ip pim hello-interval 40000',
'ip pim sparse-mode', 'ip pim border']
)
def test_nxos_pim_interface_jp(self):
@ -79,8 +85,7 @@ class TestNxosIPInterfaceModule(TestNxosModule):
set_module_args(dict(interface='eth2/1', state='default'))
self.execute_module(
changed=True,
commands=['interface eth2/1', 'ip pim dr-priority 1',
'no ip pim border', 'ip pim hello-interval 30000']
commands=['interface eth2/1', 'ip pim dr-priority 1', 'ip pim hello-interval 30000', 'no ip pim border']
)
def test_nxos_pim_interface_ip_absent(self):