2018-01-10 17:09:42 +01:00
|
|
|
#
|
|
|
|
# Copyright: Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
# Make coding more python3-ish
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2018-10-13 05:01:14 +02:00
|
|
|
from units.compat.mock import patch
|
2018-01-11 23:21:17 +01:00
|
|
|
from ansible.modules.network.onyx import onyx_bgp
|
2018-01-10 17:09:42 +01:00
|
|
|
from units.modules.utils import set_module_args
|
2018-01-11 23:21:17 +01:00
|
|
|
from .onyx_module import TestOnyxModule, load_fixture
|
2018-01-10 17:09:42 +01:00
|
|
|
|
|
|
|
|
2018-01-11 23:21:17 +01:00
|
|
|
class TestOnyxBgpModule(TestOnyxModule):
|
2018-01-10 17:09:42 +01:00
|
|
|
|
2018-01-11 23:21:17 +01:00
|
|
|
module = onyx_bgp
|
2018-01-10 17:09:42 +01:00
|
|
|
|
|
|
|
def setUp(self):
|
2018-01-11 23:21:17 +01:00
|
|
|
super(TestOnyxBgpModule, self).setUp()
|
2018-01-10 17:09:42 +01:00
|
|
|
self.mock_get_config = patch.object(
|
2018-01-11 23:21:17 +01:00
|
|
|
onyx_bgp.OnyxBgpModule, "_get_bgp_summary")
|
2018-01-10 17:09:42 +01:00
|
|
|
self.get_config = self.mock_get_config.start()
|
|
|
|
|
|
|
|
self.mock_load_config = patch(
|
2018-01-11 23:21:17 +01:00
|
|
|
'ansible.module_utils.network.onyx.onyx.load_config')
|
2018-01-10 17:09:42 +01:00
|
|
|
self.load_config = self.mock_load_config.start()
|
|
|
|
|
|
|
|
def tearDown(self):
|
2018-01-11 23:21:17 +01:00
|
|
|
super(TestOnyxBgpModule, self).tearDown()
|
2018-01-10 17:09:42 +01:00
|
|
|
self.mock_get_config.stop()
|
|
|
|
self.mock_load_config.stop()
|
|
|
|
|
|
|
|
def load_fixtures(self, commands=None, transport='cli'):
|
2018-01-11 23:21:17 +01:00
|
|
|
config_file = 'onyx_bgp_show.cfg'
|
2018-01-10 17:09:42 +01:00
|
|
|
self.get_config.return_value = load_fixture(config_file)
|
|
|
|
self.load_config.return_value = None
|
|
|
|
|
|
|
|
def test_bgp_no_change(self):
|
2019-05-11 14:21:10 +02:00
|
|
|
neighbor = dict(remote_as=322, neighbor='10.2.3.5', multihop=255)
|
2018-01-10 17:09:42 +01:00
|
|
|
set_module_args(dict(as_number=172, router_id='1.2.3.4',
|
2018-01-11 18:40:39 +01:00
|
|
|
neighbors=[neighbor],
|
2019-05-11 14:21:10 +02:00
|
|
|
networks=['172.16.1.0/24'],
|
|
|
|
evpn=True, fast_external_fallover=True,
|
|
|
|
max_paths=31, ecmp_bestpath=True,
|
|
|
|
))
|
2018-01-10 17:09:42 +01:00
|
|
|
self.execute_module(changed=False)
|
|
|
|
|
|
|
|
def test_bgp_remove(self):
|
|
|
|
set_module_args(dict(as_number=172, state='absent'))
|
|
|
|
commands = ['no router bgp 172']
|
|
|
|
self.execute_module(changed=True, commands=commands)
|
|
|
|
|
2019-05-11 14:21:10 +02:00
|
|
|
def test_bgp_with_vrf_changed(self):
|
|
|
|
set_module_args(dict(as_number=173, vrf='new_vrf'))
|
|
|
|
commands = ['no router bgp 172 vrf default', 'router bgp 173 vrf new_vrf', 'exit']
|
|
|
|
self.execute_module(changed=True, commands=commands)
|
|
|
|
|
2018-01-10 17:09:42 +01:00
|
|
|
def test_bgp_change(self):
|
|
|
|
neighbor = dict(remote_as=173, neighbor='10.2.3.4')
|
|
|
|
set_module_args(dict(as_number=174, router_id='1.2.3.4',
|
2019-05-11 14:21:10 +02:00
|
|
|
neighbors=[neighbor],
|
|
|
|
evpn=False, fast_external_fallover=False,
|
|
|
|
max_paths=32, ecmp_bestpath=False,
|
|
|
|
))
|
|
|
|
commands = ['no router bgp 172 vrf default', 'router bgp 174 vrf default', 'exit',
|
|
|
|
'router bgp 174 vrf default router-id 1.2.3.4 force',
|
|
|
|
'router bgp 174 vrf default neighbor 10.2.3.4 remote-as 173',
|
|
|
|
'no router bgp 174 vrf default neighbor evpn peer-group',
|
|
|
|
'no router bgp 174 vrf default address-family l2vpn-evpn auto-create',
|
|
|
|
'router bgp 174 vrf default no bgp fast-external-fallover',
|
|
|
|
'router bgp 174 vrf default maximum-paths 32',
|
|
|
|
'router bgp 174 vrf default no bestpath as-path multipath-relax force']
|
2018-01-10 17:09:42 +01:00
|
|
|
self.execute_module(changed=True, commands=commands)
|
|
|
|
|
|
|
|
def test_bgp_add_neighbor(self):
|
|
|
|
neighbors = [dict(remote_as=173, neighbor='10.2.3.4'),
|
2019-05-11 14:21:10 +02:00
|
|
|
dict(remote_as=175, neighbor='10.2.3.5'),
|
|
|
|
dict(remote_as=175, neighbor='10.2.3.6', multihop=250)]
|
2018-01-10 17:09:42 +01:00
|
|
|
set_module_args(dict(as_number=172, router_id='1.2.3.4',
|
2018-01-11 18:40:39 +01:00
|
|
|
neighbors=neighbors,
|
2019-05-11 14:21:10 +02:00
|
|
|
networks=['172.16.1.0/24'],
|
|
|
|
evpn=True))
|
|
|
|
commands = ['router bgp 172 vrf default neighbor 10.2.3.5 remote-as 175',
|
|
|
|
'router bgp 172 vrf default neighbor 10.2.3.6 remote-as 175',
|
|
|
|
'router bgp 172 vrf default neighbor 10.2.3.6 ebgp-multihop 250',
|
|
|
|
'router bgp 172 vrf default neighbor 10.2.3.6 peer-group evpn',
|
|
|
|
'router bgp 172 vrf default neighbor 10.2.3.4 peer-group evpn']
|
2018-01-10 17:09:42 +01:00
|
|
|
self.execute_module(changed=True, commands=commands)
|
|
|
|
|
|
|
|
def test_bgp_del_neighbor(self):
|
2018-01-11 18:40:39 +01:00
|
|
|
set_module_args(dict(as_number=172,
|
2018-12-16 08:46:28 +01:00
|
|
|
networks=['172.16.1.0/24'],
|
|
|
|
purge=True))
|
2019-05-11 14:21:10 +02:00
|
|
|
commands = ['router bgp 172 vrf default no neighbor 10.2.3.4 remote-as 173',
|
|
|
|
'router bgp 172 vrf default no neighbor 10.2.3.5 remote-as 322']
|
2018-01-10 17:09:42 +01:00
|
|
|
self.execute_module(changed=True, commands=commands)
|
2018-01-11 18:40:39 +01:00
|
|
|
|
|
|
|
def test_bgp_add_network(self):
|
|
|
|
neighbors = [dict(remote_as=173, neighbor='10.2.3.4')]
|
|
|
|
set_module_args(dict(as_number=172, router_id='1.2.3.4',
|
|
|
|
neighbors=neighbors,
|
|
|
|
networks=['172.16.1.0/24', '172.16.2.0/24']))
|
2019-05-11 14:21:10 +02:00
|
|
|
commands = ['router bgp 172 vrf default network 172.16.2.0 /24']
|
2018-01-11 18:40:39 +01:00
|
|
|
self.execute_module(changed=True, commands=commands)
|
|
|
|
|
|
|
|
def test_bgp_del_network(self):
|
|
|
|
neighbors = [dict(remote_as=173, neighbor='10.2.3.4')]
|
|
|
|
set_module_args(dict(as_number=172, neighbors=neighbors))
|
|
|
|
commands = ['router bgp 172 no network 172.16.1.0 /24']
|
|
|
|
self.execute_module(changed=True, commands=commands)
|