Commit 9e2d7b9b authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2380] some more option handling

parent c4af7dce
......@@ -50,8 +50,9 @@ the zone in. Example:
parser.add_option("-t", "--datasrc-type", dest="datasrc_type",
action="store", default='sqlite3',
help="type of data source (e.g., 'sqlite3')")
parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
help="display more about what is going on")
parser.add_option("-C", "--class", dest="zone_class", action="store",
default='IN',
help="RR class of the zone; currently must be 'IN'")
class LoadZoneRunner:
'''TBD
......@@ -78,6 +79,13 @@ class LoadZoneRunner:
raise BadArgument('data source config option cannot be omitted')
self._datasrc_config = options.conf
self._datasrc_type = options.datasrc_type
try:
self._zone_class = RRClass(options.zone_class)
except isc.dns.InvalidRRClass as ex:
raise BadArgument('Invalid zone class: ' + str(ex))
if self._zone_class != RRClass.IN():
raise BadArgument("RR class is not supported: " +
str(self._zone_class))
if len(args) != 2:
raise BadArgument('Unexpected number of arguments: %d (must be 2)'
......
......@@ -72,6 +72,7 @@ class TestLoadZoneRunner(unittest.TestCase):
self.assertEqual('example.zone', self.__runner._zone_file)
self.assertEqual(DATASRC_CONFIG, self.__runner._datasrc_config)
self.assertEqual('sqlite3', self.__runner._datasrc_type) # default
self.assertEqual(RRClass.IN(), self.__runner._zone_class) # default
def test_parse_bad_args(self):
# -c cannot be omitted (right now)
......@@ -92,6 +93,15 @@ class TestLoadZoneRunner(unittest.TestCase):
LoadZoneRunner(copt + ['bad..name', 'example.zone']).
_parse_args)
# Bad class name
self.assertRaises(BadArgument,
LoadZoneRunner(copt + ['-C', 'badclass']).
_parse_args)
# Unsupported class
self.assertRaises(BadArgument,
LoadZoneRunner(copt + ['-C', 'CH']).
_parse_args)
def __common_load_setup(self):
self.__runner._zone_class = RRClass.IN()
self.__runner._zone_name = TEST_ZONE_NAME
......
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