mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
add reasons to ixf import log for add and modify actions (gh-408) (#483)
This commit is contained in:
@@ -378,12 +378,15 @@ class Importer(object):
|
|||||||
self.netixlans.append(result["netixlan"])
|
self.netixlans.append(result["netixlan"])
|
||||||
if result["created"]:
|
if result["created"]:
|
||||||
action = "add"
|
action = "add"
|
||||||
|
reason = _("New ip-address")
|
||||||
else:
|
else:
|
||||||
action = "modify"
|
action = "modify"
|
||||||
|
reason = _("Fields changed: {}").format(
|
||||||
|
", ".join(result.get("changed")))
|
||||||
|
|
||||||
self.log_peer(asn, action, "", result["netixlan"])
|
self.log_peer(asn, action, reason, result["netixlan"])
|
||||||
elif result["netixlan"]:
|
elif result["netixlan"]:
|
||||||
self.log_peer(asn, "noop", "", result["netixlan"])
|
self.log_peer(asn, "noop", _("No changes"), result["netixlan"])
|
||||||
elif result["log"]:
|
elif result["log"]:
|
||||||
self.log_peer(asn, "ignore", "\n".join(result["log"]),
|
self.log_peer(asn, "ignore", "\n".join(result["log"]),
|
||||||
netixlan_info)
|
netixlan_info)
|
||||||
|
@@ -1423,7 +1423,7 @@ class IXLan(pdb_models.IXLanBase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
log = []
|
log = []
|
||||||
changed = False
|
changed = []
|
||||||
created = False
|
created = False
|
||||||
ipv4 = netixlan_info.ipaddr4
|
ipv4 = netixlan_info.ipaddr4
|
||||||
ipv6 = netixlan_info.ipaddr6
|
ipv6 = netixlan_info.ipaddr6
|
||||||
@@ -1509,6 +1509,7 @@ class IXLan(pdb_models.IXLanBase):
|
|||||||
netixlan = NetworkIXLan(ixlan=self, network=netixlan_info.network,
|
netixlan = NetworkIXLan(ixlan=self, network=netixlan_info.network,
|
||||||
status="ok")
|
status="ok")
|
||||||
created = True
|
created = True
|
||||||
|
reason = "New ip-address"
|
||||||
|
|
||||||
# now we sync the data to our determined netixlan instance
|
# now we sync the data to our determined netixlan instance
|
||||||
|
|
||||||
@@ -1530,7 +1531,7 @@ class IXLan(pdb_models.IXLanBase):
|
|||||||
# other.save()
|
# other.save()
|
||||||
|
|
||||||
netixlan.ipaddr4 = ipv4
|
netixlan.ipaddr4 = ipv4
|
||||||
changed = True
|
changed.append("ipaddr4")
|
||||||
|
|
||||||
# IPv6
|
# IPv6
|
||||||
if ipv6 != netixlan.ipaddr6:
|
if ipv6 != netixlan.ipaddr6:
|
||||||
@@ -1549,28 +1550,28 @@ class IXLan(pdb_models.IXLanBase):
|
|||||||
#if save or save_others:
|
#if save or save_others:
|
||||||
# other.save()
|
# other.save()
|
||||||
netixlan.ipaddr6 = ipv6
|
netixlan.ipaddr6 = ipv6
|
||||||
changed = True
|
changed.append("ipaddr6")
|
||||||
|
|
||||||
# Is the netixlan a routeserver ?
|
# Is the netixlan a routeserver ?
|
||||||
if netixlan_info.is_rs_peer != netixlan.is_rs_peer:
|
if netixlan_info.is_rs_peer != netixlan.is_rs_peer:
|
||||||
netixlan.is_rs_peer = netixlan_info.is_rs_peer
|
netixlan.is_rs_peer = netixlan_info.is_rs_peer
|
||||||
changed = True
|
changed.append("is_rs_peer")
|
||||||
|
|
||||||
# Speed
|
# Speed
|
||||||
if netixlan_info.speed != netixlan.speed and \
|
if netixlan_info.speed != netixlan.speed and \
|
||||||
(netixlan_info.speed > 0 or netixlan.speed is None):
|
(netixlan_info.speed > 0 or netixlan.speed is None):
|
||||||
netixlan.speed = netixlan_info.speed
|
netixlan.speed = netixlan_info.speed
|
||||||
changed = True
|
changed.append("speed")
|
||||||
|
|
||||||
# ASN
|
# ASN
|
||||||
if netixlan_info.asn != netixlan.asn:
|
if netixlan_info.asn != netixlan.asn:
|
||||||
netixlan.asn = netixlan_info.asn
|
netixlan.asn = netixlan_info.asn
|
||||||
changed = True
|
changed.append("asn")
|
||||||
|
|
||||||
# Network
|
# Network
|
||||||
if netixlan_info.network.id != netixlan.network.id:
|
if netixlan_info.network.id != netixlan.network.id:
|
||||||
netixlan.network = netixlan_info.network
|
netixlan.network = netixlan_info.network
|
||||||
changed = True
|
changed.append("network_id")
|
||||||
|
|
||||||
# Finally we attempt to validate the data and then save the netixlan instance
|
# Finally we attempt to validate the data and then save the netixlan instance
|
||||||
try:
|
try:
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
"ipaddr6": "2001:7f8:1::a500:2906:2"
|
"ipaddr6": "2001:7f8:1::a500:2906:2"
|
||||||
},
|
},
|
||||||
"action": "add",
|
"action": "add",
|
||||||
"reason": ""
|
"reason": "New ip-address"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"peer": {
|
"peer": {
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
"ipaddr6": "2001:7f8:1::a500:2906:1"
|
"ipaddr6": "2001:7f8:1::a500:2906:1"
|
||||||
},
|
},
|
||||||
"action": "add",
|
"action": "add",
|
||||||
"reason": ""
|
"reason": "New ip-address"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"peer": {
|
"peer": {
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
"ipaddr6": "2001:7f8:1::a500:2906:5"
|
"ipaddr6": "2001:7f8:1::a500:2906:5"
|
||||||
},
|
},
|
||||||
"action": "modify",
|
"action": "modify",
|
||||||
"reason": ""
|
"reason": "Fields changed: ipaddr6, is_rs_peer, speed"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"peer": {
|
"peer": {
|
||||||
|
@@ -213,7 +213,6 @@ class JsonMembersListTestCase(TestCase):
|
|||||||
network.save()
|
network.save()
|
||||||
r, netixlans, netixlans_deleted, log = self.ixf_importer.update(ixlan, data=self.json_data)
|
r, netixlans, netixlans_deleted, log = self.ixf_importer.update(ixlan, data=self.json_data)
|
||||||
|
|
||||||
print(json.dumps(log, indent=2))
|
|
||||||
self.assertLog(log, "skip_disabled_networks")
|
self.assertLog(log, "skip_disabled_networks")
|
||||||
self.assertEqual(len(netixlans), 0)
|
self.assertEqual(len(netixlans), 0)
|
||||||
|
|
||||||
@@ -338,7 +337,6 @@ class JsonMembersListTestCase(TestCase):
|
|||||||
resp = c.get("/export/ixlan/{}/ixp-member-list".format(ixlan.id))
|
resp = c.get("/export/ixlan/{}/ixp-member-list".format(ixlan.id))
|
||||||
self.assertEqual(resp.status_code, 200)
|
self.assertEqual(resp.status_code, 200)
|
||||||
data = json.loads(resp.content)
|
data = json.loads(resp.content)
|
||||||
print(json.dumps(data, indent=2))
|
|
||||||
with open(
|
with open(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
os.path.dirname(__file__), "data", "json_members_list",
|
os.path.dirname(__file__), "data", "json_members_list",
|
||||||
@@ -433,7 +431,18 @@ class TestImportPreview(ClientCase):
|
|||||||
super(TestImportPreview, cls).setUpTestData()
|
super(TestImportPreview, cls).setUpTestData()
|
||||||
cls.org = Organization.objects.create(name="Test Org", status="ok")
|
cls.org = Organization.objects.create(name="Test Org", status="ok")
|
||||||
cls.ix = InternetExchange.objects.create(name="Test IX", status="ok", org=cls.org)
|
cls.ix = InternetExchange.objects.create(name="Test IX", status="ok", org=cls.org)
|
||||||
|
|
||||||
cls.ixlan = IXLan.objects.create(status="ok", ix=cls.ix)
|
cls.ixlan = IXLan.objects.create(status="ok", ix=cls.ix)
|
||||||
|
IXLanPrefix.objects.create(ixlan=cls.ixlan, status="ok",
|
||||||
|
prefix="195.69.144.0/22", protocol="IPv4")
|
||||||
|
IXLanPrefix.objects.create(ixlan=cls.ixlan, status="ok",
|
||||||
|
prefix="2001:7f8:1::/64", protocol="IPv6")
|
||||||
|
|
||||||
|
cls.net = Network.objects.create(org=cls.org, status="ok",
|
||||||
|
asn=1000, name="net01")
|
||||||
|
cls.net_2 = Network.objects.create(org=cls.org, status="ok",
|
||||||
|
asn=1001, name="net02")
|
||||||
|
|
||||||
cls.admin_user = User.objects.create_user("admin","admin@localhost","admin")
|
cls.admin_user = User.objects.create_user("admin","admin@localhost","admin")
|
||||||
|
|
||||||
cls.org.admin_usergroup.user_set.add(cls.admin_user)
|
cls.org.admin_usergroup.user_set.add(cls.admin_user)
|
||||||
@@ -468,5 +477,44 @@ class TestImportPreview(ClientCase):
|
|||||||
assert response.status_code == 403
|
assert response.status_code == 403
|
||||||
|
|
||||||
|
|
||||||
|
def test_netixlan_diff(self):
|
||||||
|
netix1 = NetworkIXLan.objects.create(
|
||||||
|
network=self.net,
|
||||||
|
ixlan=self.ixlan,
|
||||||
|
status="ok",
|
||||||
|
ipaddr4="195.69.146.250",
|
||||||
|
ipaddr6="2001:7f8:1::a500:2906:1",
|
||||||
|
asn=self.net.asn,
|
||||||
|
speed=1000,
|
||||||
|
is_rs_peer=True)
|
||||||
|
|
||||||
|
netix2 = NetworkIXLan(
|
||||||
|
network=self.net_2,
|
||||||
|
status="ok",
|
||||||
|
ipaddr4="195.69.146.250",
|
||||||
|
ipaddr6="2001:7f8:1::a500:2906:2",
|
||||||
|
asn=self.net_2.asn,
|
||||||
|
speed=10000,
|
||||||
|
is_rs_peer=False)
|
||||||
|
|
||||||
|
result = self.ixlan.add_netixlan(netix2, save=False,
|
||||||
|
save_others=False)
|
||||||
|
|
||||||
|
self.assertEqual(sorted(result["changed"]), ['asn', 'ipaddr6',
|
||||||
|
'is_rs_peer', 'network_id', 'speed'])
|
||||||
|
|
||||||
|
|
||||||
|
netix2.ipaddr4 = "195.69.146.251"
|
||||||
|
netix2.ipaddr6 = netix1.ipaddr6
|
||||||
|
|
||||||
|
result = self.ixlan.add_netixlan(netix2, save=False,
|
||||||
|
save_others=False)
|
||||||
|
|
||||||
|
self.assertEqual(sorted(result["changed"]), ['asn', 'ipaddr4',
|
||||||
|
'is_rs_peer', 'network_id', 'speed'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user