Ejemplo n.º 1
0
 def do_basic_add(self, network, prefixlen, ip_type, name=None,
                  number=None):
     s = Network(network_str=network + "/" + prefixlen, ip_type=ip_type)
     s.clean()
     s.save()
     self.assertTrue(s)
     return s
Ejemplo n.º 2
0
    def setUp(self):
        self.d, _ = Domain.objects.get_or_create(name="com")
        Domain.objects.get_or_create(name="arpa")
        Domain.objects.get_or_create(name="in-addr.arpa")
        Domain.objects.get_or_create(name="10.in-addr.arpa")
        self.s = Network(network_str="10.0.0.0/16", ip_type='4')
        self.s.update_network()
        self.s.save()

        self.s1 = Network(network_str="10.2.1.0/24", ip_type='4')
        self.s1.update_network()
        self.s1.save()
    def setUp(self):
        self.d, _ = Domain.objects.get_or_create(name="com")
        Domain.objects.get_or_create(name="arpa")
        Domain.objects.get_or_create(name="in-addr.arpa")
        Domain.objects.get_or_create(name="10.in-addr.arpa")
        self.s = Network(network_str="10.0.0.0/16", ip_type='4')
        self.s.update_network()
        self.s.save()

        self.s1 = Network(network_str="10.2.1.0/24", ip_type='4')
        self.s1.update_network()
        self.s1.save()
Ejemplo n.º 4
0
    def setUp(self):
        self.d = Domain(name="com")
        self.d.save()
        Domain(name="arpa").save()
        Domain(name="in-addr.arpa").save()
        Domain(name="10.in-addr.arpa").save()
        self.s = Network(network_str="10.0.0.0/16", ip_type='4')
        self.s.update_network()
        self.s.save()

        self.s1 = Network(network_str="10.2.1.0/24", ip_type='4')
        self.s1.update_network()
        self.s1.save()
Ejemplo n.º 5
0
    def setUp(self):
        self.d = Domain(name="com")
        self.s = Network(network_str="1234:1234:1234::/16", ip_type='6')
        self.s.update_network()
        self.s.save()

        self.s1 = Network(network_str="1234:1134:1234::/32", ip_type='6')
        self.s1.update_network()
        self.s1.save()

        self.s2 = Network(network_str="fff::/4", ip_type='6')
        self.s2.update_network()
        self.s2.save()

        self.s3 = Network(network_str="ffff::/4", ip_type='6')
        self.s3.update_network()
        self.s3.save()
    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)
        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))
    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)
        r.clean()
        r.save()

        intr, errors = create_ipv4_interface(
            "foo", "8db", "8dmz.8scl3", self.system,
            "11:22:33:44:55:66", "mozilla.com")
        self.assertEqual(errors, None)
        self.assertTrue(isinstance(intr, StaticInterface))
