Skip to content

Commit d7378f5

Browse files
committed
Remove keys with null values so that _build_aerleon_definitions fails and path objects are replaced. Added test for edge case with vxlans
1 parent a03e61d commit d7378f5

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/cnaas_nms/api/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def validate_json_to_model(json_data):
3636
ret_copy = ret.copy()
3737
ret_copy["system_access_lists"] = list(ret_copy.get("access_lists", {}).keys())
3838

39+
# Remove any keys without any value
40+
ret_copy = {k: v for k, v in ret_copy.items() if v}
41+
3942
# Check if we can build aerleon definitions with the provided settings
4043
try:
4144
_build_aerleon_definitions(ret_copy)

src/cnaas_nms/api/tests/test_settings.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,37 @@ def test_access_list_reference_no_data(testclient: FlaskClient):
103103
assert "No IP addresses found for network: BGP_PEERS" in result.json["message"]
104104

105105

106+
def test_access_list_reference_vxlans(testclient: FlaskClient):
107+
"""Test that reference to vxlans falls back to standard values instead of being empty"""
108+
settings_data = {
109+
"network_definitions": {
110+
"students_gws": [
111+
{"path": "vxlans.* | [?vrf=='STUDENT'].[ipv4_gw, ipv4_secondaries, ipv6_gw][][]"},
112+
]
113+
},
114+
"access_lists": {
115+
"ACLTEST": {"terms": [{"name": "allow_bgp", "destination-address": "students_gws", "action": "accept"}]}
116+
},
117+
}
118+
119+
result = testclient.post("/api/v1.0/settings/model", json=settings_data)
120+
assert result.status_code == 200
121+
122+
123+
def test_access_list_invalid_jmespath(testclient: FlaskClient):
124+
"""Test that invalid jmespath triggers on /settings/model api"""
125+
settings_data = {
126+
"network_definitions": {
127+
"invalid_path": [
128+
{"path": "vxlans]"},
129+
]
130+
}
131+
}
132+
133+
result = testclient.post("/api/v1.0/settings/model", json=settings_data)
134+
assert result.status_code == 400
135+
136+
106137
def test_settings_model(testclient: FlaskClient):
107138
result = testclient.get("/api/v1.0/settings/model")
108139
assert result.status_code == 200

0 commit comments

Comments
 (0)