Ejemplo n.º 1
0
    def test_add_A_address_glob_records(self):
        # Test the glob form: *.foo.com A 10.0.0.1
        rec = AddressRecord(label='',
                            domain=self.o_e,
                            ip_str="128.193.0.1",
                            ip_type='4')
        rec.clean()
        rec.save()
        self.assertEqual(rec.__str__(), "oregonstate.edu A 128.193.0.1")

        data = {'label': '*', 'domain': self.f_o_e, 'ip': "128.193.0.10"}
        self.do_add_record(data)
        data = {
            'label': '*foob1ar',
            'domain': self.f_o_e,
            'ip': "128.193.0.10"
        }
        self.do_add_record(data)

        data = {'label': '*foob1ar', 'domain': self.o_e, 'ip': "128.193.0.5"}
        self.do_add_record(data)
        data = {'label': '*foo2', 'domain': self.f_o_e, 'ip': "128.193.0.7"}
        self.do_add_record(data)
        data = {'label': '*foo2', 'domain': self.o_e, 'ip': "128.193.0.2"}
        self.do_add_record(data)
        data = {'label': '*ba-r', 'domain': self.f_o_e, 'ip': "128.193.0.9"}
        self.do_add_record(data)
        data = {'label': '*ba-r', 'domain': self.o_e, 'ip': "128.193.0.4"}
        self.do_add_record(data)
Ejemplo n.º 2
0
def migrate_AAAA(zone, root_domain, soa, views):
    for (name, ttl, rdata) in zone.iterate_rdatas('AAAA'):
        name = name.to_text().strip('.')
        print str(name) + " AAAA " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
        else:
            label = name.split('.')[0]
            if label.startswith('unused'):
                continue
            domain_name = '.'.join(name.split('.')[1:])
            domain = ensure_domain(domain_name, force=True)

        ip_upper, ip_lower = ipv6_to_longs(rdata.to_text())
        if AddressRecord.objects.filter(label=label,
                                        domain=domain, ip_upper=ip_upper, ip_lower=ip_lower,
                                        ip_type='6').exists():
            a = AddressRecord.objects.get(label=label,
                                          domain=domain, ip_type='6', ip_upper=ip_upper,
                                          ip_lower=ip_lower)
        else:
            a = AddressRecord(label=label, domain=domain,
                              ip_str=rdata.to_text(), ip_type='6')
            a.clean()
            a.save()
        for view in views:
            a.views.add(view)
            a.save()
Ejemplo n.º 3
0
    def test_manual_assign_of_glue(self):
        # Test that assigning a different glue record doesn't get overriden by
        # the auto assinging during the Nameserver's clean function.
        glue = StaticInterface(
            label="ns25", domain=self.f_r, ip_str="128.193.99.10", ip_type="4", system=self.s, mac="11:22:33:44:55:66"
        )
        glue.clean()
        glue.save()
        data = {"domain": self.f_r, "server": "ns25.foo.ru"}
        ns = self.do_add(**data)
        self.assertTrue(ns.glue)
        self.assertEqual(ns.glue, glue)

        glue2 = AddressRecord(label="ns25", domain=self.f_r, ip_str="128.193.1.78", ip_type="4")
        glue2.clean()
        glue2.save()

        ns.clean()

        # Make sure things didn't get overriden.
        self.assertEqual(ns.glue, glue)

        ns.glue = glue2
        ns.save()
        # Refresh the object
        ns = Nameserver.objects.get(pk=ns.pk)
        # Again, Make sure things didn't get overriden.
        self.assertEqual(ns.glue, glue2)
        # Make sure we still can't delete.
        self.assertRaises(ValidationError, glue2.delete)
        self.assertRaises(ValidationError, ns.glue.delete)

        # We shuold be able to delelte the other one.
        glue.delete()
Ejemplo n.º 4
0
 def test_private_view_case_1_addr(self):
     a = AddressRecord(label="asf", domain=self.f_o, ip_str="10.0.0.1",
                       ip_type="4")
     a.clean()
     a.save()
     # Object has to exist before views can be assigned.
     a.views.add(self.private)
     a.save()
