Example #1
0
 def do_generic_add(self, data):
     srv = SRV(**data)
     srv.__repr__()
     srv.save()
     self.assertTrue(srv.details())
     self.assertTrue(srv.get_absolute_url())
     self.assertTrue(srv.get_edit_url())
     self.assertTrue(srv.get_delete_url())
     rsrv = SRV.objects.filter(**data)
     self.assertTrue(len(rsrv) == 1)
     return srv
 def do_generic_add(self, data):
     srv = SRV(**data)
     srv.__repr__()
     srv.save()
     self.assertTrue(srv.details())
     self.assertTrue(srv.get_absolute_url())
     self.assertTrue(srv.get_edit_url())
     self.assertTrue(srv.get_delete_url())
     rsrv = SRV.objects.filter(**data)
     self.assertTrue(len(rsrv) == 1)
     return srv
def migrate_SRV(zone, root_domain, soa, views):
    for (name, ttl, rdata) in zone.iterate_rdatas('SRV'):
        target = rdata.target.to_text().strip('.')
        port = rdata.port
        weight = rdata.weight
        prio = rdata.priority
        name = name.to_text().strip('.')
        print str(name) + " SRV " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
        else:
            label = name.split('.')[0]
            domain_name = name.split('.')[1:]
            domain = ensure_domain('.'.join(domain_name), force=True)

        if not SRV.objects.filter(label = label, domain = domain,
                target=target, port=port, weight=weight,
                priority=prio).exists():
            srv = SRV(label = label, domain = domain,
                target=target, port=port, weight=weight,
                priority=prio)
            srv.full_clean()
            srv.save()
            for view in views:
                srv.views.add(view)
                srv.save()
Example #4
0
    def test_srv_cleanup(self):
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="z.foo.poo"))
        self.assertTrue(Domain.objects.filter(name="foo.poo"))

        fqdn = "bar.x.y.z.foo.poo"
        label, the_domain = ensure_label_domain(fqdn)
        srv = SRV(
            label='_' + label, domain=the_domain, target="foo", priority=4,
            weight=4, port=34)
        srv.save()
        self.assertFalse(prune_tree(the_domain))
        srv.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="z.foo.poo"))
        self.assertTrue(Domain.objects.filter(name="foo.poo"))
    def test_srv_cname_exists(self):
        label = "testyfoo"
        data = "wat"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        CNAME.objects.get_or_create(
            label=label, domain=dom, target=data)

        rec = SRV(label=label, domain=dom, target="asdf",
                  port=2, priority=2, weight=4)

        self.assertRaises(ValidationError, rec.save)
Example #6
0
    def test_basic_add_remove5(self):
        # Make sure all record types block
        f_c = create_fake_zone("foo.foo22", suffix="")
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)

        txt = TXT(label=label, domain=the_domain, txt_data="Nthing")
        txt.save()
        self.assertFalse(prune_tree(the_domain))
        txt.delete()

        label, the_domain = ensure_label_domain(fqdn)
        addr = AddressRecord(label=label, domain=the_domain,
                             ip_type='4', ip_str="10.2.3.4")
        addr.save()
        self.assertFalse(prune_tree(the_domain))
        addr.delete()

        label, the_domain = ensure_label_domain(fqdn)
        mx = MX(label=label, domain=the_domain, server="foo", priority=4)
        mx.save()
        self.assertFalse(prune_tree(the_domain))
        mx.delete()

        label, the_domain = ensure_label_domain(fqdn)
        ns = Nameserver(domain=the_domain, server="asdfasffoo")
        ns.save()
        self.assertFalse(prune_tree(the_domain))
        ns.delete()

        label, the_domain = ensure_label_domain(fqdn)
        srv = SRV(
            label='_' + label, domain=the_domain, target="foo", priority=4,
            weight=4, port=34)
        srv.save()
        self.assertFalse(prune_tree(the_domain))
        srv.delete()
Example #7
0
def migrate_SRV(zone, root_domain, soa, views):
    for (name, ttl, rdata) in zone.iterate_rdatas('SRV'):
        target = rdata.target.to_text().strip('.')
        port = rdata.port
        weight = rdata.weight
        prio = rdata.priority
        name = name.to_text().strip('.')
        print str(name) + " SRV " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
        else:
            label = name.split('.')[0]
            domain_name = name.split('.')[1:]
            domain = ensure_domain('.'.join(domain_name), force=True)

        if SRV.objects.filter(label=label,
                              domain=domain,
                              target=target,
                              port=port,
                              weight=weight,
                              priority=prio).exists():
            srv = SRV.objects.get(label=label,
                                  domain=domain,
                                  target=target,
                                  port=port,
                                  weight=weight,
                                  priority=prio)
        else:
            srv = SRV(label=label,
                      domain=domain,
                      target=target,
                      port=port,
                      weight=weight,
                      priority=prio,
                      description=rdata.comment,
                      ttl=ttl)
            srv.full_clean()
            srv.save()

        for view in views:
            srv.views.add(view)
            srv.save()
    def test_basic_add_remove5(self):
        # Make sure all record types block
        f_c = create_fake_zone("foo.foo22", suffix="")
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)

        txt = TXT(label=label, domain=the_domain, txt_data="Nthing")
        txt.save()
        self.assertFalse(prune_tree(the_domain))
        txt.delete()

        label, the_domain = ensure_label_domain(fqdn)
        addr = AddressRecord(label=label,
                             domain=the_domain,
                             ip_type='4',
                             ip_str="10.2.3.4")
        addr.save()
        self.assertFalse(prune_tree(the_domain))
        addr.delete()

        label, the_domain = ensure_label_domain(fqdn)
        mx = MX(label=label, domain=the_domain, server="foo", priority=4)
        mx.save()
        self.assertFalse(prune_tree(the_domain))
        mx.delete()

        label, the_domain = ensure_label_domain(fqdn)
        ns = Nameserver(domain=the_domain, server="asdfasffoo")
        ns.save()
        self.assertFalse(prune_tree(the_domain))
        ns.delete()

        label, the_domain = ensure_label_domain(fqdn)
        srv = SRV(label='_' + label,
                  domain=the_domain,
                  target="foo",
                  priority=4,
                  weight=4,
                  port=34)
        srv.save()
        self.assertFalse(prune_tree(the_domain))
        srv.delete()
 def test_srv_update(self):
     srv = SRV(target="foo", priority=4, weight=4, port=34)
     self.generic_check(srv, label_prefix="_")
 class Meta:
     always_return_data = True
     queryset = SRV.objects.all()
     fields = SRV.get_api_fields() + ['views']
     authorization = Authorization()
     allowed_methods = allowed_methods