adds system_mtu argument to nxos_system (#21970)

* updates argument_spec
* adds unit test case
This commit is contained in:
Peter Sprygada 2017-02-26 11:33:58 -05:00 committed by GitHub
parent 8dbb12a9c4
commit 216877c6ca
3 changed files with 28 additions and 2 deletions

View file

@ -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: <str>; vrf: <str> }
name_servers=dict(type='list'),
system_mtu=dict(type='int'),
state=dict(default='present', choices=['present', 'absent'])
)

View file

@ -1,4 +1,5 @@
hostname nxos01
system jumbomtu 1500
!
no ip domain-lookup
ip domain-name ansible.com

View file

@ -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)