diff --git a/peeringdb_server/ixf.py b/peeringdb_server/ixf.py index 561b50d8..be9efab0 100644 --- a/peeringdb_server/ixf.py +++ b/peeringdb_server/ixf.py @@ -378,12 +378,15 @@ class Importer(object): self.netixlans.append(result["netixlan"]) if result["created"]: action = "add" + reason = _("New ip-address") else: 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"]: - self.log_peer(asn, "noop", "", result["netixlan"]) + self.log_peer(asn, "noop", _("No changes"), result["netixlan"]) elif result["log"]: self.log_peer(asn, "ignore", "\n".join(result["log"]), netixlan_info) diff --git a/peeringdb_server/models.py b/peeringdb_server/models.py index d7a78d87..a2ad73f1 100644 --- a/peeringdb_server/models.py +++ b/peeringdb_server/models.py @@ -1423,7 +1423,7 @@ class IXLan(pdb_models.IXLanBase): """ log = [] - changed = False + changed = [] created = False ipv4 = netixlan_info.ipaddr4 ipv6 = netixlan_info.ipaddr6 @@ -1509,6 +1509,7 @@ class IXLan(pdb_models.IXLanBase): netixlan = NetworkIXLan(ixlan=self, network=netixlan_info.network, status="ok") created = True + reason = "New ip-address" # now we sync the data to our determined netixlan instance @@ -1530,7 +1531,7 @@ class IXLan(pdb_models.IXLanBase): # other.save() netixlan.ipaddr4 = ipv4 - changed = True + changed.append("ipaddr4") # IPv6 if ipv6 != netixlan.ipaddr6: @@ -1549,28 +1550,28 @@ class IXLan(pdb_models.IXLanBase): #if save or save_others: # other.save() netixlan.ipaddr6 = ipv6 - changed = True + changed.append("ipaddr6") # Is the netixlan a routeserver ? if netixlan_info.is_rs_peer != netixlan.is_rs_peer: netixlan.is_rs_peer = netixlan_info.is_rs_peer - changed = True + changed.append("is_rs_peer") # Speed if netixlan_info.speed != netixlan.speed and \ (netixlan_info.speed > 0 or netixlan.speed is None): netixlan.speed = netixlan_info.speed - changed = True + changed.append("speed") # ASN if netixlan_info.asn != netixlan.asn: netixlan.asn = netixlan_info.asn - changed = True + changed.append("asn") # Network if netixlan_info.network.id != netixlan.network.id: netixlan.network = netixlan_info.network - changed = True + changed.append("network_id") # Finally we attempt to validate the data and then save the netixlan instance try: diff --git a/tests/data/ixf/logs/update_01.json b/tests/data/ixf/logs/update_01.json index 9a5f7e46..2b38d23f 100644 --- a/tests/data/ixf/logs/update_01.json +++ b/tests/data/ixf/logs/update_01.json @@ -24,7 +24,7 @@ "ipaddr6": "2001:7f8:1::a500:2906:2" }, "action": "add", - "reason": "" + "reason": "New ip-address" }, { "peer": { @@ -37,7 +37,7 @@ "ipaddr6": "2001:7f8:1::a500:2906:1" }, "action": "add", - "reason": "" + "reason": "New ip-address" }, { "peer": { @@ -50,7 +50,7 @@ "ipaddr6": "2001:7f8:1::a500:2906:5" }, "action": "modify", - "reason": "" + "reason": "Fields changed: ipaddr6, is_rs_peer, speed" }, { "peer": { diff --git a/tests/test_ixf_member_import.py b/tests/test_ixf_member_import.py index a80ed6fd..e0c30dfc 100644 --- a/tests/test_ixf_member_import.py +++ b/tests/test_ixf_member_import.py @@ -213,7 +213,6 @@ class JsonMembersListTestCase(TestCase): network.save() 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.assertEqual(len(netixlans), 0) @@ -338,7 +337,6 @@ class JsonMembersListTestCase(TestCase): resp = c.get("/export/ixlan/{}/ixp-member-list".format(ixlan.id)) self.assertEqual(resp.status_code, 200) data = json.loads(resp.content) - print(json.dumps(data, indent=2)) with open( os.path.join( os.path.dirname(__file__), "data", "json_members_list", @@ -433,7 +431,18 @@ class TestImportPreview(ClientCase): super(TestImportPreview, cls).setUpTestData() cls.org = Organization.objects.create(name="Test Org", status="ok") cls.ix = InternetExchange.objects.create(name="Test IX", status="ok", org=cls.org) + 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.org.admin_usergroup.user_set.add(cls.admin_user) @@ -468,5 +477,44 @@ class TestImportPreview(ClientCase): 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']) + + + +