1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

configures address-families when vrf is created (#28615)

* configures address-families when vrf is created

fixes #26725

* fix up unit test cases
This commit is contained in:
Peter Sprygada 2017-08-25 07:51:20 -04:00 committed by GitHub
parent a03a1cde88
commit 75293d83ca
2 changed files with 29 additions and 12 deletions

View file

@ -167,7 +167,11 @@ def get_interface_type(interface):
def add_command_to_vrf(name, cmd, commands):
if 'vrf definition %s' % name not in commands:
commands.append('vrf definition %s' % name)
commands.extend([
'vrf definition %s' % name,
'address-family ipv4', 'exit',
'address-family ipv6', 'exit',
])
commands.append(cmd)
def map_obj_to_commands(updates, module):
@ -185,7 +189,11 @@ def map_obj_to_commands(updates, module):
continue
if not have.get('state'):
commands.append('vrf definition %s' % want['name'])
commands.extend([
'vrf definition %s' % want['name'],
'address-family ipv4', 'exit',
'address-family ipv6', 'exit',
])
if needs_update(want, have, 'description'):
cmd = 'description %s' % want['description']
@ -337,6 +345,9 @@ def check_declarative_intent_params(want, module):
if rc == 0:
data = out.strip().split()
# data will be empty if the vrf was just added
if not data:
return
vrf = data[0]
interface = data[-1]
@ -356,6 +367,7 @@ def main():
name=dict(),
description=dict(),
rd=dict(),
interfaces=dict(type='list'),
delay=dict(default=10, type='int'),

View file

@ -53,7 +53,7 @@ class TestIosVrfModule(TestIosModule):
def test_ios_vrf_name(self):
set_module_args(dict(name='test_4'))
commands = ['vrf definition test_4']
commands = ['vrf definition test_4', 'address-family ipv4', 'exit', 'address-family ipv6', 'exit']
self.execute_module(changed=True, commands=commands, sort=False)
def test_ios_vrf_name_unchanged(self):
@ -62,12 +62,12 @@ class TestIosVrfModule(TestIosModule):
def test_ios_vrf_description(self):
set_module_args(dict(name='test_1', description='test string'))
commands = ['vrf definition test_1', 'description test string']
commands = ['vrf definition test_1', 'address-family ipv4', 'exit', 'address-family ipv6', 'exit', 'description test string']
self.execute_module(changed=True, commands=commands, sort=False)
def test_ios_vrf_rd(self):
set_module_args(dict(name='test_1', rd='2:100'))
commands = ['vrf definition test_1', 'rd 2:100']
commands = ['vrf definition test_1', 'address-family ipv4', 'exit', 'address-family ipv6', 'exit', 'rd 2:100']
self.execute_module(changed=True, commands=commands, sort=False)
def test_ios_vrf_interfaces(self):
@ -96,34 +96,39 @@ class TestIosVrfModule(TestIosModule):
def test_ios_vrfs_no_purge(self):
vrfs = [{'name': 'test_1'}, {'name': 'test_4'}]
set_module_args(dict(vrfs=vrfs))
commands = ['vrf definition test_4']
commands = ['vrf definition test_4',
'address-family ipv4', 'exit',
'address-family ipv6', 'exit']
self.execute_module(changed=True, commands=commands)
def test_ios_vrfs_purge(self):
vrfs = [{'name': 'test_1'}, {'name': 'test_4'}]
set_module_args(dict(vrfs=vrfs, purge=True))
commands = ['no vrf definition test_2', 'no vrf definition test_3',
'vrf definition test_4']
commands = ['vrf definition test_4',
'address-family ipv4', 'exit',
'address-family ipv6', 'exit',
'no vrf definition test_2',
'no vrf definition test_3']
self.execute_module(changed=True, commands=commands)
def test_ios_vrfs_global_arg(self):
vrfs = [{'name': 'test_1'}, {'name': 'test_2'}]
set_module_args(dict(vrfs=vrfs, description='test string'))
commands = ['vrf definition test_1', 'description test string',
'vrf definition test_2', 'description test string']
commands = ['vrf definition test_1', 'address-family ipv4', 'exit', 'address-family ipv6', 'exit', 'description test string',
'vrf definition test_2', 'address-family ipv4', 'exit', 'address-family ipv6', 'exit', 'description test string']
self.execute_module(changed=True, commands=commands, sort=False)
def test_ios_vrfs_local_override_description(self):
vrfs = [{'name': 'test_1', 'description': 'test vrf 1'},
{'name': 'test_2'}]
set_module_args(dict(vrfs=vrfs, description='test string'))
commands = ['vrf definition test_2', 'description test string']
commands = ['vrf definition test_2', 'address-family ipv4', 'exit', 'address-family ipv6', 'exit', 'description test string']
self.execute_module(changed=True, commands=commands, sort=False)
def test_ios_vrfs_local_override_state(self):
vrfs = [{'name': 'test_1', 'state': 'absent'},
{'name': 'test_2'}]
set_module_args(dict(vrfs=vrfs, description='test string'))
commands = ['no vrf definition test_1', 'vrf definition test_2',
commands = ['no vrf definition test_1', 'vrf definition test_2', 'address-family ipv4', 'exit', 'address-family ipv6', 'exit',
'description test string']
self.execute_module(changed=True, commands=commands, sort=False)