Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Ngo committed Apr 14, 2012
2 parents ae290d9 + 8666787 commit 7437132
Show file tree
Hide file tree
Showing 40 changed files with 551 additions and 181 deletions.
32 changes: 31 additions & 1 deletion README.md
Expand Up @@ -5,9 +5,12 @@ playdoh
>>> django.VERSION
(1, 3, 1, 'final', 0)
aptitude install python-dev mysql-server python-pip python-virtualenv python-mysqldb git-core libmysqlclient-dev
CREATE USER 'cyder'@'localhost' IDENTIFIED BY '****';
GRANT ALL PRIVILEGES ON *.* TO 'cyder'@'localhost';
create database cyder;
flush priviliges;
pip install coverage
Expand All @@ -18,4 +21,31 @@ pip install ipaddr
pip install Whoosh
pip install simplejson
``
pip install funfactory
git clone https://github.com/uberj/cyder.git /data/cyder
cd /data/cyder
git clone --recursive git://github.com/mozilla/playdoh-lib.git ./vendor
pip install -r requirements/compiled.txt
```

Sphinx Docs
===========
```
aptitude install python-sphinx
cd /data/cyder/docs
make html
```

Apache setup
==========
```
aptitude install apache2 libapache2-mod-wsgi
a2enmod rewrite
a2enmod proxy
```
1 change: 0 additions & 1 deletion cyder/core/cyuser/backends.py
Expand Up @@ -46,7 +46,6 @@ def has_perm(self, request, obj, action):
:class:`Domain` object.
>>> perm = request.user.get_profile().has_perm(request, domain,
... \'create\')
"""
user_level = None
user = request.user
Expand Down
2 changes: 1 addition & 1 deletion cyder/cybind/generators/bind_reverse_domain_generator.py
Expand Up @@ -4,7 +4,7 @@
import pdb
# Knobs
ip_just = 30
name_just = 10
name_just = 1
type_just = 15
class_just = 10
prio_just = 3
Expand Down
103 changes: 0 additions & 103 deletions cyder/cybind/test.py

This file was deleted.

129 changes: 129 additions & 0 deletions cyder/cybind/tests.py
@@ -0,0 +1,129 @@
import sys
import os
import pdb

from django.test import TestCase

from cyder.cydns.domain.models import Domain
from cyder.cydns.reverse_domain.models import ReverseDomain
from cyder.cydns.soa.models import SOA
from cyder.cydns.srv.models import SRV
from cyder.cydns.txt.models import TXT
from cyder.cydns.ptr.models import PTR
from cyder.cydns.mx.models import MX
from cyder.cydns.cname.models import CNAME
from cyder.cydns.address_record.models import AddressRecord
from cyder.cydns.nameserver.nameserver.models import Nameserver
from cyder.cydns.nameserver.reverse_nameserver.models import ReverseNameserver
from cyder.cybind.build import *

class BuildTests(TestCase):
def setUp(self):
s1, s1_c = SOA.objects.get_or_create(primary = "ns1.foo.gaz", contact =
"hostmaster.foo", comment="123foo.gaz2")
self.soa = s1
d, _ = Domain.objects.get_or_create(name="bgaz")
d.soa = s1
d.save()
self.dom = d
self.soa.dirty = False
self.dom.dirty = False

s2, s1_c = SOA.objects.get_or_create(primary = "ns1.foo.gaz", contact =
"hostmaster.foo", comment="123fooasdfsdf.gaz2")
self.rsoa = s2
rd, _ = ReverseDomain.objects.get_or_create(name="123")
rd.soa = s2
rd.save()
self.rdom = rd
self.rsoa.dirty = False
self.rdom.dirty = False


def test_dirty_a(self):
self.soa.dirty = False
self.dom.dirty = False
a, _ = AddressRecord.objects.get_or_create(label="asfd",
domain=self.dom, ip_str = "128.1.1.1", ip_type='4')
a.save()
self.assertTrue(self.dom.dirty)
self.assertFalse(self.soa.dirty)

def test_dirty_cname(self):
self.soa.dirty = False
self.dom.dirty = False
c = CNAME(label="asfd", domain=self.dom, data="nerp")
c.full_clean()
c.save()
self.assertTrue(self.dom.dirty)
self.assertFalse(self.soa.dirty)

def test_dirty_ptr(self):
self.rsoa.dirty = False
self.rdom.dirty = False
c = PTR(name="asfd", ip_str="123.123.123.123", ip_type="4")
c.full_clean()
c.save()
self.rdom = ReverseDomain.objects.get(pk=self.rdom.pk)
self.assertTrue(self.rdom.dirty)
self.assertFalse(self.rsoa.dirty)

def test_dirty_mx(self):
self.soa.dirty = False
self.dom.dirty = False
a, _ = MX.objects.get_or_create(label="asfd",
domain=self.dom, server = "asdf", priority=123, ttl=44)
a.save()
self.assertTrue(self.dom.dirty)
self.assertFalse(self.soa.dirty)

def test_dirty_ns(self):
self.soa.dirty = False
self.dom.dirty = False
a, _ = Nameserver.objects.get_or_create(domain=self.dom, server = "asdf")
a.save()
self.assertTrue(self.dom.dirty)
self.assertFalse(self.soa.dirty)

def test_dirty_rev_ns(self):
self.rsoa.dirty = False
self.rdom.dirty = False
a, _ = ReverseNameserver.objects.get_or_create(domain=self.rdom,
server = "asdf")
a.save()
self.assertTrue(self.rdom.dirty)
self.assertFalse(self.rsoa.dirty)

def test_dirty_rev_ns(self):
self.rsoa.dirty = False
self.rdom.dirty = False
a, _ = ReverseNameserver.objects.get_or_create(reverse_domain=self.rdom,
server = "asdf")
a.save()
self.assertTrue(self.rdom.dirty)
self.assertFalse(self.rsoa.dirty)

def test_dirty_soa(self):
self.soa.dirty = False
self.dom.dirty = False
self.soa.refresh = 123
self.soa.save()
self.assertTrue(self.soa.dirty)

def test_dirty_srv(self):
self.soa.dirty = False
self.dom.dirty = False
a, _ = SRV.objects.get_or_create(label="_asf", port=22, domain=self.dom,
target= "asdf", priority=123, weight=22)
a.save()
self.assertTrue(self.dom.dirty)
self.assertFalse(self.soa.dirty)

def test_dirty_txt(self):
self.soa.dirty = False
self.dom.dirty = False
a, _ = TXT.objects.get_or_create(label="asf", txt_data="test",
domain=self.dom)
a.save()
self.assertTrue(self.dom.dirty)
self.assertFalse(self.soa.dirty)
17 changes: 14 additions & 3 deletions cyder/cydns/address_record/models.py
Expand Up @@ -36,7 +36,8 @@ def details(self):
def clean(self):
self._check_glue_status()
super(AddressRecord, self).clean()
super(AddressRecord, self).check_for_delegation()
if self.domain.delegated:
self.validate_delegation_conditions()
super(AddressRecord, self).check_for_cname()
self.clean_ip(update_reverse_domain=False) # Function from Ip class.

Expand All @@ -57,6 +58,16 @@ def delete(self, *args, **kwargs):
format(self.record_type()))
super(AddressRecord, self).delete(*args, **kwargs)

def validate_delegation_conditions(self):
"""If our domain is delegated then an A record can only have a
name that is the same as a nameserver in that domain (glue)."""
if self.domain.nameserver_set.filter(server=self.fqdn).exists():
return
else:
# Confusing error messege?
raise ValidationError("You can only create A records in a "
"delegated domain that have an NS record pointing to them.")

def _check_glue_status(self):
"""If this record is a 'glue' record for a Nameserver instance,
do not allow modifications to this record. The Nameserver will
Expand All @@ -65,8 +76,8 @@ def _check_glue_status(self):
"""
if self.pk is None:
return
# First get this object from the database and compare it to the nameserver.nameserver.
# object about to be saved.
# First get this object from the database and compare it to the
# nameserver.nameserver. object about to be saved.
db_self = AddressRecord.objects.get(pk=self.pk)
if db_self.label == self.label and db_self.domain == self.domain:
return
Expand Down
9 changes: 9 additions & 0 deletions cyder/cydns/cname/models.py
Expand Up @@ -36,6 +36,15 @@ class Meta:
unique_together = ('domain', 'label', 'data')

def save(self, *args, **kwargs):
# If label, and domain have not changed, don't mark our domain for
# rebuilding.
if self.pk: # We need to exist in the db first.
db_self = CNAME.objects.get(pk=self.pk)
if db_self.label == self.label and db_self.domain == self.domain:
kwargs['no_build'] = True
else:
kwargs['no_build'] = False # Either nothing has changed or
# just data_domain. We want rebuild.
super(CNAME, self).save(*args, **kwargs)

def clean(self, *args, **kwargs):
Expand Down
5 changes: 3 additions & 2 deletions cyder/cydns/domain/models.py
Expand Up @@ -10,8 +10,7 @@


class Domain(models.Model, ObjectUrlMixin):
"""
A Domain is used as a foreign key for most DNS records.
"""A Domain is used as a foreign key for most DNS records.
A domain's SOA should be shared by only domains within it's zone.
Expand All @@ -35,6 +34,8 @@ class Domain(models.Model, ObjectUrlMixin):
master_domain = models.ForeignKey("self", null=True,
default=None, blank=True)
soa = models.ForeignKey(SOA, null=True, default=None, blank=True)
# This indicates if this domain (and zone) needs to be rebuilt
dirty = models.BooleanField(default=False)
delegated = models.BooleanField(default=False, null=False, blank=True)

class Meta:
Expand Down
10 changes: 10 additions & 0 deletions cyder/cydns/domain/templates/domain/domain_detail.html
Expand Up @@ -33,6 +33,16 @@
<span class="nav-item">
<a class="sub-link nav-link" href="/cydns/ptr/{{ object.pk }}/create/">Create PTR</a>
</span>
<span class="nav-item">
<a class="sub-link nav-link" href="/cydns/nameserver/{{ object.pk }}/create/">Create NS</a>
</span>
{% else %}
<span class="nav-item">
<a class="sub-link nav-link" href="/cydns/nameserver/{{ object.pk }}/create/">Create NS</a>
</span>
<span class="nav-item">
<a class="sub-link nav-link" href="/cydns/address_record/{{ object.pk }}/create/">Create Address Record</a>
</span>
{% endif %}

{% endblock %}
Expand Down

0 comments on commit 7437132

Please sign in to comment.