Skip to content

Commit

Permalink
[GCU] Validate peer_group_range ip_range are correct
Browse files Browse the repository at this point in the history
  • Loading branch information
ghooo committed Apr 28, 2022
1 parent d012be9 commit b529431
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion generic_config_updater/gu_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,32 @@ def validate_config_db_config(self, config_db_as_json):
sy.loadData(tmp_config_db_as_json)

sy.validate_data_tree()
return True

# TODO: modularize custom validations better
return self.validate_bgp_peer_group(config_db_as_json)
except sonic_yang.SonicYangException as ex:
return False

# TODO: unit-test
def validate_bgp_peer_group(self, config_db):
if "BGP_PEER_RANGE" not in config_db:
return True

visited = {}
table = config_db["BGP_PEER_RANGE"]
for peer_group_name in table:
peer_group = table[peer_group_name]
if "ip_range" not in peer_group:
continue
ip_range = peer_group["ip_range"]
for ip in ip_range:
if ip in visited:
# TODO: Return also error once https://github.com/Azure/sonic-utilities/pull/1991 lands in prod
return False #, f"{ip} is duplicated in BGP_PEER_RANGE: {set([peer_group_name, visited[ip]])}"
visited[ip] = peer_group_name

return True #, None

def crop_tables_without_yang(self, config_db_as_json):
sy = self.create_sonic_yang_with_loaded_models()

Expand Down

0 comments on commit b529431

Please sign in to comment.