From 216877c6ca22229e8ec04b1a19ac0a563abc1a2a Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Sun, 26 Feb 2017 11:33:58 -0500 Subject: [PATCH] adds system_mtu argument to nxos_system (#21970) * updates argument_spec * adds unit test case --- .../modules/network/nxos/nxos_system.py | 21 ++++++++++++++++++- .../nxos/fixtures/nxos_system_config.cfg | 1 + .../modules/network/nxos/test_nxos_system.py | 8 ++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_system.py b/lib/ansible/modules/network/nxos/nxos_system.py index e82f9dc275..628a3fc49e 100644 --- a/lib/ansible/modules/network/nxos/nxos_system.py +++ b/lib/ansible/modules/network/nxos/nxos_system.py @@ -179,6 +179,9 @@ def map_obj_to_commands(want, have, module): cmd = 'no ip name-server %s' % item['server'] remove(cmd, commands, item['vrf']) + if have['system_mtu']: + commands.append('no system jumbomtu') + if state == 'present': if needs_update('hostname'): commands.append('hostname %s' % want['hostname']) @@ -213,6 +216,9 @@ def map_obj_to_commands(want, have, module): cmd = 'ip name-server %s' % item['server'] add(cmd, commands, item['vrf']) + if needs_update('system_mtu'): + commands.append('system jumbomtu %s' % want['system_mtu']) + return commands def parse_hostname(config): @@ -262,6 +268,11 @@ def parse_name_servers(config, vrf_config): return objects +def parse_system_mtu(config): + match = re.search('^system jumbomtu (\d+)', config, re.M) + if match: + return int(match.group(1)) + def map_config_to_obj(module): config = get_config(module) configobj = NetworkConfig(indent=2, contents=config) @@ -278,13 +289,19 @@ def map_config_to_obj(module): 'domain_lookup': 'no ip domain-lookup' not in config, 'domain_name': parse_domain_name(config, vrf_config), 'domain_search': parse_domain_search(config, vrf_config), - 'name_servers': parse_name_servers(config, vrf_config) + 'name_servers': parse_name_servers(config, vrf_config), + 'system_mtu': parse_system_mtu(config) } +def validate_system_mtu(value, module): + if not 1500 <= value <= 9216: + module.fail_json(msg='system_mtu must be between 1500 and 9216') + def map_params_to_obj(module): obj = { 'hostname': module.params['hostname'], 'domain_lookup': module.params['domain_lookup'], + 'system_mtu': module.params['system_mtu'] } domain_name = ComplexList(dict( @@ -327,6 +344,8 @@ def main(): # { server: ; vrf: } name_servers=dict(type='list'), + system_mtu=dict(type='int'), + state=dict(default='present', choices=['present', 'absent']) ) diff --git a/test/units/modules/network/nxos/fixtures/nxos_system_config.cfg b/test/units/modules/network/nxos/fixtures/nxos_system_config.cfg index 27ef7f4fa9..362b733215 100644 --- a/test/units/modules/network/nxos/fixtures/nxos_system_config.cfg +++ b/test/units/modules/network/nxos/fixtures/nxos_system_config.cfg @@ -1,4 +1,5 @@ hostname nxos01 +system jumbomtu 1500 ! no ip domain-lookup ip domain-name ansible.com diff --git a/test/units/modules/network/nxos/test_nxos_system.py b/test/units/modules/network/nxos/test_nxos_system.py index f51a5ae21f..bda16401c5 100644 --- a/test/units/modules/network/nxos/test_nxos_system.py +++ b/test/units/modules/network/nxos/test_nxos_system.py @@ -109,6 +109,11 @@ class TestNxosSystemModule(TestNxosModule): 'vrf context management', 'ip name-server 1.2.3.4', 'exit'] self.execute_module(changed=True, commands=commands) + def test_nxos_system_system_mtu(self): + set_module_args(dict(system_mtu=2000)) + commands = ['system jumbomtu 2000'] + self.execute_module(changed=True, commands=commands) + def test_nxos_system_state_absent(self): set_module_args(dict(state='absent')) commands = ['no hostname', 'no ip domain-name ansible.com', @@ -118,7 +123,8 @@ class TestNxosSystemModule(TestNxosModule): 'vrf context management', 'no ip domain-list redhat.com', 'exit', 'no ip name-server 8.8.8.8', 'no ip name-server 172.26.1.1', 'vrf context management', 'no ip name-server 8.8.8.8', 'exit', - 'vrf context management', 'no ip name-server 172.26.1.1', 'exit'] + 'vrf context management', 'no ip name-server 172.26.1.1', 'exit', + 'no system jumbomtu'] self.execute_module(changed=True, commands=commands)