diff --git a/generic_config_updater/gu_common.py b/generic_config_updater/gu_common.py index 0fa1e66f92e..45da00ac1ab 100644 --- a/generic_config_updater/gu_common.py +++ b/generic_config_updater/gu_common.py @@ -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()