Ejemplo n.º 5
0
 def do_add_a(self, label, domain, ip_str, ip_type='4'):
     a = AddressRecord(label=label,
                       domain=domain,
                       ip_str=ip_str,
                       ip_type=ip_type)
     a.clean()
     a.save()
     return a
Ejemplo n.º 6
0
 def test_delete_with_cname_pointing_to_a(self):
     label = 'foo100'
     a = AddressRecord(label=label, domain=self.o_e, ip_str=
                       '128.193.1.10', ip_type='4')
     a.clean()
     a.save()
     cn = CNAME(label="foomom", domain=self.o_e, target=label + "." +
                self.o_e.name)
     cn.clean()
     cn.save()
     self.assertRaises(ValidationError, a.delete)
     a.delete(check_cname=False)
Ejemplo n.º 7
0
    def test_disallow_name_update_of_glue_A(self):
        # Glue records should not be allowed to change their name.
        glue = AddressRecord(label="ns39", domain=self.f_r, ip_str="128.193.1.77", ip_type="4")
        glue.clean()
        glue.save()
        data = {"domain": self.f_r, "server": "ns39.foo.ru"}
        ns = self.do_add(**data)
        self.assertTrue(ns.glue)
        self.assertEqual(ns.glue, glue)

        glue.label = "ns22"
        self.assertRaises(ValidationError, glue.clean)
Ejemplo n.º 8
0
 def test_delete_with_cname_pointing_to_a(self):
     label = 'foo100'
     a = AddressRecord(label=label,
                       domain=self.o_e,
                       ip_str='128.193.1.10',
                       ip_type='4')
     a.clean()
     a.save()
     cn = CNAME(label="foomom",
                domain=self.o_e,
                target=label + "." + self.o_e.name)
     cn.clean()
     cn.save()
     self.assertRaises(ValidationError, a.delete)
     a.delete(check_cname=False)
Ejemplo n.º 9
0
    def test_disallow_name_update_of_glue_A(self):
        # Glue records should not be allowed to change their name.
        glue = AddressRecord(label='ns39',
                             domain=self.f_r,
                             ip_str='128.193.1.77',
                             ip_type='4')
        glue.clean()
        glue.save()
        data = {'domain': self.f_r, 'server': 'ns39.foo.ru'}
        ns = self.do_add(**data)
        self.assertTrue(ns.glue)
        self.assertEqual(ns.glue, glue)

        glue.label = "ns22"
        self.assertRaises(ValidationError, glue.clean)
Ejemplo n.º 10
0
    def testtest_add_ns_in_domain(self):
        # Use an A record as a glue record.
        glue = AddressRecord(label="ns2", domain=self.r, ip_str="128.193.1.10", ip_type="4")
        glue.clean()
        glue.save()
        data = {"domain": self.r, "server": "ns2.ru"}
        ns = self.do_add(**data)
        self.assertTrue(ns.glue)
        self.assertEqual(ns.server, ns.glue.fqdn)
        self.assertRaises(ValidationError, glue.delete)

        glue = AddressRecord(label="ns3", domain=self.f_r, ip_str="128.193.1.10", ip_type="4")
        glue.save()
        data = {"domain": self.f_r, "server": "ns3.foo.ru"}
        ns = self.do_add(**data)
        self.assertTrue(ns.glue)
        self.assertEqual(ns.server, ns.glue.fqdn)
Ejemplo n.º 11
0
 def test2_bad_add_for_a_ptr(self):
     # PTR and A exist, then try add intr
     mac = "11:22:33:44:55:66"
     label = "9988fdfood"
     domain = self.c
     ip_str = "1112::" + mac
     kwargs = {'mac': mac, 'label': label, 'domain': domain,
               'ip_str': ip_str}
     ip_type = '6'
     a = AddressRecord(label=label, domain=domain, ip_str=ip_str,
                       ip_type=ip_type)
     a.clean()
     a.save()
     ptr = PTR(ip_str=ip_str, ip_type=ip_type, name=a.fqdn)
     ptr.clean()
     ptr.save()
     self.assertRaises(ValidationError, self.do_add, **kwargs)
