コード例 #1
0
ファイル: zone_migrate.py プロジェクト: Marlburo/inventory
def migrate_CNAME(zone, root_domain, soa, views):
    for (name, ttl, rdata) in zone.iterate_rdatas('CNAME'):
        name = name.to_text().strip('.')

        print str(name) + " CNAME " + 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)
        data = rdata.target.to_text().strip('.')

        if CNAME.objects.filter(label=label, domain=domain,
                target=data).exists():
            cn = CNAME.objects.get(
                label=label, domain=domain, target=data
            )
        else:
            cn = CNAME(
                label=label, domain=domain, target=data,
                description=rdata.comment, ttl=ttl
            )
            cn.full_clean()
            cn.save()

        for view in views:
            cn.views.add(view)
            cn.save()
コード例 #2
0
def migrate_CNAME(zone, root_domain, soa, views):
    for (name, ttl, rdata) in zone.iterate_rdatas('CNAME'):
        name = name.to_text().strip('.')

        print str(name) + " CNAME " + 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)
        data = rdata.target.to_text().strip('.')

        if CNAME.objects.filter(label=label, domain=domain,
                                target=data).exists():
            cn = CNAME.objects.get(label=label, domain=domain, target=data)
        else:
            cn = CNAME(label=label,
                       domain=domain,
                       target=data,
                       description=rdata.comment,
                       ttl=ttl)
            cn.full_clean()
            cn.save()

        for view in views:
            cn.views.add(view)
            cn.save()
コード例 #3
0
ファイル: auto_delete.py プロジェクト: Marlburo/inventory
    def test_cleanup_cname(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = create_fake_zone('foo.foo1', suffix="")
        self.assertEqual(f_c.name, 'foo.foo1')

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))

        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        fqdn = "bar.x.y.z.foo.poo"
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))
    def test_remove_has_child_records(self):
        Domain(name='com').save()
        f_c = Domain(name='foo.com')
        f_c.save()

        cn = CNAME(domain=f_c, label="no", target="asdf")
        cn.full_clean()
        cn.save()

        self.assertRaises(ValidationError, f_c.delete)
コード例 #5
0
ファイル: basic.py プロジェクト: caseybecking/inventory
    def test_remove_has_child_records(self):
        Domain(name='com').save()
        f_c = Domain(name='foo.com')
        f_c.save()

        cn = CNAME(domain=f_c, label="no", target="asdf")
        cn.full_clean()
        cn.save()

        self.assertRaises(ValidationError, f_c.delete)
    def test_basic_add_remove6(self):
        # Make sure CNAME record block
        f_c = create_fake_zone("foo.foo1", suffix="")
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
コード例 #7
0
    def test_add_with_cname(self):
        label = "cnamederp"
        domain = self.o_e
        data = "foo.com"
        cn = CNAME(label=label, domain=domain, target=data)
        cn.full_clean()
        cn.save()

        data = {'label': '', 'domain': self.o_e, 'server':
                'cnamederp.oregonstate.org', 'priority': 2, 'ttl': 2222}
        mx = MX(**data)
        self.assertRaises(ValidationError, mx.save)
コード例 #8
0
ファイル: tests.py プロジェクト: bclary/inventory
 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)
コード例 #9
0
ファイル: full_name.py プロジェクト: Marlburo/inventory
    def test_basic_add_remove6(self):
        # Make sure CNAME record block
        f_c = create_fake_zone("foo.foo1", suffix="")
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
コード例 #10
0
ファイル: full_name.py プロジェクト: Marlburo/inventory
    def test_basic_add_remove7(self):
        # try a star record
        f_c = create_fake_zone("foo.foo2", suffix="")
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "*.x.y.z.foo.foo2"
        label, the_domain = ensure_label_domain(fqdn)
        self.assertEqual('*', label)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
    def test_basic_add_remove7(self):
        # try a star record
        f_c = create_fake_zone("foo.foo2", suffix="")
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "*.x.y.z.foo.foo2"
        label, the_domain = ensure_label_domain(fqdn)
        self.assertEqual('*', label)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
