Skip to content

Commit 944e003

Browse files
committed
[GCU] Validate peer_group_range ip_range are correct
1 parent d012be9 commit 944e003

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

generic_config_updater/gu_common.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,35 @@ def validate_config_db_config(self, config_db_as_json):
118118
sy.loadData(tmp_config_db_as_json)
119119

120120
sy.validate_data_tree()
121-
return True
121+
122+
# TODO: modularize custom validations better
123+
return self.validate_bgp_peer_group(config_db_as_json)
122124
except sonic_yang.SonicYangException as ex:
123125
return False
124126

127+
# TODO: unit-test
128+
def validate_bgp_peer_group(self, config_db):
129+
if "BGP_PEER_RANGE" not in config_db:
130+
return True
131+
132+
visited = {}
133+
table = config_db["BGP_PEER_RANGE"]
134+
for peer_group_name in table:
135+
peer_group = table[peer_group_name]
136+
if "ip_range" not in peer_group:
137+
continue
138+
139+
# TODO: convert string IpAddress object for better handling of IPs
140+
# TODO: does validation only fails if exact match of IP, or if there is an intersection?
141+
ip_range = peer_group["ip_range"]
142+
for ip in ip_range:
143+
if ip in visited:
144+
# TODO: Return also error once https://github.com/Azure/sonic-utilities/pull/1991 lands in prod
145+
return False #, f"{ip} is duplicated in BGP_PEER_RANGE: {set([peer_group_name, visited[ip]])}"
146+
visited[ip] = peer_group_name
147+
148+
return True #, None
149+
125150
def crop_tables_without_yang(self, config_db_as_json):
126151
sy = self.create_sonic_yang_with_loaded_models()
127152

0 commit comments

Comments
 (0)