Add mtu option nxos_interface feature idea (#32680)

* Add mtu option nxos_interface feature idea

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* Add unit test for mtu feature

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
Trishna Guha 2017-11-13 14:48:04 +00:00 committed by GitHub
parent b0e7c71716
commit e4052c1261
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 222 additions and 2 deletions

View file

@ -69,6 +69,11 @@ options:
required: false
default: null
choices: ['layer2','layer3']
mtu:
description:
- MTU for a specific interface. Must be an even number between 576 and 9216.
required: false
version_added: 2.5
ip_forward:
description:
- Enable/Disable ip forward feature on SVIs.
@ -140,7 +145,6 @@ commands:
type: list
sample: ["interface port-channel101", "shutdown"]
'''
from ansible.module_utils.nxos import load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
@ -252,6 +256,9 @@ def get_interface(intf, module):
mode_map = {
'eth_mode': 'mode'
}
mtu_map = {
'eth_mtu': 'mtu'
}
loop_map = {
'state': 'admin_state'
}
@ -292,6 +299,7 @@ def get_interface(intf, module):
if intf_type == 'ethernet':
key_map.update(base_key_map)
key_map.update(mode_map)
key_map.update(mtu_map)
temp_dict = apply_key_map(key_map, interface_table)
temp_dict = apply_value_map(mode_value_map, temp_dict)
interface.update(temp_dict)
@ -356,6 +364,7 @@ def get_intf_args(interface):
if intf_type in ['ethernet', 'portchannel']:
arguments.extend(['mode'])
arguments.extend(['mtu'])
if intf_type == 'svi':
arguments.extend(['ip_forward', 'fabric_forwarding_anycast_gateway'])
@ -475,6 +484,10 @@ def get_interface_config_commands(interface, intf, existing):
command = 'no switchport'
commands.append(command)
mtu = interface.get('mtu')
if mtu:
commands.append('mtu {0}'.format(mtu))
admin_state = interface.get('admin_state')
if admin_state:
command = get_admin_state(interface, intf, admin_state)
@ -588,6 +601,7 @@ def main():
admin_state=dict(default='up', choices=['up', 'down'], required=False),
description=dict(required=False, default=None),
mode=dict(choices=['layer2', 'layer3'], required=False),
mtu=dict(type='int', required=False),
interface_type=dict(required=False, choices=['loopback', 'portchannel', 'svi', 'nve']),
ip_forward=dict(required=False, choices=['enable', 'disable']),
fabric_forwarding_anycast_gateway=dict(required=False, type='bool'),
@ -610,6 +624,7 @@ def main():
admin_state = module.params['admin_state']
description = module.params['description']
mode = module.params['mode']
mtu = str(module.params['mtu'])
ip_forward = module.params['ip_forward']
fabric_forwarding_anycast_gateway = module.params['fabric_forwarding_anycast_gateway']
state = module.params['state']
@ -633,7 +648,7 @@ def main():
' are only available for SVIs.')
args = dict(interface=interface, admin_state=admin_state,
description=description, mode=mode, ip_forward=ip_forward,
description=description, mode=mode, mtu=mtu, ip_forward=ip_forward,
fabric_forwarding_anycast_gateway=fabric_forwarding_anycast_gateway)
if (normalized_interface.startswith('Eth') or normalized_interface.startswith('po'))\
and "." in normalized_interface:

View file

@ -0,0 +1,93 @@
{
"TABLE_interface": {
"ROW_interface": {
"interface": "Ethernet2/5",
"state": "down",
"state_rsn_desc": "Administratively down",
"admin_state": "down",
"share_state": "Dedicated",
"eth_hw_desc": "Ethernet",
"eth_hw_addr": "0000.0000.002f",
"eth_bia_addr": "0000.0000.0000",
"eth_mtu": "1500",
"eth_bw": 1000000,
"eth_dly": 10,
"eth_reliability": "255",
"eth_txload": "1",
"eth_rxload": "1",
"medium": "broadcast",
"eth_mode": "routed",
"eth_duplex": "auto",
"eth_speed": "auto-speed",
"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": "never",
"eth_clear_counters": "never",
"eth_reset_cntr": 0,
"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
}
}
}

View file

@ -0,0 +1,81 @@
{
"TABLE_interface": {
"ROW_interface": [
{
"interface": "mgmt0",
"name": "OOB Management",
"state": "connected",
"vlan": "routed",
"duplex": "full",
"speed": "a-1000",
"type": "--"
},
{
"interface": "Ethernet2/1",
"name": "to nxos9k01",
"state": "connected",
"vlan": "routed",
"duplex": "full",
"speed": "1000",
"type": null
},
{
"interface": "Ethernet2/2",
"name": "to nxos9k02",
"state": "connected",
"vlan": "routed",
"duplex": "full",
"speed": "1000",
"type": null
},
{
"interface": "Ethernet2/3",
"state": "disabled",
"vlan": "routed",
"duplex": "auto",
"speed": "auto",
"type": null
},
{
"interface": "Ethernet2/4",
"state": "disabled",
"vlan": "routed",
"duplex": "auto",
"speed": "auto",
"type": null
},
{
"interface": "Ethernet2/5",
"state": "disabled",
"vlan": "routed",
"duplex": "auto",
"speed": "auto",
"type": null
},
{
"interface": "Ethernet2/6",
"state": "disabled",
"vlan": "routed",
"duplex": "auto",
"speed": "auto",
"type": null
},
{
"interface": "Ethernet2/7",
"state": "disabled",
"vlan": "routed",
"duplex": "auto",
"speed": "auto",
"type": null
},
{
"interface": "Ethernet2/8",
"state": "disabled",
"vlan": "routed",
"duplex": "auto",
"speed": "auto",
"type": null
}
]
}
}

View file

@ -0,0 +1,11 @@
!Command: show running-config interface Ethernet2/5
!Time: Fri Nov 10 05:50:59 2017
version 7.3(0)D1(1)
interface Ethernet2/5
shutdown
no switchport
mac-address 0000.0000.002f

View file

@ -42,7 +42,22 @@ class TestNxosInterfaceModule(TestNxosModule):
self.mock_load_config.stop()
def load_fixtures(self, commands=None, device=''):
module_name = self.module.__name__.rsplit('.', 1)[1]
def load_from_file(*args, **kwargs):
module, commands = args
output = list()
for command in commands:
if type(command) == dict:
command = command['command']
filename = str(command).split(' | ')[0].replace(' ', '_').replace('/', '_')
print(filename)
output.append(load_fixture(module_name, filename))
return output
self.load_config.return_value = None
self.run_commands.side_effect = load_from_file
def test_nxos_interface_up(self):
set_module_args(dict(interface='loopback0'))
@ -58,3 +73,8 @@ class TestNxosInterfaceModule(TestNxosModule):
set_module_args(dict(interface='loopback0', state='absent'))
result = self.execute_module(changed=False)
self.assertEqual(result['commands'], [])
def test_nxos_interface_mtu_change(self):
set_module_args(dict(interface='Ethernet2/5', mtu=1606, state='present'))
result = self.execute_module(changed=True)
self.assertEqual(result['commands'], ['interface Ethernet2/5', 'mtu 1606', 'no shutdown'])