mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-03 07:25:18 +00:00
[trac811] some more comments
added tests for get_default_value() in ConfigData removed the now unnecessary self.name_str in ZoneInfo downcase Name objects for storage in internal zones dict
This commit is contained in:
@@ -604,6 +604,28 @@ class TestXfrin(unittest.TestCase):
|
|||||||
self.assertEqual(int(TEST_MASTER_PORT),
|
self.assertEqual(int(TEST_MASTER_PORT),
|
||||||
self.xfr.xfrin_started_master_port)
|
self.xfr.xfrin_started_master_port)
|
||||||
|
|
||||||
|
def test_command_handler_retransfer_short_command4(self):
|
||||||
|
# try it when only specifying the zone name (of known zone, with
|
||||||
|
# different case)
|
||||||
|
short_args = {}
|
||||||
|
|
||||||
|
# swap the case of the zone name in our command
|
||||||
|
short_args['zone_name'] = TEST_ZONE_NAME_STR.swapcase()
|
||||||
|
|
||||||
|
zones = { 'zones': [
|
||||||
|
{ 'name': TEST_ZONE_NAME_STR,
|
||||||
|
'master_addr': TEST_MASTER_IPV4_ADDRESS,
|
||||||
|
'master_port': TEST_MASTER_PORT
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
self.xfr.config_handler(zones)
|
||||||
|
self.assertEqual(self.xfr.command_handler("retransfer",
|
||||||
|
short_args)['result'][0], 0)
|
||||||
|
self.assertEqual(TEST_MASTER_IPV4_ADDRESS,
|
||||||
|
self.xfr.xfrin_started_master_addr)
|
||||||
|
self.assertEqual(int(TEST_MASTER_PORT),
|
||||||
|
self.xfr.xfrin_started_master_port)
|
||||||
|
|
||||||
def test_command_handler_retransfer_badcommand(self):
|
def test_command_handler_retransfer_badcommand(self):
|
||||||
self.args['master'] = 'invalid'
|
self.args['master'] = 'invalid'
|
||||||
self.assertEqual(self.xfr.command_handler("retransfer",
|
self.assertEqual(self.xfr.command_handler("retransfer",
|
||||||
@@ -702,17 +724,17 @@ class TestXfrin(unittest.TestCase):
|
|||||||
self.assertIsNone(zone_info.tsig_key)
|
self.assertIsNone(zone_info.tsig_key)
|
||||||
|
|
||||||
def test_command_handler_zones(self):
|
def test_command_handler_zones(self):
|
||||||
zones1 = { 'transfers_in': 3,
|
config1 = { 'transfers_in': 3,
|
||||||
'zones': [
|
'zones': [
|
||||||
{ 'name': 'test.example.',
|
{ 'name': 'test.example.',
|
||||||
'master_addr': '192.0.2.1',
|
'master_addr': '192.0.2.1',
|
||||||
'master_port': 53
|
'master_port': 53
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
self.assertEqual(self.xfr.config_handler(zones1)['result'][0], 0)
|
self.assertEqual(self.xfr.config_handler(config1)['result'][0], 0)
|
||||||
self._check_zones_config(zones1)
|
self._check_zones_config(config1)
|
||||||
|
|
||||||
zones2 = { 'transfers_in': 4,
|
config2 = { 'transfers_in': 4,
|
||||||
'zones': [
|
'zones': [
|
||||||
{ 'name': 'test.example.',
|
{ 'name': 'test.example.',
|
||||||
'master_addr': '192.0.2.2',
|
'master_addr': '192.0.2.2',
|
||||||
@@ -720,8 +742,8 @@ class TestXfrin(unittest.TestCase):
|
|||||||
'tsig_key': "example.com:SFuWd/q99SzF8Yzd1QbB9g=="
|
'tsig_key': "example.com:SFuWd/q99SzF8Yzd1QbB9g=="
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
self.assertEqual(self.xfr.config_handler(zones2)['result'][0], 0)
|
self.assertEqual(self.xfr.config_handler(config2)['result'][0], 0)
|
||||||
self._check_zones_config(zones2)
|
self._check_zones_config(config2)
|
||||||
|
|
||||||
# test that configuring the zone multiple times fails
|
# test that configuring the zone multiple times fails
|
||||||
zones = { 'transfers_in': 5,
|
zones = { 'transfers_in': 5,
|
||||||
@@ -737,7 +759,7 @@ class TestXfrin(unittest.TestCase):
|
|||||||
]}
|
]}
|
||||||
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
||||||
# since this has failed, we should still have the previous config
|
# since this has failed, we should still have the previous config
|
||||||
self._check_zones_config(zones2)
|
self._check_zones_config(config2)
|
||||||
|
|
||||||
zones = { 'zones': [
|
zones = { 'zones': [
|
||||||
{ 'name': 'test.example.',
|
{ 'name': 'test.example.',
|
||||||
@@ -747,7 +769,7 @@ class TestXfrin(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
||||||
self._check_zones_config(zones2)
|
self._check_zones_config(config2)
|
||||||
|
|
||||||
zones = { 'zones': [
|
zones = { 'zones': [
|
||||||
{ 'master_addr': '192.0.2.4',
|
{ 'master_addr': '192.0.2.4',
|
||||||
@@ -756,7 +778,7 @@ class TestXfrin(unittest.TestCase):
|
|||||||
]}
|
]}
|
||||||
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
||||||
# since this has failed, we should still have the previous config
|
# since this has failed, we should still have the previous config
|
||||||
self._check_zones_config(zones2)
|
self._check_zones_config(config2)
|
||||||
|
|
||||||
zones = { 'zones': [
|
zones = { 'zones': [
|
||||||
{ 'name': 'bad..zone.',
|
{ 'name': 'bad..zone.',
|
||||||
@@ -766,7 +788,7 @@ class TestXfrin(unittest.TestCase):
|
|||||||
]}
|
]}
|
||||||
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
||||||
# since this has failed, we should still have the previous config
|
# since this has failed, we should still have the previous config
|
||||||
self._check_zones_config(zones2)
|
self._check_zones_config(config2)
|
||||||
|
|
||||||
zones = { 'zones': [
|
zones = { 'zones': [
|
||||||
{ 'name': '',
|
{ 'name': '',
|
||||||
@@ -776,7 +798,7 @@ class TestXfrin(unittest.TestCase):
|
|||||||
]}
|
]}
|
||||||
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
||||||
# since this has failed, we should still have the previous config
|
# since this has failed, we should still have the previous config
|
||||||
self._check_zones_config(zones2)
|
self._check_zones_config(config2)
|
||||||
|
|
||||||
zones = { 'zones': [
|
zones = { 'zones': [
|
||||||
{ 'name': 'test.example',
|
{ 'name': 'test.example',
|
||||||
@@ -786,7 +808,7 @@ class TestXfrin(unittest.TestCase):
|
|||||||
]}
|
]}
|
||||||
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
||||||
# since this has failed, we should still have the previous config
|
# since this has failed, we should still have the previous config
|
||||||
self._check_zones_config(zones2)
|
self._check_zones_config(config2)
|
||||||
|
|
||||||
zones = { 'zones': [
|
zones = { 'zones': [
|
||||||
{ 'name': 'test.example',
|
{ 'name': 'test.example',
|
||||||
@@ -796,7 +818,7 @@ class TestXfrin(unittest.TestCase):
|
|||||||
]}
|
]}
|
||||||
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
||||||
# since this has failed, we should still have the previous config
|
# since this has failed, we should still have the previous config
|
||||||
self._check_zones_config(zones2)
|
self._check_zones_config(config2)
|
||||||
|
|
||||||
zones = { 'zones': [
|
zones = { 'zones': [
|
||||||
{ 'name': 'test.example',
|
{ 'name': 'test.example',
|
||||||
@@ -808,7 +830,7 @@ class TestXfrin(unittest.TestCase):
|
|||||||
]}
|
]}
|
||||||
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
||||||
# since this has failed, we should still have the previous config
|
# since this has failed, we should still have the previous config
|
||||||
self._check_zones_config(zones2)
|
self._check_zones_config(config2)
|
||||||
|
|
||||||
# let's also add a zone that is correct too, and make sure
|
# let's also add a zone that is correct too, and make sure
|
||||||
# that the new config is not partially taken
|
# that the new config is not partially taken
|
||||||
@@ -825,7 +847,7 @@ class TestXfrin(unittest.TestCase):
|
|||||||
]}
|
]}
|
||||||
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
self.assertEqual(self.xfr.config_handler(zones)['result'][0], 1)
|
||||||
# since this has failed, we should still have the previous config
|
# since this has failed, we should still have the previous config
|
||||||
self._check_zones_config(zones2)
|
self._check_zones_config(config2)
|
||||||
|
|
||||||
|
|
||||||
def raise_interrupt():
|
def raise_interrupt():
|
||||||
|
@@ -77,8 +77,8 @@ class XfrinException(Exception):
|
|||||||
|
|
||||||
class XfrinZoneInfoException(Exception):
|
class XfrinZoneInfoException(Exception):
|
||||||
"""This exception is raised if there is an error in the given
|
"""This exception is raised if there is an error in the given
|
||||||
configuration (part), or when a command does not have the
|
configuration (part), or when a command does not have a required
|
||||||
required or bad arguments, for instance when the zone's master
|
argument or has bad arguments, for instance when the zone's master
|
||||||
address is not a valid IP address, when the zone does not
|
address is not a valid IP address, when the zone does not
|
||||||
have a name, or when multiple settings are given for the same
|
have a name, or when multiple settings are given for the same
|
||||||
zone."""
|
zone."""
|
||||||
@@ -88,7 +88,12 @@ def _check_zone_name(zone_name_str):
|
|||||||
"""Checks if the given zone name is a valid domain name, and returns
|
"""Checks if the given zone name is a valid domain name, and returns
|
||||||
it as a Name object. Raises an XfrinException if it is not."""
|
it as a Name object. Raises an XfrinException if it is not."""
|
||||||
try:
|
try:
|
||||||
return Name(zone_name_str)
|
# In the _zones dict, part of the key is the zone name,
|
||||||
|
# but due to a limitation in the Name class, we
|
||||||
|
# cannot directly use it as a dict key, and we use to_text()
|
||||||
|
#
|
||||||
|
# Downcase the name here for that reason.
|
||||||
|
return Name(zone_name_str, True)
|
||||||
except (EmptyLabel, TooLongLabel, BadLabelType, BadEscape,
|
except (EmptyLabel, TooLongLabel, BadLabelType, BadEscape,
|
||||||
TooLongName, IncompleteName) as ne:
|
TooLongName, IncompleteName) as ne:
|
||||||
raise XfrinZoneInfoException("bad zone name: " + zone_name_str + " (" + str(ne) + ")")
|
raise XfrinZoneInfoException("bad zone name: " + zone_name_str + " (" + str(ne) + ")")
|
||||||
@@ -430,8 +435,6 @@ class ZoneInfo:
|
|||||||
"""Set the name for this zone given a name string.
|
"""Set the name for this zone given a name string.
|
||||||
Raises XfrinZoneInfoException if name_str is None or if it
|
Raises XfrinZoneInfoException if name_str is None or if it
|
||||||
cannot be parsed."""
|
cannot be parsed."""
|
||||||
#TODO: remove name_str
|
|
||||||
self.name_str = name_str
|
|
||||||
if name_str is None:
|
if name_str is None:
|
||||||
raise XfrinZoneInfoException("Configuration zones list "
|
raise XfrinZoneInfoException("Configuration zones list "
|
||||||
"element does not contain "
|
"element does not contain "
|
||||||
|
@@ -237,6 +237,26 @@ class TestConfigData(unittest.TestCase):
|
|||||||
self.assertEqual(None, value)
|
self.assertEqual(None, value)
|
||||||
self.assertEqual(False, default)
|
self.assertEqual(False, default)
|
||||||
|
|
||||||
|
def test_get_default_value(self):
|
||||||
|
self.assertEqual(1, self.cd.get_default_value("item1"))
|
||||||
|
self.assertEqual('default', self.cd.get_default_value("item6/value1"))
|
||||||
|
|
||||||
|
# set some local values to something else, and see if we
|
||||||
|
# still get the default
|
||||||
|
self.cd.set_local_config({"item1": 2, "item6": { "value1": "asdf" } })
|
||||||
|
|
||||||
|
self.assertEqual((2, False), self.cd.get_value("item1"))
|
||||||
|
self.assertEqual(1, self.cd.get_default_value("item1"))
|
||||||
|
self.assertEqual(('asdf', False), self.cd.get_value("item6/value1"))
|
||||||
|
self.assertEqual('default', self.cd.get_default_value("item6/value1"))
|
||||||
|
|
||||||
|
self.assertRaises(isc.cc.data.DataNotFoundError,
|
||||||
|
self.cd.get_default_value,
|
||||||
|
"does_not_exist/value1")
|
||||||
|
self.assertRaises(isc.cc.data.DataNotFoundError,
|
||||||
|
self.cd.get_default_value,
|
||||||
|
"item6/doesnotexist")
|
||||||
|
|
||||||
def test_set_local_config(self):
|
def test_set_local_config(self):
|
||||||
self.cd.set_local_config({"item1": 2})
|
self.cd.set_local_config({"item1": 2})
|
||||||
value, default = self.cd.get_value("item1")
|
value, default = self.cd.get_value("item1")
|
||||||
|
Reference in New Issue
Block a user