コード例 #12
0
ファイル: basic.py プロジェクト: caseybecking/inventory
    def test_existing_cname_new_domain(self):
        name = "bo"
        b_dom, _ = Domain.objects.get_or_create(name=name, delegated=False)

        name = "to.bo"
        t_dom, _ = Domain.objects.get_or_create(name=name, delegated=False)

        cn = CNAME(domain=t_dom, label="no", target="asdf")
        cn.full_clean()
        cn.save()

        name = "no.to.bo"
        n_dom = Domain(name=name, delegated=False)
        self.assertRaises(ValidationError, n_dom.save)
    def do_add(self, label, domain, data):
        cn = CNAME(label=label, domain=domain, target=data)
        cn.full_clean()
        cn.save()
        cn.save()
        self.assertTrue(cn.get_absolute_url())
        self.assertTrue(cn.get_edit_url())
        self.assertTrue(cn.get_delete_url())
        self.assertTrue(cn.details())

        cs = CNAME.objects.filter(
            label=label, domain=domain, target=data)
        self.assertEqual(len(cs), 1)
        return cn
    def test_existing_cname_new_domain(self):
        name = "bo"
        b_dom, _ = Domain.objects.get_or_create(name=name, delegated=False)

        name = "to.bo"
        t_dom, _ = Domain.objects.get_or_create(name=name, delegated=False)

        cn = CNAME(domain=t_dom, label="no", target="asdf")
        cn.full_clean()
        cn.save()

        name = "no.to.bo"
        n_dom = Domain(name=name, delegated=False)
        self.assertRaises(ValidationError, n_dom.save)
コード例 #15
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)
コード例 #16
0
ファイル: tests.py プロジェクト: Marlburo/inventory
    def test_no_ns_in_view(self):
        root_domain = create_fake_zone("asdfdjhjd")
        ns = root_domain.nameserver_set.all()[0]

        cn = CNAME(label='asdf', domain=root_domain, target='test.com')
        cn.full_clean()
        cn.save()
        cn.views.add(self.public_view)

        self.assertTrue(ns.domain.soa == cn.domain.soa)

        # We now should have a nameserver and a cname in the public view. The
        # nameserver should not be allowed to disable it's public view

        # Try to remove the public view
        self.assertTrue(self.public_view in ns.views.all())
        self.assertTrue(self.private_view in ns.views.all())
        post_data = self.update_rdtype(self.post_data())
        post_data['domain'] = ns.domain.pk
        post_data['views'] = [self.private_view.pk]
        post_data['record_pk'] = ns.pk
        resp = self.c.post('/en-US/mozdns/record/record_ajax/',
                           data=post_data)
        self.assertEqual(resp.status_code, 200)
        # Make sure it's still there
        ns = Nameserver.objects.get(pk=ns.pk)  # fetch
        # Make sure the view is still there
        # The clean method should prevent it from being deleted
        self.assertTrue(self.public_view in ns.views.all())

        # Try to remove the private view
        # This should be allowed
        self.assertTrue(self.public_view in ns.views.all())
        post_data = self.update_rdtype(self.post_data())
        post_data['views'] = [self.public_view.pk]
        post_data['record_pk'] = ns.pk
        resp = self.c.post('/en-US/mozdns/record/record_ajax/',
                           data=post_data)
        self.assertEqual(resp.status_code, 200)
        # Make sure it's still there
        ns = Nameserver.objects.get(pk=ns.pk)  # fetch
        # Make sure the view is still there
        # The clean method should prevent it from being deleted
        self.assertTrue(self.private_view not in ns.views.all())
    def test_no_ns_in_view(self):
        root_domain = create_fake_zone("asdfdjhjd")
        ns = root_domain.nameserver_set.all()[0]

        cn = CNAME(label='asdf', domain=root_domain, target='test.com')
        cn.full_clean()
        cn.save()
        cn.views.add(self.public_view)

        self.assertTrue(ns.domain.soa == cn.domain.soa)

        # We now should have a nameserver and a cname in the public view. The
        # nameserver should not be allowed to disable it's public view

        # Try to remove the public view
        self.assertTrue(self.public_view in ns.views.all())
        self.assertTrue(self.private_view in ns.views.all())
        post_data = self.update_rdtype(self.post_data())
        post_data['domain'] = ns.domain.pk
        post_data['views'] = [self.private_view.pk]
        post_data['record_pk'] = ns.pk
        resp = self.c.post('/en-US/mozdns/record/record_ajax/', data=post_data)
        self.assertEqual(resp.status_code, 200)
        # Make sure it's still there
        ns = Nameserver.objects.get(pk=ns.pk)  # fetch
        # Make sure the view is still there
        # The clean method should prevent it from being deleted
        self.assertTrue(self.public_view in ns.views.all())

        # Try to remove the private view
        # This should be allowed
        self.assertTrue(self.public_view in ns.views.all())
        post_data = self.update_rdtype(self.post_data())
        post_data['views'] = [self.public_view.pk]
        post_data['record_pk'] = ns.pk
        resp = self.c.post('/en-US/mozdns/record/record_ajax/', data=post_data)
        self.assertEqual(resp.status_code, 200)
        # Make sure it's still there
        ns = Nameserver.objects.get(pk=ns.pk)  # fetch
        # Make sure the view is still there
        # The clean method should prevent it from being deleted
        self.assertTrue(self.private_view not in ns.views.all())
