add FQDN type to use instead of str to keep host and domain separate
This commit is contained in:
parent
435204da87
commit
f13d985f4a
@ -10,13 +10,22 @@ pytestmark = pytest.mark.django_db
|
|||||||
|
|
||||||
from dns.resolver import NXDOMAIN, NoAnswer
|
from dns.resolver import NXDOMAIN, NoAnswer
|
||||||
|
|
||||||
from ..dnstools import add, delete, update, query_ns, rev_lookup, parse_name, update_ns, SameIpError, DnsUpdateError
|
from ..dnstools import (add, delete, update, query_ns, rev_lookup, parse_name, update_ns,
|
||||||
|
SameIpError, DnsUpdateError, FQDN)
|
||||||
|
|
||||||
# see also conftest.py
|
# see also conftest.py
|
||||||
BASEDOMAIN = 'nsupdate.info'
|
BASEDOMAIN = 'nsupdate.info'
|
||||||
INVALID_HOST = 'test999.' + BASEDOMAIN # this can't get updated
|
INVALID_HOST = 'test999.' + BASEDOMAIN # this can't get updated
|
||||||
|
|
||||||
|
|
||||||
|
class TestFQDN(object):
|
||||||
|
def test_create(self):
|
||||||
|
fqdn = FQDN('test', 'example.org')
|
||||||
|
assert fqdn.host == 'test'
|
||||||
|
assert fqdn.domain == 'example.org'
|
||||||
|
assert str(fqdn) == 'test.example.org'
|
||||||
|
|
||||||
|
|
||||||
def remove_records(host, records=('A', 'AAAA', )):
|
def remove_records(host, records=('A', 'AAAA', )):
|
||||||
# make sure the records are not there
|
# make sure the records are not there
|
||||||
for record in records:
|
for record in records:
|
||||||
|
@ -18,6 +18,7 @@ UNAVAILABLE_RETRY = 300.0
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -35,6 +36,29 @@ import dns.tsigkeyring
|
|||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
|
||||||
|
|
||||||
|
class FQDN(namedtuple('FQDN', ['host', 'domain'])):
|
||||||
|
"""
|
||||||
|
named tuple to represent a fully qualified domain name:
|
||||||
|
|
||||||
|
* a host in a zone/domain
|
||||||
|
* just a zone/domain (give host=None when creating)
|
||||||
|
|
||||||
|
use this instead of str so that the information is not lost
|
||||||
|
what the host part is vs. what the domain part is.
|
||||||
|
|
||||||
|
e.g. foo.bar.example.org could be a host foo in domain bar.example.org
|
||||||
|
or a host foo.bar in domain example.org.
|
||||||
|
"""
|
||||||
|
def __str__(self):
|
||||||
|
"""
|
||||||
|
when transforming this into a str, just give the fqdn
|
||||||
|
"""
|
||||||
|
if self.host:
|
||||||
|
return self.host + '.' + self.domain
|
||||||
|
else:
|
||||||
|
return self.domain
|
||||||
|
|
||||||
|
|
||||||
Timeout = dns.resolver.Timeout
|
Timeout = dns.resolver.Timeout
|
||||||
NoNameservers = dns.resolver.NoNameservers
|
NoNameservers = dns.resolver.NoNameservers
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user