Ejemplo n.º 8
0
    def setUp(self):
        self.system = System()
        d1 = create_fake_zone("mozilla.com.com", suffix="")
        soa = d1.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.mozilla.com.com")
        d.soa = soa
        d.save()
        d1, _ = Domain.objects.get_or_create(name="corp.phx1.mozilla.com.com")
        d1.soa = soa
        d1.save()
        d2, _ = Domain.objects.get_or_create(
            name="private.corp.phx1.mozilla.com.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="ip6.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()
Ejemplo n.º 9
0
    def setUp(self):
        self.d = Domain(name="com")
        self.s = Network(network_str="1234:1234:1234::/16", ip_type='6')
        self.s.update_network()
        self.s.save()

        self.s1 = Network(network_str="1234:1134:1234::/32", ip_type='6')
        self.s1.update_network()
        self.s1.save()

        self.s2 = Network(network_str="fff::/4", ip_type='6')
        self.s2.update_network()
        self.s2.save()

        self.s3 = Network(network_str="ffff::/4", ip_type='6')
        self.s3.update_network()
        self.s3.save()
Ejemplo n.º 10
0
 def do_basic_add(self,
                  network,
                  prefixlen,
                  ip_type,
                  name=None,
                  number=None):
     s = Network(network_str=network + "/" + prefixlen, ip_type=ip_type)
     s.clean()
     s.save()
     self.assertTrue(s)
     return s
    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)
        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)
 def test5_create_ipv4_interface(self):
     v, _ = Vlan.objects.get_or_create(name="5db", number=3)
     s, _ = Site.objects.get_or_create(name="5scl3")
     d, _ = Domain.objects.get_or_create(name="5scl3.mozilla.com")
     d, _ = Domain.objects.get_or_create(name="5db.5scl3.mozilla.com")
     n = Network(network_str="10.0.0.0/8", ip_type="4")
     n.clean()
     n.site = s
     n.vlan = v
     n.save()
     intr, errors = create_ipv4_interface(
         "foo", "5db", "5scl3", 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" in errors)
class V4RangeTests(TestCase):
    def setUp(self):
        self.d, _ = Domain.objects.get_or_create(name="com")
        Domain.objects.get_or_create(name="arpa")
        Domain.objects.get_or_create(name="in-addr.arpa")
        Domain.objects.get_or_create(name="10.in-addr.arpa")
        self.s = Network(network_str="10.0.0.0/16", ip_type='4')
        self.s.update_network()
        self.s.save()

        self.s1 = Network(network_str="10.2.1.0/24", ip_type='4')
        self.s1.update_network()
        self.s1.save()

    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)
        r.__repr__()
        r.save()
        return r

    def test1_create(self):
        start_str = "10.0.0.1"
        end_str = "10.0.0.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

    def test2_create(self):
        start_str = "10.0.1.1"
        end_str = "10.0.1.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

    def test2_bad_create(self):
        # start > end
        start_str = "10.0.0.2"
        end_str = "10.0.0.1"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test3_bad_create(self):
        # outside of network
        start_str = "11.0.0.2"
        end_str = "10.0.0.88"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test4_bad_create(self):
        # outside of network
        start_str = "10.2.0.0"
        end_str = "10.2.1.88"
        default_domain = self.d
        network = self.s1
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test5_bad_create(self):
        # duplicate
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test6_bad_create(self):
        # Partial overlap
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }

        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.30"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }

        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test7_bad_create(self):
        # Partial overlap
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.56"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test8_bad_create(self):
        # Full overlap
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.2"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test9_bad_create(self):
        # Full overlap
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.2"
        end_str = "10.0.4.54"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test10_bad_create(self):
        # Duplicate add
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        start_str = "10.0.5.2"
        end_str = "10.0.5.56"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }

        self.do_add(**kwargs)
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test11_bad_create(self):
        # More overlap tests
        start_str = "10.0.4.5"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.60"
        end_str = "10.0.4.63"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.4"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.2"
        end_str = "10.0.4.54"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test12_bad_create(self):
        # Update range to something outside of the subnet.
        start_str = "10.0.4.5"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.60"
        end_str = "10.0.4.63"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.4"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        r = self.do_add(**kwargs)
        r.end_str = "160.0.4.60"

        self.assertRaises(ValidationError, r.clean)

    def test13_bad_create(self):
        start_str = "10.0.4.5"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test1_freeip(self):
        start_str = "10.0.33.1"
        end_str = "10.0.33.3"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'
        system = create_fake_host(hostname="fooasdf.mozilla.com")

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        r = self.do_add(**kwargs)
        self.assertEqual(str(r.get_next_ip()), "10.0.33.1")
        self.assertEqual(str(r.get_next_ip()), "10.0.33.1")
        StaticReg.objects.create(label="foobar",
                                 domain=self.d,
                                 ip_type='4',
                                 ip_str=str(r.get_next_ip()),
                                 system=system)
        self.assertEqual(str(r.get_next_ip()), "10.0.33.2")
        StaticReg.objects.create(label="foobar",
                                 domain=self.d,
                                 ip_type='4',
                                 ip_str=str(r.get_next_ip()),
                                 system=system)
        self.assertEqual(str(r.get_next_ip()), "10.0.33.3")
        StaticReg.objects.create(label="foobar",
                                 domain=self.d,
                                 ip_type='4',
                                 ip_str=str(r.get_next_ip()),
                                 system=system)
        self.assertEqual(r.get_next_ip(), None)
