Example #1
0
    def test_create_from_peeringdb(self, *_):
        asn = 65536

        # Illegal ASN
        self.assertIsNone(AutonomousSystem.create_from_peeringdb(64500))

        # Create the AS
        a_s = AutonomousSystem.create_from_peeringdb(asn)
        self.assertIsNotNone(a_s)
        self.assertEqual(asn, a_s.asn)

        exists = True
        try:
            AutonomousSystem.objects.get(asn=asn)
        except AutonomousSystem.DoesNotExist:
            exists = False
        self.assertTrue(exists)

        # Trying to re-create the AS should just return it
        a_s = AutonomousSystem.create_from_peeringdb(asn)
        self.assertIsNotNone(a_s)
        self.assertEqual(asn, a_s.asn)

        exists = True
        try:
            AutonomousSystem.objects.get(asn=asn)
        except (
                AutonomousSystem.DoesNotExist,
                AutonomousSystem.MultipleObjectsReturned,
        ):
            exists = False
        self.assertTrue(exists)
    def setUpTestData(cls):
        AutonomousSystem.objects.bulk_create([
            AutonomousSystem(asn=64501, name="Autonomous System 1"),
            AutonomousSystem(asn=64502, name="Autonomous System 2"),
            AutonomousSystem(asn=64503, name="Autonomous System 3"),
        ])

        cls.form_data = {
            "asn": 64504,
            "name": "Autonomous System 4",
            "name_peeringdb_sync": False,
            "contact_email": "",
            "contact_name": "",
            "contact_phone": "",
            "export_routing_policies": [],
            "import_routing_policies": [],
            "ipv4_max_prefixes": 0,
            "ipv4_max_prefixes_peeringdb_sync": False,
            "ipv6_max_prefixes": 0,
            "ipv6_max_prefixes_peeringdb_sync": False,
            "irr_as_set": None,
            "irr_as_set_peeringdb_sync": False,
            "potential_internet_exchange_peering_sessions": [],
            "comments": "",
            "tags": "",
        }
 def setUpTestData(cls):
     AutonomousSystem.objects.bulk_create([
         AutonomousSystem(
             asn=64501,
             name="Autonomous System 1",
             irr_as_set="AS-SET-1",
             ipv6_max_prefixes=1,
             ipv4_max_prefixes=0,
             affiliated=True,
         ),
         AutonomousSystem(
             asn=64502,
             name="Autonomous System 2",
             irr_as_set="AS-SET-2",
             ipv6_max_prefixes=0,
             ipv4_max_prefixes=1,
         ),
         AutonomousSystem(
             asn=64503,
             name="Autonomous System 3",
             irr_as_set="AS-SET-3",
             ipv6_max_prefixes=0,
             ipv4_max_prefixes=0,
         ),
     ])
Example #4
0
    def test_enqueue_webhook_bulk_delete(self):
        asns = (
            AutonomousSystem(asn=64500, name="AS 1"),
            AutonomousSystem(asn=64501, name="AS 2"),
            AutonomousSystem(asn=64502, name="AS 3"),
        )
        AutonomousSystem.objects.bulk_create(asns)
        for asn in asns:
            asn.tags.set(Tag.objects.filter(name__in=["Foo", "Bar"]))

        # Delete three objects via the REST API
        data = [{"id": asn.pk} for asn in asns]
        url = reverse("peering-api:autonomoussystem-list")
        response = self.client.delete(url, data, format="json", **self.header)
        self.assertHttpStatus(response, status.HTTP_204_NO_CONTENT)

        # Verify that a job was queued for the object update webhook
        self.assertEqual(self.queue.count, 3)
        for i, job in enumerate(self.queue.jobs):
            self.assertEqual(
                job.kwargs["webhook"], Webhook.objects.get(type_delete=True)
            )
            self.assertEqual(job.kwargs["event"], ObjectChangeAction.DELETE)
            self.assertEqual(job.kwargs["model_name"], "autonomoussystem")
            self.assertEqual(job.kwargs["data"]["id"], asns[i].pk)
            self.assertEqual(job.kwargs["snapshots"]["prechange"]["name"], asns[i].name)
            self.assertEqual(
                sorted(job.kwargs["snapshots"]["prechange"]["tags"]), ["Bar", "Foo"]
            )
