|
@@ -2144,16 +2144,19 @@ class TestStatisticsXfrinConn(TestXfrinConnection):
|
|
|
self._const_sec = round(delta.days * 86400 + delta.seconds +
|
|
|
delta.microseconds * 1E-6, 6)
|
|
|
# List of statistics counter names and expected initial values
|
|
|
- self.__name_to_counter = (('axfrreqv4', 0),
|
|
|
- ('axfrreqv6', 0),
|
|
|
- ('ixfrreqv4', 0),
|
|
|
- ('ixfrreqv6', 0),
|
|
|
- ('last_axfr_duration', 0.0),
|
|
|
- ('last_ixfr_duration', 0.0),
|
|
|
- ('soaoutv4', 0),
|
|
|
- ('soaoutv6', 0),
|
|
|
- ('xfrfail', 0),
|
|
|
- ('xfrsuccess', 0))
|
|
|
+ self.__name_to_perzone_counter = (('axfrreqv4', 0),
|
|
|
+ ('axfrreqv6', 0),
|
|
|
+ ('ixfrreqv4', 0),
|
|
|
+ ('ixfrreqv6', 0),
|
|
|
+ ('last_axfr_duration', 0.0),
|
|
|
+ ('last_ixfr_duration', 0.0),
|
|
|
+ ('soaoutv4', 0),
|
|
|
+ ('soaoutv6', 0),
|
|
|
+ ('xfrfail', 0),
|
|
|
+ ('xfrsuccess', 0))
|
|
|
+ self.__name_to_counter = ('soa_in_progress',
|
|
|
+ 'ixfr_running',
|
|
|
+ 'axfr_running')
|
|
|
self.__zones = 'zones'
|
|
|
|
|
|
def tearDown(self):
|
|
@@ -2168,25 +2171,41 @@ class TestStatisticsXfrinConn(TestXfrinConnection):
|
|
|
def _check_init_statistics(self):
|
|
|
'''checks exception being raised if not incremented statistics
|
|
|
counter gotten'''
|
|
|
- for (name, exp) in self.__name_to_counter:
|
|
|
+ for (name, exp) in self.__name_to_perzone_counter:
|
|
|
self.assertRaises(isc.cc.data.DataNotFoundError,
|
|
|
self.conn._counters.get, self.__zones,
|
|
|
TEST_ZONE_NAME_STR, name)
|
|
|
+ for name in self.__name_to_counter:
|
|
|
+ self.assertRaises(isc.cc.data.DataNotFoundError,
|
|
|
+ self.conn._counters.get, name)
|
|
|
|
|
|
- def _check_updated_statistics(self, overwrite):
|
|
|
+ def _check_updated_perzone_statistics(self, overwrite):
|
|
|
'''checks getting expect values after updating the pairs of
|
|
|
- statistics counter name and value on to the "overwrite"
|
|
|
+ per-zone statistics counter name and value on to the "overwrite"
|
|
|
dictionary'''
|
|
|
- name2count = dict(self.__name_to_counter)
|
|
|
+ name2count = dict(self.__name_to_perzone_counter)
|
|
|
name2count.update(overwrite)
|
|
|
for (name, exp) in name2count.items():
|
|
|
act = self.conn._counters.get(self.__zones,
|
|
|
TEST_RRCLASS_STR,
|
|
|
TEST_ZONE_NAME_STR,
|
|
|
name)
|
|
|
- msg = '%s is expected %s but actually %s' % (name, exp, act)
|
|
|
+ msg = '%s: expected %s but actually got %s' % (name, exp, act)
|
|
|
self.assertEqual(exp, act, msg=msg)
|
|
|
|
|
|
+ def _check_updated_statistics(self, expects):
|
|
|
+ '''checks counters in expects are incremented. also checks other
|
|
|
+ counters which are not in expects are not incremented.'''
|
|
|
+ for name in self.__name_to_counter:
|
|
|
+ if name in expects:
|
|
|
+ exp = expects[name]
|
|
|
+ act = self.conn._counters.get(name)
|
|
|
+ msg = '%s: expected %s but actually got %s' % (name, exp, act)
|
|
|
+ self.assertEqual(exp, act, msg=msg)
|
|
|
+ else:
|
|
|
+ self.assertRaises(isc.cc.data.DataNotFoundError,
|
|
|
+ self.conn._counters.get, name)
|
|
|
+
|
|
|
class TestStatisticsXfrinAXFRv4(TestStatisticsXfrinConn):
|
|
|
'''Xfrin AXFR tests for IPv4 to check statistics counters'''
|
|
|
def test_soaout(self):
|
|
@@ -2195,7 +2214,7 @@ class TestStatisticsXfrinAXFRv4(TestStatisticsXfrinConn):
|
|
|
self.conn.response_generator = self._create_soa_response_data
|
|
|
self._check_init_statistics()
|
|
|
self.assertEqual(self.conn._check_soa_serial(), XFRIN_OK)
|
|
|
- self._check_updated_statistics({'soaout' + self._ipver: 1})
|
|
|
+ self._check_updated_perzone_statistics({'soaout' + self._ipver: 1})
|
|
|
|
|
|
def test_axfrreq_xfrsuccess_last_axfr_duration(self):
|
|
|
'''tests that axfrreqv4 or axfrreqv6 and xfrsuccess counters
|
|
@@ -2203,9 +2222,10 @@ class TestStatisticsXfrinAXFRv4(TestStatisticsXfrinConn):
|
|
|
self.conn.response_generator = self._create_normal_response_data
|
|
|
self._check_init_statistics()
|
|
|
self.assertEqual(self.conn.do_xfrin(False), XFRIN_OK)
|
|
|
- self._check_updated_statistics({'axfrreq' + self._ipver: 1,
|
|
|
- 'xfrsuccess': 1,
|
|
|
- 'last_axfr_duration': self._const_sec})
|
|
|
+ self._check_updated_perzone_statistics({'axfrreq' + self._ipver: 1,
|
|
|
+ 'xfrsuccess': 1,
|
|
|
+ 'last_axfr_duration':
|
|
|
+ self._const_sec})
|
|
|
|
|
|
def test_axfrreq_xfrsuccess_last_axfr_duration2(self):
|
|
|
'''tests that axfrreqv4 or axfrreqv6 and xfrsuccess counters
|
|
@@ -2216,10 +2236,10 @@ class TestStatisticsXfrinAXFRv4(TestStatisticsXfrinConn):
|
|
|
self.conn._handle_xfrin_responses = exception_raiser
|
|
|
self._check_init_statistics()
|
|
|
self.assertEqual(self.conn.do_xfrin(False), XFRIN_OK)
|
|
|
- self._check_updated_statistics({'axfrreq' + self._ipver: 1,
|
|
|
- 'xfrsuccess': 1,
|
|
|
- 'last_axfr_duration':
|
|
|
- self._const_sec})
|
|
|
+ self._check_updated_perzone_statistics({'axfrreq' + self._ipver: 1,
|
|
|
+ 'xfrsuccess': 1,
|
|
|
+ 'last_axfr_duration':
|
|
|
+ self._const_sec})
|
|
|
|
|
|
def test_axfrreq_xfrfail(self):
|
|
|
'''tests that axfrreqv4 or axfrreqv6 and xfrfail counters are
|
|
@@ -2235,8 +2255,47 @@ class TestStatisticsXfrinAXFRv4(TestStatisticsXfrinConn):
|
|
|
self.conn._handle_xfrin_responses = exception_raiser
|
|
|
self.assertEqual(self.conn.do_xfrin(False), XFRIN_FAIL)
|
|
|
count += 1
|
|
|
- self._check_updated_statistics({'axfrreq' + self._ipver: count,
|
|
|
- 'xfrfail': count})
|
|
|
+ self._check_updated_perzone_statistics({'axfrreq' + self._ipver:
|
|
|
+ count,
|
|
|
+ 'xfrfail': count})
|
|
|
+
|
|
|
+ def test_soa_in_progress1(self):
|
|
|
+ '''tests that an soa_in_progress counter is incremented and decremented
|
|
|
+ when an soa query succeeds'''
|
|
|
+ self.conn.response_generator = self._create_soa_response_data
|
|
|
+ self._check_init_statistics()
|
|
|
+ self.assertEqual(self.conn._check_soa_serial(), XFRIN_OK)
|
|
|
+ self._check_updated_statistics({'soa_in_progress': 0})
|
|
|
+
|
|
|
+ def test_soa_in_progress2(self):
|
|
|
+ '''tests that an soa_in_progress counter is incremented and decremented
|
|
|
+ even if socket.error is raised from XfrinConnection._send_query()'''
|
|
|
+ def exception_raiser(x):
|
|
|
+ raise socket.error()
|
|
|
+ self.conn._send_query = exception_raiser
|
|
|
+ self._check_init_statistics()
|
|
|
+ self.assertRaises(socket.error, self.conn._check_soa_serial)
|
|
|
+ self._check_updated_statistics({'soa_in_progress': 0})
|
|
|
+
|
|
|
+ def test_axfr_running1(self):
|
|
|
+ '''tests that axfr_running counter is incremented and decremented'''
|
|
|
+ self.conn.response_generator = self._create_normal_response_data
|
|
|
+ self._check_init_statistics()
|
|
|
+ self.assertEqual(self.conn.do_xfrin(False), XFRIN_OK)
|
|
|
+ self._check_updated_statistics({'axfr_running': 0})
|
|
|
+
|
|
|
+ def test_axfr_running2(self):
|
|
|
+ '''tests that axfr_running counter is incremented and decremented even
|
|
|
+ if some failure exceptions are expected to be raised inside do_xfrin():
|
|
|
+ XfrinZoneError, XfrinProtocolError, XfrinException, and Exception'''
|
|
|
+ self._check_init_statistics()
|
|
|
+ for ex in [XfrinZoneError, XfrinProtocolError, XfrinException,
|
|
|
+ Exception]:
|
|
|
+ def exception_raiser():
|
|
|
+ raise ex()
|
|
|
+ self.conn._handle_xfrin_responses = exception_raiser
|
|
|
+ self.assertEqual(self.conn.do_xfrin(False), XFRIN_FAIL)
|
|
|
+ self._check_updated_statistics({'axfr_running': 0})
|
|
|
|
|
|
class TestStatisticsXfrinIXFRv4(TestStatisticsXfrinConn):
|
|
|
'''Xfrin IXFR tests for IPv4 to check statistics counters'''
|
|
@@ -2251,10 +2310,10 @@ class TestStatisticsXfrinIXFRv4(TestStatisticsXfrinConn):
|
|
|
self.conn.response_generator = create_ixfr_response
|
|
|
self._check_init_statistics()
|
|
|
self.assertEqual(XFRIN_OK, self.conn.do_xfrin(False, RRType.IXFR))
|
|
|
- self._check_updated_statistics({'ixfrreq' + self._ipver: 1,
|
|
|
- 'xfrsuccess': 1,
|
|
|
- 'last_ixfr_duration':
|
|
|
- self._const_sec})
|
|
|
+ self._check_updated_perzone_statistics({'ixfrreq' + self._ipver: 1,
|
|
|
+ 'xfrsuccess': 1,
|
|
|
+ 'last_ixfr_duration':
|
|
|
+ self._const_sec})
|
|
|
|
|
|
def test_ixfrreq_xfrsuccess_last_ixfr_duration2(self):
|
|
|
'''tests that ixfrreqv4 or ixfrreqv6 and xfrsuccess counters
|
|
@@ -2265,10 +2324,10 @@ class TestStatisticsXfrinIXFRv4(TestStatisticsXfrinConn):
|
|
|
self.conn._handle_xfrin_responses = exception_raiser
|
|
|
self._check_init_statistics()
|
|
|
self.assertEqual(self.conn.do_xfrin(False, RRType.IXFR), XFRIN_OK)
|
|
|
- self._check_updated_statistics({'ixfrreq' + self._ipver: 1,
|
|
|
- 'xfrsuccess': 1,
|
|
|
- 'last_ixfr_duration':
|
|
|
- self._const_sec})
|
|
|
+ self._check_updated_perzone_statistics({'ixfrreq' + self._ipver: 1,
|
|
|
+ 'xfrsuccess': 1,
|
|
|
+ 'last_ixfr_duration':
|
|
|
+ self._const_sec})
|
|
|
|
|
|
def test_ixfrreq_xfrfail(self):
|
|
|
'''tests that ixfrreqv4 or ixfrreqv6 and xfrfail counters are
|
|
@@ -2284,8 +2343,36 @@ class TestStatisticsXfrinIXFRv4(TestStatisticsXfrinConn):
|
|
|
self.conn._handle_xfrin_responses = exception_raiser
|
|
|
self.assertEqual(self.conn.do_xfrin(False, RRType.IXFR), XFRIN_FAIL)
|
|
|
count += 1
|
|
|
- self._check_updated_statistics({'ixfrreq' + self._ipver: count,
|
|
|
- 'xfrfail': count})
|
|
|
+ self._check_updated_perzone_statistics({'ixfrreq' + self._ipver:
|
|
|
+ count,
|
|
|
+ 'xfrfail': count})
|
|
|
+
|
|
|
+ def test_ixfr_running1(self):
|
|
|
+ '''tests that ixfr_running counter is incremented and decremented'''
|
|
|
+ def create_ixfr_response():
|
|
|
+ self.conn.reply_data = self.conn.create_response_data(
|
|
|
+ questions=[Question(TEST_ZONE_NAME, TEST_RRCLASS,
|
|
|
+ RRType.IXFR)],
|
|
|
+ answers=[soa_rrset, begin_soa_rrset, soa_rrset, soa_rrset])
|
|
|
+ self.conn.response_generator = create_ixfr_response
|
|
|
+ self._check_init_statistics()
|
|
|
+ self.assertEqual(XFRIN_OK, self.conn.do_xfrin(False, RRType.IXFR))
|
|
|
+ self._check_updated_statistics({'ixfr_running': 0})
|
|
|
+
|
|
|
+ def test_ixfr_running2(self):
|
|
|
+ '''tests that ixfr_running counter is incremented and decremented even
|
|
|
+ if some failure exceptions are expected to be raised inside do_xfrin():
|
|
|
+ XfrinZoneError, XfrinProtocolError, XfrinException, and Exception'''
|
|
|
+ self._check_init_statistics()
|
|
|
+ count = 0
|
|
|
+ for ex in [XfrinZoneError, XfrinProtocolError, XfrinException,
|
|
|
+ Exception]:
|
|
|
+ def exception_raiser():
|
|
|
+ raise ex()
|
|
|
+ self.conn._handle_xfrin_responses = exception_raiser
|
|
|
+ self.assertEqual(self.conn.do_xfrin(False, RRType.IXFR), XFRIN_FAIL)
|
|
|
+ count += 1
|
|
|
+ self._check_updated_statistics({'ixfr_running': 0})
|
|
|
|
|
|
class TestStatisticsXfrinAXFRv6(TestStatisticsXfrinAXFRv4):
|
|
|
'''Same tests as TestStatisticsXfrinAXFRv4 for IPv6'''
|