コード例 #18
0
    def test_integration3_zone(self):
        root_domain = create_fake_zone("wee3.wee.mozilla.com", "")
        res, error = compile_to_django("zone=:wee3.wee.mozilla.com")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 1)
        self.assertEqual(len(res['NS']), 1)
        cn = CNAME(label="host1", domain=root_domain, target="whop.whop")
        cn.save()
        res, error = compile_to_django("zone=:wee3.wee.mozilla.com host1")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 0)
        self.assertEqual(len(res['NS']), 0)
        self.assertEqual(len(res['CNAME']), 1)

        res, error = compile_to_django("zone=:wee3.wee.mozilla.com "
                                       "type=:CNAME")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 0)
        self.assertEqual(len(res['NS']), 0)
        self.assertEqual(len(res['CNAME']), 1)
コード例 #19
0
ファイル: full_name.py プロジェクト: Marlburo/inventory
    def test_basic_add_remove8(self):
        # Make sure a record's label is changed to '' when a domain with the
        # same name as it's fqdn is created.
        f_c = create_fake_zone("foo.foo3", suffix="")
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "www.x.y.z.foo.foo3"
        label, the_domain = ensure_label_domain(fqdn)
        self.assertEqual('www', label)
        self.assertEqual('x.y.z.foo.foo3', the_domain.name)
        self.assertTrue(the_domain.pk)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        fqdn = "*.www.x.y.z.foo.foo3"
        label2, the_domain2 = ensure_label_domain(fqdn)
        cname = CNAME.objects.get(fqdn=cname.fqdn)
        self.assertEqual('', cname.label)
        self.assertEqual('www.x.y.z.foo.foo3', cname.domain.name)
        self.assertEqual('*', label2)
        self.assertEqual('www.x.y.z.foo.foo3', the_domain2.name)
    def test_basic_add_remove8(self):
        # Make sure a record's label is changed to '' when a domain with the
        # same name as it's fqdn is created.
        f_c = create_fake_zone("foo.foo3", suffix="")
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "www.x.y.z.foo.foo3"
        label, the_domain = ensure_label_domain(fqdn)
        self.assertEqual('www', label)
        self.assertEqual('x.y.z.foo.foo3', the_domain.name)
        self.assertTrue(the_domain.pk)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        fqdn = "*.www.x.y.z.foo.foo3"
        label2, the_domain2 = ensure_label_domain(fqdn)
        cname = CNAME.objects.get(fqdn=cname.fqdn)
        self.assertEqual('', cname.label)
        self.assertEqual('www.x.y.z.foo.foo3', cname.domain.name)
        self.assertEqual('*', label2)
        self.assertEqual('www.x.y.z.foo.foo3', the_domain2.name)