|
@@ -1,4 +1,4 @@
|
|
-# Copyright (C) 2010 Internet Systems Consortium.
|
|
|
|
|
|
+# Copyright (C) 2010-2012 Internet Systems Consortium.
|
|
#
|
|
#
|
|
# Permission to use, copy, modify, and distribute this software for any
|
|
# Permission to use, copy, modify, and distribute this software for any
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
@@ -270,6 +270,7 @@ class TestXfroutSessionBase(unittest.TestCase):
|
|
|
|
|
|
def setUp(self):
|
|
def setUp(self):
|
|
self.sock = MySocket(socket.AF_INET,socket.SOCK_STREAM)
|
|
self.sock = MySocket(socket.AF_INET,socket.SOCK_STREAM)
|
|
|
|
+ self.setup_counters()
|
|
self.xfrsess = MyXfroutSession(self.sock, None, Dbserver(),
|
|
self.xfrsess = MyXfroutSession(self.sock, None, Dbserver(),
|
|
TSIGKeyRing(),
|
|
TSIGKeyRing(),
|
|
(socket.AF_INET, socket.SOCK_STREAM,
|
|
(socket.AF_INET, socket.SOCK_STREAM,
|
|
@@ -278,22 +279,54 @@ class TestXfroutSessionBase(unittest.TestCase):
|
|
isc.acl.dns.REQUEST_LOADER.load(
|
|
isc.acl.dns.REQUEST_LOADER.load(
|
|
[{"action": "ACCEPT"}]),
|
|
[{"action": "ACCEPT"}]),
|
|
{},
|
|
{},
|
|
- counter_xfrrej=self._counter_xfrrej,
|
|
|
|
- counter_xfrreqdone=self._counter_xfrreqdone)
|
|
|
|
|
|
+ **self._counters)
|
|
self.set_request_type(RRType.AXFR()) # test AXFR by default
|
|
self.set_request_type(RRType.AXFR()) # test AXFR by default
|
|
self.mdata = self.create_request_data()
|
|
self.mdata = self.create_request_data()
|
|
self.soa_rrset = create_soa(SOA_CURRENT_VERSION)
|
|
self.soa_rrset = create_soa(SOA_CURRENT_VERSION)
|
|
# some test replaces a module-wide function. We should ensure the
|
|
# some test replaces a module-wide function. We should ensure the
|
|
# original is used elsewhere.
|
|
# original is used elsewhere.
|
|
self.orig_get_rrset_len = xfrout.get_rrset_len
|
|
self.orig_get_rrset_len = xfrout.get_rrset_len
|
|
- self._zone_name_xfrrej = None
|
|
|
|
- self._zone_name_xfrreqdone = None
|
|
|
|
|
|
|
|
- def _counter_xfrrej(self, zone_name):
|
|
|
|
- self._zone_name_xfrrej = zone_name
|
|
|
|
|
|
+ def setup_counters(self):
|
|
|
|
+ self._statistics_data = {
|
|
|
|
+ 'zones' : {
|
|
|
|
+ TEST_ZONE_NAME_STR : {
|
|
|
|
+ 'xfrrej': 0,
|
|
|
|
+ 'xfrreqdone': 0
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ 'axfr_started': 0,
|
|
|
|
+ 'ixfr_started': 0,
|
|
|
|
+ 'axfr_ended': 0,
|
|
|
|
+ 'ixfr_ended': 0
|
|
|
|
+ }
|
|
|
|
+ def _counter_xfrrej(zone_name):
|
|
|
|
+ self._statistics_data['zones'][zone_name]['xfrrej'] += 1
|
|
|
|
+ def _counter_xfrreqdone(zone_name):
|
|
|
|
+ self._statistics_data['zones'][zone_name]['xfrreqdone'] += 1
|
|
|
|
+ def _inc_ixfr_running():
|
|
|
|
+ self._statistics_data['ixfr_started'] += 1
|
|
|
|
+ def _dec_ixfr_running():
|
|
|
|
+ self._statistics_data['ixfr_ended'] += 1
|
|
|
|
+ def _inc_axfr_running():
|
|
|
|
+ self._statistics_data['axfr_started'] += 1
|
|
|
|
+ def _dec_axfr_running():
|
|
|
|
+ self._statistics_data['axfr_ended'] += 1
|
|
|
|
+ self._counters = {
|
|
|
|
+ 'counter_xfrrej': _counter_xfrrej,
|
|
|
|
+ 'counter_xfrreqdone': _counter_xfrreqdone,
|
|
|
|
+ 'inc_ixfr_running': _inc_ixfr_running,
|
|
|
|
+ 'dec_ixfr_running': _dec_ixfr_running,
|
|
|
|
+ 'inc_axfr_running': _inc_axfr_running,
|
|
|
|
+ 'dec_axfr_running': _dec_axfr_running
|
|
|
|
+ }
|
|
|
|
|
|
- def _counter_xfrreqdone(self, zone_name):
|
|
|
|
- self._zone_name_xfrreqdone = zone_name
|
|
|
|
|
|
+ def get_counter(self, name):
|
|
|
|
+ if name.find('ixfr_') == 0 or name.find('axfr_') == 0:
|
|
|
|
+ return self._statistics_data[name]
|
|
|
|
+ else:
|
|
|
|
+ return \
|
|
|
|
+ self._statistics_data['zones'][TEST_ZONE_NAME_STR][name]
|
|
|
|
|
|
def tearDown(self):
|
|
def tearDown(self):
|
|
xfrout.get_rrset_len = self.orig_get_rrset_len
|
|
xfrout.get_rrset_len = self.orig_get_rrset_len
|
|
@@ -386,6 +419,8 @@ class TestXfroutSession(TestXfroutSessionBase):
|
|
"action": "DROP"
|
|
"action": "DROP"
|
|
}
|
|
}
|
|
]))
|
|
]))
|
|
|
|
+ # check the 'xfrrej' counter initially
|
|
|
|
+ self.assertEqual(self.get_counter('xfrrej'), 0)
|
|
# Localhost (the default in this test) is accepted
|
|
# Localhost (the default in this test) is accepted
|
|
rcode, msg = self.xfrsess._parse_query_message(self.mdata)
|
|
rcode, msg = self.xfrsess._parse_query_message(self.mdata)
|
|
self.assertEqual(rcode.to_text(), "NOERROR")
|
|
self.assertEqual(rcode.to_text(), "NOERROR")
|
|
@@ -399,6 +434,8 @@ class TestXfroutSession(TestXfroutSessionBase):
|
|
('192.0.2.2', 12345))
|
|
('192.0.2.2', 12345))
|
|
rcode, msg = self.xfrsess._parse_query_message(self.mdata)
|
|
rcode, msg = self.xfrsess._parse_query_message(self.mdata)
|
|
self.assertEqual(rcode.to_text(), "REFUSED")
|
|
self.assertEqual(rcode.to_text(), "REFUSED")
|
|
|
|
+ # check the 'xfrrej' counter after incrementing
|
|
|
|
+ self.assertEqual(self.get_counter('xfrrej'), 1)
|
|
|
|
|
|
# TSIG signed request
|
|
# TSIG signed request
|
|
request_data = self.create_request_data(with_tsig=True)
|
|
request_data = self.create_request_data(with_tsig=True)
|
|
@@ -427,6 +464,8 @@ class TestXfroutSession(TestXfroutSessionBase):
|
|
]))
|
|
]))
|
|
[rcode, msg] = self.xfrsess._parse_query_message(request_data)
|
|
[rcode, msg] = self.xfrsess._parse_query_message(request_data)
|
|
self.assertEqual(rcode.to_text(), "REFUSED")
|
|
self.assertEqual(rcode.to_text(), "REFUSED")
|
|
|
|
+ # check the 'xfrrej' counter after incrementing
|
|
|
|
+ self.assertEqual(self.get_counter('xfrrej'), 2)
|
|
|
|
|
|
# ACL using TSIG: no TSIG; should be rejected
|
|
# ACL using TSIG: no TSIG; should be rejected
|
|
acl_setter(isc.acl.dns.REQUEST_LOADER.load([
|
|
acl_setter(isc.acl.dns.REQUEST_LOADER.load([
|
|
@@ -434,6 +473,8 @@ class TestXfroutSession(TestXfroutSessionBase):
|
|
]))
|
|
]))
|
|
[rcode, msg] = self.xfrsess._parse_query_message(self.mdata)
|
|
[rcode, msg] = self.xfrsess._parse_query_message(self.mdata)
|
|
self.assertEqual(rcode.to_text(), "REFUSED")
|
|
self.assertEqual(rcode.to_text(), "REFUSED")
|
|
|
|
+ # check the 'xfrrej' counter after incrementing
|
|
|
|
+ self.assertEqual(self.get_counter('xfrrej'), 3)
|
|
|
|
|
|
#
|
|
#
|
|
# ACL using IP + TSIG: both should match
|
|
# ACL using IP + TSIG: both should match
|
|
@@ -453,34 +494,28 @@ class TestXfroutSession(TestXfroutSessionBase):
|
|
('192.0.2.2', 12345))
|
|
('192.0.2.2', 12345))
|
|
[rcode, msg] = self.xfrsess._parse_query_message(request_data)
|
|
[rcode, msg] = self.xfrsess._parse_query_message(request_data)
|
|
self.assertEqual(rcode.to_text(), "REFUSED")
|
|
self.assertEqual(rcode.to_text(), "REFUSED")
|
|
|
|
+ # check the 'xfrrej' counter after incrementing
|
|
|
|
+ self.assertEqual(self.get_counter('xfrrej'), 4)
|
|
# Address matches, but TSIG doesn't (not included)
|
|
# Address matches, but TSIG doesn't (not included)
|
|
self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
|
|
self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
|
|
('192.0.2.1', 12345))
|
|
('192.0.2.1', 12345))
|
|
[rcode, msg] = self.xfrsess._parse_query_message(self.mdata)
|
|
[rcode, msg] = self.xfrsess._parse_query_message(self.mdata)
|
|
self.assertEqual(rcode.to_text(), "REFUSED")
|
|
self.assertEqual(rcode.to_text(), "REFUSED")
|
|
|
|
+ # check the 'xfrrej' counter after incrementing
|
|
|
|
+ self.assertEqual(self.get_counter('xfrrej'), 5)
|
|
# Neither address nor TSIG matches
|
|
# Neither address nor TSIG matches
|
|
self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
|
|
self.xfrsess._remote = (socket.AF_INET, socket.SOCK_STREAM,
|
|
('192.0.2.2', 12345))
|
|
('192.0.2.2', 12345))
|
|
[rcode, msg] = self.xfrsess._parse_query_message(self.mdata)
|
|
[rcode, msg] = self.xfrsess._parse_query_message(self.mdata)
|
|
self.assertEqual(rcode.to_text(), "REFUSED")
|
|
self.assertEqual(rcode.to_text(), "REFUSED")
|
|
|
|
+ # check the 'xfrrej' counter after incrementing
|
|
|
|
+ self.assertEqual(self.get_counter('xfrrej'), 6)
|
|
|
|
|
|
def test_transfer_acl(self):
|
|
def test_transfer_acl(self):
|
|
# ACL checks only with the default ACL
|
|
# ACL checks only with the default ACL
|
|
def acl_setter(acl):
|
|
def acl_setter(acl):
|
|
self.xfrsess._acl = acl
|
|
self.xfrsess._acl = acl
|
|
- self.assertIsNone(self._zone_name_xfrrej)
|
|
|
|
- self.check_transfer_acl(acl_setter)
|
|
|
|
- self.assertEqual(self._zone_name_xfrrej, TEST_ZONE_NAME_STR)
|
|
|
|
-
|
|
|
|
- def test_transfer_acl_with_nonetype_xfrrej(self):
|
|
|
|
- # ACL checks only with the default ACL and NoneType xfrrej
|
|
|
|
- # counter
|
|
|
|
- def acl_setter(acl):
|
|
|
|
- self.xfrsess._acl = acl
|
|
|
|
- self.xfrsess._counter_xfrrej = None
|
|
|
|
- self.assertIsNone(self._zone_name_xfrrej)
|
|
|
|
self.check_transfer_acl(acl_setter)
|
|
self.check_transfer_acl(acl_setter)
|
|
- self.assertIsNone(self._zone_name_xfrrej)
|
|
|
|
|
|
|
|
def test_transfer_acl_with_notcallable_xfrrej(self):
|
|
def test_transfer_acl_with_notcallable_xfrrej(self):
|
|
# ACL checks only with the default ACL and not callable xfrrej
|
|
# ACL checks only with the default ACL and not callable xfrrej
|
|
@@ -500,9 +535,7 @@ class TestXfroutSession(TestXfroutSessionBase):
|
|
self.xfrsess._zone_config[zone_key]['transfer_acl'] = acl
|
|
self.xfrsess._zone_config[zone_key]['transfer_acl'] = acl
|
|
self.xfrsess._acl = isc.acl.dns.REQUEST_LOADER.load([
|
|
self.xfrsess._acl = isc.acl.dns.REQUEST_LOADER.load([
|
|
{"from": "127.0.0.1", "action": "DROP"}])
|
|
{"from": "127.0.0.1", "action": "DROP"}])
|
|
- self.assertIsNone(self._zone_name_xfrrej)
|
|
|
|
self.check_transfer_acl(acl_setter)
|
|
self.check_transfer_acl(acl_setter)
|
|
- self.assertEqual(self._zone_name_xfrrej, TEST_ZONE_NAME_STR)
|
|
|
|
|
|
|
|
def test_transfer_zoneacl_nomatch(self):
|
|
def test_transfer_zoneacl_nomatch(self):
|
|
# similar to the previous one, but the per zone doesn't match the
|
|
# similar to the previous one, but the per zone doesn't match the
|
|
@@ -514,9 +547,7 @@ class TestXfroutSession(TestXfroutSessionBase):
|
|
isc.acl.dns.REQUEST_LOADER.load([
|
|
isc.acl.dns.REQUEST_LOADER.load([
|
|
{"from": "127.0.0.1", "action": "DROP"}])
|
|
{"from": "127.0.0.1", "action": "DROP"}])
|
|
self.xfrsess._acl = acl
|
|
self.xfrsess._acl = acl
|
|
- self.assertIsNone(self._zone_name_xfrrej)
|
|
|
|
self.check_transfer_acl(acl_setter)
|
|
self.check_transfer_acl(acl_setter)
|
|
- self.assertEqual(self._zone_name_xfrrej, TEST_ZONE_NAME_STR)
|
|
|
|
|
|
|
|
def test_get_transfer_acl(self):
|
|
def test_get_transfer_acl(self):
|
|
# set the default ACL. If there's no specific zone ACL, this one
|
|
# set the default ACL. If there's no specific zone ACL, this one
|
|
@@ -866,25 +897,11 @@ class TestXfroutSession(TestXfroutSessionBase):
|
|
def myreply(msg, sock):
|
|
def myreply(msg, sock):
|
|
self.sock.send(b"success")
|
|
self.sock.send(b"success")
|
|
|
|
|
|
- self.assertIsNone(self._zone_name_xfrreqdone)
|
|
|
|
|
|
+ self.assertEqual(self.get_counter('xfrreqdone'), 0)
|
|
self.xfrsess._reply_xfrout_query = myreply
|
|
self.xfrsess._reply_xfrout_query = myreply
|
|
self.xfrsess.dns_xfrout_start(self.sock, self.mdata)
|
|
self.xfrsess.dns_xfrout_start(self.sock, self.mdata)
|
|
self.assertEqual(self.sock.readsent(), b"success")
|
|
self.assertEqual(self.sock.readsent(), b"success")
|
|
- self.assertEqual(self._zone_name_xfrreqdone, TEST_ZONE_NAME_STR)
|
|
|
|
-
|
|
|
|
- def test_dns_xfrout_start_with_nonetype_xfrreqdone(self):
|
|
|
|
- def noerror(msg, name, rrclass):
|
|
|
|
- return Rcode.NOERROR()
|
|
|
|
- self.xfrsess._xfrout_setup = noerror
|
|
|
|
-
|
|
|
|
- def myreply(msg, sock):
|
|
|
|
- self.sock.send(b"success")
|
|
|
|
-
|
|
|
|
- self.assertIsNone(self._zone_name_xfrreqdone)
|
|
|
|
- self.xfrsess._reply_xfrout_query = myreply
|
|
|
|
- self.xfrsess._counter_xfrreqdone = None
|
|
|
|
- self.xfrsess.dns_xfrout_start(self.sock, self.mdata)
|
|
|
|
- self.assertIsNone(self._zone_name_xfrreqdone)
|
|
|
|
|
|
+ self.assertGreater(self.get_counter('xfrreqdone'), 0)
|
|
|
|
|
|
def test_dns_xfrout_start_with_notcallable_xfrreqdone(self):
|
|
def test_dns_xfrout_start_with_notcallable_xfrreqdone(self):
|
|
def noerror(msg, name, rrclass):
|
|
def noerror(msg, name, rrclass):
|
|
@@ -1154,10 +1171,20 @@ class TestXfroutSessionWithSQLite3(TestXfroutSessionBase):
|
|
self.assertTrue(rrsets_equal(expected_rr, actual_rr))
|
|
self.assertTrue(rrsets_equal(expected_rr, actual_rr))
|
|
|
|
|
|
def test_axfr_normal_session(self):
|
|
def test_axfr_normal_session(self):
|
|
|
|
+ self.assertEqual(self.get_counter('axfr_started'), 0)
|
|
|
|
+ self.assertEqual(self.get_counter('axfr_ended'), 0)
|
|
|
|
+ self.assertEqual(self.get_counter('ixfr_started'), 0)
|
|
|
|
+ self.assertEqual(self.get_counter('ixfr_ended'), 0)
|
|
XfroutSession._handle(self.xfrsess)
|
|
XfroutSession._handle(self.xfrsess)
|
|
response = self.sock.read_msg(Message.PRESERVE_ORDER);
|
|
response = self.sock.read_msg(Message.PRESERVE_ORDER);
|
|
self.assertEqual(Rcode.NOERROR(), response.get_rcode())
|
|
self.assertEqual(Rcode.NOERROR(), response.get_rcode())
|
|
self.check_axfr_stream(response)
|
|
self.check_axfr_stream(response)
|
|
|
|
+ self.assertEqual(self.xfrsess._request_type, RRType.AXFR())
|
|
|
|
+ self.assertNotEqual(self.xfrsess._request_type, RRType.IXFR())
|
|
|
|
+ self.assertEqual(self.get_counter('axfr_started'), 1)
|
|
|
|
+ self.assertEqual(self.get_counter('axfr_ended'), 1)
|
|
|
|
+ self.assertEqual(self.get_counter('ixfr_started'), 0)
|
|
|
|
+ self.assertEqual(self.get_counter('ixfr_ended'), 0)
|
|
|
|
|
|
def test_ixfr_to_axfr(self):
|
|
def test_ixfr_to_axfr(self):
|
|
self.xfrsess._request_data = \
|
|
self.xfrsess._request_data = \
|
|
@@ -1176,6 +1203,10 @@ class TestXfroutSessionWithSQLite3(TestXfroutSessionBase):
|
|
# two beginning and trailing SOAs.
|
|
# two beginning and trailing SOAs.
|
|
self.xfrsess._request_data = \
|
|
self.xfrsess._request_data = \
|
|
self.create_request_data(ixfr=IXFR_OK_VERSION)
|
|
self.create_request_data(ixfr=IXFR_OK_VERSION)
|
|
|
|
+ self.assertEqual(self.get_counter('axfr_started'), 0)
|
|
|
|
+ self.assertEqual(self.get_counter('axfr_ended'), 0)
|
|
|
|
+ self.assertEqual(self.get_counter('ixfr_started'), 0)
|
|
|
|
+ self.assertEqual(self.get_counter('ixfr_ended'), 0)
|
|
XfroutSession._handle(self.xfrsess)
|
|
XfroutSession._handle(self.xfrsess)
|
|
response = self.sock.read_msg(Message.PRESERVE_ORDER)
|
|
response = self.sock.read_msg(Message.PRESERVE_ORDER)
|
|
actual_records = response.get_section(Message.SECTION_ANSWER)
|
|
actual_records = response.get_section(Message.SECTION_ANSWER)
|
|
@@ -1191,6 +1222,12 @@ class TestXfroutSessionWithSQLite3(TestXfroutSessionBase):
|
|
self.assertEqual(len(expected_records), len(actual_records))
|
|
self.assertEqual(len(expected_records), len(actual_records))
|
|
for (expected_rr, actual_rr) in zip(expected_records, actual_records):
|
|
for (expected_rr, actual_rr) in zip(expected_records, actual_records):
|
|
self.assertTrue(rrsets_equal(expected_rr, actual_rr))
|
|
self.assertTrue(rrsets_equal(expected_rr, actual_rr))
|
|
|
|
+ self.assertNotEqual(self.xfrsess._request_type, RRType.AXFR())
|
|
|
|
+ self.assertEqual(self.xfrsess._request_type, RRType.IXFR())
|
|
|
|
+ self.assertEqual(self.get_counter('axfr_started'), 0)
|
|
|
|
+ self.assertEqual(self.get_counter('axfr_ended'), 0)
|
|
|
|
+ self.assertEqual(self.get_counter('ixfr_started'), 1)
|
|
|
|
+ self.assertEqual(self.get_counter('ixfr_ended'), 1)
|
|
|
|
|
|
def ixfr_soa_only_common_checks(self, request_serial):
|
|
def ixfr_soa_only_common_checks(self, request_serial):
|
|
self.xfrsess._request_data = \
|
|
self.xfrsess._request_data = \
|
|
@@ -1578,9 +1615,9 @@ class MyXfroutServer(XfroutServer):
|
|
|
|
|
|
class TestXfroutCounter(unittest.TestCase):
|
|
class TestXfroutCounter(unittest.TestCase):
|
|
def setUp(self):
|
|
def setUp(self):
|
|
- statistics_spec = \
|
|
|
|
- isc.config.module_spec_from_file(\
|
|
|
|
- xfrout.SPECFILE_LOCATION).get_statistics_spec()
|
|
|
|
|
|
+ self._module_spec = isc.config.module_spec_from_file(\
|
|
|
|
+ xfrout.SPECFILE_LOCATION)
|
|
|
|
+ statistics_spec = self._module_spec.get_statistics_spec()
|
|
self.xfrout_counter = XfroutCounter(statistics_spec)
|
|
self.xfrout_counter = XfroutCounter(statistics_spec)
|
|
self._counters = isc.config.spec_name_list(\
|
|
self._counters = isc.config.spec_name_list(\
|
|
isc.config.find_spec_part(\
|
|
isc.config.find_spec_part(\
|
|
@@ -1591,22 +1628,23 @@ class TestXfroutCounter(unittest.TestCase):
|
|
self._cycle = 10000 # number of counting per thread
|
|
self._cycle = 10000 # number of counting per thread
|
|
|
|
|
|
def test_get_default_statistics_data(self):
|
|
def test_get_default_statistics_data(self):
|
|
- self.assertEqual(self.xfrout_counter._get_default_statistics_data(),
|
|
|
|
- {XfroutCounter.perzone_prefix: {
|
|
|
|
- XfroutCounter.entire_server: \
|
|
|
|
- dict([(cnt, 0) for cnt in self._counters])
|
|
|
|
- }})
|
|
|
|
-
|
|
|
|
- def setup_incrementer(self, incrementer):
|
|
|
|
|
|
+ self.assertTrue(\
|
|
|
|
+ self._module_spec.validate_statistics(\
|
|
|
|
+ True,
|
|
|
|
+ self.xfrout_counter._get_default_statistics_data(),
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ def setup_incrementer(self, incrementer, *args):
|
|
self._started.wait()
|
|
self._started.wait()
|
|
- for i in range(self._cycle): incrementer(TEST_ZONE_NAME_STR)
|
|
|
|
|
|
+ for i in range(self._cycle): incrementer(*args)
|
|
|
|
|
|
- def start_incrementer(self, incrementer):
|
|
|
|
|
|
+ def start_incrementer(self, incrementer, *args):
|
|
threads = []
|
|
threads = []
|
|
for i in range(self._number):
|
|
for i in range(self._number):
|
|
threads.append(threading.Thread(\
|
|
threads.append(threading.Thread(\
|
|
- target=self.setup_incrementer,\
|
|
|
|
- args=(incrementer,)\
|
|
|
|
|
|
+ target=self.setup_incrementer, \
|
|
|
|
+ args=(incrementer,) + args \
|
|
))
|
|
))
|
|
for th in threads: th.start()
|
|
for th in threads: th.start()
|
|
self._started.set()
|
|
self._started.set()
|
|
@@ -1618,24 +1656,61 @@ class TestXfroutCounter(unittest.TestCase):
|
|
'%s/%s/%s' % (XfroutCounter.perzone_prefix,\
|
|
'%s/%s/%s' % (XfroutCounter.perzone_prefix,\
|
|
zone_name, counter_name))
|
|
zone_name, counter_name))
|
|
|
|
|
|
- def test_incrementers(self):
|
|
|
|
|
|
+ def test_incdecrementers(self):
|
|
|
|
+ # for per-zone counters
|
|
result = { XfroutCounter.entire_server: {},
|
|
result = { XfroutCounter.entire_server: {},
|
|
TEST_ZONE_NAME_STR: {} }
|
|
TEST_ZONE_NAME_STR: {} }
|
|
for counter_name in self._counters:
|
|
for counter_name in self._counters:
|
|
- incrementer = getattr(self.xfrout_counter, 'inc_%s' % counter_name)
|
|
|
|
- self.start_incrementer(incrementer)
|
|
|
|
- self.assertEqual(self.get_count(\
|
|
|
|
- TEST_ZONE_NAME_STR, counter_name), \
|
|
|
|
- self._number * self._cycle)
|
|
|
|
- self.assertEqual(self.get_count(\
|
|
|
|
- XfroutCounter.entire_server, counter_name), \
|
|
|
|
- self._number * self._cycle)
|
|
|
|
- result[XfroutCounter.entire_server][counter_name] = \
|
|
|
|
- result[TEST_ZONE_NAME_STR][counter_name] = \
|
|
|
|
- self._number * self._cycle
|
|
|
|
|
|
+ cntrs_xfrss = \
|
|
|
|
+ self.xfrout_counter.get_counters_for_xfroutsession()
|
|
|
|
+ cntrs_notfy = \
|
|
|
|
+ self.xfrout_counter.get_counters_for_notifyout()
|
|
|
|
+ cnt_name = 'counter_%s' % counter_name
|
|
|
|
+ incrementer = None
|
|
|
|
+ if cnt_name in cntrs_xfrss:
|
|
|
|
+ incrementer = cntrs_xfrss[cnt_name]
|
|
|
|
+ else:
|
|
|
|
+ incrementer = cntrs_notfy[cnt_name]
|
|
|
|
+ self.start_incrementer(incrementer, TEST_ZONE_NAME_STR)
|
|
|
|
+ self.assertEqual(self.get_count(\
|
|
|
|
+ TEST_ZONE_NAME_STR, counter_name), \
|
|
|
|
+ self._number * self._cycle)
|
|
|
|
+ self.assertEqual(self.get_count(\
|
|
|
|
+ XfroutCounter.entire_server, counter_name), \
|
|
|
|
+ self._number * self._cycle)
|
|
|
|
+ result[XfroutCounter.entire_server][counter_name] = \
|
|
|
|
+ result[TEST_ZONE_NAME_STR][counter_name] = \
|
|
|
|
+ self._number * self._cycle
|
|
|
|
+ statistics_data = {XfroutCounter.perzone_prefix: result}
|
|
|
|
+
|
|
|
|
+ # for {a|i}xfrrunning counters
|
|
|
|
+ for counter_name in self.xfrout_counter._xfrrunning_names:
|
|
|
|
+ incrementer = \
|
|
|
|
+ dict(self.xfrout_counter.get_counters_for_xfroutsession(), \
|
|
|
|
+ **self.xfrout_counter.get_counters_for_notifyout())\
|
|
|
|
+ ['inc_%s' % counter_name]
|
|
|
|
+ self.start_incrementer(incrementer)
|
|
|
|
+ self.assertEqual(
|
|
|
|
+ self.xfrout_counter.get_statistics()[counter_name],
|
|
|
|
+ self._number * self._cycle
|
|
|
|
+ )
|
|
|
|
+ decrementer = \
|
|
|
|
+ dict(self.xfrout_counter.get_counters_for_xfroutsession(), \
|
|
|
|
+ **self.xfrout_counter.get_counters_for_notifyout())\
|
|
|
|
+ ['dec_%s' % counter_name]
|
|
|
|
+ self.start_incrementer(decrementer)
|
|
|
|
+ self.assertEqual(
|
|
|
|
+ self.xfrout_counter.get_statistics()[counter_name],
|
|
|
|
+ 0)
|
|
|
|
+ statistics_data[counter_name] = 0
|
|
self.assertEqual(
|
|
self.assertEqual(
|
|
self.xfrout_counter.get_statistics(),
|
|
self.xfrout_counter.get_statistics(),
|
|
- {XfroutCounter.perzone_prefix: result})
|
|
|
|
|
|
+ statistics_data)
|
|
|
|
+ self.assertTrue(\
|
|
|
|
+ self._module_spec.validate_statistics(\
|
|
|
|
+ True, statistics_data
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
|
|
def test_add_perzone_counter(self):
|
|
def test_add_perzone_counter(self):
|
|
for counter_name in self._counters:
|
|
for counter_name in self._counters:
|