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

[2380] supported the case of creating a new zone and then loading

parent a8ac0d40
......@@ -69,6 +69,10 @@ class LoadZoneRunner:
def _do_load(self):
datasrc_client = DataSourceClient(self._datasrc_type,
self._datasrc_config)
created = datasrc_client.create_zone(self._zone_name)
if created:
logger.info(LOADZONE_ZONE_CREATED, self._zone_name,
self._zone_class)
loader = ZoneLoader(datasrc_client, self._zone_name, self._zone_file)
loader.load()
......
......@@ -17,3 +17,5 @@
# messages are in the correct order.
% LOADZONE_ARGUMENT_ERROR Error in command line arguments: %1
% LOADZONE_ZONE_CREATED Zone %1/%2 does not exist in the data source, newly created
......@@ -29,6 +29,7 @@ READ_ZONE_DB_FILE = TESTDATA_PATH + "rwtest.sqlite3" # original, to be copied
LOCAL_TESTDATA_PATH = os.environ['LOCAL_TESTDATA_PATH'] + os.sep
READ_ZONE_DB_FILE = TESTDATA_PATH + "rwtest.sqlite3" # original, to be copied
NEW_ZONE_TXT_FILE = LOCAL_TESTDATA_PATH + "example.org.zone"
ALT_NEW_ZONE_TXT_FILE = TESTDATA_PATH + "example.com.zone"
TESTDATA_WRITE_PATH = os.environ['TESTDATA_WRITE_PATH'] + os.sep
WRITE_ZONE_DB_FILE = TESTDATA_WRITE_PATH + "rwtest.sqlite3.copied"
TEST_ZONE_NAME = Name('example.org')
......@@ -39,6 +40,9 @@ ORIG_SOA_TXT = 'example.org. 3600 IN SOA ns1.example.org. ' +\
'admin.example.org. 1234 3600 1800 2419200 7200\n'
NEW_SOA_TXT = 'example.org. 3600 IN SOA ns.example.org. ' +\
'admin.example.org. 1235 3600 1800 2419200 7200\n'
# This is the brandnew SOA for a newly created zone
ALT_NEW_SOA_TXT = 'example.com. 3600 IN SOA ns.example.com. ' +\
'admin.example.com. 1234 3600 1800 2419200 7200\n'
class TestLoadZoneRunner(unittest.TestCase):
def setUp(self):
......@@ -75,26 +79,45 @@ class TestLoadZoneRunner(unittest.TestCase):
LoadZoneRunner(['bad..name', 'example.zone']).
_parse_args)
def check_zone_soa(self, soa_txt):
"Check that the given SOA RR exists and matches the expected string"
def __common_load_setup(self):
self.__runner._zone_class = RRClass.IN()
self.__runner._zone_name = TEST_ZONE_NAME
self.__runner._zone_file = NEW_ZONE_TXT_FILE
self.__runner._datasrc_type = 'sqlite3'
self.__runner._datasrc_config = DATASRC_CONFIG
def __check_zone_soa(self, soa_txt, zone_name=TEST_ZONE_NAME):
"""Check that the given SOA RR exists and matches the expected string
If soa_txt is None, the zone is expected to be non-existent.
"""
client = DataSourceClient('sqlite3', DATASRC_CONFIG)
result, finder = client.find_zone(TEST_ZONE_NAME)
result, finder = client.find_zone(zone_name)
if soa_txt is None:
self.assertEqual(client.NOTFOUND, result)
return
self.assertEqual(client.SUCCESS, result)
result, rrset, _ = finder.find(TEST_ZONE_NAME, RRType.SOA())
result, rrset, _ = finder.find(zone_name, RRType.SOA())
self.assertEqual(finder.SUCCESS, result)
self.assertEqual(soa_txt, rrset.to_text())
def test_load_update(self):
'''successful case to loading new contents to an existing zone.'''
self.__runner._zone_class = RRClass.IN()
self.__runner._zone_name = TEST_ZONE_NAME
self.__runner._zone_file = NEW_ZONE_TXT_FILE
self.__runner._datasrc_type = 'sqlite3'
self.__runner._datasrc_config = DATASRC_CONFIG
self.check_zone_soa(ORIG_SOA_TXT)
self.__common_load_setup()
self.__check_zone_soa(ORIG_SOA_TXT)
self.__runner._do_load()
self.__check_zone_soa(NEW_SOA_TXT)
def test_create_and_load(self):
'''successful case to loading contents to a new zone (created).'''
self.__common_load_setup()
self.__runner._zone_name = Name('example.com')
self.__runner._zone_file = ALT_NEW_ZONE_TXT_FILE
self.__check_zone_soa(None, zone_name=Name('example.com'))
self.__runner._do_load()
self.check_zone_soa(NEW_SOA_TXT)
self.__check_zone_soa(ALT_NEW_SOA_TXT, zone_name=Name('example.com'))
if __name__== "__main__":
isc.log.resetUnitTestRootLogger()
......
Markdown is supported
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