Ejemplo n.º 12
0
 def test2_bad_add_for_a_ptr(self):
     # PTR and A exist, then try add intr
     mac = "11:22:33:44:55:66"
     label = "9988fdfood"
     domain = self.c
     ip_str = "10.0.0.1"
     kwargs = {'mac': mac, 'label': label, 'domain': domain,
               'ip_str': ip_str}
     ip_type = '4'
     a = AddressRecord(label=label, domain=domain, ip_str=ip_str,
                       ip_type=ip_type)
     a.clean()
     a.save()
     ptr = PTR(ip_str=ip_str, ip_type=ip_type, name=a.fqdn)
     ptr.clean()
     ptr.save()
     self.assertRaises(ValidationError, self.do_add, **kwargs)
Ejemplo n.º 13
0
    def testtest_add_ns_in_domain(self):
        # Use an A record as a glue record.
        glue = AddressRecord(label='ns2', domain=self.r,
                             ip_str='128.193.1.10', ip_type='4')
        glue.clean()
        glue.save()
        data = {'domain': self.r, 'server': 'ns2.ru'}
        ns = self.do_add(**data)
        self.assertTrue(ns.glue)
        self.assertEqual(ns.server, ns.glue.fqdn)
        self.assertRaises(ValidationError, glue.delete)

        glue = AddressRecord(label='ns3', domain=self.f_r,
                             ip_str='128.193.1.10', ip_type='4')
        glue.save()
        data = {'domain': self.f_r, 'server': 'ns3.foo.ru'}
        ns = self.do_add(**data)
        self.assertTrue(ns.glue)
        self.assertEqual(ns.server, ns.glue.fqdn)
Ejemplo n.º 14
0
    def test_add_A_address_records(self):
        rec = AddressRecord( label = '', domain = self.o_e , ip_str= "128.193.0.1", ip_type='4')
        rec.clean()
        rec.save()
        self.assertEqual( rec.__str__(), "oregonstate.edu A 128.193.0.1" )

        data = {'label': 'foob1ar','domain': self.f_o_e ,'ip': "128.193.0.10"}
        self.do_add_record( data )

        data = {'label': 'foob1ar','domain': self.o_e ,'ip': "128.193.0.5"}
        self.do_add_record( data )
        data = {'label': 'foo2','domain': self.f_o_e ,'ip': "128.193.0.7"}
        self.do_add_record( data )
        data = {'label': 'foo2','domain': self.o_e ,'ip': "128.193.0.2"}
        self.do_add_record( data )
        data = {'label': 'ba-r','domain': self.f_o_e ,'ip': "128.193.0.9"}
        self.do_add_record( data )
        data = {'label': 'ba-r','domain': self.o_e ,'ip': "128.193.0.4"}
        self.do_add_record( data )
Ejemplo n.º 15
0
    def test_manual_assign_of_glue(self):
        # Test that assigning a different glue record doesn't get overriden by
        # the auto assinging during the Nameserver's clean function.
        glue = StaticInterface(label='ns25',
                               domain=self.f_r,
                               ip_str='128.193.99.10',
                               ip_type='4',
                               system=self.s,
                               mac="11:22:33:44:55:66")
        glue.clean()
        glue.save()
        data = {'domain': self.f_r, 'server': 'ns25.foo.ru'}
        ns = self.do_add(**data)
        self.assertTrue(ns.glue)
        self.assertEqual(ns.glue, glue)

        glue2 = AddressRecord(label='ns25',
                              domain=self.f_r,
                              ip_str='128.193.1.78',
                              ip_type='4')
        glue2.clean()
        glue2.save()

        ns.clean()

        # Make sure things didn't get overriden.
        self.assertEqual(ns.glue, glue)

        ns.glue = glue2
        ns.save()
        # Refresh the object
        ns = Nameserver.objects.get(pk=ns.pk)
        # Again, Make sure things didn't get overriden.
        self.assertEqual(ns.glue, glue2)
        # Make sure we still can't delete.
        self.assertRaises(ValidationError, glue2.delete)
        self.assertRaises(ValidationError, ns.glue.delete)

        # We shuold be able to delelte the other one.
        glue.delete()
