Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
8693df3c
Commit
8693df3c
authored
Dec 13, 2012
by
JINMEI Tatuya
Browse files
[2380] handled and tested some failure cases
parent
b3ea9e70
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/bin/loadzone/loadzone.py.in
View file @
8693df3c
...
...
@@ -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:
...
...
src/bin/loadzone/loadzone_messages.mes
View file @
8693df3c
...
...
@@ -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
src/bin/loadzone/tests/Makefile.am
View file @
8693df3c
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.
...
...
src/bin/loadzone/tests/loadzone_test.py
View file @
8693df3c
...
...
@@ -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
()
src/bin/loadzone/tests/testdata/broken-example.org.zone
0 → 100644
View file @
8693df3c
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment