Esempio n. 1
0
    def test1_create_ipv4_interface_network_str(self):
        v, _ = Vlan.objects.get_or_create(name="12db", number=3)
        s, _ = Site.objects.get_or_create(name="12scl3")
        d, _ = Domain.objects.get_or_create(name="12scl3.mozilla.com")
        d, _ = Domain.objects.get_or_create(name="12db.12scl3.mozilla.com")

        d, _ = Domain.objects.get_or_create(name="arpa")
        d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
        d, _ = Domain.objects.get_or_create(name="12.in-addr.arpa")
        n = Network(network_str="12.0.0.0/24", ip_type="4")
        n.clean()
        n.site = s
        n.vlan = v
        n.save()

        n1 = Network(network_str="12.0.1.0/24", ip_type="4")
        n1.clean()
        n1.site = s
        n1.vlan = v
        n1.save()

        r = Range(start_str="12.0.0.0",
                  end_str="12.0.0.2",
                  network=n,
                  ip_type='4')
        r.clean()
        r.save()

        r1 = Range(start_str="12.0.1.0",
                   end_str="12.0.1.2",
                   network=n1,
                   ip_type='4')
        r1.clean()
        r1.save()

        intr, errors = create_ipv4_interface("foo", "12db", "12scl3",
                                             self.system, "11:22:33:4e:55:66",
                                             "mozilla.com")
        self.assertTrue('network' in errors)
        self.assertTrue(
            errors['network'][0].find("too many networks associated") != -1)
        # Look for a non-existant network
        intr, errors = create_ipv4_interface("foo",
                                             "12db",
                                             "12scl3",
                                             self.system,
                                             "11:22:33:4e:55:66",
                                             "mozilla.com",
                                             network_str="12.0.99.0/24")
        self.assertTrue('network' in errors)
        intr, errors = create_ipv4_interface("foo",
                                             "12db",
                                             "12scl3",
                                             self.system,
                                             "11:22:33:4e:55:66",
                                             "mozilla.com",
                                             network_str="12.0.0.0/24")
        self.assertFalse(errors)
        self.assertTrue(isinstance(intr, StaticInterface))
Esempio n. 2
0
    def test2_create_ipv4_interface_from_domain(self):

        v, _ = Vlan.objects.get_or_create(name="private", number=3)
        s, _ = Site.objects.get_or_create(name="phx1")
        s1, _ = Site.objects.get_or_create(name="corp", parent=s)
        d, _ = Domain.objects.get_or_create(name="phx1.mozilla.com")
        d1, _ = Domain.objects.get_or_create(name="corp.phx1.mozilla.com")
        d2, _ = Domain.objects.get_or_create(
            name="private.corp.phx1.mozilla.com")

        d, _ = Domain.objects.get_or_create(name="arpa")
        d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
        d, _ = Domain.objects.get_or_create(name="14.in-addr.arpa")
        n = Network(network_str="14.0.0.0/8", ip_type="4")
        n.clean()
        n.site = s1
        n.vlan = v
        n.save()

        r = Range(start_str="14.0.0.0",
                  end_str="14.0.0.2",
                  network=n,
                  ip_type='4')
        r.clean()
        r.save()

        intr, errors = create_ipv4_intr_from_domain("foo", "private.corp.phx1",
                                                    self.system,
                                                    "11:22:33:44:55:66")
        self.assertEqual(errors, None)
        self.assertTrue(isinstance(intr, StaticInterface))
Esempio n. 3
0
    def test_bad_delete(self):
        network = "129.0.0.0"
        prefixlen = "24"
        kwargs = {'network': network, 'prefixlen': prefixlen, 'ip_type': '4'}
        s = self.do_basic_add(**kwargs)
        s_pk = s.pk
        self.assertTrue(s)

        d = Domain(name="asdf")
        d.save()

        start_str = "129.0.0.1"
        end_str = "129.0.0.255"
        network = s

        r = Range(start_str=start_str,
                  end_str=end_str,
                  network=network,
                  ip_type='4')
        r.clean()
        r.save()

        self.assertEqual(r.network, s)
        self.assertTrue(len(s.range_set.all()) == 1)

        self.assertRaises(ValidationError, s.delete)
        self.assertTrue(Network.objects.get(pk=s_pk))

        r.delete()
        s.delete()
        self.assertEqual(len(Network.objects.filter(pk=s_pk)), 0)
