Merge pull request #236 from elnappo/fix-168
fixes #168, test updates when a domain is set to available
This commit is contained in:
commit
52a9093345
@ -80,6 +80,7 @@ def db_init(db): # note: db is a predefined fixture and required here to have t
|
|||||||
nameserver_update_algorithm=NAMESERVER_UPDATE_ALGORITHM,
|
nameserver_update_algorithm=NAMESERVER_UPDATE_ALGORITHM,
|
||||||
nameserver_update_secret=NAMESERVER_UPDATE_SECRET,
|
nameserver_update_secret=NAMESERVER_UPDATE_SECRET,
|
||||||
public=NAMESERVER_PUBLIC,
|
public=NAMESERVER_PUBLIC,
|
||||||
|
available=True,
|
||||||
created_by=u,
|
created_by=u,
|
||||||
)
|
)
|
||||||
# this is for querying:
|
# this is for querying:
|
||||||
@ -90,6 +91,7 @@ def db_init(db): # note: db is a predefined fixture and required here to have t
|
|||||||
nameserver_update_algorithm=NAMESERVER_UPDATE_ALGORITHM,
|
nameserver_update_algorithm=NAMESERVER_UPDATE_ALGORITHM,
|
||||||
nameserver_update_secret='invalid=', # we don't send updates there (and the real key is really secret)
|
nameserver_update_secret='invalid=', # we don't send updates there (and the real key is really secret)
|
||||||
public=NAMESERVER_PUBLIC,
|
public=NAMESERVER_PUBLIC,
|
||||||
|
available=True,
|
||||||
created_by=u2,
|
created_by=u2,
|
||||||
)
|
)
|
||||||
# a Host for api / session update tests
|
# a Host for api / session update tests
|
||||||
|
@ -32,6 +32,7 @@ import dns.query
|
|||||||
import dns.update
|
import dns.update
|
||||||
import dns.tsig
|
import dns.tsig
|
||||||
import dns.tsigkeyring
|
import dns.tsigkeyring
|
||||||
|
import dns.exception
|
||||||
|
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
|
||||||
@ -98,6 +99,31 @@ def check_ip(ipaddr, keys=('ipv4', 'ipv6')):
|
|||||||
return keys[af == dns.inet.AF_INET6]
|
return keys[af == dns.inet.AF_INET6]
|
||||||
|
|
||||||
|
|
||||||
|
def check_domain(domain):
|
||||||
|
fqdn = FQDN(host="connectivity-test", domain=domain)
|
||||||
|
|
||||||
|
from .models import Domain
|
||||||
|
d = Domain.objects.get(name=domain)
|
||||||
|
# temporarily set domain to available
|
||||||
|
domain_available_state = d.available
|
||||||
|
d.available = True
|
||||||
|
d.save()
|
||||||
|
|
||||||
|
try:
|
||||||
|
# add to primary
|
||||||
|
add(fqdn, "8.8.8.8")
|
||||||
|
# delete on primary
|
||||||
|
delete(fqdn)
|
||||||
|
|
||||||
|
except (dns.exception.DNSException, ) as e:
|
||||||
|
raise NameServerNotAvailable(str(e))
|
||||||
|
|
||||||
|
finally:
|
||||||
|
# reset domain available
|
||||||
|
d.available = domain_available_state
|
||||||
|
d.save()
|
||||||
|
|
||||||
|
|
||||||
def add(fqdn, ipaddr, ttl=60):
|
def add(fqdn, ipaddr, ttl=60):
|
||||||
"""
|
"""
|
||||||
intelligent dns adder - first does a lookup on the master server to find
|
intelligent dns adder - first does a lookup on the master server to find
|
||||||
|
@ -4,8 +4,10 @@ form definitions (which fields are available, order, autofocus, ...)
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from .models import Host, RelatedHost, Domain, ServiceUpdaterHostConfig
|
from .models import Host, RelatedHost, Domain, ServiceUpdaterHostConfig
|
||||||
|
from .dnstools import check_domain, NameServerNotAvailable
|
||||||
|
|
||||||
|
|
||||||
class CreateHostForm(forms.ModelForm):
|
class CreateHostForm(forms.ModelForm):
|
||||||
@ -44,14 +46,33 @@ class EditRelatedHostForm(forms.ModelForm):
|
|||||||
class CreateDomainForm(forms.ModelForm):
|
class CreateDomainForm(forms.ModelForm):
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
model = Domain
|
model = Domain
|
||||||
fields = ['name', 'nameserver_ip', 'nameserver2_ip', 'nameserver_update_algorithm',
|
fields = ['name', 'nameserver_ip', 'nameserver2_ip', 'nameserver_update_algorithm', 'comment']
|
||||||
'public', 'available', 'comment']
|
|
||||||
widgets = {
|
widgets = {
|
||||||
'name': forms.widgets.TextInput(attrs=dict(autofocus=None)),
|
'name': forms.widgets.TextInput(attrs=dict(autofocus=None)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class EditDomainForm(forms.ModelForm):
|
class EditDomainForm(forms.ModelForm):
|
||||||
|
def clean(self):
|
||||||
|
cleaned_data = super(EditDomainForm, self).clean()
|
||||||
|
|
||||||
|
if self.cleaned_data['available']:
|
||||||
|
try:
|
||||||
|
check_domain(self.instance.name)
|
||||||
|
|
||||||
|
except (NameServerNotAvailable, ):
|
||||||
|
raise forms.ValidationError(
|
||||||
|
_("Failed to add/delete a test host on %(domain)s, check your DNS server configuration. "
|
||||||
|
"This is a requirement for setting the available flag."),
|
||||||
|
code='invalid',
|
||||||
|
params={'domain': self.instance.name}
|
||||||
|
)
|
||||||
|
|
||||||
|
if cleaned_data['public'] and not cleaned_data['available']:
|
||||||
|
raise forms.ValidationError(
|
||||||
|
_("Domain must be available to be public"),
|
||||||
|
code='invalid')
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
model = Domain
|
model = Domain
|
||||||
fields = ['comment', 'nameserver_ip', 'nameserver2_ip', 'public', 'available',
|
fields = ['comment', 'nameserver_ip', 'nameserver2_ip', 'public', 'available',
|
||||||
|
19
nsupdate/main/migrations/0008_auto_20151229_1255.py
Normal file
19
nsupdate/main/migrations/0008_auto_20151229_1255.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0007_auto_20150425_1741'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='domain',
|
||||||
|
name='available',
|
||||||
|
field=models.BooleanField(default=False, help_text="Check if nameserver is available/reachable - if not checked, we'll pause querying/updating this nameserver for a while", verbose_name='available'),
|
||||||
|
),
|
||||||
|
]
|
15
nsupdate/main/migrations/0009_merge.py
Normal file
15
nsupdate/main/migrations/0009_merge.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0008_auto_20151228_1342'),
|
||||||
|
('main', '0008_auto_20151229_1255'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
]
|
@ -115,7 +115,7 @@ class Domain(models.Model):
|
|||||||
# gets set to False if we have trouble reaching the nameserver
|
# gets set to False if we have trouble reaching the nameserver
|
||||||
available = models.BooleanField(
|
available = models.BooleanField(
|
||||||
_("available"),
|
_("available"),
|
||||||
default=True,
|
default=False,
|
||||||
help_text=_("Check if nameserver is available/reachable - "
|
help_text=_("Check if nameserver is available/reachable - "
|
||||||
"if not checked, we'll pause querying/updating this nameserver for a while"))
|
"if not checked, we'll pause querying/updating this nameserver for a while"))
|
||||||
comment = models.CharField(
|
comment = models.CharField(
|
||||||
|
@ -153,7 +153,7 @@ class Command(BaseCommand):
|
|||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for h in Host.objects.all():
|
for h in Host.objects.all():
|
||||||
if stale_check:
|
if stale_check:
|
||||||
host = h.name + "." + h.domain
|
host = h.name + "." + h.domain.name
|
||||||
comment = h.comment
|
comment = h.comment
|
||||||
creator = h.created_by
|
creator = h.created_by
|
||||||
staleness, email_msg, log_msg = check_staleness(h)
|
staleness, email_msg, log_msg = check_staleness(h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user