Merge "Improved dnsutils coverage"
This commit is contained in:
commit
9d253ad6ed
|
@ -89,15 +89,9 @@ def from_dnspython_zone(dnspython_zone):
|
||||||
|
|
||||||
def dnspyrecords_to_recordsetlist(dnspython_records):
|
def dnspyrecords_to_recordsetlist(dnspython_records):
|
||||||
rrsets = objects.RecordSetList()
|
rrsets = objects.RecordSetList()
|
||||||
|
|
||||||
for rname in dnspython_records.keys():
|
for rname in dnspython_records.keys():
|
||||||
for rdataset in dnspython_records[rname]:
|
for rdataset in dnspython_records[rname]:
|
||||||
rrset = dnspythonrecord_to_recordset(rname, rdataset)
|
rrsets.append(dnspythonrecord_to_recordset(rname, rdataset))
|
||||||
|
|
||||||
if rrset is None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
rrsets.append(rrset)
|
|
||||||
return rrsets
|
return rrsets
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,6 +106,7 @@ def dnspythonrecord_to_recordset(rname, rdataset):
|
||||||
'name': name,
|
'name': name,
|
||||||
'type': record_type
|
'type': record_type
|
||||||
}
|
}
|
||||||
|
|
||||||
if rdataset.ttl != 0:
|
if rdataset.ttl != 0:
|
||||||
values['ttl'] = rdataset.ttl
|
values['ttl'] = rdataset.ttl
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
$ORIGIN example.com.
|
||||||
|
example.com. 0 IN SOA ns1.example.com. nsadmin.example.com. (
|
||||||
|
2013091101 ; serial
|
||||||
|
7200 ; refresh
|
||||||
|
3600 ; retry
|
||||||
|
2419200 ; expire
|
||||||
|
10800 ; minimum
|
||||||
|
)
|
||||||
|
ipv4.example.com. 300 IN A 192.0.0.1
|
||||||
|
ipv6.example.com. 10800 IN AAAA fd00::1
|
||||||
|
cname.example.com. 10800 IN CNAME example.com.
|
||||||
|
example.com. 10800 IN MX 5 192.0.0.2
|
||||||
|
example.com. 10800 IN MX 10 192.0.0.3
|
||||||
|
_http._tcp.example.com. 10800 IN SRV 10 0 80 192.0.0.4
|
||||||
|
_http._tcp.example.com. 10800 IN SRV 10 5 80 192.0.0.5
|
||||||
|
example.com. 10800 IN TXT "abc" "def"
|
||||||
|
example.com. 10800 IN SPF "v=spf1 mx a"
|
||||||
|
example.com. 10800 IN NS ns1.example.com.
|
||||||
|
example.com. 10800 IN NS ns2.example.com.
|
||||||
|
delegation.example.com. 10800 IN NS ns1.example.com.
|
||||||
|
1.0.0.192.in-addr.arpa. 10800 IN PTR ipv4.example.com.
|
|
@ -130,9 +130,24 @@ class TestUtils(designate.tests.TestCase):
|
||||||
|
|
||||||
self.assertIsInstance(zone, objects.zone.Zone)
|
self.assertIsInstance(zone, objects.zone.Zone)
|
||||||
|
|
||||||
|
def test_from_dnspython_zone_zero_soa(self):
|
||||||
|
CONF.set_override('min_ttl', 1234, 'service:central')
|
||||||
|
|
||||||
|
zone_file = self.get_zonefile_fixture(variant='zerosoa')
|
||||||
|
|
||||||
|
dnspython_zone = dns.zone.from_text(
|
||||||
|
zone_file,
|
||||||
|
relativize=False,
|
||||||
|
check_origin=False
|
||||||
|
)
|
||||||
|
|
||||||
|
zone = dnsutils.from_dnspython_zone(dnspython_zone)
|
||||||
|
|
||||||
|
self.assertIsInstance(zone, objects.zone.Zone)
|
||||||
|
self.assertEqual(1234, zone.ttl)
|
||||||
|
|
||||||
def test_from_dnspython_zone_no_soa(self):
|
def test_from_dnspython_zone_no_soa(self):
|
||||||
zone_file = self.get_zonefile_fixture(variant='nosoa')
|
zone_file = self.get_zonefile_fixture(variant='nosoa')
|
||||||
|
|
||||||
dnspython_zone = dns.zone.from_text(
|
dnspython_zone = dns.zone.from_text(
|
||||||
zone_file,
|
zone_file,
|
||||||
relativize=False,
|
relativize=False,
|
||||||
|
|
|
@ -19,6 +19,7 @@ from unittest import mock
|
||||||
import dns
|
import dns
|
||||||
import dns.exception
|
import dns.exception
|
||||||
import dns.message
|
import dns.message
|
||||||
|
import dns.name
|
||||||
import dns.rcode
|
import dns.rcode
|
||||||
import dns.rdatatype
|
import dns.rdatatype
|
||||||
import dns.zone
|
import dns.zone
|
||||||
|
@ -39,6 +40,19 @@ class TestDNSUtils(oslotest.base.BaseTestCase):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.useFixture(cfg_fixture.Config(CONF))
|
self.useFixture(cfg_fixture.Config(CONF))
|
||||||
|
|
||||||
|
def test_dnspyrecords_to_recordsetlist(self):
|
||||||
|
node = dns.node.Node()
|
||||||
|
node.rdatasets.append(
|
||||||
|
dns.rdataset.from_text('in', 'a', 0, '192.0.2.1')
|
||||||
|
)
|
||||||
|
dnspython_records = {
|
||||||
|
dns.name.Name(labels=[b'ipv4', b'example', b'org', b'']): node
|
||||||
|
}
|
||||||
|
recorset = dnsutils.dnspyrecords_to_recordsetlist(dnspython_records)
|
||||||
|
self.assertEqual(1, len(recorset))
|
||||||
|
self.assertEqual('ipv4.example.org.', recorset[0].name)
|
||||||
|
self.assertIsNone(recorset[0].ttl)
|
||||||
|
|
||||||
@mock.patch('socket.getaddrinfo')
|
@mock.patch('socket.getaddrinfo')
|
||||||
def test_get_ip_address(self, mock_getaddrinfo):
|
def test_get_ip_address(self, mock_getaddrinfo):
|
||||||
mock_getaddrinfo.return_value = [
|
mock_getaddrinfo.return_value = [
|
||||||
|
|
Loading…
Reference in New Issue