Ejemplo n.º 14
0
class V4RangeTests(TestCase):

    def setUp(self):
        self.d = Domain(name="com")
        self.d.save()
        Domain(name="arpa").save()
        Domain(name="in-addr.arpa").save()
        Domain(name="10.in-addr.arpa").save()
        self.s = Network(network_str="10.0.0.0/16", ip_type='4')
        self.s.update_network()
        self.s.save()

        self.s1 = Network(network_str="10.2.1.0/24", ip_type='4')
        self.s1.update_network()
        self.s1.save()

    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)
        r.__repr__()
        r.save()
        return r

    def test1_create(self):
        start_str = "10.0.0.1"
        end_str = "10.0.0.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

    def test2_create(self):
        start_str = "10.0.1.1"
        end_str = "10.0.1.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

    def test2_bad_create(self):
        # start > end
        start_str = "10.0.0.2"
        end_str = "10.0.0.1"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test3_bad_create(self):
        # outside of network
        start_str = "11.0.0.2"
        end_str = "10.0.0.88"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test4_bad_create(self):
        # outside of network
        start_str = "10.2.0.0"
        end_str = "10.2.1.88"
        default_domain = self.d
        network = self.s1
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test5_bad_create(self):
        # duplicate
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test6_bad_create(self):
        # Partial overlap
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}

        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.30"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}

        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test7_bad_create(self):
        # Partial overlap
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.56"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test8_bad_create(self):
        # Full overlap
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        start_str = "10.0.4.2"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test9_bad_create(self):
        # Full overlap
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        start_str = "10.0.4.2"
        end_str = "10.0.4.54"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test10_bad_create(self):
        # Duplicate add
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        start_str = "10.0.5.2"
        end_str = "10.0.5.56"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}

        self.do_add(**kwargs)
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test11_bad_create(self):
        # More overlap tests
        start_str = "10.0.4.5"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        start_str = "10.0.4.60"
        end_str = "10.0.4.63"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.4"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        start_str = "10.0.4.2"
        end_str = "10.0.4.54"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test12_bad_create(self):
        # Update range to something outside of the subnet.
        start_str = "10.0.4.5"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        start_str = "10.0.4.60"
        end_str = "10.0.4.63"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.4"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        r = self.do_add(**kwargs)
        r.end_str = "160.0.4.60"

        self.assertRaises(ValidationError, r.clean)

    def test13_bad_create(self):
        start_str = "10.0.4.5"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test1_freeip(self):
        start_str = "10.0.33.1"
        end_str = "10.0.33.3"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '4'
        system = create_fake_host(hostname="foo.mozilla.com")

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        r = self.do_add(**kwargs)
        self.assertEqual(str(r.get_next_ip()), "10.0.33.1")
        self.assertEqual(str(r.get_next_ip()), "10.0.33.1")
        StaticReg.objects.create(
            label="foo", domain=self.d, ip_type='4',
            ip_str=str(r.get_next_ip()), system=system
        )
        self.assertEqual(str(r.get_next_ip()), "10.0.33.2")
        StaticReg.objects.create(
            label="foo", domain=self.d, ip_type='4',
            ip_str=str(r.get_next_ip()), system=system
        )
        self.assertEqual(str(r.get_next_ip()), "10.0.33.3")
        StaticReg.objects.create(
            label="foo", domain=self.d, ip_type='4',
            ip_str=str(r.get_next_ip()), system=system
        )
        self.assertEqual(r.get_next_ip(), None)
Ejemplo n.º 15
0
 def create_domains(self):
     private = View(name="private")
     private.save()
     public = View(name="public")
     public.save()
     Domain(name='com').save()
     Domain(name='mozilla.com').save()
     Domain(name='dc.mozilla.com').save()
     Domain(name='vlan.dc.mozilla.com').save()
     Domain(name='arpa').save()
     Domain(name='in-addr.arpa').save()
     Domain(name='10.in-addr.arpa').save()
     Domain(name='66.in-addr.arpa').save()
     vlan = Vlan(name='vlan', number=99)
     vlan.save()
     site = Site(name='dc')
     site.save()
     network = Network(network_str="10.0.0.0/8", ip_type='4')
     network2 = Network(network_str="66.66.66.0/24", ip_type='4')
     network2.update_network()
     network2.save()
     network.vlan = vlan
     network.site = site
     network.update_network()
     network.save()
     r = Range(
         start_str='10.99.99.1',
         end_str='10.99.99.254',
         network=network,)
     r.clean()
     r.save()
     r = Range(
         start_str='66.66.66.1',
         end_str='66.66.66.254',
         network=network2,)
     r.clean()
     r.save()
