|
@@ -0,0 +1,117 @@
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import isc.log
|
|
|
|
+import unittest
|
|
|
|
+from isc.dns import *
|
|
|
|
+from isc.datasrc import DataSourceClient
|
|
|
|
+from isc.ddns.zone_config import *
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+TEST_ZONE_NAME = Name('example.org')
|
|
|
|
+TEST_SECONDARY_ZONE_NAME = Name('example.com')
|
|
|
|
+TEST_RRCLASS = RRClass.IN()
|
|
|
|
+
|
|
|
|
+class FakeDataSourceClient:
|
|
|
|
+ '''Faked data source client used in the ZoneConfigTest.
|
|
|
|
+
|
|
|
|
+ It emulates isc.datasrc.DataSourceClient, but only has to provide
|
|
|
|
+ the find_zone() interface (and only the first element of the return
|
|
|
|
+ value matters). By default it returns 'SUCCESS' (exact match) for
|
|
|
|
+ any input. It can be dynamically customized via the set_find_result()
|
|
|
|
+ method.
|
|
|
|
+
|
|
|
|
+ '''
|
|
|
|
+ def __init__(self):
|
|
|
|
+ self.__find_result = DataSourceClient.SUCCESS
|
|
|
|
+
|
|
|
|
+ def find_zone(self, zname):
|
|
|
|
+ return (self.__find_result, None)
|
|
|
|
+
|
|
|
|
+ def set_find_result(self, result):
|
|
|
|
+ self.__find_result = result
|
|
|
|
+
|
|
|
|
+class ZoneConfigTest(unittest.TestCase):
|
|
|
|
+ '''Some basic tests for the ZoneConfig class.'''
|
|
|
|
+ def setUp(self):
|
|
|
|
+ self.__datasrc_client = FakeDataSourceClient()
|
|
|
|
+ self.zconfig = ZoneConfig([(TEST_SECONDARY_ZONE_NAME, TEST_RRCLASS)],
|
|
|
|
+ TEST_RRCLASS, self.__datasrc_client)
|
|
|
|
+
|
|
|
|
+ def test_find_zone(self):
|
|
|
|
+
|
|
|
|
+ self.assertEqual((ZONE_PRIMARY, self.__datasrc_client),
|
|
|
|
+ (self.zconfig.find_zone(TEST_ZONE_NAME, TEST_RRCLASS)))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ self.assertEqual((ZONE_SECONDARY, None),
|
|
|
|
+ (self.zconfig.find_zone(TEST_SECONDARY_ZONE_NAME,
|
|
|
|
+ TEST_RRCLASS)))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ self.__datasrc_client.set_find_result(DataSourceClient.NOTFOUND)
|
|
|
|
+ self.assertEqual((ZONE_NOTFOUND, None),
|
|
|
|
+ (self.zconfig.find_zone(Name('example'),
|
|
|
|
+ TEST_RRCLASS)))
|
|
|
|
+
|
|
|
|
+ self.__datasrc_client.set_find_result(DataSourceClient.PARTIALMATCH)
|
|
|
|
+ self.assertEqual((ZONE_NOTFOUND, None),
|
|
|
|
+ (self.zconfig.find_zone(Name('example'),
|
|
|
|
+ TEST_RRCLASS)))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ self.__datasrc_client.set_find_result(DataSourceClient.NOTFOUND)
|
|
|
|
+ self.assertEqual((ZONE_NOTFOUND, None),
|
|
|
|
+ (self.zconfig.find_zone(TEST_ZONE_NAME,
|
|
|
|
+ TEST_RRCLASS)))
|
|
|
|
+
|
|
|
|
+ self.__datasrc_client.set_find_result(DataSourceClient.SUCCESS)
|
|
|
|
+ zconfig = ZoneConfig([(TEST_SECONDARY_ZONE_NAME, TEST_RRCLASS)],
|
|
|
|
+ RRClass.CH(), self.__datasrc_client)
|
|
|
|
+ self.assertEqual((ZONE_NOTFOUND, None),
|
|
|
|
+ (zconfig.find_zone(TEST_ZONE_NAME, TEST_RRCLASS)))
|
|
|
|
+
|
|
|
|
+ zconfig = ZoneConfig([(TEST_ZONE_NAME, TEST_RRCLASS)],
|
|
|
|
+ RRClass.CH(), self.__datasrc_client)
|
|
|
|
+ self.assertEqual((ZONE_NOTFOUND, None),
|
|
|
|
+ (zconfig.find_zone(TEST_ZONE_NAME, TEST_RRCLASS)))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ zconfig = ZoneConfig([], TEST_RRCLASS, self.__datasrc_client)
|
|
|
|
+ self.assertEqual((ZONE_PRIMARY, self.__datasrc_client),
|
|
|
|
+ (self.zconfig.find_zone(TEST_ZONE_NAME, TEST_RRCLASS)))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ zconfig = ZoneConfig([(TEST_SECONDARY_ZONE_NAME, TEST_RRCLASS),
|
|
|
|
+ (Name('example'), TEST_RRCLASS),
|
|
|
|
+ (Name('sub.example.org'), TEST_RRCLASS),
|
|
|
|
+ (TEST_ZONE_NAME, RRClass.CH())],
|
|
|
|
+ TEST_RRCLASS, self.__datasrc_client)
|
|
|
|
+ self.assertEqual((ZONE_PRIMARY, self.__datasrc_client),
|
|
|
|
+ (self.zconfig.find_zone(TEST_ZONE_NAME, TEST_RRCLASS)))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ zconfig = ZoneConfig([(TEST_SECONDARY_ZONE_NAME, TEST_RRCLASS),
|
|
|
|
+ (TEST_SECONDARY_ZONE_NAME, TEST_RRCLASS)],
|
|
|
|
+ TEST_RRCLASS, self.__datasrc_client)
|
|
|
|
+ self.assertEqual((ZONE_PRIMARY, self.__datasrc_client),
|
|
|
|
+ (self.zconfig.find_zone(TEST_ZONE_NAME, TEST_RRCLASS)))
|
|
|
|
+
|
|
|
|
+if __name__ == "__main__":
|
|
|
|
+ isc.log.init("bind10")
|
|
|
|
+ isc.log.resetUnitTestRootLogger()
|
|
|
|
+ unittest.main()
|