Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VyOS v1.4 support for BGP (T6892 & T6888 & T6822) #367

Merged
merged 38 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
af91688
VyOS v1.4 support for BGP (T6892)
omnom62 Nov 28, 2024
c10b03a
WIP: chnages to scanners and facts for BGP on v1.4
omnom62 Nov 30, 2024
4e83507
scanners and facts modification to support as_numberless commands
omnom62 Dec 1, 2024
89c469f
remove optional regex groups
omnom62 Dec 1, 2024
bdf9104
VyOS v1.4 BGP system-as functionality
omnom62 Dec 1, 2024
68b9c33
bgp_af linter
omnom62 Dec 1, 2024
dc8dbbc
bgp_global mods and testing
omnom62 Dec 2, 2024
dc41dd2
bgp_global v.1.4 support
omnom62 Dec 2, 2024
6bf61fa
linter fixes
omnom62 Dec 2, 2024
c676bb1
bgp_global and bgp_af fixed 1.3 test cases
omnom62 Dec 3, 2024
f9645bd
unit tests for bgp modules for both versions
omnom62 Dec 3, 2024
ffc9533
obsolete stranzas removed from bgp_global for both versions
omnom62 Dec 3, 2024
e71c031
some typos removed
omnom62 Dec 4, 2024
9d1c0c4
bgp_global rst updates
omnom62 Dec 4, 2024
d12f92a
t6829 related draft changes
omnom62 Dec 5, 2024
730f22e
Draft changes to unit tests fot original set and t6888 updates
omnom62 Dec 5, 2024
08a3e41
changelog
omnom62 Dec 5, 2024
2d4aaac
D.R.Y for bgp_global and testmodule names
omnom62 Dec 6, 2024
0715d68
linter fixes
omnom62 Dec 6, 2024
c0a388c
fixtures for bgp_af options testts
omnom62 Dec 8, 2024
b2821bf
stranzas options processing
omnom62 Dec 11, 2024
d10dff4
T6888 bgp option test func and cases
omnom62 Dec 11, 2024
b51f014
clean-up draft code and update to rm_templates
omnom62 Dec 11, 2024
b92a8ef
v14 system-as change supported in conf and tests
omnom62 Dec 11, 2024
c777efd
T6822 BGP global passive bugfix
omnom62 Dec 13, 2024
61785d4
clean-up
omnom62 Dec 13, 2024
b37c770
T6829: update integration tests
gaige Dec 15, 2024
1d0a98d
T6829: fix integration tests for global
gaige Dec 15, 2024
c969dbd
T6829: fix integration tests for bgp_global
gaige Dec 15, 2024
08ef2a3
T6829: fix for 1.4 AF integration tests
gaige Dec 15, 2024
4dad478
T6829: fix unit tests after removing obsolete items
gaige Dec 15, 2024
40bba69
T6829: fix sanity test failures
gaige Dec 15, 2024
46a8323
T6829: fix documentation
gaige Dec 15, 2024
0f2fb47
Lint and comments are addressed
omnom62 Dec 16, 2024
dedeffd
rtt.yaml and fix to integration tests
omnom62 Dec 16, 2024
f7d9875
updated fragments for bgp_global
omnom62 Dec 16, 2024
07af8a8
lint fixes
omnom62 Dec 16, 2024
8f2b653
Merge branch 'main' into bgp_af_rework_t6829
omnom62 Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
Bgp_address_familyTemplate,
)

from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family_14 import (
Bgp_address_familyTemplate14,
)

from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version

from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion


class Bgp_address_family(ResourceModule):
"""
Expand All @@ -49,12 +57,30 @@ def __init__(self, module):
)
self.parsers = []

def _validate_template(self):
version = get_os_version(self._module)
if LooseVersion(version) >= LooseVersion("1.4"):
self._tmplt = Bgp_address_familyTemplate14()
else:
self._tmplt = Bgp_address_familyTemplate()

def parse(self):
""" override parse to check template """
self._validate_template()
return super().parse()

def get_parser(self, name):
"""get_parsers"""
self._validate_template()
return super().get_parser(name)

def execute_module(self):
"""Execute the module

