Commit e45fa27d authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[1288] switch to new API 3: use the zone iterator in reply_xfrout_query()

instead of the old API.  Now we can completely drop
_create_rrset_from_db_record, so did it.  With this change the main xfrout
code is free from the old API.
parent 1e9bc2c1
......@@ -575,34 +575,23 @@ class TestXfroutSession(unittest.TestCase):
self.assertEqual(self.sock.readsent(), b"success")
def test_reply_xfrout_query_noerror(self):
global sqlite3_ds
def get_zone_datas(zone, file):
return [(4, 3, 'example.com.', 'com.example.', 3600, 'SOA', None,
'master.example.com. admin.example.com. ' +
'1234 3600 1800 2419200 7200')]
sqlite3_ds.get_zone_datas = get_zone_datas
self.xfrsess._soa = self.soa_rrset
self.xfrsess._iterator = [self.soa_rrset]
self.xfrsess._reply_xfrout_query(self.getmsg(), self.sock, "example.com.")
reply_msg = self.sock.read_msg()
self.assertEqual(reply_msg.get_rr_count(Message.SECTION_ANSWER), 2)
def test_reply_xfrout_query_noerror_with_tsig(self):
rrset_data = (4, 3, 'a.example.com.', 'com.example.', 3600, 'A', None, '192.168.1.1')
global sqlite3_ds
rrset = RRset(Name('a.example.com'), RRClass.IN(), RRType.A(),
RRTTL(3600))
rrset.add_rdata(Rdata(RRType.A(), RRClass.IN(), '192.0.2.1'))
global xfrout
def get_zone_datas(zone, file):
zone_rrsets = []
for i in range(0, 100):
zone_rrsets.insert(i, rrset_data)
return zone_rrsets
def get_rrset_len(rrset):
return 65520
sqlite3_ds.get_zone_datas = get_zone_datas
self.xfrsess._soa = self.soa_rrset
self.xfrsess._iterator = [rrset for i in range(0, 100)]
xfrout.get_rrset_len = get_rrset_len
self.xfrsess._tsig_ctx = self.create_mock_tsig_ctx(TSIGError.NOERROR)
......
......@@ -22,7 +22,6 @@ import isc.cc
import threading
import struct
import signal
from isc.datasrc import sqlite3_ds # should be obsoleted
from isc.datasrc import DataSourceClient, ZoneFinder
from socketserver import *
import os
......@@ -332,16 +331,6 @@ class XfroutSession():
msg.set_header_flag(Message.HEADERFLAG_QR)
return msg
def _create_rrset_from_db_record(self, record):
'''Create one rrset from one record of datasource, if the schema of record is changed,
This function should be updated first.
'''
rrtype_ = RRType(record[5])
rdata_ = Rdata(rrtype_, RRClass("IN"), " ".join(record[7:]))
rrset_ = RRset(Name(record[2]), RRClass("IN"), rrtype_, RRTTL( int(record[4])))
rrset_.add_rdata(rdata_)
return rrset_
def _send_message_with_last_soa(self, msg, sock_fd, rrset_soa, message_upper_len,
count_since_last_tsig_sign):
'''Add the SOA record to the end of message. If it can't be
......@@ -373,22 +362,21 @@ class XfroutSession():
message_upper_len = get_rrset_len(self._soa) + self._tsig_len
for rr_data in sqlite3_ds.get_zone_datas(zone_name, self._server.get_db_file()):
if self._server._shutdown_event.is_set(): # Check if xfrout is shutdown
for rrset in self._iterator:
# Check if xfrout is shutdown
if self._server._shutdown_event.is_set():
logger.info(XFROUT_STOPPING)
return
# TODO: RRType.SOA() ?
if RRType(rr_data[5]) == RRType("SOA"): #ignore soa record
continue
rrset_ = self._create_rrset_from_db_record(rr_data)
if rrset.get_type() == RRType.SOA():
continue
# We calculate the maximum size of the RRset (i.e. the
# size without compression) and use that to see if we
# may have reached the limit
rrset_len = get_rrset_len(rrset_)
rrset_len = get_rrset_len(rrset)
if message_upper_len + rrset_len < XFROUT_MAX_MESSAGE_SIZE:
msg.add_rrset(Message.SECTION_ANSWER, rrset_)
msg.add_rrset(Message.SECTION_ANSWER, rrset)
message_upper_len += rrset_len
continue
......@@ -401,7 +389,8 @@ class XfroutSession():
count_since_last_tsig_sign += 1
msg = self._clear_message(msg)
msg.add_rrset(Message.SECTION_ANSWER, rrset_) # Add the rrset to the new message
# Add the RR to the new message
msg.add_rrset(Message.SECTION_ANSWER, rrset)
# Reserve tsig space for signed packet
if count_since_last_tsig_sign == TSIG_SIGN_EVERY_NTH:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment