import io
from isc.testutils.tsigctx_mock import MockTSIGContext
from xfrin import *
+from isc.xfrin.diff import Diff
import isc.log
#
TEST_RRCLASS, TEST_DB_FILE,
threading.Event(),
TEST_MASTER_IPV4_ADDRINFO)
+ self.begin_soa = RRset(TEST_ZONE_NAME, TEST_RRCLASS, RRType.SOA(),
+ RRTTL(3600))
+ self.begin_soa.add_rdata(Rdata(RRType.SOA(), TEST_RRCLASS,
+ 'm. r. 1230 0 0 0 0'))
self.ns_rrset = RRset(TEST_ZONE_NAME, TEST_RRCLASS, RRType.NS(),
RRTTL(3600))
self.ns_rrset.add_rdata(Rdata(RRType.NS(), TEST_RRCLASS,
'ns.example.com'))
+ self.__data_operations = []
+ self.conn._diff = Diff(self, TEST_ZONE_NAME)
+
+ # The following methods are to emulate a data source updater used by
+ # the Diff object. For our testing purposes they can simply be no-op.
+ def get_updater(self, zone_name, replace):
+ return self
+
+ def add_rrset(self, rrset):
+ pass
+
+ def remove_rrset(self, rrset):
+ pass
+
+ def commit(self):
+ pass
class TestXfrinInitialSOA(TestXfrinState):
def setUp(self):
def test_handle_ixfr_begin_soa(self):
self.conn._request_type = RRType.IXFR()
- begin_soa = RRset(TEST_ZONE_NAME, TEST_RRCLASS, RRType.SOA(),
- RRTTL(3600))
- begin_soa.add_rdata(Rdata(RRType.SOA(), TEST_RRCLASS,
- 'm. r. 1230 0 0 0 0'))
- self.assertFalse(self.state.handle_rr(self.conn, begin_soa))
+ self.assertFalse(self.state.handle_rr(self.conn, self.begin_soa))
self.assertEqual(type(XfrinIXFRDeleteSOA()),
type(self.conn.get_xfrstate()))
# If the original type is AXFR, other conditions aren't considered,
# and AXFR processing will continue
self.conn._request_type = RRType.AXFR()
- begin_soa = RRset(TEST_ZONE_NAME, TEST_RRCLASS, RRType.SOA(),
- RRTTL(3600))
- begin_soa.add_rdata(Rdata(RRType.SOA(), TEST_RRCLASS,
- 'm. r. 1230 0 0 0 0'))
- self.assertFalse(self.state.handle_rr(self.conn, begin_soa))
+ self.assertFalse(self.state.handle_rr(self.conn, self.begin_soa))
self.assertEqual(type(XfrinAXFR()), type(self.conn.get_xfrstate()))
def test_handle_ixfr_to_axfr(self):
self.assertFalse(self.state.handle_rr(self.conn, soa_rrset))
self.assertEqual(type(XfrinAXFR()), type(self.conn.get_xfrstate()))
+class TestXfrinIAXFDeleteSOA(TestXfrinState):
+ def setUp(self):
+ super().setUp()
+ self.state = XfrinIXFRDeleteSOA()
+
+ def test_handle_rr(self):
+ self.assertTrue(self.state.handle_rr(self.conn, self.begin_soa))
+ self.assertEqual(type(XfrinIXFRDelete()),
+ type(self.conn.get_xfrstate()))
+ self.assertEqual([('remove', self.begin_soa)],
+ self.conn._diff.get_buffer())
+
+ def test_handle_non_soa(self):
+ self.assertRaises(XfrinException, self.state.handle_rr, self.conn,
+ self.ns_rrset)
+
class TestXfrinConnection(unittest.TestCase):
def setUp(self):
if os.path.exists(TEST_DB_FILE):
from isc.notify import notify_out
import isc.util.process
import isc.net.parse
+import isc.xfrin.diff
from isc.log_messages.xfrin_messages import *
isc.log.init("b10-xfrin")
self.set_xfrstate(conn, XfrinIXFRDeleteSOA())
else:
logger.debug(DBG_XFRIN_TRACE, XFRIN_GOT_NONINCREMENTAL_RESP,
- conn.zone_str())
+ conn.zone_str())
self.set_xfrstate(conn, XfrinAXFR())
return False # need to revisit this RR in an update context
class XfrinIXFRDeleteSOA(XfrinState):
- pass
+ def handle_rr(self, conn, rr):
+ if rr.get_type() != RRType.SOA():
+ # this shouldn't happen; should this occur it means an internal
+ # bug.
+ raise XfrinException(rr.get_type().to_text() + \
+ ' RR is given in IXFRDeleteSOA state')
+ conn._diff.remove_data(rr)
+ self.set_xfrstate(conn, XfrinIXFRDelete())
+ return True
class XfrinAXFR(XfrinState):
pass
+class XfrinIXFRDelete(XfrinState):
+ pass
+
class XfrinConnection(asyncore.dispatcher):
'''Do xfrin in this class. '''