:rtype: A dictionary
:returns: The result from module execution
"""
self._validate_template()
if self.state not in ["parsed", "gathered"]:
self.generate_commands()
self.run_commands()
Expand All @@ -67,6 +93,9 @@ def generate_commands(self):
wantd = {}
haved = {}

# if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
omnom62 marked this conversation as resolved.
Show resolved Hide resolved
# self._tmplt.set_as_number(self.want.get("as_number"))

if self.want.get("as_number") == self.have.get("as_number") or not self.have:
if self.want:
wantd = {self.want["as_number"]: self.want}
Expand Down Expand Up @@ -103,6 +132,9 @@ def _compare(self, want, have):
the `want` and `have` data with the `parsers` defined
for the Bgp_address_family network resource.
"""
if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
omnom62 marked this conversation as resolved.
Show resolved Hide resolved
self._compare_asn(want, have)

self._compare_af(want, have)
self._compare_neighbors(want, have)
# Do the negation first
Expand Down Expand Up @@ -275,6 +307,12 @@ def _compare_lists(self, want, have, as_number, afi):
"redistribute.route_map",
"redistribute.table",
]

if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
delete_asn = ""
else:
delete_asn = " " + str(as_number)

for attrib in ["redistribute", "networks", "aggregate_address"]:
wdict = want.pop(attrib, {})
hdict = have.pop(attrib, {})
Expand All @@ -300,8 +338,8 @@ def _compare_lists(self, want, have, as_number, afi):
attrib = re.sub("_", "-", attrib)
attrib = re.sub("networks", "network", attrib)
self.commands.append(
"delete protocols bgp "
+ str(as_number)
"delete protocols bgp"
+ delete_asn
+ " "
+ "address-family "
+ afi
Expand All @@ -319,6 +357,15 @@ def _compare_lists(self, want, have, as_number, afi):
},
)

def _compare_asn(self, want, have):
if want.get("as_number") and not have.get("as_number"):
self.commands.append(
"set protocols bgp "
+ "system-as "
+ " "
+ str(want.get("as_number")),
)

def _bgp_af_list_to_dict(self, entry):
for name, proc in iteritems(entry):
if "address_family" in proc:
Expand Down
64 changes: 60 additions & 4 deletions plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
Bgp_globalTemplate,
)

from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global_14 import (
Bgp_globalTemplate14,
)

from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version

from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion


class Bgp_global(ResourceModule):
"""
Expand All @@ -48,12 +56,32 @@ def __init__(self, module):
)
self.parsers = []

def _validate_template(self):
version = get_os_version(self._module)
if LooseVersion(version) >= LooseVersion("1.4"):
self._tmplt = Bgp_globalTemplate14()
else:
self._tmplt = Bgp_globalTemplate()

def parse(self):
""" override parse to check template """
self._validate_template()
return super().parse()

def get_parser(self, name):
"""get_parsers"""
self._module.fail_json(msg="#2")
omnom62 marked this conversation as resolved.
Show resolved Hide resolved
self._validate_template()
return super().get_parser(name)

def execute_module(self):
"""Execute the module

:rtype: A dictionary
:returns: The result from module execution
"""

self._validate_template()
if self.state not in ["parsed", "gathered"]:
self.generate_commands()
self.run_commands()
Expand Down Expand Up @@ -105,6 +133,9 @@ def _compare(self, want, have):
the `want` and `have` data with the `parsers` defined
for the Bgp_global network resource.
"""
if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
self._compare_asn(want, have)
omnom62 marked this conversation as resolved.
Show resolved Hide resolved

parsers = ["maximum_paths", "timers"]
self._compare_neighbor(want, have)
self._compare_lists(want, have)
Expand Down Expand Up @@ -179,9 +210,11 @@ def _compare_neighbor(self, want, have):
"network.backdoor",
"network.route_map",
]

wneigh = want.pop("neighbor", {})
hneigh = have.pop("neighbor", {})
self._compare_neigh_lists(wneigh, hneigh)

for name, entry in iteritems(wneigh):
for k, v in entry.items():
if k == "address":
Expand All @@ -206,8 +239,12 @@ def _compare_neighbor(self, want, have):
)
self._module.fail_json(msg=msg)
else:
if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
delete_asn = ""
else :
delete_asn = " " + str(have["as_number"])
self.commands.append(
"delete protocols bgp " + str(have["as_number"]) + " neighbor " + name,
"delete protocols bgp" + delete_asn + " neighbor " + name,
)
continue
for k, v in entry.items():
Expand Down Expand Up @@ -243,6 +280,7 @@ def _compare_bgp_params(self, want, have):
"bgp_params.routerid",
"bgp_params.scan_time",
]