Ejemplo n.º 16
0
    def test_private_view_case_3_addr(self):
        a = AddressRecord(label="asf3", domain=self.f_o, ip_str="10.0.0.1",
                          ip_type="4")
        a.clean()
        a.save()
        a.views.add(self.private)
        a.save()
        # Object has to exist before views can be assigned.
        a.views.add(self.public)
        self.assertFalse(a.views.filter(name="public"))

        a = AddressRecord(label="asf3", domain=self.f_o, ip_str="172.30.0.1",
                          ip_type="4")
        a.clean()
        a.save()
        a.views.add(self.private)
        a.save()
        # Object has to exist before views can be assigned.
        a.views.add(self.public)
        self.assertFalse(a.views.filter(name="public"))

        a = AddressRecord(label="asf3", domain=self.f_o, ip_str="192.168.0.1",
                          ip_type="4")
        a.clean()
        a.save()
        a.views.add(self.private)
        a.save()
        # Object has to exist before views can be assigned.
        a.views.add(self.public)
        self.assertFalse(a.views.filter(name="public"))
Ejemplo n.º 17
0
    def testtest_add_ns_in_domain(self):
        # Use an A record as a glue record.
        glue = AddressRecord(label='ns2',
                             domain=self.r,
                             ip_str='128.193.1.10',
                             ip_type='4')
        glue.clean()
        glue.save()
        data = {'domain': self.r, 'server': 'ns2.ru'}
        ns = self.do_add(**data)
        self.assertTrue(ns.glue)
        self.assertEqual(ns.server, ns.glue.fqdn)
        self.assertRaises(ValidationError, glue.delete)

        glue = AddressRecord(label='ns3',
                             domain=self.f_r,
                             ip_str='128.193.1.10',
                             ip_type='4')
        glue.save()
        data = {'domain': self.f_r, 'server': 'ns3.foo.ru'}
        ns = self.do_add(**data)
        self.assertTrue(ns.glue)
        self.assertEqual(ns.server, ns.glue.fqdn)
Ejemplo n.º 18
0
def migrate_AAAA(zone, root_domain, soa, views):
    for (name, ttl, rdata) in zone.iterate_rdatas('AAAA'):
        name = name.to_text().strip('.')
        print str(name) + " AAAA " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
        else:
            label = name.split('.')[0]
            if label.startswith('unused'):
                continue
            domain_name = '.'.join(name.split('.')[1:])
            domain = ensure_domain(domain_name, force=True)

        ip_upper, ip_lower = ipv6_to_longs(rdata.to_text())
        if AddressRecord.objects.filter(label=label,
                                        domain=domain,
                                        ip_upper=ip_upper,
                                        ip_lower=ip_lower,
                                        ip_type='6').exists():
            a = AddressRecord.objects.get(label=label,
                                          domain=domain,
                                          ip_type='6',
                                          ip_upper=ip_upper,
                                          ip_lower=ip_lower)
        else:
            a = AddressRecord(label=label,
                              domain=domain,
                              ip_str=rdata.to_text(),
                              ip_type='6')
            a.clean()
            a.save()
        for view in views:
            a.views.add(view)
            a.save()
