Skip to content

Commit

Permalink
Merge branch 'gh_1244' into 'support_202209'
Browse files Browse the repository at this point in the history
IX-F importer fails on nulled ipv4 / ipv6 properties in vlan_list entries #1244

See merge request gh/peeringdb/peeringdb!320
  • Loading branch information
vegu committed Sep 29, 2022
2 parents 20305bf + e92d3eb commit 5fbf35d
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
9 changes: 9 additions & 0 deletions peeringdb_server/ixf.py
Expand Up @@ -377,6 +377,15 @@ def sanitize_vlans(self, vlans):

id = vlan.get("vlan_id", 0)

# the ix-f schema allows setting ipv4 and ipv6 to
# null, in which case remove the property

if "ipv4" in vlan and not vlan.get("ipv4"):
del vlan["ipv4"]

if "ipv6" in vlan and not vlan.get("ipv6"):
del vlan["ipv6"]

# neither ipv4 nor ipv6 is specified, there is
# nothing to sanitize here, so skip

Expand Down
4 changes: 4 additions & 0 deletions tests/data/ixf/vlan/test9.expected
@@ -0,0 +1,4 @@
{
"vlan_list": [
]
}
9 changes: 9 additions & 0 deletions tests/data/ixf/vlan/test9.input
@@ -0,0 +1,9 @@
{
"vlan_list": [
{
"vlan_id":2,
"ipv4":null,
"ipv6":null
}
]
}
51 changes: 51 additions & 0 deletions tests/data/json_members_list/ixf.member.null.ip.vlan.json
@@ -0,0 +1,51 @@
{
"timestamp": "2020-07-13T09:23:47Z",
"version": "1.0",
"ixp_list": [
{
"shortname": "Test Exchange",
"ixp_id": 1,
"ixf_id": 1
}
],
"member_list": [
{
"asnum": 1001,
"member_type": "peering",
"name": "Netflix",
"url": "http://netflix.com/",
"contact_email": [
"peering@netflix.com",
"mrpeering@netflix.com"
],
"contact_phone": [
"+1 1234 5678"
],
"contact_hours": "8/5",
"peering_policy": "open",
"peering_policy_url": "https://www.netflix.com/openconnect/",
"member_since": "2009-02-04T00:00:00Z",
"connection_list": [
{
"ixp_id": 42,
"connected_since": "2009-02-04T00:00:00Z",
"state": "connected",
"if_list": [
{
"switch_id": 1,
"if_speed": 20000,
"if_type": "LR4"
}
],
"vlan_list": [
{
"vlan_id": 1,
"ipv4": null,
"ipv6": null
}
]
}
]
}
]
}
31 changes: 31 additions & 0 deletions tests/test_ixf_member_import_protocol.py
Expand Up @@ -2297,6 +2297,37 @@ def test_mark_invalid_multiple_vlans(entities, save):
# Test idempotent
assert_idempotent(importer, ixlan, data)

@pytest.mark.django_db
def test_vlan_null_ips(entities, save):
"""
The IX-F data contains a vlan that has null values for ipv4 and ipv6
Importer should treat them the same as if they werent set at all (#1244)
"""

data = setup_test_data("ixf.member.null.ip.vlan")
ixlan = entities["ixlan"][0]

importer = ixf.Importer()
importer.sanitize(data)

if not save:
return assert_idempotent(importer, ixlan, data, save=False)

importer.update(ixlan, data=data)
importer.notify_proposals()

assert importer.ixlan.ixf_ixp_import_error_notified is None
assert importer.ixlan.ixf_ixp_import_error is None
assert_no_emails(ix=ixlan.ix)

# Assert idempotent / lock
importer.sanitize(data)
importer.update(ixlan, data=data)

assert importer.ixlan.ixf_ixp_import_error_notified is None
assert importer.ixlan.ixf_ixp_import_error is None
assert_no_emails(ix=ixlan.ix)


@pytest.mark.django_db
def test_vlan_list_empty(entities, save):
Expand Down

0 comments on commit 5fbf35d

Please sign in to comment.