Esempio n. 4
0
    def test8_create_ipv4_interface(self):
        v, _ = Vlan.objects.get_or_create(name="8db", number=3)
        s, _ = Site.objects.get_or_create(name="8scl3")
        s1, _ = Site.objects.get_or_create(name="8dmz", parent=s)
        d, _ = Domain.objects.get_or_create(name="8scl3.mozilla.com")
        d, _ = Domain.objects.get_or_create(name="8dmz.8scl3.mozilla.com")
        d, _ = Domain.objects.get_or_create(name="8db.8dmz.8scl3.mozilla.com")

        d, _ = Domain.objects.get_or_create(name="arpa")
        d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
        d, _ = Domain.objects.get_or_create(name="15.in-addr.arpa")
        n = Network(network_str="15.0.0.0/8", ip_type="4")
        n.clean()
        n.site = s1
        n.vlan = v
        n.save()

        r = Range(start_str="15.0.0.0",
                  end_str="15.0.0.2",
                  network=n,
                  ip_type='4')
        r.clean()
        r.save()

        intr, errors = create_ipv4_interface(label="foo",
                                             vlan_str="8db",
                                             site_str="8dmz.8scl3",
                                             system=self.system,
                                             mac="11:22:33:44:55:66",
                                             domain_suffix="mozilla.com")
        self.assertEqual(errors, None)
        self.assertTrue(isinstance(intr, StaticInterface))
Esempio n. 5
0
    def setUp(self):
        self.system = System()
        self.system.save()
        d1 = create_fake_zone("oregonstate.com", suffix="")
        soa = d1.soa
        self.soa = soa

        v, _ = Vlan.objects.get_or_create(name="private", number=3)
        s, _ = Site.objects.get_or_create(name="phx1")
        s1, _ = Site.objects.get_or_create(name="corp", parent=s)
        d, _ = Domain.objects.get_or_create(name="phx1.oregonstate.com")
        d.soa = soa
        d.save()
        d1, _ = Domain.objects.get_or_create(name="corp.phx1.oregonstate.com")
        d1.soa = soa
        d1.save()
        d2, _ = Domain.objects.get_or_create(
            name="private.corp.phx1.oregonstate.com")
        d2.soa = soa
        d2.save()

        d, _ = Domain.objects.get_or_create(name="arpa")
        d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
        d, _ = Domain.objects.get_or_create(name="15.in-addr.arpa")
        n = Network(network_str="15.0.0.0/8", ip_type="4")
        n.clean()
        n.site = s1
        n.vlan = v
        n.save()

        r = Range(start_str="15.0.0.0", end_str="15.0.0.10",
                  network=n, ip_type='4')
        r.clean()
        r.save()
Esempio n. 6
0
    def test_bad_resize(self):
        network = "129.0.0.0"
        prefixlen = "24"
        kwargs = {'network': network, 'prefixlen': prefixlen, 'ip_type': '4'}
        s = self.do_basic_add(**kwargs)
        self.assertTrue(s)

        d = Domain(name="asdf")
        d.save()

        start_str = "129.0.0.1"
        end_str = "129.0.0.255"
        network = s

        r = Range(start_str=start_str,
                  end_str=end_str,
                  network=network,
                  ip_type='4')
        r.save()

        self.assertEqual(r.network, s)
        self.assertTrue(len(s.range_set.all()) == 1)

        s.network_str = "129.0.0.0/25"
        self.assertRaises(ValidationError, s.clean)
Esempio n. 7
0
    def test6_create_ipv4_interface(self):
        v, _ = Vlan.objects.get_or_create(name="6db", number=3)
        s, _ = Site.objects.get_or_create(name="6scl3")
        d, _ = Domain.objects.get_or_create(name="6scl3.mozilla.com")
        d, _ = Domain.objects.get_or_create(name="6db.6scl3.mozilla.com")
        d, _ = Domain.objects.get_or_create(name="arpa")
        d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
        d, _ = Domain.objects.get_or_create(name="11.in-addr.arpa")
        n = Network(network_str="11.0.0.0/8", ip_type="4")
        n.clean()
        n.site = s
        n.vlan = v
        n.save()

        r = Range(start_str="11.0.0.0",
                  end_str="11.0.0.2",
                  network=n,
                  ip_type='4')
        r.clean()
        r.save()

        s = StaticInterface(label="fab",
                            domain=d,
                            ip_type="4",
                            ip_str="11.0.0.0",
                            system=self.system,
                            mac="00:00:00:00:00:00")
        s.clean()
        s.save()

        s = StaticInterface(label="fab",
                            domain=d,
                            ip_type="4",
                            ip_str="11.0.0.1",
                            system=self.system,
                            mac="00:00:00:00:00:00")
        s.clean()
        s.save()

        s = StaticInterface(label="fab",
                            domain=d,
                            ip_type="4",
                            ip_str="11.0.0.2",
                            system=self.system,
                            mac="00:00:00:00:00:00")
        s.clean()
        s.save()

        intr, errors = create_ipv4_interface("foo", "6db", "6scl3",
                                             self.system, "11:22:33:44:55:66",
                                             "mozilla.com")
        self.assertEqual(intr, None)
        self.assertTrue("vlan" not in errors)
        self.assertTrue("site" not in errors)
        self.assertTrue("domain" not in errors)
        self.assertTrue("network" not in errors)
        self.assertTrue("range" not in errors)
        self.assertTrue("ip" in errors)
