Feature #2964
closedinfoedit: configuration editor
100%
Description
Develop infoedit, a programmatic INFO-format configuration file editor for use in IntegrationTests.
Background
Many scenario requires editing the NFD configuration file.
There are two approaches:
- Embed a complete NFD configuration file in the scenario code.
- Benefit: The complete configuration file is visible.
- Drawback: It's not obvious what are the significant changes that differ from the default configuration.
- Drawback: When NFD configuration file introduces a backwards-incompatible change, scenarios designed in this way will be broken.
- Use an
awkorsedscript to modify the default configuration file.- Benefit: It's easy to see what changes are needed.
- Drawback: To perform a complex modification, the script gets tricky and becomes unreadable.
- Drawback: Neither
awknorsedunderstands INFO format, so the script isn't robust to formatting changes.
Feature
This feature is to develop infoedit, a command line utility that programmatically edits a configuration file.
Command line options:
-f file: specifies a file to edit-s path: specifies a property-tree path to modify-v value: used with-s path, sets the value at the path-d path: deletes all subtrees matching the path-a path: adds a subtree at the path; the subtree is read from stdin-r path: replaces a subtree at the path; equivalent to-d pathfollowed by-a path
Every invocation performs one edit.
The file is modified in place.
To perform multiple edits, invoke the utility multiple times on the same file.
Sample command lines:
./infoedit -f nfd.conf -s general.user -v ndn.user
./infoedit -f nfd.conf -s tables.strategy_choice./site -v /localhost/nfd/strategy/broadcast
./infoedit -f nfd.conf -d tables.strategy_choice./
./infoedit -f nfd.conf -d authorizations
./infoedit -f nfd.conf -a rib.localhost_security <<<EOT
trust-anchor
{
type any
}
EOT
Placement
infoedit design is tailored to integration tests.
It should live in integration-tests repository, and compiled in a step of install_apps.py.
Updated by Junxiao Shi over 10 years ago
Code snippet that performs the actions in the example:
ptree pt;
std::istringstream input(" \n\
; comment1 \n\
\n\
general ; comment2 \n\
{ \n\
user user ; comment3 \n\
group group \n\
} \n\
\n\
tables \n\
{ \n\
strategy_choice \n\
{ \n\
/ /localhost/nfd/strategy/best-route \n\
/site /localhost/nfd/strategy/broadcast \n\
} \n\
} \n\
\n\
authorizations \n\
{ \n\
authorize \n\
{ \n\
certfile file1.cert \n\
} \n\
authorize \n\
{ \n\
certfile file2.cert \n\
} \n\
} \n\
");
read_info(input, pt);
// -s general.user -v ndn-user
pt.put("general.user", "ndn-user");
// -s tables.strategy_choice./site -v /localhost/nfd/strategy/broadcast
pt.put("tables.strategy_choice./site", "/localhost/nfd/strategy/broadcast");
// -d tables.strategy_choice./
boost::optional<ptree&> child = pt.get_child_optional("tables.strategy_choice");
if (child) {
child->erase("/");
}
// -d authorizations
pt.erase("authorizations");
// -a rib.localhost_security
ptree pt2;
std::istringstream input2(" \n\
trust-anchor \n\
{ \n\
type any \n\
} \n\
");
read_info(input2, pt2);
pt.add_child("rib.localhost_security", pt2);
write_info(std::cout, pt);
Updated by Junxiao Shi over 10 years ago
- Blocks Feature #2201: Remote prefix registration test scenario added
Updated by Junxiao Shi over 10 years ago
- Description updated (diff)
- Assignee set to Yanbiao Li
Updated by Junxiao Shi about 10 years ago
- Status changed from Code review to Closed
Updated by Alex Afanasyev almost 10 years ago
Just for the record.
Alternative to implementing an app would be to use http://augeas.net/ library that is designed for exactly the same purpose and supports multiple formats (probably not Boost.INFO, but should not be too hard to enable).
Updated by Junxiao Shi almost 10 years ago
- Blocks Feature #3387: infoedit: install from GitHub added