[svn] commit: r1625 - in /branches/trac90/src: bin/bind10/ bin/cmdctl/ lib/config/ lib/config/testdata/ lib/config/tests/ lib/python/isc/config/ lib/python/isc/config/tests/
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Mar 22 10:56:19 UTC 2010
Author: jelte
Date: Mon Mar 22 10:56:18 2010
New Revision: 1625
Log:
support for module descriptions, added initial descriptions to specfiles
(descriptions are not read out in bindctl yet, currently only config data and commands specs are sent, we'll probably need to change this to send the complete module specification in one go)
Added:
branches/trac90/src/lib/config/testdata/spec25.spec
branches/trac90/src/lib/config/testdata/spec26.spec
Modified:
branches/trac90/src/bin/bind10/bob.spec
branches/trac90/src/bin/cmdctl/cmdctl.spec
branches/trac90/src/lib/config/Makefile.am
branches/trac90/src/lib/config/module_spec.cc
branches/trac90/src/lib/config/module_spec.h
branches/trac90/src/lib/config/tests/module_spec_unittests.cc
branches/trac90/src/lib/python/isc/config/module_spec.py
branches/trac90/src/lib/python/isc/config/tests/module_spec_test.py
Modified: branches/trac90/src/bin/bind10/bob.spec
==============================================================================
--- branches/trac90/src/bin/bind10/bob.spec (original)
+++ branches/trac90/src/bin/bind10/bob.spec Mon Mar 22 10:56:18 2010
@@ -1,6 +1,7 @@
{
"module_spec": {
"module_name": "Boss",
+ "module_description": "Master process",
"config_data": [
{
"item_name": "example_string",
Modified: branches/trac90/src/bin/cmdctl/cmdctl.spec
==============================================================================
--- branches/trac90/src/bin/cmdctl/cmdctl.spec (original)
+++ branches/trac90/src/bin/cmdctl/cmdctl.spec Mon Mar 22 10:56:18 2010
@@ -1,6 +1,7 @@
{
"module_spec": {
"module_name": "Cmdctl",
+ "module_description": "Interface for command and control",
"config_data": [
{
"item_name": "key_file",
Modified: branches/trac90/src/lib/config/Makefile.am
==============================================================================
--- branches/trac90/src/lib/config/Makefile.am (original)
+++ branches/trac90/src/lib/config/Makefile.am Mon Mar 22 10:56:18 2010
@@ -46,3 +46,5 @@
EXTRA_DIST += testdata/spec22.spec
EXTRA_DIST += testdata/spec23.spec
EXTRA_DIST += testdata/spec24.spec
+EXTRA_DIST += testdata/spec25.spec
+EXTRA_DIST += testdata/spec26.spec
Modified: branches/trac90/src/lib/config/module_spec.cc
==============================================================================
--- branches/trac90/src/lib/config/module_spec.cc (original)
+++ branches/trac90/src/lib/config/module_spec.cc Mon Mar 22 10:56:18 2010
@@ -145,6 +145,7 @@
static void
check_data_specification(const ElementPtr& spec) {
check_leaf_item(spec, "module_name", Element::string, true);
+ check_leaf_item(spec, "module_description", Element::string, false);
// config_data is not mandatory; module could just define
// commands and have no config
if (spec->contains("config_data")) {
@@ -202,6 +203,16 @@
ModuleSpec::getModuleName() const
{
return module_specification->get("module_name")->stringValue();
+}
+
+const std::string
+ModuleSpec::getModuleDescription() const
+{
+ if (module_specification->contains("module_description")) {
+ return module_specification->get("module_description")->stringValue();
+ } else {
+ return std::string("");
+ }
}
bool
Modified: branches/trac90/src/lib/config/module_spec.h
==============================================================================
--- branches/trac90/src/lib/config/module_spec.h (original)
+++ branches/trac90/src/lib/config/module_spec.h Mon Mar 22 10:56:18 2010
@@ -77,6 +77,10 @@
/// Returns the module name as specified by the specification
const std::string getModuleName() const;
+ /// Returns the module description as specified by the specification
+ /// returns an empty string if there is no description
+ const std::string getModuleDescription() const;
+
// returns true if the given element conforms to this data
// configuration specification
/// Validates the given configuration data for this specification.
Modified: branches/trac90/src/lib/config/tests/module_spec_unittests.cc
==============================================================================
--- branches/trac90/src/lib/config/tests/module_spec_unittests.cc (original)
+++ branches/trac90/src/lib/config/tests/module_spec_unittests.cc Mon Mar 22 10:56:18 2010
@@ -60,6 +60,12 @@
dd = moduleSpecFromFile(specfile("spec2.spec"));
EXPECT_EQ("[ {\"command_args\": [ {\"item_default\": \"\", \"item_name\": \"message\", \"item_optional\": False, \"item_type\": \"string\"} ], \"command_description\": \"Print the given message to stdout\", \"command_name\": \"print_message\"}, {\"command_args\": [ ], \"command_description\": \"Shut down BIND 10\", \"command_name\": \"shutdown\"} ]", dd.getCommandsSpec()->str());
EXPECT_EQ("Spec2", dd.getModuleName());
+ EXPECT_EQ("", dd.getModuleDescription());
+
+ dd = moduleSpecFromFile(specfile("spec25.spec"));
+ EXPECT_EQ("Spec25", dd.getModuleName());
+ EXPECT_EQ("Just an empty module", dd.getModuleDescription());
+ EXPECT_THROW(moduleSpecFromFile(specfile("spec26.spec")), ModuleSpecError);
std::ifstream file;
file.open(specfile("spec1.spec").c_str());
Modified: branches/trac90/src/lib/python/isc/config/module_spec.py
==============================================================================
--- branches/trac90/src/lib/python/isc/config/module_spec.py (original)
+++ branches/trac90/src/lib/python/isc/config/module_spec.py Mon Mar 22 10:56:18 2010
@@ -86,8 +86,18 @@
def get_module_name(self):
"""Returns a string containing the name of the module as
- specified by the specification given at __init__"""
+ specified by the specification given at __init__()"""
return self._module_spec['module_name']
+
+ def get_module_description(self):
+ """Returns a string containing the description of the module as
+ specified by the specification given at __init__().
+ Returns an empty string if there is no description.
+ """
+ if 'module_description' in self._module_spec:
+ return self._module_spec['module_description']
+ else:
+ return ""
def get_full_spec(self):
"""Returns a dict representation of the full module specification"""
@@ -123,6 +133,9 @@
raise ModuleSpecError("data specification not a dict")
if "module_name" not in module_spec:
raise ModuleSpecError("no module_name in module_spec")
+ if "module_description" in module_spec and \
+ type(module_spec["module_description"]) != str:
+ raise ModuleSpecError("module_description is not a string")
if "config_data" in module_spec:
_check_config_spec(module_spec["config_data"])
if "commands" in module_spec:
Modified: branches/trac90/src/lib/python/isc/config/tests/module_spec_test.py
==============================================================================
--- branches/trac90/src/lib/python/isc/config/tests/module_spec_test.py (original)
+++ branches/trac90/src/lib/python/isc/config/tests/module_spec_test.py Mon Mar 22 10:56:18 2010
@@ -73,6 +73,7 @@
self.assertRaises(ModuleSpecError, self.read_spec_file, "spec19.spec")
self.assertRaises(ModuleSpecError, self.read_spec_file, "spec20.spec")
self.assertRaises(ModuleSpecError, self.read_spec_file, "spec21.spec")
+ self.assertRaises(ModuleSpecError, self.read_spec_file, "spec26.spec")
def validate_data(self, specfile_name, datafile_name):
dd = self.read_spec_file(specfile_name);
@@ -95,6 +96,10 @@
self.assertRaises(ModuleSpecError, ModuleSpec, 1)
module_spec = isc.config.module_spec_from_file(self.spec_file("spec1.spec"), False)
self.spec1(module_spec)
+
+ module_spec = isc.config.module_spec_from_file(self.spec_file("spec25.spec"), True)
+ self.assertEqual("Spec25", module_spec.get_module_name())
+ self.assertEqual("Just an empty module", module_spec.get_module_description())
def test_str(self):
module_spec = isc.config.module_spec_from_file(self.spec_file("spec1.spec"), False)
More information about the bind10-changes
mailing list