Esempio n. 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)
Esempio n. 2
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"]))
Esempio n. 3
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())
Esempio n. 4
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)