mirror of https://github.com/ansible/ansible.git
Fix nxos_switchport and unit test (#26131)
* fix nxos_switchport Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * nxos_switchport unit test Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * legacy file * update unit test * handle exceptionpull/26519/head
parent
6af53cf0ef
commit
c5fb4bbcc0
@ -0,0 +1,97 @@
|
||||
{
|
||||
"TABLE_interface": {
|
||||
"ROW_interface": {
|
||||
"interface": "Ethernet2/1",
|
||||
"state": "up",
|
||||
"admin_state": "up",
|
||||
"share_state": "Dedicated",
|
||||
"eth_hw_desc": "Ethernet",
|
||||
"eth_hw_addr": "fa16.3e00.0001",
|
||||
"eth_bia_addr": "fa16.3e27.f279",
|
||||
"desc": "to nxos03",
|
||||
"eth_ip_addr": "10.0.0.45",
|
||||
"eth_ip_mask": 30,
|
||||
"eth_ip_prefix": "10.0.0.44",
|
||||
"eth_mtu": "1500",
|
||||
"eth_bw": 1000000,
|
||||
"eth_dly": 10,
|
||||
"eth_reliability": "255",
|
||||
"eth_txload": "1",
|
||||
"eth_rxload": "1",
|
||||
"medium": "broadcast",
|
||||
"eth_mode": "access",
|
||||
"eth_bundle": 0,
|
||||
"eth_duplex": "full",
|
||||
"eth_speed": "1000 Mb/s",
|
||||
"eth_beacon": "off",
|
||||
"eth_autoneg": "off",
|
||||
"eth_in_flowctrl": "off",
|
||||
"eth_out_flowctrl": "off",
|
||||
"eth_mdix": "off",
|
||||
"eth_swt_monitor": "off",
|
||||
"eth_ethertype": "0x8100",
|
||||
"eth_eee_state": "n/a",
|
||||
"eth_link_flapped": "13week(s) 0day(s)",
|
||||
"eth_clear_counters": "never",
|
||||
"eth_reset_cntr": 1,
|
||||
"eth_load_interval1_rx": 0,
|
||||
"eth_inrate1_bits": 0,
|
||||
"eth_inrate1_pkts": 0,
|
||||
"eth_load_interval1_tx": 0,
|
||||
"eth_outrate1_bits": 0,
|
||||
"eth_outrate1_pkts": 0,
|
||||
"eth_inrate1_summary_bits": "0 bps",
|
||||
"eth_inrate1_summary_pkts": "0 pps",
|
||||
"eth_outrate1_summary_bits": "0 bps",
|
||||
"eth_outrate1_summary_pkts": "0 pps",
|
||||
"eth_load_interval2_rx": 0,
|
||||
"eth_inrate2_bits": 0,
|
||||
"eth_inrate2_pkts": 0,
|
||||
"eth_load_interval2_tx": 0,
|
||||
"eth_outrate2_bits": 0,
|
||||
"eth_outrate2_pkts": 0,
|
||||
"eth_inrate2_summary_bits": "0 bps",
|
||||
"eth_inrate2_summary_pkts": "0 pps",
|
||||
"eth_outrate2_summary_bits": "0 bps",
|
||||
"eth_outrate2_summary_pkts": "0 pps",
|
||||
"eth_inucast": 0,
|
||||
"eth_inmcast": 0,
|
||||
"eth_inbcast": 0,
|
||||
"eth_inpkts": 0,
|
||||
"eth_inbytes": 0,
|
||||
"eth_jumbo_inpkts": 0,
|
||||
"eth_storm_supp": 0,
|
||||
"eth_runts": 0,
|
||||
"eth_giants": 0,
|
||||
"eth_crc": 0,
|
||||
"eth_nobuf": 0,
|
||||
"eth_inerr": 0,
|
||||
"eth_frame": 0,
|
||||
"eth_overrun": 0,
|
||||
"eth_underrun": 0,
|
||||
"eth_ignored": 0,
|
||||
"eth_watchdog": 0,
|
||||
"eth_bad_eth": 0,
|
||||
"eth_bad_proto": 0,
|
||||
"eth_in_ifdown_drops": 0,
|
||||
"eth_dribble": 0,
|
||||
"eth_indiscard": 0,
|
||||
"eth_inpause": 0,
|
||||
"eth_outucast": 0,
|
||||
"eth_outmcast": 0,
|
||||
"eth_outbcast": 0,
|
||||
"eth_outpkts": 0,
|
||||
"eth_outbytes": 0,
|
||||
"eth_jumbo_outpkts": 0,
|
||||
"eth_outerr": 0,
|
||||
"eth_coll": 0,
|
||||
"eth_deferred": 0,
|
||||
"eth_latecoll": 0,
|
||||
"eth_lostcarrier": 0,
|
||||
"eth_nocarrier": 0,
|
||||
"eth_babbles": 0,
|
||||
"eth_outdiscard": 0,
|
||||
"eth_outpause": 0
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
{
|
||||
"TABLE_interface": {
|
||||
"ROW_interface": {
|
||||
"interface": "Ethernet2/1",
|
||||
"oper_mode": "access",
|
||||
"switchport": "Enabled",
|
||||
"access_vlan": 2,
|
||||
"access_vlan_name": "VLAN2",
|
||||
"native_vlan": 10,
|
||||
"native_vlan_name": "VLAN10",
|
||||
"trunk_vlans": "1-50"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
{
|
||||
"TABLE_vlanbrief": {
|
||||
"ROW_vlanbrief": {
|
||||
"vlanshowbr-vlanid": 1,
|
||||
"vlanshowbr-vlanid-utf": 1,
|
||||
"vlanshowbr-vlanname": "VLAN1",
|
||||
"vlanshowbr-vlanstate": "active",
|
||||
"vlanshowbr-shutstate": "noshutdown"
|
||||
}
|
||||
},
|
||||
"TABLE_mtuinfo": {
|
||||
"ROW_mtuinfo": {
|
||||
"vlanshowinfo-vlanid": 1,
|
||||
"vlanshowinfo-media-type": "enet",
|
||||
"vlanshowinfo-vlanmode": "ce-vlan"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
# (c) 2016 Red Hat Inc.
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
|
||||
from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.nxos import nxos_switchport
|
||||
from .nxos_module import TestNxosModule, load_fixture, set_module_args
|
||||
|
||||
|
||||
class TestNxosSwitchportModule(TestNxosModule):
|
||||
|
||||
module = nxos_switchport
|
||||
|
||||
def setUp(self):
|
||||
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_switchport.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_switchport.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
def tearDown(self):
|
||||
self.mock_run_commands.stop()
|
||||
self.mock_load_config.stop()
|
||||
|
||||
def load_fixtures(self, commands=None, device=''):
|
||||
def load_from_file(*args, **kwargs):
|
||||
module, commands = args
|
||||
output = list()
|
||||
for command in commands:
|
||||
filename = str(command).split(' | ')[0].replace(' ', '_')
|
||||
filename = filename.replace('2/1', '')
|
||||
output.append(load_fixture('nxos_switchport', filename))
|
||||
return output
|
||||
|
||||
self.run_commands.side_effect = load_from_file
|
||||
self.load_config.return_value = None
|
||||
|
||||
def test_nxos_switchport_present(self):
|
||||
set_module_args(dict(interface='Ethernet2/1', mode='access', access_vlan=1, state='present'))
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['interface ethernet2/1', 'switchport access vlan 1'])
|
||||
|
||||
def test_nxos_switchport_unconfigured(self):
|
||||
set_module_args(dict(interface='Ethernet2/1', state='unconfigured'))
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['interface ethernet2/1',
|
||||
'switchport mode access',
|
||||
'switch access vlan 1',
|
||||
'switchport trunk native vlan 1',
|
||||
'switchport trunk allowed vlan all'])
|
||||
|
||||
def test_nxos_switchport_absent(self):
|
||||
set_module_args(dict(interface='Ethernet2/1', mode='access', access_vlan=3, state='absent'))
|
||||
result = self.execute_module(changed=False)
|
||||
self.assertEqual(result['commands'], [])
|
Loading…
Reference in New Issue