diff options
author | omnom62 <75066712+omnom62@users.noreply.github.com> | 2024-12-20 05:33:39 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-20 05:33:39 +1000 |
commit | cae1c6cc42fa786095433692a6d685f029bbde2e (patch) | |
tree | ba553267e68b14df2cec4d5c2ce359bab673aa40 /tests/unit | |
parent | 001ed7481a23874f931e4bfb681e88506a5e6a0d (diff) | |
download | vyos.vyos-cae1c6cc42fa786095433692a6d685f029bbde2e.tar.gz vyos.vyos-cae1c6cc42fa786095433692a6d685f029bbde2e.zip |
VyOS v1.4 support for BGP (T6892 & T6888 & T6822) (#367)
* VyOS v1.4 support for BGP (T6892)
* WIP: chnages to scanners and facts for BGP on v1.4
* scanners and facts modification to support as_numberless commands
* remove optional regex groups
* VyOS v1.4 BGP system-as functionality
* bgp_af linter
* bgp_global mods and testing
* bgp_global v.1.4 support
* linter fixes
* bgp_global and bgp_af fixed 1.3 test cases
* unit tests for bgp modules for both versions
* obsolete stranzas removed from bgp_global for both versions
* some typos removed
* bgp_global rst updates
* t6829 related draft changes
* Draft changes to unit tests fot original set and t6888 updates
* changelog
* D.R.Y for bgp_global and testmodule names
* linter fixes
* fixtures for bgp_af options testts
* stranzas options processing
* T6888 bgp option test func and cases
* clean-up draft code and update to rm_templates
* v14 system-as change supported in conf and tests
* T6822 BGP global passive bugfix
* clean-up
* T6829: update integration tests
* T6829: fix integration tests for global
* T6829: fix integration tests for bgp_global
* T6829: fix for 1.4 AF integration tests
* T6829: fix unit tests after removing obsolete items
* T6829: fix sanity test failures
* T6829: fix documentation
* Lint and comments are addressed
* rtt.yaml and fix to integration tests
* updated fragments for bgp_global
* lint fixes
---------
Co-authored-by: Gaige B. Paulsen <gaige@cluetrust.com>
Diffstat (limited to 'tests/unit')
11 files changed, 1792 insertions, 145 deletions
diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_address_family_config_14.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_address_family_config_14.cfg new file mode 100644 index 00000000..20b8ee28 --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_address_family_config_14.cfg @@ -0,0 +1,8 @@ +set protocols bgp system-as 65536 +set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set +set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 route-map 'map01' +set protocols bgp address-family ipv4-unicast network 192.2.13.0/24 backdoor +set protocols bgp address-family ipv6-unicast redistribute ripng metric '20' +set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast route-map export 'map01' +set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound +set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_af_ops_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_af_ops_config.cfg new file mode 100644 index 00000000..bc2704aa --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_af_ops_config.cfg @@ -0,0 +1,5 @@ +set protocols bgp 65536 address-family ipv4-unicast network 192.1.13.0/24 +set protocols bgp 65536 address-family ipv4-unicast network 192.2.13.0/24 backdoor +set protocols bgp 65536 address-family ipv6-unicast redistribute ripng metric '20' +set protocols bgp 65536 address-family ipv4-unicast redistribute rip metric '15' +set protocols bgp 65536 address-family ipv4-unicast redistribute ospf
\ No newline at end of file diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_af_ops_config_14.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_af_ops_config_14.cfg new file mode 100644 index 00000000..b09da39d --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_af_ops_config_14.cfg @@ -0,0 +1,6 @@ +set protocols bgp system-as '65536' +set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 +set protocols bgp address-family ipv4-unicast network 192.2.13.0/24 backdoor +set protocols bgp address-family ipv6-unicast redistribute ripng metric '20' +set protocols bgp address-family ipv4-unicast redistribute rip metric '15' +set protocols bgp address-family ipv4-unicast redistribute ospf
\ No newline at end of file diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config.cfg index 7d990d6b..7f6b1698 100644 --- a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config.cfg +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config.cfg @@ -1,5 +1,4 @@ set protocols bgp 65536 neighbor 5001::64 address-family 'ipv6-unicast' set protocols bgp 65536 neighbor 5001::64 ebgp-multihop '2' -set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34' set protocols bgp 65536 neighbor 5001::64 remote-as '65535' set protocols bgp 65536 neighbor 5001::64 update-source '2001:db8::1' diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config_14.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config_14.cfg new file mode 100644 index 00000000..385ed1ec --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config_14.cfg @@ -0,0 +1,5 @@ +set protocols bgp system-as 65536 +set protocols bgp neighbor 5001::64 address-family 'ipv6-unicast' +set protocols bgp neighbor 5001::64 ebgp-multihop '2' +set protocols bgp neighbor 5001::64 remote-as '65535' +set protocols bgp neighbor 5001::64 update-source '2001:db8::1' diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config.cfg index 00c615fd..0142ccef 100644 --- a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config.cfg +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config.cfg @@ -1,23 +1,13 @@ set protocols bgp 65536 neighbor 10.0.0.4 'disable-connected-check' set protocols bgp 65536 neighbor 10.0.0.4 timers holdtime '30' set protocols bgp 65536 neighbor 10.0.0.4 timers keepalive '10' -set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged 'as-path' -set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged 'med' set protocols bgp 65536 neighbor 192.168.0.2 ebgp-multihop '2' set protocols bgp 65536 neighbor 192.168.0.2 remote-as '65535' -set protocols bgp 65536 neighbor 192.168.0.2 soft-reconfiguration 'inbound' set protocols bgp 65536 neighbor 192.168.0.2 update-source '192.168.0.1' set protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop '2' -set protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix '34' set protocols bgp 65536 neighbor 2001:db8::2 remote-as '65535' set protocols bgp 65536 neighbor 2001:db8::2 update-source '2001:db8::1' -set protocols bgp 65536 network 172.16.42.32/27 'backdoor' -set protocols bgp 65536 network 172.16.42.251/32 route-map 'map01' set protocols bgp 65536 parameters bestpath as-path 'confed' set protocols bgp 65536 parameters bestpath 'compare-routerid' set protocols bgp 65536 parameters default 'no-ipv4-unicast' set protocols bgp 65536 parameters router-id '10.1.1.1' -set protocols bgp 65536 neighbor 10.0.0.4 capability orf prefix-list 'receive' -set protocols bgp 65536 redistribute kernel route-map 'map01' -set protocols bgp 65536 redistribute static metric '20' -set protocols bgp 65536 redistribute static route-map 'map01' diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config_14.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config_14.cfg new file mode 100644 index 00000000..f6674ecd --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config_14.cfg @@ -0,0 +1,14 @@ +set protocols bgp system-as 65536 +set protocols bgp neighbor 10.0.0.4 'disable-connected-check' +set protocols bgp neighbor 10.0.0.4 timers holdtime '30' +set protocols bgp neighbor 10.0.0.4 timers keepalive '10' +set protocols bgp neighbor 192.168.0.2 ebgp-multihop '2' +set protocols bgp neighbor 192.168.0.2 remote-as '65535' +set protocols bgp neighbor 192.168.0.2 update-source '192.168.0.1' +set protocols bgp neighbor 2001:db8::2 ebgp-multihop '2' +set protocols bgp neighbor 2001:db8::2 remote-as '65535' +set protocols bgp neighbor 2001:db8::2 update-source '2001:db8::1' +set protocols bgp parameters bestpath as-path 'confed' +set protocols bgp parameters bestpath 'compare-routerid' +set protocols bgp parameters default 'no-ipv4-unicast' +set protocols bgp parameters router-id '10.1.1.1' diff --git a/tests/unit/modules/network/vyos/test_vyos_bgp_address_family.py b/tests/unit/modules/network/vyos/test_vyos_bgp_address_family.py index 87b3ad9d..7ea9b2cd 100644 --- a/tests/unit/modules/network/vyos/test_vyos_bgp_address_family.py +++ b/tests/unit/modules/network/vyos/test_vyos_bgp_address_family.py @@ -29,11 +29,11 @@ from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_ar from .vyos_module import TestVyosModule, load_fixture -class TestVyosBgpafModule(TestVyosModule): +class TestVyosBgpafModule13(TestVyosModule): module = vyos_bgp_address_family def setUp(self): - super(TestVyosBgpafModule, self).setUp() + super(TestVyosBgpafModule13, self).setUp() self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) @@ -44,11 +44,25 @@ class TestVyosBgpafModule(TestVyosModule): + "bgp_address_family.bgp_address_family.Bgp_address_familyFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() + self.mock_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_address_family.bgp_address_family.get_os_version" + ) + self.test_version = "1.2" + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = self.test_version + self.mock_facts_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family.get_os_version" + ) + self.get_facts_os_version = self.mock_facts_get_os_version.start() + self.get_facts_os_version.return_value = self.test_version + self.maxDiff = None def tearDown(self): - super(TestVyosBgpafModule, self).tearDown() + super(TestVyosBgpafModule13, self).tearDown() self.mock_get_resource_connection_config.stop() self.mock_execute_show_command.stop() + self.mock_get_os_version.stop() + self.mock_facts_get_os_version.stop() def load_fixtures(self, commands=None, filename=None): if filename is None: @@ -600,3 +614,177 @@ class TestVyosBgpafModule(TestVyosModule): ], } self.assertEqual(sorted(gather_list), sorted(result["gathered"])) + + +class TestVyosBgpafOpsModule13(TestVyosModule): + module = vyos_bgp_address_family + + def setUp(self): + super(TestVyosBgpafOpsModule13, self).setUp() + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", + ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts." + + "bgp_address_family.bgp_address_family.Bgp_address_familyFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + self.mock_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_address_family.bgp_address_family.get_os_version" + ) + self.test_version = "1.2" + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = self.test_version + self.mock_facts_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family.get_os_version" + ) + self.get_facts_os_version = self.mock_facts_get_os_version.start() + self.get_facts_os_version.return_value = self.test_version + self.maxDiff = None + + def tearDown(self): + super(TestVyosBgpafOpsModule13, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_execute_show_command.stop() + self.mock_get_os_version.stop() + self.mock_facts_get_os_version.stop() + + def load_fixtures(self, commands=None, filename=None): + if filename is None: + filename = "vyos_bgp_af_ops_config.cfg" + + def load_from_file(*args, **kwargs): + output = load_fixture(filename) + return output + + self.execute_show_command.side_effect = load_from_file + + def test_vyos_bgp_address_family_merged(self): + set_module_args( + dict( + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.3.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ospfv3", metric=20)], + ), + ], + ), + ), + ) + commands = [ + "set protocols bgp 65536 address-family ipv4-unicast network 192.3.13.0/24 backdoor", + "set protocols bgp 65536 address-family ipv6-unicast redistribute ospfv3 metric 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_replaced(self): + set_module_args( + dict( + state="replaced", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.1.13.0/24", backdoor=True), + ], + redistribute=[ + dict(protocol="ospf", metric=25), + ] + ), + dict( + afi="ipv6", + redistribute=[ + dict(protocol="ospfv3", metric=20), + dict(protocol="ripng") + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp 65536 address-family ipv6-unicast redistribute ripng metric", + "delete protocols bgp 65536 address-family ipv4-unicast network 192.2.13.0/24", + "delete protocols bgp 65536 address-family ipv4-unicast redistribute rip", + "set protocols bgp 65536 address-family ipv4-unicast redistribute ospf metric 25", + "set protocols bgp 65536 address-family ipv4-unicast network 192.1.13.0/24 backdoor", + "set protocols bgp 65536 address-family ipv6-unicast redistribute ospfv3 metric 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_overridden(self): + set_module_args( + dict( + state="overridden", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.1.13.0/24", backdoor=True), + ], + redistribute=[ + dict(protocol="ospf", metric=25), + ] + ), + dict( + afi="ipv6", + redistribute=[ + dict(protocol="ospfv3", metric=20), + dict(protocol="ripng") + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp 65536 address-family ipv6-unicast redistribute ripng metric", + "delete protocols bgp 65536 address-family ipv4-unicast network 192.2.13.0/24", + "delete protocols bgp 65536 address-family ipv4-unicast redistribute rip", + "set protocols bgp 65536 address-family ipv4-unicast redistribute ospf metric 25", + "set protocols bgp 65536 address-family ipv4-unicast network 192.1.13.0/24 backdoor", + "set protocols bgp 65536 address-family ipv6-unicast redistribute ospfv3 metric 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_deleted(self): + set_module_args( + dict( + state="deleted", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.2.13.0/24"), + ] + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng")], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp 65536 address-family ipv4-unicast", + "delete protocols bgp 65536 address-family ipv6-unicast", + ] + + self.execute_module(changed=True, commands=commands) diff --git a/tests/unit/modules/network/vyos/test_vyos_bgp_address_family14.py b/tests/unit/modules/network/vyos/test_vyos_bgp_address_family14.py new file mode 100644 index 00000000..9e615ff0 --- /dev/null +++ b/tests/unit/modules/network/vyos/test_vyos_bgp_address_family14.py @@ -0,0 +1,1000 @@ +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from unittest.mock import patch + +from ansible_collections.vyos.vyos.plugins.modules import vyos_bgp_address_family +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + +from .vyos_module import TestVyosModule, load_fixture + + +class TestVyosBgpafModule14(TestVyosModule): + module = vyos_bgp_address_family + + def setUp(self): + super(TestVyosBgpafModule14, self).setUp() + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", + ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts." + + "bgp_address_family.bgp_address_family.Bgp_address_familyFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + self.mock_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_address_family.bgp_address_family.get_os_version" + ) + self.test_version = "1.4" + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = self.test_version + self.mock_facts_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family.get_os_version" + ) + self.get_facts_os_version = self.mock_facts_get_os_version.start() + self.get_facts_os_version.return_value = self.test_version + self.maxDiff = None + + def tearDown(self): + super(TestVyosBgpafModule14, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_execute_show_command.stop() + self.mock_get_os_version.stop() + self.mock_facts_get_os_version.stop() + + def load_fixtures(self, commands=None, filename=None): + if filename is None: + filename = "vyos_bgp_address_family_config_14.cfg" + + def load_from_file(*args, **kwargs): + output = load_fixture(filename) + return output + + self.execute_show_command.side_effect = load_from_file + + def test_vyos_bgp_address_family_merged_idempotent(self): + set_module_args( + dict( + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_bgp_address_family_merged(self): + set_module_args( + dict( + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", summary_only=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ospfv3", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.10.21.25", + address_family=[ + dict( + afi="ipv6", + distribute_list=[dict(action="export", acl=10)], + route_server_client=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv4", + filter_list=[ + dict(action="export", path_list="list01"), + ], + capability=dict(orf="send"), + ), + ], + ), + ], + ), + ), + ) + commands = [ + "set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-setipv4-unicast aggregate-address 192.0.2.0/24 summary-only", + "set protocols bgp address-family ipv6-unicast redistribute ospfv3 metric 20", + "set protocols bgp neighbor 203.0.113.5 address-family ipv4-unicast filter-list export list01", + "set protocols bgp neighbor 203.0.113.5 address-family ipv4-unicast capability prefix-list send", + "set protocols bgp neighbor 192.10.21.25 address-family ipv6-unicast distribute-list export 10", + "set protocols bgp neighbor 192.10.21.25 address-family ipv6-unicast route-server-client", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_replaced_idempotent(self): + set_module_args( + dict( + state="replaced", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_bgp_address_family_replaced(self): + set_module_args( + dict( + state="replaced", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", summary_only=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ospfv3", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.10.21.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="import", route_map="map01")], + ), + dict( + afi="ipv6", + distribute_list=[dict(action="export", acl=10)], + route_server_client=True, + ), + ], + ), + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv4", + filter_list=[ + dict(action="export", path_list="list01"), + ], + capability=dict(orf="send"), + ), + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged", + "delete protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration", + "delete protocols bgp address-family ipv6-unicast redistribute ripng", + "delete protocols bgp address-family ipv4-unicast network 192.2.13.0/24", + "set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 summary-only", + "set protocols bgp address-family ipv6-unicast redistribute ospfv3 metric 20", + "set protocols bgp neighbor 192.10.21.25 address-family ipv4-unicast route-map import map01", + "set protocols bgp neighbor 192.10.21.25 address-family ipv6-unicast distribute-list export 10", + "set protocols bgp neighbor 192.10.21.25 address-family ipv6-unicast route-server-client", + "set protocols bgp neighbor 203.0.113.5 address-family ipv4-unicast filter-list export list01", + "set protocols bgp neighbor 203.0.113.5 address-family ipv4-unicast capability prefix-list send", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_overridden_idempotent(self): + set_module_args( + dict( + state="overridden", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_bgp_address_family_overridden(self): + set_module_args( + dict( + state="overridden", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ospfv3", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.10.21.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="import", route_map="map01")], + ), + dict( + afi="ipv6", + distribute_list=[dict(action="export", acl=10)], + route_server_client=True, + ), + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp neighbor 203.0.113.5 address-family", + "delete protocols bgp neighbor 192.0.2.25 address-family", + "delete protocols bgp address-family ipv6-unicast redistribute ripng", + "delete protocols bgp address-family ipv4 aggregate-address", + "delete protocols bgp address-family ipv4-unicast network 192.2.13.0/24", + "set protocols bgp address-family ipv6-unicast redistribute ospfv3 metric 20", + "set protocols bgp neighbor 192.10.21.25 address-family ipv4-unicast route-map import map01", + "set protocols bgp neighbor 192.10.21.25 address-family ipv6-unicast distribute-list export 10", + "set protocols bgp neighbor 192.10.21.25 address-family ipv6-unicast route-server-client", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_deleted(self): + set_module_args( + dict( + state="deleted", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp address-family ipv4-unicast", + "delete protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast", + "delete protocols bgp neighbor 203.0.113.5 address-family", + ] + + self.execute_module(changed=True, commands=commands) + + # def test_vyos_bgp_address_family_incorrect_instance(self): + # set_module_args( + # dict( + # state="overridden", + # config=dict( + # as_number=100, + # address_family=[ + # dict( + # afi="ipv4", + # networks=[ + # dict(prefix="192.1.13.0/24", route_map="map01"), + # ], + # ), + # dict( + # afi="ipv6", + # redistribute=[dict(protocol="ospfv3", metric=20)], + # ), + # ], + # neighbors=[ + # dict( + # neighbor_address="192.10.21.25", + # address_family=[ + # dict( + # afi="ipv4", + # route_map=[dict(action="import", route_map="map01")], + # ), + # dict( + # afi="ipv6", + # distribute_list=[dict(action="export", acl=10)], + # route_server_client=True, + # ), + # ], + # ), + # ], + # ), + # ), + # ) + # result = self.execute_module(failed=True) + # self.assertIn("Only one bgp instance is allowed per device", result["msg"]) + + def test_vyos_bgp_address_family_rendered(self): + set_module_args( + dict( + state="rendered", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + rendered_cmds = [ + "set protocols bgp system-as 65536", + "set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 route-map map01", + "set protocols bgp address-family ipv4-unicast network 192.2.13.0/24 backdoor", + "set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set", + "set protocols bgp address-family ipv6-unicast redistribute ripng metric 20", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast route-map export map01", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound", + "set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop", + ] + result = self.execute_module(changed=False) + self.assertEqual( + sorted(result["rendered"]), + sorted(rendered_cmds), + result["rendered"], + ) + + def test_vyos_bgp_address_family_parsed(self): + commands = [ + "set protocols bgp system-as 65536", + "set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 route-map map01", + "set protocols bgp address-family ipv4-unicast network 192.2.13.0/24 backdoor", + "set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set", + "set protocols bgp address-family ipv6-unicast redistribute ripng metric 20", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast route-map export map01", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound", + "set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop", + ] + + parsed_str = "\n".join(commands) + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_list = { + "as_number": 65536, + "address_family": [ + { + "afi": "ipv4", + "networks": [ + {"prefix": "192.1.13.0/24", "route_map": "map01"}, + {"prefix": "192.2.13.0/24", "backdoor": True}, + ], + "aggregate_address": [{"prefix": "192.0.2.0/24", "as_set": True}], + }, + { + "afi": "ipv6", + "redistribute": [{"protocol": "ripng", "metric": 20}], + }, + ], + "neighbors": [ + { + "neighbor_address": "192.0.2.25", + "address_family": [ + {"afi": "ipv4", "soft_reconfiguration": True}, + ], + }, + { + "neighbor_address": "203.0.113.5", + "address_family": [ + { + "afi": "ipv6", + "attribute_unchanged": {"next_hop": True}, + }, + ], + }, + ], + } + self.assertEqual(sorted(parsed_list), sorted(result["parsed"])) + + def test_vyos_bgp_address_family_gathered(self): + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = { + "as_number": 65536, + "address_family": [ + { + "afi": "ipv4", + "networks": [ + {"prefix": "192.1.13.0/24", "route_map": "map01"}, + {"prefix": "192.2.13.0/24", "backdoor": True}, + ], + "aggregate_address": [{"prefix": "192.0.2.0/24", "as_set": True}], + }, + { + "afi": "ipv6", + "redistribute": [{"protocol": "ripng", "metric": 20}], + }, + ], + "neighbors": [ + { + "neighbor_address": "192.0.2.25", + "address_family": [ + {"afi": "ipv4", "soft_reconfiguration": True}, + ], + }, + { + "neighbor_address": "203.0.113.5", + "address_family": [ + { + "afi": "ipv6", + "attribute_unchanged": {"next_hop": True}, + }, + ], + }, + ], + } + self.assertEqual(sorted(gather_list), sorted(result["gathered"])) + + def test_vyos_bgp_address_family_replaced_asn(self): + set_module_args( + dict( + state="replaced", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_bgp_address_family_overridden_asn(self): + set_module_args( + dict( + state="overridden", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_bgp_address_family_replaced_asn(self): + set_module_args( + dict( + state="replaced", + config=dict( + as_number=65540, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + commands = [ + "set protocols bgp system-as 65540", + "set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set", + "set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 route-map map01", + "set protocols bgp address-family ipv4-unicast network 192.2.13.0/24 backdoor", + "set protocols bgp address-family ipv6-unicast redistribute ripng metric 20", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast route-map export map01", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound", + "set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_overridden_asn(self): + set_module_args( + dict( + state="overridden", + config=dict( + as_number=65540, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp address-family ipv4 aggregate-address", + "delete protocols bgp address-family ipv4 network", + "delete protocols bgp address-family ipv6 redistribute", + "delete protocols bgp neighbor 192.0.2.25 address-family", + "delete protocols bgp neighbor 203.0.113.5 address-family", + "set protocols bgp system-as 65540", + "set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set", + "set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 route-map map01", + "set protocols bgp address-family ipv4-unicast network 192.2.13.0/24 backdoor", + "set protocols bgp address-family ipv6-unicast redistribute ripng metric 20", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast route-map export map01", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound", + "set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop", + ] + self.execute_module(changed=True, commands=commands) + + +class TestVyosBgpafOpsModule14(TestVyosModule): + module = vyos_bgp_address_family + + def setUp(self): + super(TestVyosBgpafOpsModule14, self).setUp() + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", + ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts." + + "bgp_address_family.bgp_address_family.Bgp_address_familyFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + self.mock_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_address_family.bgp_address_family.get_os_version" + ) + self.test_version = "1.4" + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = self.test_version + self.mock_facts_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family.get_os_version" + ) + self.get_facts_os_version = self.mock_facts_get_os_version.start() + self.get_facts_os_version.return_value = self.test_version + self.maxDiff = None + + def tearDown(self): + super(TestVyosBgpafOpsModule14, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_execute_show_command.stop() + self.mock_get_os_version.stop() + self.mock_facts_get_os_version.stop() + + def load_fixtures(self, commands=None, filename=None): + if filename is None: + filename = "vyos_bgp_af_ops_config_14.cfg" + + def load_from_file(*args, **kwargs): + output = load_fixture(filename) + return output + + self.execute_show_command.side_effect = load_from_file + + def test_vyos_bgp_address_family_merged(self): + set_module_args( + dict( + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.3.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ospfv3", metric=20)], + ), + ], + ), + ), + ) + commands = [ + "set protocols bgp address-family ipv4-unicast network 192.3.13.0/24 backdoor", + "set protocols bgp address-family ipv6-unicast redistribute ospfv3 metric 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_replaced(self): + set_module_args( + dict( + state="replaced", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.1.13.0/24", backdoor=True), + ], + redistribute=[ + dict(protocol="ospf", metric=25), + ] + ), + dict( + afi="ipv6", + redistribute=[ + dict(protocol="ospfv3", metric=20), + dict(protocol="ripng") + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp address-family ipv6-unicast redistribute ripng metric", + "delete protocols bgp address-family ipv4-unicast network 192.2.13.0/24", + "delete protocols bgp address-family ipv4-unicast redistribute rip", + "set protocols bgp address-family ipv4-unicast redistribute ospf metric 25", + "set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 backdoor", + "set protocols bgp address-family ipv6-unicast redistribute ospfv3 metric 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_overridden(self): + set_module_args( + dict( + state="overridden", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.1.13.0/24", backdoor=True), + ], + redistribute=[ + dict(protocol="ospf", metric=25), + ] + ), + dict( + afi="ipv6", + redistribute=[ + dict(protocol="ospfv3", metric=20), + dict(protocol="ripng") + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp address-family ipv6-unicast redistribute ripng metric", + "delete protocols bgp address-family ipv4-unicast network 192.2.13.0/24", + "delete protocols bgp address-family ipv4-unicast redistribute rip", + "set protocols bgp address-family ipv4-unicast redistribute ospf metric 25", + "set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 backdoor", + "set protocols bgp address-family ipv6-unicast redistribute ospfv3 metric 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_deleted(self): + set_module_args( + dict( + state="deleted", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.2.13.0/24"), + ] + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng")], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp address-family ipv4-unicast", + "delete protocols bgp address-family ipv6-unicast", + ] + + self.execute_module(changed=True, commands=commands) diff --git a/tests/unit/modules/network/vyos/test_vyos_bgp_global.py b/tests/unit/modules/network/vyos/test_vyos_bgp_global.py index 99d17ce5..e363f77b 100644 --- a/tests/unit/modules/network/vyos/test_vyos_bgp_global.py +++ b/tests/unit/modules/network/vyos/test_vyos_bgp_global.py @@ -55,6 +55,18 @@ class TestVyosBgpglobalModule(TestVyosModule): ) self.execute_show_command = self.mock_execute_show_command.start() + self.mock_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_global.bgp_global.get_os_version", + ) + self.test_version = "1.2" + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = self.test_version + self.mock_facts_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global.get_os_version", + ) + self.get_facts_os_version = self.mock_facts_get_os_version.start() + self.get_facts_os_version.return_value = self.test_version + self.maxDiff = None def tearDown(self): super(TestVyosBgpglobalModule, self).tearDown() @@ -62,6 +74,8 @@ class TestVyosBgpglobalModule(TestVyosModule): self.mock_get_resource_connection_facts.stop() self.mock_execute_show_command.stop() self.mock_execute_show_command_config.stop() + self.mock_get_os_version.stop() + self.mock_facts_get_os_version.stop() def load_fixtures(self, commands=None, filename=None): if filename is None: @@ -84,38 +98,34 @@ class TestVyosBgpglobalModule(TestVyosModule): address="10.0.0.4", disable_connected_check=True, timers=dict(holdtime=30, keepalive=10), - capability=dict(orf="receive"), ), dict( address="192.168.0.2", - attribute_unchanged=dict(as_path=True, med=True), ebgp_multihop=2, remote_as="65535", - soft_reconfiguration=True, update_source="192.168.0.1", ), dict( address="2001:db8::2", ebgp_multihop=2, remote_as="65535", - maximum_prefix=34, update_source="2001:db8::1", ), ], - network=[ - dict(address="172.16.42.32/27", backdoor=True), - dict(address="172.16.42.251/32", route_map="map01"), - ], + # network=[ + # dict(address="172.16.42.32/27", backdoor=True), + # dict(address="172.16.42.251/32", route_map="map01"), + # ], bgp_params=dict( bestpath=dict(as_path="confed", compare_routerid=True), default=dict(no_ipv4_unicast=True), router_id="10.1.1.1", ), - redistribute=[ - dict(protocol="kernel", route_map="map01"), - dict(protocol="static", metric=20), - dict(protocol="static", route_map="map01"), - ], + # redistribute=[ + # dict(protocol="kernel", route_map="map01"), + # dict(protocol="static", metric=20), + # dict(protocol="static", route_map="map01"), + # ], ), state="merged", ), @@ -127,21 +137,12 @@ class TestVyosBgpglobalModule(TestVyosModule): dict( config=dict( as_number="65536", - maximum_paths=[ - dict(path="ebgp", count=20), - dict(path="ibgp", count=45), - ], neighbor=[ dict( address="2001:db8::2", ebgp_multihop=2, remote_as="65535", - maximum_prefix=34, update_source="2001:db8::1", - distribute_list=[ - dict(action="export", acl=31), - dict(action="import", acl=9), - ], ), ], bgp_params=dict( @@ -153,12 +154,8 @@ class TestVyosBgpglobalModule(TestVyosModule): ), ) commands = [ - "set protocols bgp 65536 neighbor 2001:db8::2 distribute-list export 31", - "set protocols bgp 65536 neighbor 2001:db8::2 distribute-list import 9", "set protocols bgp 65536 parameters confederation peers 20", "set protocols bgp 65536 parameters confederation identifier 66", - "set protocols bgp 65536 maximum-paths ebgp 20", - "set protocols bgp 65536 maximum-paths ibgp 45", ] self.execute_module(changed=True, commands=commands) @@ -172,38 +169,34 @@ class TestVyosBgpglobalModule(TestVyosModule): address="10.0.0.4", disable_connected_check=True, timers=dict(holdtime=30, keepalive=10), - capability=dict(orf="receive"), ), dict( address="192.168.0.2", - attribute_unchanged=dict(as_path=True, med=True), ebgp_multihop=2, remote_as="65535", - soft_reconfiguration=True, update_source="192.168.0.1", ), dict( address="2001:db8::2", ebgp_multihop=2, remote_as="65535", - maximum_prefix=34, update_source="2001:db8::1", ), ], - network=[ - dict(address="172.16.42.32/27", backdoor=True), - dict(address="172.16.42.251/32", route_map="map01"), - ], + # network=[ + # dict(address="172.16.42.32/27", backdoor=True), + # dict(address="172.16.42.251/32", route_map="map01"), + # ], bgp_params=dict( bestpath=dict(as_path="confed", compare_routerid=True), default=dict(no_ipv4_unicast=True), router_id="10.1.1.1", ), - redistribute=[ - dict(protocol="kernel", route_map="map01"), - dict(protocol="static", metric=20), - dict(protocol="static", route_map="map01"), - ], + # redistribute=[ + # dict(protocol="kernel", route_map="map01"), + # dict(protocol="static", metric=20), + # dict(protocol="static", route_map="map01"), + # ], ), state="replaced", ), @@ -220,19 +213,11 @@ class TestVyosBgpglobalModule(TestVyosModule): neighbor=[ dict( address="200.11.155.3", - prefix_list=[ - dict(action="export", prefix_list=10), - ], - allowas_in=10, ), dict( address="2001:db8::2", remote_as="65535", - as_override=True, default_originate="map01", - route_map=[ - dict(action="export", route_map="map01"), - ], ), ], bgp_params=dict( @@ -249,17 +234,12 @@ class TestVyosBgpglobalModule(TestVyosModule): "delete protocols bgp 65536 parameters default", "delete protocols bgp 65536 parameters bestpath compare-routerid", "delete protocols bgp 65536 parameters bestpath as-path confed", - "delete protocols bgp 65536 network", - "delete protocols bgp 65536 redistribute", + # "delete protocols bgp 65536 network", + # "delete protocols bgp 65536 redistribute", "delete protocols bgp 65536 neighbor 2001:db8::2 update-source 2001:db8::1", - "delete protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix 34", "delete protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop 2", "delete protocols bgp 65536 neighbor 192.168.0.2", "delete protocols bgp 65536 neighbor 10.0.0.4", - "set protocols bgp 65536 neighbor 200.11.155.3 prefix-list export 10", - "set protocols bgp 65536 neighbor 200.11.155.3 allowas-in number 10", - "set protocols bgp 65536 neighbor 2001:db8::2 as-override", - "set protocols bgp 65536 neighbor 2001:db8::2 route-map export map01", "set protocols bgp 65536 parameters log-neighbor-changes", "set protocols bgp 65536 parameters no-client-to-client-reflection", "set protocols bgp 65536 parameters confederation peers 20", @@ -286,19 +266,11 @@ class TestVyosBgpglobalModule(TestVyosModule): neighbor=[ dict( address="200.11.155.3", - prefix_list=[ - dict(action="export", prefix_list=10), - ], - allowas_in=10, ), dict( address="2001:db8::2", remote_as="65535", - as_override=True, default_originate="map01", - route_map=[ - dict(action="export", route_map="map01"), - ], ), ], bgp_params=dict( @@ -323,19 +295,11 @@ class TestVyosBgpglobalModule(TestVyosModule): neighbor=[ dict( address="200.11.155.3", - prefix_list=[ - dict(action="export", prefix_list=10), - ], - allowas_in=10, ), dict( address="2001:db8::2", remote_as="65535", - as_override=True, default_originate="map01", - route_map=[ - dict(action="export", route_map="map01"), - ], ), ], bgp_params=dict( @@ -364,38 +328,34 @@ class TestVyosBgpglobalModule(TestVyosModule): address="10.0.0.4", disable_connected_check=True, timers=dict(holdtime=30, keepalive=10), - capability=dict(orf="receive"), ), dict( address="192.168.0.2", - attribute_unchanged=dict(as_path=True, med=True), ebgp_multihop=2, remote_as="65535", - soft_reconfiguration=True, update_source="192.168.0.1", ), dict( address="2001:db8::2", ebgp_multihop=2, remote_as="65535", - maximum_prefix=34, update_source="2001:db8::1", ), ], - network=[ - dict(address="172.16.42.32/27", backdoor=True), - dict(address="172.16.42.251/32", route_map="map01"), - ], + # network=[ + # dict(address="172.16.42.32/27", backdoor=True), + # dict(address="172.16.42.251/32", route_map="map01"), + # ], bgp_params=dict( bestpath=dict(as_path="confed", compare_routerid=True), default=dict(no_ipv4_unicast=True), router_id="10.1.1.1", ), - redistribute=[ - dict(protocol="kernel", route_map="map01"), - dict(protocol="static", metric=20), - dict(protocol="static", route_map="map01"), - ], + # redistribute=[ + # dict(protocol="kernel", route_map="map01"), + # dict(protocol="static", metric=20), + # dict(protocol="static", route_map="map01"), + # ], ), state="rendered", ), @@ -404,22 +364,16 @@ class TestVyosBgpglobalModule(TestVyosModule): "set protocols bgp 65536 neighbor 10.0.0.4 disable-connected-check", "set protocols bgp 65536 neighbor 10.0.0.4 timers holdtime 30", "set protocols bgp 65536 neighbor 10.0.0.4 timers keepalive 10", - "set protocols bgp 65536 neighbor 10.0.0.4 capability orf prefix-list receive", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged as-path", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged med", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged next-hop", "set protocols bgp 65536 neighbor 192.168.0.2 ebgp-multihop 2", "set protocols bgp 65536 neighbor 192.168.0.2 remote-as 65535", - "set protocols bgp 65536 neighbor 192.168.0.2 soft-reconfiguration", "set protocols bgp 65536 neighbor 192.168.0.2 update-source 192.168.0.1", "set protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop 2", "set protocols bgp 65536 neighbor 2001:db8::2 remote-as 65535", - "set protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix 34", "set protocols bgp 65536 neighbor 2001:db8::2 update-source 2001:db8::1", - "set protocols bgp 65536 redistribute kernel route-map map01", - "set protocols bgp 65536 redistribute static route-map map01", - "set protocols bgp 65536 network 172.16.42.32/27 backdoor", - "set protocols bgp 65536 network 172.16.42.251/32 route-map map01", + # "set protocols bgp 65536 redistribute kernel route-map map01", + # "set protocols bgp 65536 redistribute static route-map map01", + # "set protocols bgp 65536 network 172.16.42.32/27 backdoor", + # "set protocols bgp 65536 network 172.16.42.251/32 route-map map01", "set protocols bgp 65536 parameters bestpath as-path confed", "set protocols bgp 65536 parameters bestpath compare-routerid", "set protocols bgp 65536 parameters default no-ipv4-unicast", @@ -437,22 +391,16 @@ class TestVyosBgpglobalModule(TestVyosModule): "set protocols bgp 65536 neighbor 10.0.0.4 disable-connected-check", "set protocols bgp 65536 neighbor 10.0.0.4 timers holdtime 30", "set protocols bgp 65536 neighbor 10.0.0.4 timers keepalive 10", - "set protocols bgp 65536 neighbor 10.0.0.4 capability orf prefix-list receive", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged as-path", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged med", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged next-hop", "set protocols bgp 65536 neighbor 192.168.0.2 ebgp-multihop 2", "set protocols bgp 65536 neighbor 192.168.0.2 remote-as 65535", - "set protocols bgp 65536 neighbor 192.168.0.2 soft-reconfiguration", "set protocols bgp 65536 neighbor 192.168.0.2 update-source 192.168.0.1", "set protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop 2", "set protocols bgp 65536 neighbor 2001:db8::2 remote-as 65535", - "set protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix 34", "set protocols bgp 65536 neighbor 2001:db8::2 update-source 2001:db8::1", - "set protocols bgp 65536 redistribute kernel route-map map01", - "set protocols bgp 65536 redistribute static route-map map01", - "set protocols bgp 65536 network 172.16.42.32/27 backdoor", - "set protocols bgp 65536 network 172.16.42.251/32 route-map map01", + # "set protocols bgp 65536 redistribute kernel route-map map01", + # "set protocols bgp 65536 redistribute static route-map map01", + # "set protocols bgp 65536 network 172.16.42.32/27 backdoor", + # "set protocols bgp 65536 network 172.16.42.251/32 route-map map01", "set protocols bgp 65536 parameters bestpath as-path confed", "set protocols bgp 65536 parameters bestpath compare-routerid", "set protocols bgp 65536 parameters default no-ipv4-unicast", @@ -471,17 +419,11 @@ class TestVyosBgpglobalModule(TestVyosModule): "neighbor": [ { "address": "10.0.0.4", - "capability": {"orf": "receive"}, "disable_connected_check": True, "timers": {"holdtime": 30, "keepalive": 10}, }, { "address": "192.168.0.2", - "attribute_unchanged": { - "as_path": True, - "med": True, - "next_hop": True, - }, "ebgp_multihop": 2, "remote_as": 65535, "update_source": "192.168.0.1", @@ -489,19 +431,18 @@ class TestVyosBgpglobalModule(TestVyosModule): { "address": "2001:db8::2", "ebgp_multihop": 2, - "maximum_prefix": 34, "remote_as": 65535, "update_source": "2001:db8::1", }, ], - "network": [ - {"address": "172.16.42.32/27", "backdoor": True}, - {"address": "172.16.42.251/32", "route_map": "map01"}, - ], - "redistribute": [ - {"protocol": "kernel", "route_map": "map01"}, - {"protocol": "static", "route_map": "map01"}, - ], + # "network": [ + # {"address": "172.16.42.32/27", "backdoor": True}, + # {"address": "172.16.42.251/32", "route_map": "map01"}, + # ], + # "redistribute": [ + # {"protocol": "kernel", "route_map": "map01"}, + # {"protocol": "static", "route_map": "map01"}, + # ], } self.assertEqual(sorted(parsed_list), sorted(result["parsed"])) @@ -518,34 +459,30 @@ class TestVyosBgpglobalModule(TestVyosModule): "neighbor": [ { "address": "10.0.0.4", - "capability": {"orf": "receive"}, "disable_connected_check": True, "timers": {"holdtime": 30, "keepalive": 10}, }, { "address": "192.168.0.2", - "attribute_unchanged": {"as_path": True, "med": True}, "ebgp_multihop": 2, "remote_as": 65535, - "soft_reconfiguration": True, "update_source": "192.168.0.1", }, { "address": "2001:db8::2", "ebgp_multihop": 2, - "maximum_prefix": 34, "remote_as": 65535, "update_source": "2001:db8::1", }, ], - "network": [ - {"address": "172.16.42.32/27", "backdoor": True}, - {"address": "172.16.42.251/32", "route_map": "map01"}, - ], - "redistribute": [ - {"protocol": "kernel", "route_map": "map01"}, - {"metric": 20, "protocol": "static"}, - {"protocol": "static", "route_map": "map01"}, - ], + # "network": [ + # {"address": "172.16.42.32/27", "backdoor": True}, + # {"address": "172.16.42.251/32", "route_map": "map01"}, + # ], + # "redistribute": [ + # {"protocol": "kernel", "route_map": "map01"}, + # {"metric": 20, "protocol": "static"}, + # {"protocol": "static", "route_map": "map01"}, + # ], } self.assertEqual(sorted(gather_list), sorted(result["gathered"])) diff --git a/tests/unit/modules/network/vyos/test_vyos_bgp_global14.py b/tests/unit/modules/network/vyos/test_vyos_bgp_global14.py new file mode 100644 index 00000000..ee647616 --- /dev/null +++ b/tests/unit/modules/network/vyos/test_vyos_bgp_global14.py @@ -0,0 +1,495 @@ +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from unittest.mock import patch + +from ansible_collections.vyos.vyos.plugins.modules import vyos_bgp_global +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + +from .vyos_module import TestVyosModule, load_fixture + + +class TestVyosBgpglobalModule(TestVyosModule): + module = vyos_bgp_global + + def setUp(self): + super(TestVyosBgpglobalModule, self).setUp() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", + ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + + self.mock_execute_show_command_config = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_global.bgp_global.Bgp_global._get_config", + ) + self.execute_show_command_config = self.mock_execute_show_command_config.start() + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", + ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + + self.mock_execute_show_command = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global.Bgp_globalFacts.get_device_data", + ) + + self.execute_show_command = self.mock_execute_show_command.start() + self.mock_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_global.bgp_global.get_os_version", + ) + self.test_version = "1.4" + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = self.test_version + self.mock_facts_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global.get_os_version", + ) + self.get_facts_os_version = self.mock_facts_get_os_version.start() + self.get_facts_os_version.return_value = self.test_version + self.maxDiff = None + + def tearDown(self): + super(TestVyosBgpglobalModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_execute_show_command.stop() + self.mock_execute_show_command_config.stop() + self.mock_get_os_version.stop() + self.mock_facts_get_os_version.stop() + + def load_fixtures(self, commands=None, filename=None): + if filename is None: + filename = "vyos_bgp_global_config_14.cfg" + + def load_from_file(*args, **kwargs): + output = load_fixture(filename) + return output + + self.execute_show_command.side_effect = load_from_file + self.execute_show_command_config.side_effect = load_from_file + + def test_vyos_bgp_global_merged_idempotent(self): + set_module_args( + dict( + config=dict( + as_number="65536", + neighbor=[ + dict( + address="10.0.0.4", + disable_connected_check=True, + timers=dict(holdtime=30, keepalive=10), + ), + dict( + address="192.168.0.2", + ebgp_multihop=2, + remote_as="65535", + update_source="192.168.0.1", + ), + dict( + address="2001:db8::2", + ebgp_multihop=2, + remote_as="65535", + update_source="2001:db8::1", + ), + ], + # network=[ + # dict(address="172.16.42.32/27", backdoor=True), + # dict(address="172.16.42.251/32", route_map="map01"), + # ], + bgp_params=dict( + bestpath=dict(as_path="confed", compare_routerid=True), + default=dict(no_ipv4_unicast=True), + router_id="10.1.1.1", + ), + # redistribute=[ + # dict(protocol="kernel", route_map="map01"), + # dict(protocol="static", metric=20), + # dict(protocol="static", route_map="map01"), + # ], + ), + state="merged", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_bgp_global_merged(self): + set_module_args( + dict( + config=dict( + as_number="65536", + neighbor=[ + dict( + address="2001:db8::2", + ebgp_multihop=2, + remote_as="65535", + update_source="2001:db8::1", + ), + ], + bgp_params=dict( + confederation=[dict(peers=20), dict(identifier=66)], + router_id="10.1.1.1", + ), + ), + state="merged", + ), + ) + commands = [ + "set protocols bgp parameters confederation peers 20", + "set protocols bgp parameters confederation identifier 66", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_global_replaced_idempotent(self): + set_module_args( + dict( + config=dict( + as_number="65536", + neighbor=[ + dict( + address="10.0.0.4", + disable_connected_check=True, + timers=dict(holdtime=30, keepalive=10), + ), + dict( + address="192.168.0.2", + ebgp_multihop=2, + remote_as="65535", + update_source="192.168.0.1", + ), + dict( + address="2001:db8::2", + ebgp_multihop=2, + remote_as="65535", + update_source="2001:db8::1", + ), + ], + # network=[ + # dict(address="172.16.42.32/27", backdoor=True), + # dict(address="172.16.42.251/32", route_map="map01"), + # ], + bgp_params=dict( + bestpath=dict(as_path="confed", compare_routerid=True), + default=dict(no_ipv4_unicast=True), + router_id="10.1.1.1", + ), + # redistribute=[ + # dict(protocol="kernel", route_map="map01"), + # dict(protocol="static", metric=20), + # dict(protocol="static", route_map="map01"), + # ], + ), + state="replaced", + ), + ) + self.execute_module(changed=False, commands=[]) + + # + def test_vyos_bgp_global_replaced(self): + set_module_args( + dict( + config=dict( + as_number="65536", + timers=dict(holdtime=30, keepalive=10), + neighbor=[ + dict( + address="200.11.155.3", + ), + dict( + address="2001:db8::2", + remote_as="65535", + default_originate="map01", + ), + ], + bgp_params=dict( + log_neighbor_changes=True, + no_client_to_client_reflection=True, + confederation=[dict(peers=20), dict(identifier=66)], + router_id="10.1.1.1", + ), + ), + state="replaced", + ), + ) + commands = [ + "delete protocols bgp parameters default", + "delete protocols bgp parameters bestpath compare-routerid", + "delete protocols bgp parameters bestpath as-path confed", + # "delete protocols bgp network", + # "delete protocols bgp redistribute", + "delete protocols bgp neighbor 2001:db8::2 update-source 2001:db8::1", + "delete protocols bgp neighbor 2001:db8::2 ebgp-multihop 2", + "delete protocols bgp neighbor 192.168.0.2", + "delete protocols bgp neighbor 10.0.0.4", + "set protocols bgp parameters log-neighbor-changes", + "set protocols bgp parameters no-client-to-client-reflection", + "set protocols bgp parameters confederation peers 20", + "set protocols bgp parameters confederation identifier 66", + "set protocols bgp timers holdtime 30", + "set protocols bgp timers keepalive 10", + ] + self.execute_module(changed=True, commands=commands) + + # + def test_vyos_bgp_global_purged(self): + set_module_args(dict(config=dict(as_number="65536"), state="purged")) + # + commands = ["delete protocols bgp"] + self.execute_module(changed=True, commands=commands) + + # + # def test_vyos_bgp_global_incorrect_instance(self): + # set_module_args( + # dict( + # config=dict( + # as_number="100", + # timers=dict(holdtime=30, keepalive=10), + # neighbor=[ + # dict( + # address="200.11.155.3", + # allowas_in=10, + # ), + # dict( + # address="2001:db8::2", + # remote_as="65535", + # as_override=True, + # default_originate="map01", + # route_map=[ + # dict(action="export", route_map="map01"), + # ], + # ), + # ], + # bgp_params=dict( + # log_neighbor_changes=True, + # no_client_to_client_reflection=True, + # confederation=[dict(peers=20), dict(identifier=66)], + # router_id="10.1.1.1", + # ), + # ), + # state="replaced", + # ), + # ) + # result = self.execute_module(failed=True) + # self.assertIn("Only one bgp instance is allowed per device", result["msg"]) + + def test_vyos_bgp_global_replaced_af(self): + set_module_args( + dict( + config=dict( + as_number="65536", + timers=dict(holdtime=30, keepalive=10), + neighbor=[ + dict( + address="200.11.155.3", + ), + dict( + address="2001:db8::2", + remote_as="65535", + default_originate="map01", + ), + ], + bgp_params=dict( + log_neighbor_changes=True, + no_client_to_client_reflection=True, + confederation=[dict(peers=20), dict(identifier=66)], + router_id="10.1.1.1", + ), + ), + state="replaced", + ), + ) + result = self.execute_module(failed=True, filename="vyos_bgp_global_af_config_14.cfg") + self.assertIn( + "Use the _bgp_address_family module to delete the address_family under neighbor 5001::64, before replacing/deleting the neighbor.", + result["msg"], + ) + + def test_vyos_bgp_global_rendered(self): + set_module_args( + dict( + config=dict( + as_number="65536", + neighbor=[ + dict( + address="10.0.0.4", + disable_connected_check=True, + timers=dict(holdtime=30, keepalive=10), + ), + dict( + address="192.168.0.2", + ebgp_multihop=2, + remote_as="65535", + update_source="192.168.0.1", + ), + dict( + address="2001:db8::2", + ebgp_multihop=2, + remote_as="65535", + update_source="2001:db8::1", + ), + ], + # network=[ + # dict(address="172.16.42.32/27", backdoor=True), + # dict(address="172.16.42.251/32", route_map="map01"), + # ], + bgp_params=dict( + bestpath=dict(as_path="confed", compare_routerid=True), + default=dict(no_ipv4_unicast=True), + router_id="10.1.1.1", + ), + # redistribute=[ + # dict(protocol="kernel", route_map="map01"), + # dict(protocol="static", metric=20), + # dict(protocol="static", route_map="map01"), + # ], + ), + state="rendered", + ), + ) + rendered_cmds = [ + "set protocols bgp system-as 65536", + "set protocols bgp neighbor 10.0.0.4 disable-connected-check", + "set protocols bgp neighbor 10.0.0.4 timers holdtime 30", + "set protocols bgp neighbor 10.0.0.4 timers keepalive 10", + "set protocols bgp neighbor 192.168.0.2 ebgp-multihop 2", + "set protocols bgp neighbor 192.168.0.2 remote-as 65535", + "set protocols bgp neighbor 192.168.0.2 update-source 192.168.0.1", + "set protocols bgp neighbor 2001:db8::2 ebgp-multihop 2", + "set protocols bgp neighbor 2001:db8::2 remote-as 65535", + "set protocols bgp neighbor 2001:db8::2 update-source 2001:db8::1", + # "set protocols bgp redistribute kernel route-map map01", + # "set protocols bgp redistribute static route-map map01", + # "set protocols bgp network 172.16.42.32/27 backdoor", + # "set protocols bgp network 172.16.42.251/32 route-map map01", + "set protocols bgp parameters bestpath as-path confed", + "set protocols bgp parameters bestpath compare-routerid", + "set protocols bgp parameters default no-ipv4-unicast", + "set protocols bgp parameters router-id 10.1.1.1", + ] + result = self.execute_module(changed=False) + self.assertEqual( + sorted(result["rendered"]), + sorted(rendered_cmds), + result["rendered"], + ) + + def test_vyos_bgp_global_parsed(self): + commands = [ + "set protocols bgp system-as 65536", + "set protocols bgp neighbor 10.0.0.4 disable-connected-check", + "set protocols bgp neighbor 10.0.0.4 timers holdtime 30", + "set protocols bgp neighbor 10.0.0.4 timers keepalive 10", + "set protocols bgp neighbor 192.168.0.2 ebgp-multihop 2", + "set protocols bgp neighbor 192.168.0.2 remote-as 65535", + "set protocols bgp neighbor 192.168.0.2 update-source 192.168.0.1", + "set protocols bgp neighbor 2001:db8::2 ebgp-multihop 2", + "set protocols bgp neighbor 2001:db8::2 remote-as 65535", + "set protocols bgp neighbor 2001:db8::2 update-source 2001:db8::1", + # "set protocols bgp redistribute kernel route-map map01", + # "set protocols bgp redistribute static route-map map01", + # "set protocols bgp network 172.16.42.32/27 backdoor", + # "set protocols bgp network 172.16.42.251/32 route-map map01", + "set protocols bgp parameters bestpath as-path confed", + "set protocols bgp parameters bestpath compare-routerid", + "set protocols bgp parameters default no-ipv4-unicast", + "set protocols bgp parameters router-id 10.1.1.1", + ] + parsed_str = "\n".join(commands) + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_list = { + "as_number": 65536, + "bgp_params": { + "bestpath": {"as_path": "confed", "compare_routerid": True}, + "default": {"no_ipv4_unicast": True}, + "router_id": "10.1.1.1", + }, + "neighbor": [ + { + "address": "10.0.0.4", + "disable_connected_check": True, + "timers": {"holdtime": 30, "keepalive": 10}, + }, + { + "address": "192.168.0.2", + "ebgp_multihop": 2, + "remote_as": 65535, + "update_source": "192.168.0.1", + }, + { + "address": "2001:db8::2", + "ebgp_multihop": 2, + "remote_as": 65535, + "update_source": "2001:db8::1", + }, + ], + # "network": [ + # {"address": "172.16.42.32/27", "backdoor": True}, + # {"address": "172.16.42.251/32", "route_map": "map01"}, + # ], + # "redistribute": [ + # {"protocol": "kernel", "route_map": "map01"}, + # {"protocol": "static", "route_map": "map01"}, + # ], + } + self.assertEqual(sorted(parsed_list), sorted(result["parsed"])) + + def test_vyos_bgp_global_gathered(self): + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = { + "as_number": 65536, + "bgp_params": { + "bestpath": {"as_path": "confed", "compare_routerid": True}, + "default": {"no_ipv4_unicast": True}, + "router_id": "10.1.1.1", + }, + "neighbor": [ + { + "address": "10.0.0.4", + "disable_connected_check": True, + "timers": {"holdtime": 30, "keepalive": 10}, + }, + { + "address": "192.168.0.2", + "ebgp_multihop": 2, + "remote_as": 65535, + "update_source": "192.168.0.1", + }, + { + "address": "2001:db8::2", + "ebgp_multihop": 2, + "remote_as": 65535, + "update_source": "2001:db8::1", + }, + ], + # "network": [ + # {"address": "172.16.42.32/27", "backdoor": True}, + # {"address": "172.16.42.251/32", "route_map": "map01"}, + # ], + # "redistribute": [ + # {"protocol": "kernel", "route_map": "map01"}, + # {"metric": 20, "protocol": "static"}, + # {"protocol": "static", "route_map": "map01"}, + # ], + } + self.assertEqual(sorted(gather_list), sorted(result["gathered"])) |