Esempio n. 8
0
 def do_add(self, start_str, end_str, default_domain, \
                                 network, rtype, ip_type):
     r = Range(start_str=start_str,
               end_str=end_str,
               network=network,
               ip_type=ip_type)
     r.__repr__()
     r.save()
     return r
Esempio n. 9
0
    def test_check_valid_ranges_v4_valid(self):
        n = Network(network_str='10.0.0.0/8')
        n.full_clean()
        n.save()

        r = Range(ip_type='4', start_str='10.4.0.2', end_str='10.4.255.254',
                  network=n)
        r.full_clean()
        r.save()

        n.network_str = '10.4.0.0/16'
        n.full_clean()
        n.save()
Esempio n. 10
0
    def test_check_valid_ranges_v4_start_low(self):
        n = Network(network_str='10.0.0.0/8')
        n.full_clean()
        n.save()

        r = Range(ip_type='4', start_str='10.3.0.2', end_str='10.4.255.254',
                  network=n)
        r.full_clean()
        r.save()

        n.network_str = '10.4.0.0/16'
        with self.assertRaises(ValidationError):
            n.full_clean()
            n.save()
Esempio n. 11
0
    def setUp(self):
        self.system = System()
        Domain.objects.get_or_create(name="com")
        d1, _ = Domain.objects.get_or_create(name="mozilla.com")
        soa, _ = SOA.objects.get_or_create(primary="fo.bar",
                                           contact="foo.bar.com",
                                           comment="foo bar")
        self.s = soa
        d1.soa = soa
        d1.save()

        v, _ = Vlan.objects.get_or_create(name="private", number=3)
        s, _ = Site.objects.get_or_create(name="phx1")
        s1, _ = Site.objects.get_or_create(name="corp", parent=s)
        d, _ = Domain.objects.get_or_create(name="phx1.mozilla.com")
        d.soa = soa
        d.save()
        d1, _ = Domain.objects.get_or_create(name="corp.phx1.mozilla.com")
        d1.soa = soa
        d1.save()
        d2, _ = Domain.objects.get_or_create(
            name="private.corp.phx1.mozilla.com")
        d2.soa = soa
        d2.save()

        d, _ = Domain.objects.get_or_create(name="arpa")
        d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
        d, _ = Domain.objects.get_or_create(name="ipv6.arpa")
        d, _ = Domain.objects.get_or_create(name="15.in-addr.arpa")
        d, _ = Domain.objects.get_or_create(name="2.in-addr.arpa")
        n = Network(network_str="15.0.0.0/8", ip_type="4")
        n.clean()
        n.site = s1
        n.vlan = v
        n.save()

        r = Range(start_str="15.0.0.0", end_str="15.0.0.10", network=n)
        r.clean()
        r.save()
Esempio n. 12
0
    def test7_create_ipv4_interface(self):
        v, _ = Vlan.objects.get_or_create(name="7db", number=3)
        s, _ = Site.objects.get_or_create(name="7scl3")
        d, _ = Domain.objects.get_or_create(name="7scl3.mozilla.com")
        d, _ = Domain.objects.get_or_create(name="7db.7scl3.mozilla.com")

        d, _ = Domain.objects.get_or_create(name="arpa")
        d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
        d, _ = Domain.objects.get_or_create(name="12.in-addr.arpa")
        n = Network(network_str="12.0.0.0/8", ip_type="4")
        n.clean()
        n.site = s
        n.vlan = v
        n.save()

        r = Range(start_str="12.0.0.0", end_str="12.0.0.2", network=n)
        r.clean()
        r.save()

        intr, errors = create_ipv4_interface("foo", "7db", "7scl3",
                                             self.system, "11:22:33:44:55:66",
                                             "mozilla.com")
        self.assertEqual(errors, None)
        self.assertTrue(isinstance(intr, StaticInterface))