Commit 1f26ac53 authored by Jelte Jansen's avatar Jelte Jansen

[trac926] call it 'named set', not 'named map'

(to avoid confusion with 'normal' maps)
parent 71fb1054
......@@ -636,11 +636,11 @@ class BindCmdInterpreter(Cmd):
# we have more data to show
line += "/"
else:
# if type is named_map, don't print value if None
# if type is named_set, don't print value if None
# (it is either {} meaning empty, or None, meaning
# there actually is data, but not to be shown with
# the current command
if value_map['type'] == 'named_map' and\
if value_map['type'] == 'named_set' and\
value_map['value'] is None:
line += "/\t"
else:
......
......@@ -48,10 +48,10 @@
}
},
{ "item_name": "new_zones",
"item_type": "named_map",
"item_type": "named_set",
"item_optional": false,
"item_default": {},
"named_map_item_spec": {
"named_set_item_spec": {
"item_name": "zone",
"item_type": "map",
"item_default": {},
......
......@@ -511,7 +511,7 @@ Element::nameToType(const std::string& type_name) {
return (Element::list);
} else if (type_name == "map") {
return (Element::map);
} else if (type_name == "named_map") {
} else if (type_name == "named_set") {
return (Element::map);
} else if (type_name == "null") {
return (Element::null);
......
......@@ -71,9 +71,9 @@ check_config_item(ConstElementPtr spec) {
if (spec->get("item_type")->stringValue() == "map") {
check_leaf_item(spec, "map_item_spec", Element::list, true);
check_config_item_list(spec->get("map_item_spec"));
} else if (spec->get("item_type")->stringValue() == "named_map") {
check_leaf_item(spec, "named_map_item_spec", Element::map, true);
check_config_item(spec->get("named_map_item_spec"));
} else if (spec->get("item_type")->stringValue() == "named_set") {
check_leaf_item(spec, "named_set_item_spec", Element::map, true);
check_config_item(spec->get("named_set_item_spec"));
}
}
......@@ -290,7 +290,7 @@ check_type(ConstElementPtr spec, ConstElementPtr element) {
break;
case Element::map:
return (cur_item_type == "map" ||
cur_item_type == "named_map");
cur_item_type == "named_set");
break;
}
return (false);
......@@ -327,7 +327,7 @@ ModuleSpec::validateItem(ConstElementPtr spec, ConstElementPtr data,
}
}
if (data->getType() == Element::map) {
// either a 'normal' map or a 'named' map
// either a 'normal' map or a 'named' set
if (spec->contains("map_item_spec")) {
if (!validateSpecList(spec->get("map_item_spec"), data, full, errors)) {
return (false);
......@@ -336,7 +336,7 @@ ModuleSpec::validateItem(ConstElementPtr spec, ConstElementPtr data,
typedef std::pair<std::string, ConstElementPtr> maptype;
BOOST_FOREACH(maptype m, data->mapValue()) {
if (!validateItem(spec->get("named_map_item_spec"), m.second, full, errors)) {
if (!validateItem(spec->get("named_set_item_spec"), m.second, full, errors)) {
return (false);
}
}
......
......@@ -212,7 +212,7 @@ TEST(ModuleSpec, CommandValidation) {
}
TEST(ModuleSpec, NamedMapValidation) {
TEST(ModuleSpec, NamedSetValidation) {
ModuleSpec dd = moduleSpecFromFile(specfile("spec32.spec"));
ElementPtr errors = Element::createList();
......
{
"named_map_item": { "foo": 1, "bar": 2 }
"named_set_item": { "foo": 1, "bar": 2 }
}
{
"named_map_item": { "foo": "wrongtype", "bar": 2 }
"named_set_item": { "foo": "wrongtype", "bar": 2 }
}
{
"named_map_item": []
"named_set_item": []
}
......@@ -2,12 +2,12 @@
"module_spec": {
"module_name": "Spec32",
"config_data": [
{ "item_name": "named_map_item",
"item_type": "named_map",
{ "item_name": "named_set_item",
"item_type": "named_set",
"item_optional": false,
"item_default": { "a": 1, "b": 2 },
"named_map_item_spec": {
"item_name": "named_map_element",
"named_set_item_spec": {
"item_name": "named_set_element",
"item_type": "integer",
"item_optional": false,
"item_default": 3
......
......@@ -444,11 +444,11 @@ class UIModuleCCSession(MultiConfigData):
else:
raise isc.cc.data.DataAlreadyPresentError(value + " already in " + identifier)
def _add_value_to_named_map(self, identifier, value, item_value):
def _add_value_to_named_set(self, identifier, value, item_value):
if value is None:
raise isc.cc.data.DataNotFoundError("Need a name to add a new item to named_map " + str(identifier))
raise isc.cc.data.DataNotFoundError("Need a name to add a new item to named_set " + str(identifier))
elif type(value) != str:
raise isc.cc.data.DataTypeError("Name for named_map " + identifier + " must be a string")
raise isc.cc.data.DataTypeError("Name for named_set " + identifier + " must be a string")
else:
cur_map, status = self.get_value(identifier)
if not cur_map:
......@@ -477,16 +477,16 @@ class UIModuleCCSession(MultiConfigData):
if value_str is not None:
value = isc.cc.data.parse_value_str(value_str)
# the specified element must be a list or a named_map
# the specified element must be a list or a named_set
if 'list_item_spec' in module_spec:
self._add_value_to_list(identifier, value)
elif 'named_map_item_spec' in module_spec:
elif 'named_set_item_spec' in module_spec:
item_value = None
if 'item_default' in module_spec['named_map_item_spec']:
item_value = module_spec['named_map_item_spec']['item_default']
self._add_value_to_named_map(identifier, value, item_value)
if 'item_default' in module_spec['named_set_item_spec']:
item_value = module_spec['named_set_item_spec']['item_default']
self._add_value_to_named_set(identifier, value, item_value)
else:
raise isc.cc.data.DataNotFoundError(str(identifier) + " is not a list or a named map")
raise isc.cc.data.DataNotFoundError(str(identifier) + " is not a list or a named set")
def _remove_value_from_list(self, identifier, value):
if value is None:
......@@ -504,11 +504,11 @@ class UIModuleCCSession(MultiConfigData):
cur_list.remove(value)
self.set_value(identifier, cur_list)
def _remove_value_from_named_map(self, identifier, value):
def _remove_value_from_named_set(self, identifier, value):
if value is None:
raise isc.cc.data.DataNotFoundError("Need a name to remove an item from named_map " + str(identifier))
raise isc.cc.data.DataNotFoundError("Need a name to remove an item from named_set " + str(identifier))
elif type(value) != str:
raise isc.cc.data.DataTypeError("Name for named_map " + identifier + " must be a string")
raise isc.cc.data.DataTypeError("Name for named_set " + identifier + " must be a string")
else:
cur_map, status = self.get_value(identifier)
if not cur_map:
......@@ -516,10 +516,10 @@ class UIModuleCCSession(MultiConfigData):
if value in cur_map:
del cur_map[value]
else:
raise isc.cc.data.DataNotFoundError(value + " not found in named_map " + str(identifier))
raise isc.cc.data.DataNotFoundError(value + " not found in named_set " + str(identifier))
def remove_value(self, identifier, value_str):
"""Remove a value from a configuration list or named map.
"""Remove a value from a configuration list or named set.
The value string must be a string representation of the full
item. Raises a DataTypeError if the value at the identifier
is not a list, or if the given value_str does not match the
......@@ -536,10 +536,10 @@ class UIModuleCCSession(MultiConfigData):
if value is not None:
isc.config.config_data.check_type(module_spec['list_item_spec'], value)
self._remove_value_from_list(identifier, value)
elif 'named_map_item_spec' in module_spec:
self._remove_value_from_named_map(identifier, value)
elif 'named_set_item_spec' in module_spec:
self._remove_value_from_named_set(identifier, value)
else:
raise isc.cc.data.DataNotFoundError(str(identifier) + " is not a list or a named_map")
raise isc.cc.data.DataNotFoundError(str(identifier) + " is not a list or a named_set")
......
......@@ -145,8 +145,8 @@ def _find_spec_part_single(cur_spec, id_part):
return cur_spec['list_item_spec']
# not found
raise isc.cc.data.DataNotFoundError(id + " not found")
elif type(cur_spec) == dict and 'named_map_item_spec' in cur_spec.keys():
return cur_spec['named_map_item_spec']
elif type(cur_spec) == dict and 'named_set_item_spec' in cur_spec.keys():
return cur_spec['named_set_item_spec']
elif type(cur_spec) == list:
for cur_spec_item in cur_spec:
if cur_spec_item['item_name'] == id:
......@@ -193,7 +193,7 @@ def spec_name_list(spec, prefix="", recurse=False):
result.extend(spec_name_list(map_el['map_item_spec'], prefix + map_el['item_name'], recurse))
else:
result.append(prefix + name)
elif 'named_map_item_spec' in spec:
elif 'named_set_item_spec' in spec:
# we added a '/' above, but in this one case we don't want it
result.append(prefix[:-1])
pass
......@@ -419,7 +419,7 @@ class MultiConfigData:
id_list = module + "/" + id_prefix + "/" + item_id
id_prefix += "/" + id_part
part_spec = find_spec_part(self._specifications[module].get_config_spec(), id_prefix)
if part_spec['item_type'] == 'named_map':
if part_spec['item_type'] == 'named_set':
if len(id_parts) == 0:
if 'item_default' in part_spec:
return part_spec['item_default']
......@@ -427,21 +427,21 @@ class MultiConfigData:
return None
id_part = id_parts.pop(0)
named_map_value, type = self.get_value(id_list)
if id_part in named_map_value:
named_set_value, type = self.get_value(id_list)
if id_part in named_set_value:
if len(id_parts) > 0:
# we are looking for the *default* value.
# so if not present in here, we need to
# lookup the one from the spec
rest_of_id = "/".join(id_parts)
result = isc.cc.data.find_no_exc(named_map_value[id_part], rest_of_id)
result = isc.cc.data.find_no_exc(named_set_value[id_part], rest_of_id)
if result is None:
spec_part = self.find_spec_part(identifier)
if 'item_default' in spec_part:
return spec_part['item_default']
return result
else:
return named_map_value[id_part]
return named_set_value[id_part]
else:
return None
elif list_indices is not None:
......@@ -481,9 +481,9 @@ class MultiConfigData:
spec = find_spec_part(self._specifications[module].get_config_spec(), id)
if 'item_default' in spec:
# one special case, named_map
if spec['item_type'] == 'named_map':
print("is " + id_part + " in named map?")
# one special case, named_set
if spec['item_type'] == 'named_set':
print("is " + id_part + " in named set?")
return spec['item_default']
else:
return spec['item_default']
......@@ -551,7 +551,7 @@ class MultiConfigData:
# almost never interested in just its name
spec_part_map = spec_part['map_item_spec']
self._append_value_item(result, spec_part_map, identifier, all)
elif item_type == "named_map":
elif item_type == "named_set":
value, status = self.get_value(identifier)
# show just the one entry, when either the map is empty,
......@@ -567,10 +567,10 @@ class MultiConfigData:
None, status)
result.append(entry)
else:
spec_part_named_map = spec_part['named_map_item_spec']
spec_part_named_set = spec_part['named_set_item_spec']
for entry in value:
self._append_value_item(result,
spec_part_named_map,
spec_part_named_set,
identifier + "/" + entry,
all)
else:
......@@ -667,16 +667,16 @@ class MultiConfigData:
def _get_list_items(self, item_name):
"""This method is used in get_config_item_list, to add list
indices and named_map names to the completion list. If
the given item_name is for a list or named_map, it'll
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."""
spec_part = self.find_spec_part(item_name)
if 'item_type' in spec_part and \
spec_part['item_type'] == 'named_map':
spec_part['item_type'] == 'named_set':
subslash = ""
if spec_part['named_map_item_spec']['item_type'] == 'map' or\
spec_part['named_map_item_spec']['item_type'] == 'named_map':
if spec_part['named_set_item_spec']['item_type'] == 'map' or\
spec_part['named_set_item_spec']['item_type'] == 'named_set':
subslash = "/"
values, status = self.get_value(item_name)
if len(values) > 0:
......
......@@ -229,7 +229,7 @@ def _check_item_spec(config_item):
item_type = config_item["item_type"]
if type(item_type) != str:
raise ModuleSpecError("item_type in " + item_name + " is not a string: " + str(type(item_type)))
if item_type not in ["integer", "real", "boolean", "string", "list", "map", "named_map", "any"]:
if item_type not in ["integer", "real", "boolean", "string", "list", "map", "named_set", "any"]:
raise ModuleSpecError("unknown item_type in " + item_name + ": " + item_type)
if "item_optional" in config_item:
if type(config_item["item_optional"]) != bool:
......@@ -293,7 +293,7 @@ def _validate_type(spec, value, errors):
if errors != None:
errors.append(str(value) + " should be a map")
return False
elif data_type == "named_map" and type(value) != dict:
elif data_type == "named_set" and type(value) != dict:
if errors != None:
errors.append(str(value) + " should be a map")
return False
......@@ -316,11 +316,11 @@ def _validate_item(spec, full, data, errors):
if not _validate_spec_list(spec['map_item_spec'], full, data, errors):
return False
else:
named_map_spec = spec['named_map_item_spec']
named_set_spec = spec['named_set_item_spec']
for data_el in data.values():
if not _validate_type(named_map_spec, data_el, errors):
if not _validate_type(named_set_spec, data_el, errors):
return False
if not _validate_item(named_map_spec, full, data_el, errors):
if not _validate_item(named_set_spec, full, data_el, errors):
return False
return True
......
......@@ -691,7 +691,7 @@ class TestUIModuleCCSession(unittest.TestCase):
fake_conn.set_get_answer('/config_data', { 'version': BIND10_CONFIG_DATA_VERSION })
return UIModuleCCSession(fake_conn)
def create_uccs_named_map(self, fake_conn):
def create_uccs_named_set(self, fake_conn):
module_spec = isc.config.module_spec_from_file(self.spec_file("spec32.spec"))
fake_conn.set_get_answer('/module_spec', { module_spec.get_module_name(): module_spec.get_full_spec()})
fake_conn.set_get_answer('/config_data', { 'version': BIND10_CONFIG_DATA_VERSION })
......@@ -742,26 +742,26 @@ class TestUIModuleCCSession(unittest.TestCase):
uccs.remove_value("Spec2/item5[0]", None)
self.assertEqual({'Spec2': {'item5': []}}, uccs._local_changes)
def test_add_remove_value_named_map(self):
def test_add_remove_value_named_set(self):
fake_conn = fakeUIConn()
uccs = self.create_uccs_named_map(fake_conn)
value, status = uccs.get_value("/Spec32/named_map_item")
uccs = self.create_uccs_named_set(fake_conn)
value, status = uccs.get_value("/Spec32/named_set_item")
self.assertEqual({'a': 1, 'b': 2}, value)
uccs.add_value("/Spec32/named_map_item", "foo")
value, status = uccs.get_value("/Spec32/named_map_item")
uccs.add_value("/Spec32/named_set_item", "foo")
value, status = uccs.get_value("/Spec32/named_set_item")
self.assertEqual({'a': 1, 'b': 2, 'foo': 3}, value)
uccs.remove_value("/Spec32/named_map_item", "a")
uccs.remove_value("/Spec32/named_map_item", "foo")
value, status = uccs.get_value("/Spec32/named_map_item")
uccs.remove_value("/Spec32/named_set_item", "a")
uccs.remove_value("/Spec32/named_set_item", "foo")
value, status = uccs.get_value("/Spec32/named_set_item")
self.assertEqual({'b': 2}, value)
self.assertRaises(isc.cc.data.DataNotFoundError,
uccs.set_value,
"/Spec32/named_map_item/no_such_item",
"/Spec32/named_set_item/no_such_item",
4)
self.assertRaises(isc.cc.data.DataNotFoundError,
uccs.remove_value, "/Spec32/named_map_item",
uccs.remove_value, "/Spec32/named_set_item",
"no_such_item")
def test_commit(self):
......
......@@ -425,13 +425,13 @@ class TestMultiConfigData(unittest.TestCase):
module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec32.spec")
self.mcd.set_specification(module_spec)
value = self.mcd.get_default_value("Spec32/named_map_item")
value = self.mcd.get_default_value("Spec32/named_set_item")
self.assertEqual({ 'a': 1, 'b': 2}, value)
value = self.mcd.get_default_value("Spec32/named_map_item/a")
value = self.mcd.get_default_value("Spec32/named_set_item/a")
self.assertEqual(1, value)
value = self.mcd.get_default_value("Spec32/named_map_item/b")
value = self.mcd.get_default_value("Spec32/named_set_item/b")
self.assertEqual(2, value)
value = self.mcd.get_default_value("Spec32/named_map_item/no_such_item")
value = self.mcd.get_default_value("Spec32/named_set_item/no_such_item")
self.assertEqual(None, value)
def test_get_value(self):
......@@ -557,27 +557,27 @@ class TestMultiConfigData(unittest.TestCase):
maps = self.mcd.get_value_maps("/Spec22/value9")
self.assertEqual(expected, maps)
def test_get_value_maps_named_map(self):
def test_get_value_maps_named_set(self):
module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec32.spec")
self.mcd.set_specification(module_spec)
maps = self.mcd.get_value_maps()
self.assertEqual([{'default': False, 'type': 'module',
'name': 'Spec32', 'value': None,
'modified': False}], maps)
maps = self.mcd.get_value_maps("/Spec32/named_map_item")
maps = self.mcd.get_value_maps("/Spec32/named_set_item")
self.assertEqual([{'default': True, 'type': 'integer',
'name': 'Spec32/named_map_item/a',
'name': 'Spec32/named_set_item/a',
'value': 1, 'modified': False},
{'default': True, 'type': 'integer',
'name': 'Spec32/named_map_item/b',
'name': 'Spec32/named_set_item/b',
'value': 2, 'modified': False}], maps)
maps = self.mcd.get_value_maps("/Spec32/named_map_item/a")
maps = self.mcd.get_value_maps("/Spec32/named_set_item/a")
self.assertEqual([{'default': True, 'type': 'integer',
'name': 'Spec32/named_map_item/a',
'name': 'Spec32/named_set_item/a',
'value': 1, 'modified': False}], maps)
maps = self.mcd.get_value_maps("/Spec32/named_map_item/b")
maps = self.mcd.get_value_maps("/Spec32/named_set_item/b")
self.assertEqual([{'default': True, 'type': 'integer',
'name': 'Spec32/named_map_item/b',
'name': 'Spec32/named_set_item/b',
'value': 2, 'modified': False}], maps)
def test_set_value(self):
......@@ -618,7 +618,7 @@ class TestMultiConfigData(unittest.TestCase):
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)
def test_get_config_item_list_named_map(self):
def test_get_config_item_list_named_set(self):
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 + "spec32.spec")
......@@ -628,12 +628,12 @@ class TestMultiConfigData(unittest.TestCase):
config_items = self.mcd.get_config_item_list(None, False)
self.assertEqual(['Spec32'], config_items)
config_items = self.mcd.get_config_item_list(None, True)
self.assertEqual(['Spec32/named_map_item'], config_items)
self.mcd.set_value('Spec32/named_map_item', { "aaaa": 4, "aabb": 5, "bbbb": 6})
config_items = self.mcd.get_config_item_list("/Spec32/named_map_item", True)
self.assertEqual(['Spec32/named_map_item/aaaa',
'Spec32/named_map_item/aabb',
'Spec32/named_map_item/bbbb',
self.assertEqual(['Spec32/named_set_item'], config_items)
self.mcd.set_value('Spec32/named_set_item', { "aaaa": 4, "aabb": 5, "bbbb": 6})
config_items = self.mcd.get_config_item_list("/Spec32/named_set_item", True)
self.assertEqual(['Spec32/named_set_item/aaaa',
'Spec32/named_set_item/aabb',
'Spec32/named_set_item/bbbb',
], config_items)
if __name__ == '__main__':
......
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