Skip to content

Commit 029941a

Browse files
committed
manage edge bgp_password: honor boolean, validate password required when enabled
- Template: if bgp_password_enable is true, send password; if false, send empty password - Validation: rule 321 now rejects bgp_password_enable=true without a non-empty bgp_password - Always emit BGP_PASSWORD key for dcnm_policy diff detection
1 parent 6dec077 commit 029941a

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

roles/dtc/common/templates/ndfc_edge_connections.j2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
description: {{ 'nace_bgp_peer_template_dci_underlay_jython_' + link.source_device + '_' + link.source_interface + '_' + link.dest_device }}
1818
name: bgp_peer_template_dci_underlay_jython
1919
policy_vars:
20-
{% if link.bgp_section is defined and link.bgp_section.bgp_password is defined and link.bgp_section.bgp_password is not none and link.bgp_section.bgp_password | length > 0 %}
21-
BGP_PASSWORD_ENABLE: true
20+
{% if link.bgp_section.bgp_password_enable | default(defaults.vxlan.topology.edge_connections.bgp_section.bgp_password_enable) | bool %}
2221
BGP_PASSWORD: "{{ link.bgp_section.bgp_password }}"
22+
BGP_PASSWORD_ENABLE: true
2323
{% else %}
24+
BGP_PASSWORD: ""
2425
BGP_PASSWORD_ENABLE: false
2526
{% endif %}
2627
TEMPLATE_NAME: {{ data_model_extended.vxlan.fabric.name + '-' + link.dest_fabric + '-IPV4-EBGP' }}

roles/validate/files/rules/common/321_topology_edge_connections.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Rule:
22
id = "321"
3-
description = "Verify edge connections have valid source devices and interfaces"
3+
description = "Verify edge connections have valid source devices, interfaces, and bgp password configuration"
44
severity = "HIGH"
55

66
@classmethod
@@ -42,6 +42,26 @@ def match(cls, data_model):
4242
f"vxlan.topology.edge_connections.{source_device} source_interface must not contain a '.' (sub-interfaces are not allowed)."
4343
)
4444

45+
# Verify bgp_password is provided when bgp_password_enable is true
46+
bgp_section = edge_connection.get("bgp_section", {})
47+
defaults = data_model.get("defaults", {})
48+
default_bgp_pw_enable = (
49+
defaults.get("vxlan", {})
50+
.get("topology", {})
51+
.get("edge_connections", {})
52+
.get("bgp_section", {})
53+
.get("bgp_password_enable", False)
54+
)
55+
bgp_password_enable = bgp_section.get("bgp_password_enable", default_bgp_pw_enable)
56+
bgp_password = bgp_section.get("bgp_password", "")
57+
58+
if bgp_password_enable and (not bgp_password or str(bgp_password).strip() == ""):
59+
results.append(
60+
f"vxlan.topology.edge_connections.{source_device} "
61+
f"bgp_password_enable is true but bgp_password is not provided. "
62+
f"A non-empty bgp_password is required when bgp_password_enable is true."
63+
)
64+
4565
return results
4666

4767
@classmethod

0 commit comments

Comments
 (0)