Ejemplo n.º 16
0
class V6RangeTests(TestCase):

    def setUp(self):
        self.d = Domain(name="com")
        self.s = Network(network_str="1234:1234:1234::/16", ip_type='6')
        self.s.update_network()
        self.s.save()

        self.s1 = Network(network_str="1234:1134:1234::/32", ip_type='6')
        self.s1.update_network()
        self.s1.save()

        self.s2 = Network(network_str="fff::/4", ip_type='6')
        self.s2.update_network()
        self.s2.save()

        self.s3 = Network(network_str="ffff::/4", ip_type='6')
        self.s3.update_network()
        self.s3.save()

    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)
        r.__repr__()
        r.save()
        return r

    def test1_create(self):
        start_str = "1234:1234:1234:1::"
        end_str = "1234:1234:1234:1234:1234:1234::"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

    def test2_create(self):
        start_str = "1234:1234:1234:1234::"
        end_str = "1234:1234:1235:1234:1234:1234::"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

    def test3_create(self):
        start_str = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0"
        end_str = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe"
        default_domain = self.d
        network = self.s3
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        r = self.do_add(**kwargs)
        self.assertEqual(r.start_upper, 0xffffffffffffffff)
        self.assertEqual(r.start_lower, 0xfffffffffffffff0)
        self.assertEqual(r.end_upper, 0xffffffffffffffff)
        self.assertEqual(r.end_lower, 0xfffffffffffffffe)

    def test2_bad_create(self):
        # start > end
        start_str = "1234:1235:1234:1235::"
        end_str = "1234:1235:1234:1234::"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test3_bad_create(self):
        # outside of network
        start_str = "2235:1235:1234:1233::"
        end_str = "2235:1235:1234:1234::"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test4_bad_create(self):
        # outside of network
        start_str = "1234:1234:1234:1::"
        end_str = "1234:1234:1234:1234:1234:1234::"
        default_domain = self.d
        network = self.s1
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test5_bad_create(self):
        # duplicate
        start_str = "1234:123e:1234:1234::"
        end_str = "1234:123e:1235:1234:1234:1234::"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        start_str = "1234:123e:1234:1234::"
        end_str = "1234:123e:1235:1234:1234:1234::"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test6_bad_create(self):
        # Partial overlap
        # start_str = "10.0.4.1"
        # end_str = "10.0.4.55"
        start_str = "fe:1::"
        end_str = "fe:1:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}

        self.do_add(**kwargs)

        # start_str = "10.0.4.1"
        # end_str = "10.0.4.30"
        start_str = "fe:1::"
        end_str = "fe:1:3::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}

        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test7_bad_create(self):
        # Partial overlap
        # start_str = "10.0.4.1"
        # end_str = "10.0.4.55"
        start_str = "fe1:1::"
        end_str = "fe1:1:3::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        # start_str = "10.0.4.1"
        # end_str = "10.0.4.56"
        start_str = "fe1:1::"
        end_str = "fe1:1:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str, 'default_domain':
            default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test8_bad_create(self):
        # Full overlap
        # start_str = "10.0.4.1"
        # end_str = "10.0.4.55"
        start_str = "fe2:1::"
        end_str = "fe2:1:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        # start_str = "10.0.4.2"
        # end_str = "10.0.4.55"
        start_str = "fe2:1:2::"
        end_str = "fe2:1:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test9_bad_create(self):
        # Full overlap
        # start_str = "10.0.4.1"
        # end_str = "10.0.4.55"
        start_str = "fe3:1:1::"
        end_str = "fe3:1:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        # start_str = "10.0.4.2"
        # end_str = "10.0.4.54"
        start_str = "fe3:1:2::"
        end_str = "fe3:1:3::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test10_bad_create(self):
        # Duplicate add
        # start_str = "10.0.4.1"
        # end_str = "10.0.4.55"
        start_str = "fe5:1:1::"
        end_str = "fe5:1:55::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        # start_str = "10.0.5.2"
        # end_str = "10.0.5.56"
        start_str = "fe5:1:56::"
        end_str = "fe5:1:57::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}

        self.do_add(**kwargs)
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test11_bad_create(self):
        # More overlap tests
        # start_str = "10.0.4.5"
        # end_str = "10.0.4.55"
        start_str = "fe6:4:5::"
        end_str = "fe6:4:55::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        # start_str = "10.0.4.60"
        # end_str = "10.0.4.63"
        start_str = "fe6:4:60::"
        end_str = "fe6:4:63::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        # start_str = "10.0.4.1"
        # end_str = "10.0.4.4"
        start_str = "fe6:4:1::"
        end_str = "fe6:4:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        # start_str = "10.0.4.2"
        # end_str = "10.0.4.54"
        start_str = "fe6:4:2::"
        end_str = "fe6:4:54::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test12_bad_create(self):
        # Update range to something outside of the subnet.
        # start_str = "10.0.4.5"
        # end_str = "10.0.4.55"
        start_str = "fe7:4:5::"
        end_str = "fe7:4:55::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        # start_str = "10.0.4.60"
        # end_str = "10.0.4.63"
        start_str = "fe7:4:60::"
        end_str = "fe7:4:63::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)

        # start_str = "10.0.4.1"
        # end_str = "10.0.4.4"
        start_str = "fe7:4:1::"
        end_str = "fe7:4:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        r = self.do_add(**kwargs)
        r.end_str = "ffff:ffff:ffff::"

        self.assertRaises(ValidationError, r.clean)

    def test13_bad_create(self):
        # start_str = "10.0.4.5"
        # end_str = "10.0.4.55"
        start_str = "fe8:4:5::"
        end_str = "fe8:4:55::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str, 'end_str': end_str,
            'default_domain': default_domain,
            'network': network, 'rtype': rtype, 'ip_type': ip_type}
        self.do_add(**kwargs)
        self.assertRaises(ValidationError, self.do_add, **kwargs)