Ejemplo n.º 19
0
                if addrs:
                    for exists_a in addrs:
                        # It got here. It exists
                        need_to_recreate_a = True
                        ip_str = exists_a.ip_str
                        ip_type = exists_a.ip_type
                        exists_a.delete(check_cname=False)
                        a = AddressRecord(label='',
                                          ip_str=ip_str,
                                          ip_type=ip_type)
                        clober_objects.append(a)
                domain, created = Domain.objects.get_or_create(
                    name=domain_name)
                for a in clober_objects:
                    a.domain = domain
                    a.clean()
                    try:
                        a.save()
                    except Exception, e:
                        pdb.set_trace()
                        pass

                if created and domain.master_domain and domain.master_domain.soa:
                    #domain.soa = domain.master_domain.soa
                    #domain.save()
                    null_all_soas(domain)
                    set_all_soas(domain, domain.master_domain.soa)
        ip_upper, ip_lower = ipv6_to_longs(rdata.to_text())
        if AddressRecord.objects.filter(label=label,
                                        domain=domain,
                                        ip_upper=ip_upper,
Ejemplo n.º 20
0
def populate_forward_dns(zone, root_domain, views=None):
    for (name, ttl, rdata) in zone.iterate_rdatas('SOA'):
        print str(name) + " SOA " + str(rdata)
        exists = SOA.objects.filter(minimum=rdata.minimum,
                                    contact=rdata.rname.to_text().strip('.'),
                                    primary=rdata.mname.to_text().strip('.'),
                                    comment="SOA for"
                                    " {0}".format(root_domain))
        if exists:
            soa = exists[0]
        else:
            soa = SOA(serial=rdata.serial,
                      minimum=rdata.minimum,
                      contact=rdata.rname.to_text().strip('.'),
                      primary=rdata.mname.to_text().strip('.'),
                      comment="SOA for"
                      " {0}".format(root_domain))
            soa.clean()
            soa.save()
        domain_split = list(reversed(name.to_text().strip('.').split('.')))
        for i in range(len(domain_split)):
            domain_name = domain_split[:i + 1]
            base_domain, created = Domain.objects.get_or_create(
                name='.'.join(list(reversed(domain_name))))

        null_all_soas(base_domain)
        base_domain.soa = soa
        base_domain.save()
        set_all_soas(base_domain, soa)

    names = []
    for (name, ttl, rdata) in zone.iterate_rdatas('A'):
        names.append((name.to_text().strip('.'), rdata))
    sorted_names = list(
        sorted(names,
               cmp=lambda n1, n2: -1
               if len(n1[0].split('.')) > len(n2[0].split('.')) else 1))

    for name, rdata in sorted_names:
        print str(name) + " A " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
        else:
            label = name.split('.')[0]
            if label.find('unused') != -1:
                continue
            parts = list(reversed(name.split('.')[1:]))
            domain_name = ''
            for i in range(len(parts)):
                domain_name = parts[i] + '.' + domain_name
                domain_name = domain_name.strip('.')
                # We need to check for A records who have a name with this
                # domain.
                addrs = AddressRecord.objects.filter(fqdn=domain_name,
                                                     ip_type='4')
                clober_objects = []
                if addrs:
                    for exists_a in addrs:
                        # It got here. It exists
                        need_to_recreate_a = True
                        ip_str = exists_a.ip_str
                        exists_a.delete(check_cname=False)
                        a = AddressRecord(label='', ip_str=ip_str, ip_type='4')
                        clober_objects.append(a)
                domain, created = Domain.objects.get_or_create(
                    name=domain_name)
                for a in clober_objects:
                    a.domain = domain
                    a.clean()
                    try:
                        a.save()
                    except Exception, e:
                        pdb.set_trace()
                        pass

                if created and domain.master_domain and domain.master_domain.soa:
                    #domain.soa = domain.master_domain.soa
                    #domain.save()
                    null_all_soas(domain)
                    set_all_soas(domain, domain.master_domain.soa)
        a, _ = AddressRecord.objects.get_or_create(label=label,
                                                   domain=domain,
                                                   ip_str=rdata.to_text(),
                                                   ip_type='4')
        if views:
            for view in views:
                a.views.add(view)
                try:
                    a.save()
                except Exception, e:
                    pdb.set_trace()
                    pass
Ejemplo n.º 21
0
def populate_forward_dns(zone, root_domain, views=None):
    for (name, ttl, rdata) in zone.iterate_rdatas('SOA'):
        print str(name) + " SOA " + str(rdata)
        exists = SOA.objects.filter(minimum=rdata.minimum,
                                    contact=rdata.rname.to_text().strip('.'),
                                    primary=rdata.mname.to_text().strip('.'), comment="SOA for"
                                    " {0}".format(root_domain))
        if exists:
            soa = exists[0]
        else:
            soa = SOA(serial=rdata.serial, minimum=rdata.minimum,
                      contact=rdata.rname.to_text().strip('.'),
                      primary=rdata.mname.to_text().strip('.'), comment="SOA for"
                      " {0}".format(root_domain))
            soa.clean()
            soa.save()
        domain_split = list(reversed(name.to_text().strip('.').split('.')))
        for i in range(len(domain_split)):
            domain_name = domain_split[:i + 1]
            base_domain, created = Domain.objects.get_or_create(name=
                                                                '.'.join(list(reversed(domain_name))))

        null_all_soas(base_domain)
        base_domain.soa = soa
        base_domain.save()
        set_all_soas(base_domain, soa)

    names = []
    for (name, ttl, rdata) in zone.iterate_rdatas('A'):
        names.append((name.to_text().strip('.'), rdata))
    sorted_names = list(sorted(names, cmp=lambda n1, n2: -1 if
                               len(n1[0].split('.')) > len(n2[0].split('.')) else 1))

    for name, rdata in sorted_names:
        print str(name) + " A " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
        else:
            label = name.split('.')[0]
            if label.find('unused') != -1:
                continue
            parts = list(reversed(name.split('.')[1:]))
            domain_name = ''
            for i in range(len(parts)):
                domain_name = parts[i] + '.' + domain_name
                domain_name = domain_name.strip('.')
                # We need to check for A records who have a name with this
                # domain.
                addrs = AddressRecord.objects.filter(fqdn=domain_name,
                                                     ip_type='4')
                clober_objects = []
                if addrs:
                    for exists_a in addrs:
                        # It got here. It exists
                        need_to_recreate_a = True
                        ip_str = exists_a.ip_str
                        exists_a.delete(check_cname=False)
                        a = AddressRecord(label='', ip_str=ip_str, ip_type='4')
                        clober_objects.append(a)
                domain, created = Domain.objects.get_or_create(name=
                                                               domain_name)
                for a in clober_objects:
                    a.domain = domain
                    a.clean()
                    try:
                        a.save()
                    except Exception, e:
                        pdb.set_trace()
                        pass

                if created and domain.master_domain and domain.master_domain.soa:
                    #domain.soa = domain.master_domain.soa
                    #domain.save()
                    null_all_soas(domain)
                    set_all_soas(domain, domain.master_domain.soa)
        a, _ = AddressRecord.objects.get_or_create(label=label,
                                                   domain=domain, ip_str=rdata.to_text(), ip_type='4')
        if views:
            for view in views:
                a.views.add(view)
                try:
                    a.save()
                except Exception, e:
                    pdb.set_trace()
                    pass
Ejemplo n.º 22
0
                clober_objects = []
                if addrs:
                    for exists_a in addrs:
                        # It got here. It exists
                        need_to_recreate_a = True
                        ip_str = exists_a.ip_str
                        ip_type = exists_a.ip_type
                        exists_a.delete(check_cname=False)
                        a = AddressRecord(label='', ip_str=ip_str,
                                          ip_type=ip_type)
                        clober_objects.append(a)
                domain, created = Domain.objects.get_or_create(name=
                                                               domain_name)
                for a in clober_objects:
                    a.domain = domain
                    a.clean()
                    try:
                        a.save()
                    except Exception, e:
                        pdb.set_trace()
                        pass

                if created and domain.master_domain and domain.master_domain.soa:
                    #domain.soa = domain.master_domain.soa
                    #domain.save()
                    null_all_soas(domain)
                    set_all_soas(domain, domain.master_domain.soa)
        ip_upper, ip_lower = ipv6_to_longs(rdata.to_text())
        if AddressRecord.objects.filter(label=label,
                                        domain=domain, ip_upper=ip_upper, ip_lower=ip_lower,
                                        ip_type='6').exists():
Ejemplo n.º 23
0
 def do_add_a(self, label, domain, ip_str, ip_type='4'):
     a = AddressRecord(label=label, domain=domain, ip_str=ip_str,
                       ip_type=ip_type)
     a.clean()
     a.save()
     return a