BIND 10 trac2254, updated. 362430efc09897c1e7d7bdf2bf7b4cffd9fd2e3b [2254] cleanup and a few more comments
BIND 10 source code commits
bind10-changes at lists.isc.org
Sun Sep 30 11:24:50 UTC 2012
The branch, trac2254 has been updated
via 362430efc09897c1e7d7bdf2bf7b4cffd9fd2e3b (commit)
via dfa822ebc063f5ae636e55e4f999bce3096483e1 (commit)
via 26cd9b7104c48ecce553cab9c8e7de6f57c8e88f (commit)
via 971e8bc5f615ebf009a4b1a60998151054ca34a5 (commit)
from 9b730d026d634dbefdc50eea9d63df77201e30f4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 362430efc09897c1e7d7bdf2bf7b4cffd9fd2e3b
Author: Jelte Jansen <jelte at isc.org>
Date: Sun Sep 30 13:22:17 2012 +0200
[2254] cleanup and a few more comments
commit dfa822ebc063f5ae636e55e4f999bce3096483e1
Author: Jelte Jansen <jelte at isc.org>
Date: Sun Sep 30 12:56:36 2012 +0200
[2254] expand _get_list_items comments more
commit 26cd9b7104c48ecce553cab9c8e7de6f57c8e88f
Author: Jelte Jansen <jelte at isc.org>
Date: Sun Sep 30 12:48:40 2012 +0200
[2254] Add more docstring to _get_list_items
commit 971e8bc5f615ebf009a4b1a60998151054ca34a5
Author: Jelte Jansen <jelte at isc.org>
Date: Sun Sep 30 12:31:31 2012 +0200
[2254] direct test for find_spec_part change
-----------------------------------------------------------------------
Summary of changes:
src/lib/python/isc/config/config_data.py | 56 +++++++++++++++++-
.../python/isc/config/tests/config_data_test.py | 60 +++++++++++++++++---
2 files changed, 104 insertions(+), 12 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/python/isc/config/config_data.py b/src/lib/python/isc/config/config_data.py
index 654bdd7..7fde0ea 100644
--- a/src/lib/python/isc/config/config_data.py
+++ b/src/lib/python/isc/config/config_data.py
@@ -799,24 +799,74 @@ class MultiConfigData:
indices and named_set names to the completion list. If
the given item_name is for a list or named_set, it'll
return a list of those (appended to item_name), otherwise
- the list will only contain the item_name itself."""
+ the list will only contain the item_name itself.
+
+ If the item is a named set, and it's contents are maps
+ or named_sets as well, a / is appended to the result
+ strings.
+
+ If the item is a list, this method is then called recursively
+ for each list entry.
+
+ This behaviour is slightly arbitrary, and currently reflects
+ the most probable way the resulting data should look like;
+ for lists, bindctl would always expect their contents to
+ be added as well. For named_sets, however, we do not
+ do recursion, since the resulting list may be too long.
+ This will probably change in a revision of the way this
+ data is handled; ideally, the result should always recurse,
+ but only up to a limited depth, and the resulting list
+ should probably be paginated clientside.
+
+ Parameters:
+ item_name (string): the (full) identifier for the list or
+ named_set to enumerate.
+
+ Returns a list of strings with item names
+
+ Examples:
+ _get_list_items("Module/some_item")
+ where item is not a list of a named_set, or where
+ said list or named set is empty, returns
+ ["Module/some_item"]
+ _get_list_items("Module/named_set")
+ where the named_set contains items with names 'a'
+ and 'b', returns
+ [ "Module/named_set/a", "Module/named_set/b" ]
+ _get_list_items("Module/named_set_of_maps")
+ where the named_set contains items with names 'a'
+ and 'b', and those items are maps themselves
+ (or other named_sets), returns
+ [ "Module/named_set/a/", "Module/named_set/b/" ]
+ _get_list_items("Module/list")
+ where the list contains 2 elements, returns
+ [ "Module/list[0]", "Module/list[1]" ]
+ _get_list_items("Module/list")
+ where the list contains 2 elements, returns
+ [ "Module/list[0]", "Module/list[1]" ]
+ """
spec_part = self.find_spec_part(item_name)
if spec_part_is_named_set(spec_part):
- values, status = self.get_value(item_name)
+ values, _ = self.get_value(item_name)
if values is not None and len(values) > 0:
subslash = ""
if spec_part['named_set_item_spec']['item_type'] == 'map' or\
spec_part['named_set_item_spec']['item_type'] == 'named_set':
subslash = "/"
+ # Don't recurse for named_sets (so as not to return too
+ # much data), but do add a / so the client so that
+ # the user can immediately tab-complete further if needed.
return [ item_name + "/" + v + subslash for v in values.keys() ]
else:
return [ item_name ]
elif spec_part_is_list(spec_part):
- values, status = self.get_value(item_name)
+ values, _ = self.get_value(item_name)
if values is not None and len(values) > 0:
result = []
for i in range(len(values)):
name = item_name + '[%d]' % i
+ # Recurse for list entries, so that its sub-contents
+ # are also added to the result
result.extend(self._get_list_items(name))
return result
else:
diff --git a/src/lib/python/isc/config/tests/config_data_test.py b/src/lib/python/isc/config/tests/config_data_test.py
index 1a5c92f..e8a77af 100644
--- a/src/lib/python/isc/config/tests/config_data_test.py
+++ b/src/lib/python/isc/config/tests/config_data_test.py
@@ -389,12 +389,37 @@ class TestMultiConfigData(unittest.TestCase):
self.assertEqual(None, spec_part)
spec_part = self.mcd.find_spec_part("/Spec2/item1")
self.assertEqual(None, spec_part)
- module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec2.spec")
+ module_spec = isc.config.module_spec_from_file(self.data_path +
+ os.sep + "spec2.spec")
self.mcd.set_specification(module_spec)
spec_part = self.mcd.find_spec_part("Spec2/item1")
- self.assertEqual({'item_name': 'item1', 'item_type': 'integer', 'item_optional': False, 'item_default': 1, }, spec_part)
+ self.assertEqual({'item_name': 'item1', 'item_type': 'integer',
+ 'item_optional': False, 'item_default': 1, },
+ spec_part)
+
+ # For lists, either the spec of the list itself, or the
+ # spec for the list contents should be returned (the
+ # latter when an index is given in the identifier)
+ spec_part = self.mcd.find_spec_part("Spec2/item5")
+ self.assertEqual({'item_default': ['a', 'b'],
+ 'item_name': 'item5',
+ 'item_optional': False,
+ 'item_type': 'list',
+ 'list_item_spec': {'item_default': '',
+ 'item_name': 'list_element',
+ 'item_optional': False,
+ 'item_type': 'string'}},
+ spec_part)
+ spec_part = self.mcd.find_spec_part("Spec2/item5[0]")
+ self.assertEqual({'item_default': '',
+ 'item_name': 'list_element',
+ 'item_optional': False,
+ 'item_type': 'string'},
+ spec_part)
+
def test_find_spec_part_nested(self):
+ # Check that find_spec_part works for nested lists
module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec30.spec")
self.mcd.set_specification(module_spec)
spec_part = self.mcd.find_spec_part("/lists/first_list_items[0]/second_list_items[1]/final_element")
@@ -403,6 +428,7 @@ class TestMultiConfigData(unittest.TestCase):
self.assertEqual(None, spec_part)
def test_find_spec_part_nested2(self):
+ # Check that find_spec_part works for nested lists and maps
module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec31.spec")
self.mcd.set_specification(module_spec)
spec_part = self.mcd.find_spec_part("/lists/first_list_items[0]/second_list_items[1]/map_element/list1[1]/list2[2]")
@@ -650,7 +676,7 @@ class TestMultiConfigData(unittest.TestCase):
self.assertEqual(expected, maps)
# A slash at the end should not produce different output with
- # indices too
+ # indices either
expected2 = [{'default': True,
'type': 'integer',
'name': 'Spec22/value5[1]',
@@ -732,6 +758,8 @@ class TestMultiConfigData(unittest.TestCase):
self.assertRaises(isc.cc.data.DataNotFoundError, self.mcd.unset, "Spec2/doesnotexist")
def test_get_config_item_list(self):
+ # Test get_config_item_list(), which returns a list of the config
+ # items in a specification.
config_items = self.mcd.get_config_item_list()
self.assertEqual([], config_items)
module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec2.spec")
@@ -741,20 +769,34 @@ class TestMultiConfigData(unittest.TestCase):
config_items = self.mcd.get_config_item_list(None, False)
self.assertEqual(['Spec2'], config_items)
config_items = self.mcd.get_config_item_list(None, True)
- self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3', 'Spec2/item4', 'Spec2/item5', 'Spec2/item6/value1', 'Spec2/item6/value2'], config_items)
+ self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3',
+ 'Spec2/item4', 'Spec2/item5', 'Spec2/item6/value1',
+ 'Spec2/item6/value2'], config_items)
config_items = self.mcd.get_config_item_list("Spec2", True)
- self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3', 'Spec2/item4', 'Spec2/item5[0]', 'Spec2/item5[1]', 'Spec2/item6/value1', 'Spec2/item6/value2'], config_items)
+ self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3',
+ 'Spec2/item4', 'Spec2/item5[0]', 'Spec2/item5[1]',
+ 'Spec2/item6/value1', 'Spec2/item6/value2'],
+ config_items)
config_items = self.mcd.get_config_item_list("Spec2")
- self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3', 'Spec2/item4', 'Spec2/item5[0]', 'Spec2/item5[1]', 'Spec2/item6'], config_items)
+ self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3',
+ 'Spec2/item4', 'Spec2/item5[0]', 'Spec2/item5[1]',
+ 'Spec2/item6'], config_items)
config_items = self.mcd.get_config_item_list("/Spec2")
- self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3', 'Spec2/item4', 'Spec2/item5[0]', 'Spec2/item5[1]', 'Spec2/item6'], config_items)
+ self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3',
+ 'Spec2/item4', 'Spec2/item5[0]', 'Spec2/item5[1]',
+ 'Spec2/item6'], config_items)
config_items = self.mcd.get_config_item_list("Spec2", True)
- self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3', 'Spec2/item4', 'Spec2/item5[0]', 'Spec2/item5[1]', 'Spec2/item6/value1', 'Spec2/item6/value2'], config_items)
+ self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3',
+ 'Spec2/item4', 'Spec2/item5[0]', 'Spec2/item5[1]',
+ 'Spec2/item6/value1', 'Spec2/item6/value2'],
+ config_items)
# When lists are empty, it should only show the name
self.mcd.set_value('Spec2/item5', [])
config_items = self.mcd.get_config_item_list("Spec2", True)
- self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3', 'Spec2/item4', 'Spec2/item5', 'Spec2/item6/value1', 'Spec2/item6/value2'], config_items)
+ self.assertEqual(['Spec2/item1', 'Spec2/item2', 'Spec2/item3',
+ 'Spec2/item4', 'Spec2/item5', 'Spec2/item6/value1',
+ 'Spec2/item6/value2'], config_items)
def test_is_named_set(self):
module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec32.spec")
More information about the bind10-changes
mailing list