Ejemplo n.º 17
0
    def create_domains(self):
        private = View(name="private")
        private.save()
        public = View(name="public")
        public.save()
        d0 = create_fake_zone("dc.mozilla.com", suffix="")
        s = d0.soa
        d = Domain(name='vlan.dc.mozilla.com')
        d.save()
        d.soa = s
        d.save()
        Domain(name='arpa').save()
        Domain(name='in-addr.arpa').save()

        # Create Reverse Domains
        d = create_fake_zone("10.in-addr.arpa", suffix="")

        d = create_fake_zone("66.in-addr.arpa", suffix="")

        vlan = Vlan(name='vlan', number=99)
        vlan.save()
        site = Site(name='dc')
        site.save()
        network = Network(network_str="10.0.0.0/8", ip_type='4')
        network2 = Network(network_str="66.66.66.0/24", ip_type='4')
        network2.update_network()
        network2.save()
        network.vlan = vlan
        network.site = site
        network.update_network()
        network.save()
        r = Range(
            start_str='10.99.99.1',
            end_str='10.99.99.254',
            network=network,)
        r.clean()
        r.save()
        r = Range(
            start_str='66.66.66.1',
            end_str='66.66.66.254',
            network=network2,)
        r.clean()
        r.save()
 class Meta:
     always_return_data = True
     queryset = Network.objects.all()
     fields = Network.get_api_fields()
     authorization = Authorization()
     allowed_methods = allowed_methods
    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)
        r.clean()
        r.save()

        r1 = Range(start_str="12.0.1.0", end_str="12.0.1.2",
                   network=n1)
        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))
def calc_networks_str(network_str, ip_type):
    network = Network(network_str=network_str, ip_type=ip_type)
    return calc_networks(network)
def calc_parent_str(network_str, ip_type):
    network = Network(network_str=network_str, ip_type=ip_type)
    return calc_parent(network)