wbgp = want.pop("bgp_params", {})
hbgp = have.pop("bgp_params", {})
for name, entry in iteritems(wbgp):
Expand Down Expand Up @@ -287,12 +325,16 @@ def _compare_bgp_params(self, want, have):
},
)
if not wbgp and hbgp:
self.commands.append("delete protocols bgp " + str(have["as_number"]) + " parameters")
if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
delete_asn = ""
else:
delete_asn = " " + str(have["as_number"])
self.commands.append("delete protocols bgp" + delete_asn + " parameters")
hbgp = {}
for name, entry in iteritems(hbgp):
if name == "confederation":
self.commands.append(
"delete protocols bgp " + str(have["as_number"]) + " parameters confederation",
"delete protocols bgp" + delete_asn + " parameters confederation",
)
elif name == "distance":
distance_parsers = [
Expand Down Expand Up @@ -325,6 +367,7 @@ def _compare_lists(self, want, have):
"redistribute.route_map",
"aggregate_address",
]

for attrib in ["redistribute", "network", "aggregate_address"]:
wdict = want.pop(attrib, {})
hdict = have.pop(attrib, {})
Expand All @@ -339,8 +382,12 @@ def _compare_lists(self, want, have):
# remove remaining items in have for replaced
if not wdict and hdict:
attrib = re.sub("_", "-", attrib)
if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
delete_asn = ""
else :
delete_asn = " " + str(have["as_number"])
self.commands.append(
"delete protocols bgp " + str(have["as_number"]) + " " + attrib,
"delete protocols bgp" + delete_asn + " " + attrib,
)
hdict = {}
for key, entry in iteritems(hdict):
Expand Down Expand Up @@ -392,6 +439,15 @@ def _bgp_global_list_to_dict(self, entry):
redis_dict.update({entry["protocol"]: entry})
proc["redistribute"] = redis_dict

def _compare_asn(self, want, have):
if want.get("as_number") and not have.get("as_number"):
self.commands.append(
"set protocols bgp "
+ "system-as"
+ " "
+ str(want.get("as_number")),
)

omnom62 marked this conversation as resolved.
Show resolved Hide resolved
def _check_af(self, neighbor):
af_present = False
if self._connection:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family import (
Bgp_address_familyTemplate,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family_14 import (
Bgp_address_familyTemplate14,
)

from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version

from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion


class Bgp_address_familyFacts(object):
Expand Down Expand Up @@ -55,11 +62,14 @@ def populate_facts(self, connection, ansible_facts, data=None):
data = self.get_device_data(connection)

for resource in data.splitlines():
if "address-family" in resource:
if "address-family" in resource or "system-as" in resource:
gaige marked this conversation as resolved.
Show resolved Hide resolved
config_lines.append(re.sub("'", "", resource))

# parse native config using the Bgp_address_family template
bgp_address_family_parser = Bgp_address_familyTemplate(lines=config_lines)
# parse native config using the Bgp_address_family template based on version
if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
bgp_address_family_parser = Bgp_address_familyTemplate14(lines=config_lines)
else:
bgp_address_family_parser = Bgp_address_familyTemplate(lines=config_lines)
objs = bgp_address_family_parser.parse()
if objs:
if "address_family" in objs:
Expand Down
16 changes: 14 additions & 2 deletions plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
Bgp_globalTemplate,
)

from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global_14 import (
Bgp_globalTemplate14,
)

from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version

from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion


class Bgp_globalFacts(object):
"""The vyos bgp_global facts class"""
Expand Down Expand Up @@ -55,10 +63,14 @@ def populate_facts(self, connection, ansible_facts, data=None):
data = self.get_device_data(connection)

for resource in data.splitlines():
if "address-family" not in resource:
if "address-family" not in resource in resource:
omnom62 marked this conversation as resolved.
Show resolved Hide resolved
config_lines.append(re.sub("'", "", resource))

bgp_global_parser = Bgp_globalTemplate(lines=config_lines, module=self._module)
if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
bgp_global_parser = Bgp_globalTemplate14(lines=config_lines, module=self._module)
else:
bgp_global_parser = Bgp_globalTemplate(lines=config_lines, module=self._module)

objs = bgp_global_parser.parse()

if "neighbor" in objs:
Expand Down
Loading
Loading