Commit 8693df3c authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2380] handled and tested some failure cases

parent b3ea9e70
......@@ -67,14 +67,21 @@ class LoadZoneRunner:
str(ex))
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()
try:
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()
return
except Exception as ex:
logger.error(LOADZONE_LOAD_ERROR, self._zone_name,
self._zone_class, ex)
raise ex
def run(self):
try:
......
......@@ -19,3 +19,5 @@
% LOADZONE_ARGUMENT_ERROR Error in command line arguments: %1
% LOADZONE_ZONE_CREATED Zone %1/%2 does not exist in the data source, newly created
% LOADZONE_LOAD_ERROR Failed to load zone %1/%2: %3
PYCOVERAGE_RUN=@PYCOVERAGE_RUN@
PYTESTS = loadzone_test.py
EXTRA_DIST = $(PYTESTS)
EXTRA_DIST += testdata/example.org.zone
EXTRA_DIST += testdata/broken-example.org.zone
# If necessary (rare cases), explicitly specify paths to dynamic libraries
# required by loadable python modules.
......
......@@ -53,7 +53,10 @@ class TestLoadZoneRunner(unittest.TestCase):
self.__runner = LoadZoneRunner(self.__args)
def tearDown(self):
pass
# Delete the used DB file; if some of the tests unexpectedly fail
# unexpectedly in the middle of updating the DB, a lock could stay
# there and would affect the other tests that would otherwise succeed.
os.unlink(WRITE_ZONE_DB_FILE)
def test_init(self):
'''
......@@ -119,6 +122,32 @@ class TestLoadZoneRunner(unittest.TestCase):
self.__runner._do_load()
self.__check_zone_soa(ALT_NEW_SOA_TXT, zone_name=Name('example.com'))
def test_load_fail_badconfig(self):
'''Load attempt fails due to broken datasrc config.'''
self.__common_load_setup()
self.__runner._datasrc_config = "invalid config"
self.__check_zone_soa(ORIG_SOA_TXT)
self.assertRaises(isc.datasrc.Error, self.__runner._do_load)
self.__check_zone_soa(ORIG_SOA_TXT) # no change to the zone
def test_load_fail_badzone(self):
'''Load attempt fails due to broken zone file.'''
self.__common_load_setup()
self.__runner._zone_file = \
LOCAL_TESTDATA_PATH + '/broken-example.org.zone'
self.__check_zone_soa(ORIG_SOA_TXT)
self.assertRaises(isc.datasrc.MasterFileError, self.__runner._do_load)
self.__check_zone_soa(ORIG_SOA_TXT)
def test_load_fail_noloader(self):
'''Load attempt fails because loading isn't supported'''
self.__common_load_setup()
self.__runner._datasrc_type = 'memory'
self.__runner._datasrc_config = '{"type": "memory"}'
self.__check_zone_soa(ORIG_SOA_TXT)
self.assertRaises(isc.datasrc.NotImplemented, self.__runner._do_load)
self.__check_zone_soa(ORIG_SOA_TXT)
if __name__== "__main__":
isc.log.resetUnitTestRootLogger()
unittest.main()
example.org. 3600 IN SOA (
ns.example.org.
admin.example.org.
1235
3600 ;1H
1800 ;30M
2419200
7200)
example.org. 3600 IN NS ns.example.org.
ns.example.org. 3600 IN A 192.0.2.1
bad..name.example.org. 3600 IN AAAA 2001:db8::1
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