Ejemplo n.º 22
0
class V4RangeTests(TestCase):
    def setUp(self):
        self.d = Domain(name="com")
        self.d.save()
        Domain(name="arpa").save()
        Domain(name="in-addr.arpa").save()
        Domain(name="10.in-addr.arpa").save()
        self.s = Network(network_str="10.0.0.0/16", ip_type="4")
        self.s.update_network()
        self.s.save()

        self.s1 = Network(network_str="10.2.1.0/24", ip_type="4")
        self.s1.update_network()
        self.s1.save()

    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)
        r.__repr__()
        r.save()
        return r

    def test1_create(self):
        start_str = "10.0.0.1"
        end_str = "10.0.0.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)

    def test2_create(self):
        start_str = "10.0.1.1"
        end_str = "10.0.1.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)

    def test2_bad_create(self):
        # start > end
        start_str = "10.0.0.2"
        end_str = "10.0.0.1"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test3_bad_create(self):
        # outside of network
        start_str = "11.0.0.2"
        end_str = "10.0.0.88"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test4_bad_create(self):
        # outside of network
        start_str = "10.2.0.0"
        end_str = "10.2.1.88"
        default_domain = self.d
        network = self.s1
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test5_bad_create(self):
        # duplicate
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test6_bad_create(self):
        # Partial overlap
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }

        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.30"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }

        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test7_bad_create(self):
        # Partial overlap
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.56"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test8_bad_create(self):
        # Full overlap
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.2"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test9_bad_create(self):
        # Full overlap
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.2"
        end_str = "10.0.4.54"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test10_bad_create(self):
        # Duplicate add
        start_str = "10.0.4.1"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)

        start_str = "10.0.5.2"
        end_str = "10.0.5.56"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }

        self.do_add(**kwargs)
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test11_bad_create(self):
        # More overlap tests
        start_str = "10.0.4.5"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.60"
        end_str = "10.0.4.63"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.4"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.2"
        end_str = "10.0.4.54"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test12_bad_create(self):
        # Update range to something outside of the subnet.
        start_str = "10.0.4.5"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.60"
        end_str = "10.0.4.63"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)

        start_str = "10.0.4.1"
        end_str = "10.0.4.4"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        r = self.do_add(**kwargs)
        r.end_str = "160.0.4.60"

        self.assertRaises(ValidationError, r.clean)

    def test13_bad_create(self):
        start_str = "10.0.4.5"
        end_str = "10.0.4.55"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        self.do_add(**kwargs)
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test1_freeip(self):
        start_str = "10.0.33.1"
        end_str = "10.0.33.3"
        default_domain = self.d
        network = self.s
        rtype = "s"
        ip_type = "4"
        system = System()

        kwargs = {
            "start_str": start_str,
            "end_str": end_str,
            "default_domain": default_domain,
            "network": network,
            "rtype": rtype,
            "ip_type": ip_type,
        }
        r = self.do_add(**kwargs)
        self.assertEqual(str(r.get_next_ip()), "10.0.33.1")
        self.assertEqual(str(r.get_next_ip()), "10.0.33.1")
        s = StaticInterface(
            label="foo", domain=self.d, ip_type="4", ip_str=str(r.get_next_ip()), system=system, mac="00:00:00:00:00:00"
        )
        s.clean()
        s.save()
        self.assertEqual(str(r.get_next_ip()), "10.0.33.2")
        s = StaticInterface(
            label="foo", domain=self.d, ip_type="4", ip_str=str(r.get_next_ip()), system=system, mac="00:00:00:00:00:00"
        )
        s.clean()
        s.save()
        self.assertEqual(str(r.get_next_ip()), "10.0.33.3")
        s = StaticInterface(
            label="foo", domain=self.d, ip_type="4", ip_str=str(r.get_next_ip()), system=system, mac="00:00:00:00:00:00"
        )
        s.clean()
        s.save()
        self.assertEqual(r.get_next_ip(), None)