Example #5
0
    def test_does_exist(self):
        asn = 201281

        # AS should not exist
        autonomous_system = AutonomousSystem.does_exist(asn)
        self.assertEqual(None, autonomous_system)

        # Create the AS
        new_as = AutonomousSystem.objects.create(asn=asn, name="Guillaume Mazoyer")

        # AS must exist
        autonomous_system = AutonomousSystem.does_exist(asn)
        self.assertEqual(asn, new_as.asn)
Example #6
0
    def test_does_exist(self):
        asn = 29467

        # AS should not exist
        autonomous_system = AutonomousSystem.does_exist(asn)
        self.assertEqual(None, autonomous_system)

        # Create the AS
        new_as = AutonomousSystem.objects.create(asn=asn, name="LuxNetwork S.A.")

        # AS must exist
        autonomous_system = AutonomousSystem.does_exist(asn)
        self.assertEqual(asn, new_as.asn)
 def setUpTestData(cls):
     AutonomousSystem.objects.bulk_create([
         AutonomousSystem(asn=65536,
                          name="Example 1",
                          irr_as_set="AS-MOCKED"),
         AutonomousSystem(asn=64496,
                          name="Example 2",
                          irr_as_set="AS-EXAMPLE-2"),
         AutonomousSystem(asn=64497,
                          name="Example 3",
                          irr_as_set="AS-EXAMPLE-3"),
     ])
     cls.autonomous_system = AutonomousSystem.objects.get(asn=65536)
     load_peeringdb_data()
Example #8
0
 def test_get_irr_as_set_prefixes(self):
     autonomous_system = AutonomousSystem.create_from_peeringdb(201281)
     prefixes = autonomous_system.get_irr_as_set_prefixes()
     self.assertEqual(autonomous_system.ipv6_max_prefixes,
                      len(prefixes["ipv6"]))
     self.assertEqual(autonomous_system.ipv4_max_prefixes,
                      len(prefixes["ipv4"]))
Example #9
0
    def test_synchronize_with_peeringdb(self, *_):
        # Create legal AS to sync with PeeringDB
        asn = 65536
        a_s = AutonomousSystem.create_from_peeringdb(asn)
        self.assertEqual(asn, a_s.asn)
        self.assertTrue(a_s.synchronize_with_peeringdb())

        # Create illegal AS to fail sync with PeeringDB
        asn = 64500
        a_s = AutonomousSystem.objects.create(asn=asn, name="Test")
        self.assertEqual(asn, a_s.asn)
        self.assertFalse(a_s.synchronize_with_peeringdb())
    def setUpTestData(cls):
        AutonomousSystem.objects.bulk_create([
            AutonomousSystem(asn=64501, name="Autonomous System 1"),
            AutonomousSystem(asn=64502, name="Autonomous System 2"),
            AutonomousSystem(asn=64503, name="Autonomous System 3"),
        ])

        cls.form_data = {
            "asn": 64504,
            "name": "Autonomous System 4",
            "name_peeringdb_sync": False,
            "export_routing_policies": [],
            "import_routing_policies": [],
            "ipv4_max_prefixes": 0,
            "ipv4_max_prefixes_peeringdb_sync": False,
            "ipv6_max_prefixes": 0,
            "ipv6_max_prefixes_peeringdb_sync": False,
            "irr_as_set": None,
            "irr_as_set_peeringdb_sync": False,
            "comments": "",
            "affiliated": False,
            "tags": [],
        }
Example #11
0
    def test_create_from_peeringdb(self):
        asn = 201281

        # Illegal ASN
        self.assertIsNone(AutonomousSystem.create_from_peeringdb(64500))

        # Must not exist at first
        self.assertIsNone(AutonomousSystem.does_exist(asn))

        # Create the AS
        autonomous_system1 = AutonomousSystem.create_from_peeringdb(asn)
        self.assertEqual(asn, autonomous_system1.asn)

        # Must exist now
        self.assertEqual(asn, AutonomousSystem.does_exist(asn).asn)

        # Must not rise error, just return the AS
        autonomous_system2 = AutonomousSystem.create_from_peeringdb(asn)
        self.assertEqual(asn, autonomous_system2.asn)

        # Must exist now also
        self.assertEqual(asn, AutonomousSystem.does_exist(asn).asn)