Ejemplo n.º 23
0
class V6RangeTests(TestCase):
    def setUp(self):
        self.d = Domain(name="com")
        self.s = Network(network_str="1234:1234:1234::/16", ip_type='6')
        self.s.update_network()
        self.s.save()

        self.s1 = Network(network_str="1234:1134:1234::/32", ip_type='6')
        self.s1.update_network()
        self.s1.save()

        self.s2 = Network(network_str="fff::/4", ip_type='6')
        self.s2.update_network()
        self.s2.save()

        self.s3 = Network(network_str="ffff::/4", ip_type='6')
        self.s3.update_network()
        self.s3.save()

    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)
        r.__repr__()
        r.save()
        return r

    def test1_create(self):
        start_str = "1234:1234:1234:1::"
        end_str = "1234:1234:1234:1234:1234:1234::"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

    def test2_create(self):
        start_str = "1234:1234:1234:1234::"
        end_str = "1234:1234:1235:1234:1234:1234::"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

    def test3_create(self):
        start_str = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0"
        end_str = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe"
        default_domain = self.d
        network = self.s3
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        r = self.do_add(**kwargs)
        self.assertEqual(r.start_upper, 0xffffffffffffffff)
        self.assertEqual(r.start_lower, 0xfffffffffffffff0)
        self.assertEqual(r.end_upper, 0xffffffffffffffff)
        self.assertEqual(r.end_lower, 0xfffffffffffffffe)

    def test2_bad_create(self):
        # start > end
        start_str = "1234:1235:1234:1235::"
        end_str = "1234:1235:1234:1234::"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test3_bad_create(self):
        # outside of network
        start_str = "2235:1235:1234:1233::"
        end_str = "2235:1235:1234:1234::"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test4_bad_create(self):
        # outside of network
        start_str = "1234:1234:1234:1::"
        end_str = "1234:1234:1234:1234:1234:1234::"
        default_domain = self.d
        network = self.s1
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test5_bad_create(self):
        # duplicate
        start_str = "1234:123e:1234:1234::"
        end_str = "1234:123e:1235:1234:1234:1234::"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        start_str = "1234:123e:1234:1234::"
        end_str = "1234:123e:1235:1234:1234:1234::"
        default_domain = self.d
        network = self.s
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test6_bad_create(self):
        # Partial overlap
        # start_str = "10.0.4.1"
        # end_str = "10.0.4.55"
        start_str = "fe:1::"
        end_str = "fe:1:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }

        self.do_add(**kwargs)

        # start_str = "10.0.4.1"
        # end_str = "10.0.4.30"
        start_str = "fe:1::"
        end_str = "fe:1:3::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }

        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test7_bad_create(self):
        # Partial overlap
        # start_str = "10.0.4.1"
        # end_str = "10.0.4.55"
        start_str = "fe1:1::"
        end_str = "fe1:1:3::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        # start_str = "10.0.4.1"
        # end_str = "10.0.4.56"
        start_str = "fe1:1::"
        end_str = "fe1:1:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test8_bad_create(self):
        # Full overlap
        # start_str = "10.0.4.1"
        # end_str = "10.0.4.55"
        start_str = "fe2:1::"
        end_str = "fe2:1:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        # start_str = "10.0.4.2"
        # end_str = "10.0.4.55"
        start_str = "fe2:1:2::"
        end_str = "fe2:1:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test9_bad_create(self):
        # Full overlap
        # start_str = "10.0.4.1"
        # end_str = "10.0.4.55"
        start_str = "fe3:1:1::"
        end_str = "fe3:1:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        # start_str = "10.0.4.2"
        # end_str = "10.0.4.54"
        start_str = "fe3:1:2::"
        end_str = "fe3:1:3::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test10_bad_create(self):
        # Duplicate add
        # start_str = "10.0.4.1"
        # end_str = "10.0.4.55"
        start_str = "fe5:1:1::"
        end_str = "fe5:1:55::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        # start_str = "10.0.5.2"
        # end_str = "10.0.5.56"
        start_str = "fe5:1:56::"
        end_str = "fe5:1:57::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }

        self.do_add(**kwargs)
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test11_bad_create(self):
        # More overlap tests
        # start_str = "10.0.4.5"
        # end_str = "10.0.4.55"
        start_str = "fe6:4:5::"
        end_str = "fe6:4:55::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        # start_str = "10.0.4.60"
        # end_str = "10.0.4.63"
        start_str = "fe6:4:60::"
        end_str = "fe6:4:63::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        # start_str = "10.0.4.1"
        # end_str = "10.0.4.4"
        start_str = "fe6:4:1::"
        end_str = "fe6:4:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        # start_str = "10.0.4.2"
        # end_str = "10.0.4.54"
        start_str = "fe6:4:2::"
        end_str = "fe6:4:54::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.assertRaises(ValidationError, self.do_add, **kwargs)

    def test12_bad_create(self):
        # Update range to something outside of the subnet.
        # start_str = "10.0.4.5"
        # end_str = "10.0.4.55"
        start_str = "fe7:4:5::"
        end_str = "fe7:4:55::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        # start_str = "10.0.4.60"
        # end_str = "10.0.4.63"
        start_str = "fe7:4:60::"
        end_str = "fe7:4:63::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)

        # start_str = "10.0.4.1"
        # end_str = "10.0.4.4"
        start_str = "fe7:4:1::"
        end_str = "fe7:4:4::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        r = self.do_add(**kwargs)
        r.end_str = "ffff:ffff:ffff::"

        self.assertRaises(ValidationError, r.clean)

    def test13_bad_create(self):
        # start_str = "10.0.4.5"
        # end_str = "10.0.4.55"
        start_str = "fe8:4:5::"
        end_str = "fe8:4:55::"
        default_domain = self.d
        network = self.s2
        rtype = 's'
        ip_type = '6'

        kwargs = {
            'start_str': start_str,
            'end_str': end_str,
            'default_domain': default_domain,
            'network': network,
            'rtype': rtype,
            'ip_type': ip_type
        }
        self.do_add(**kwargs)
        self.assertRaises(ValidationError, self.do_add, **kwargs)