New backend switch: -q : Quit startup directly after upgrading and print result on stdout
This commit is contained in:
parent
daeab85446
commit
5b81c43d96
7 changed files with 368 additions and 1 deletions
|
|
@ -86,6 +86,7 @@ Expected: July 2020
|
|||
|
||||
### Minor changes
|
||||
|
||||
* New backend switch: `-q` : Quit startup directly after upgrading and print result on stdout.
|
||||
* Enhanced Clixon if-feature handling:
|
||||
* If-feature now supports and/or lists, such as: `if-feature "a and b"` and `if-feature "a or b or c"`. However, full if-feature-expr including `not` and nested boolean experessions is still not supported.
|
||||
* Sanity check: if an `if-feature` statement exists, a corresponding `feature` statement must exists that declares that feature.
|
||||
|
|
|
|||
|
|
@ -206,6 +206,14 @@ startup_common(clicon_handle h,
|
|||
if (ret == 0)
|
||||
goto fail;
|
||||
}
|
||||
#if 1
|
||||
if (clicon_quit_upgrade_get(h) == 1){ /* Print upgraded db */
|
||||
if (xmldb_dump(h, stdout, xt) < 0)
|
||||
goto done;
|
||||
exit(0); /* This is fairly abrupt , but need to avoid side-effects of rewinding
|
||||
stack. Alternative is to make a separate function stack for this. */
|
||||
}
|
||||
#endif
|
||||
/* If empty skip. Note upgrading can add children, so it may be empty before that. */
|
||||
if (xml_child_nr(xt) == 0){
|
||||
td->td_target = xt;
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@
|
|||
#include "backend_startup.h"
|
||||
|
||||
/* Command line options to be passed to getopt(3) */
|
||||
#define BACKEND_OPTS "hD:f:l:d:p:b:Fza:u:P:1s:c:U:g:y:o:"
|
||||
#define BACKEND_OPTS "hD:f:l:d:p:b:Fza:u:P:1qs:c:U:g:y:o:"
|
||||
|
||||
#define BACKEND_LOGFILE "/usr/local/var/clixon_backend.log"
|
||||
|
||||
|
|
@ -414,6 +414,7 @@ usage(clicon_handle h,
|
|||
"\t-1\t\tRun once and then quit (dont wait for events)\n"
|
||||
"\t-s <mode>\tSpecify backend startup mode: none|startup|running|init)\n"
|
||||
"\t-c <file>\tLoad extra xml configuration, but don't commit.\n"
|
||||
"\t-q \tQuit startup directly after upgrading and print result on stdout\n"
|
||||
"\t-U <user>\tRun backend daemon as this user AND drop privileges permanently\n"
|
||||
"\t-g <group>\tClient membership required to this group (default: %s)\n"
|
||||
|
||||
|
|
@ -579,6 +580,10 @@ main(int argc,
|
|||
case '1' : /* Quit after reading database once - dont wait for events */
|
||||
once = 1;
|
||||
break;
|
||||
case 'q': /* Quit directly after startup upgrading and print result on stdout */
|
||||
if (clicon_quit_upgrade_set(h, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case 's' : /* startup mode */
|
||||
if (clicon_option_add(h, "CLICON_STARTUP_MODE", optarg) < 0)
|
||||
goto done;
|
||||
|
|
@ -843,6 +848,10 @@ main(int argc,
|
|||
goto done;
|
||||
/* if status = STARTUP_INVALID, cbret contains info */
|
||||
}
|
||||
/* Quit after upgrade catch-all, running/startup quits in upgrade code */
|
||||
if (clicon_quit_upgrade_get(h) == 1)
|
||||
goto done;
|
||||
|
||||
/*
|
||||
* Disable unknown to anydata auto-creation after startup
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -117,4 +117,8 @@ int clicon_argv_set(clicon_handle h, char *argv0, int argc, char **argv);
|
|||
int clicon_session_id_set(clicon_handle h, uint32_t id);
|
||||
int clicon_session_id_get(clicon_handle h, uint32_t *id);
|
||||
|
||||
/* If set, quit startup directly after upgrade */
|
||||
int clicon_quit_upgrade_get(clicon_handle h);
|
||||
int clicon_quit_upgrade_set(clicon_handle h, int val);
|
||||
|
||||
#endif /* _CLIXON_DATA_H_ */
|
||||
|
|
|
|||
|
|
@ -74,5 +74,6 @@ cxobj *xmldb_cache_get(clicon_handle h, const char *db);
|
|||
int xmldb_modified_get(clicon_handle h, const char *db);
|
||||
int xmldb_modified_set(clicon_handle h, const char *db, int value);
|
||||
|
||||
int xmldb_dump(clicon_handle h, FILE *f, cxobj *xt);
|
||||
|
||||
#endif /* _CLIXON_DATASTORE_H */
|
||||
|
|
|
|||
|
|
@ -713,3 +713,37 @@ clicon_session_id_set(clicon_handle h,
|
|||
clicon_hash_add(cdat, "session-id", &id, sizeof(uint32_t));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Get quit-after-upgrade flag
|
||||
* @param[in] h Clicon handle
|
||||
* @retval 1 Flag set: quit startup directly after upgrade
|
||||
* @retval 0 Flag not set
|
||||
* If set, quit startup directly after upgrade
|
||||
*/
|
||||
int
|
||||
clicon_quit_upgrade_get(clicon_handle h)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
void *p;
|
||||
|
||||
if ((p = clicon_hash_value(cdat, "quit-after-upgrade", NULL)) == NULL)
|
||||
return 0;
|
||||
return *(int*)p;
|
||||
}
|
||||
|
||||
/*! Set quit-after-upgrade flag
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] val Set or reset flag
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* If set, quit startup directly after upgrade
|
||||
*/
|
||||
int
|
||||
clicon_quit_upgrade_set(clicon_handle h,
|
||||
int val)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
||||
clicon_hash_add(cdat, "quit-after-upgrade", &val, sizeof(int));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
310
test/test_upgrade_quit.sh
Executable file
310
test/test_upgrade_quit.sh
Executable file
|
|
@ -0,0 +1,310 @@
|
|||
#!/usr/bin/env bash
|
||||
# Test quit startup after upgrade (-q) functionality
|
||||
# The yang is from test_upgrade_interfaces and the upgrade code
|
||||
# is implemented in the main example
|
||||
# The test is just having 2014 xml syntax in file and the backend printing the upgraded
|
||||
# syntax to stdout
|
||||
# The output syntax is datastore syntax, as a running db would have looked like
|
||||
# Note that the admin and stats field are non-config in the original, not here
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
APPNAME=example
|
||||
|
||||
cfg=$dir/conf.xml
|
||||
if2014=$dir/interfaces@2014-05-08.yang
|
||||
if2018=$dir/interfaces@2018-02-20.yang
|
||||
|
||||
# Original simplified version - note all is config to allow for storing in
|
||||
# datastore
|
||||
cat <<EOF > $if2014
|
||||
module interfaces{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:interfaces";
|
||||
prefix "if";
|
||||
|
||||
import ietf-yang-types {
|
||||
prefix yang;
|
||||
}
|
||||
revision 2014-05-08 {
|
||||
description
|
||||
"Initial revision.";
|
||||
reference
|
||||
"RFC 7223: A YANG Data Model for Interface Management";
|
||||
}
|
||||
feature if-mib {
|
||||
description
|
||||
"This feature indicates that the device implements
|
||||
the IF-MIB.";
|
||||
reference
|
||||
"RFC 2863: The Interfaces Group MIB";
|
||||
}
|
||||
container interfaces {
|
||||
description
|
||||
"Interface configuration parameters.";
|
||||
|
||||
list interface {
|
||||
key "name";
|
||||
leaf name {
|
||||
type string;
|
||||
}
|
||||
leaf description {
|
||||
type string;
|
||||
}
|
||||
|
||||
|
||||
leaf type {
|
||||
type string;
|
||||
mandatory true;
|
||||
}
|
||||
leaf link-up-down-trap-enable {
|
||||
if-feature if-mib;
|
||||
type enumeration {
|
||||
enum enabled;
|
||||
enum disabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
container interfaces-state {
|
||||
list interface {
|
||||
key "name";
|
||||
leaf name {
|
||||
type string;
|
||||
}
|
||||
leaf admin-status {
|
||||
if-feature if-mib;
|
||||
type enumeration {
|
||||
enum up;
|
||||
enum down;
|
||||
enum testing;
|
||||
}
|
||||
mandatory true;
|
||||
}
|
||||
container statistics {
|
||||
leaf in-octets {
|
||||
type yang:counter64;
|
||||
}
|
||||
leaf in-unicast-pkts {
|
||||
type yang:counter64;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EOF
|
||||
|
||||
cat <<EOF > $if2018
|
||||
module interfaces{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:interfaces";
|
||||
prefix "if";
|
||||
|
||||
import ietf-yang-types {
|
||||
prefix yang;
|
||||
}
|
||||
revision 2018-02-20 {
|
||||
description
|
||||
"Updated to support NMDA.";
|
||||
reference
|
||||
"RFC 8343: A YANG Data Model for Interface Management";
|
||||
}
|
||||
revision 2014-05-08 {
|
||||
description
|
||||
"Initial revision.";
|
||||
reference
|
||||
"RFC 7223: A YANG Data Model for Interface Management";
|
||||
}
|
||||
feature if-mib {
|
||||
description
|
||||
"This feature indicates that the device implements
|
||||
the IF-MIB.";
|
||||
reference
|
||||
"RFC 2863: The Interfaces Group MIB";
|
||||
}
|
||||
container interfaces {
|
||||
description
|
||||
"Interface configuration parameters.";
|
||||
|
||||
list interface {
|
||||
key "name";
|
||||
leaf name {
|
||||
type string;
|
||||
}
|
||||
container docs{
|
||||
description "Original description is wrapped and renamed";
|
||||
leaf descr {
|
||||
type string;
|
||||
}
|
||||
}
|
||||
leaf type {
|
||||
type string;
|
||||
mandatory true;
|
||||
}
|
||||
leaf link-up-down-trap-enable {
|
||||
if-feature if-mib;
|
||||
type enumeration {
|
||||
enum enabled;
|
||||
enum disabled;
|
||||
}
|
||||
}
|
||||
leaf admin-status {
|
||||
if-feature if-mib;
|
||||
type enumeration {
|
||||
enum up;
|
||||
enum down;
|
||||
enum testing;
|
||||
}
|
||||
mandatory true;
|
||||
}
|
||||
container statistics {
|
||||
leaf in-octets {
|
||||
type decimal64{
|
||||
fraction-digits 3;
|
||||
}
|
||||
}
|
||||
leaf in-unicast-pkts {
|
||||
type yang:counter64;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Create startup db revision from 2014-05-08 to be upgraded to 2018-02-20
|
||||
# This is 2014 syntax
|
||||
cat <<EOF > $dir/startup_db
|
||||
<config>
|
||||
<modules-state xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library">
|
||||
<module-set-id>42</module-set-id>
|
||||
<module>
|
||||
<name>interfaces</name>
|
||||
<revision>2014-05-08</revision>
|
||||
<namespace>urn:example:interfaces</namespace>
|
||||
</module>
|
||||
</modules-state>
|
||||
<interfaces xmlns="urn:example:interfaces">
|
||||
<interface>
|
||||
<name>e0</name>
|
||||
<type>eth</type>
|
||||
<description>First interface</description>
|
||||
</interface>
|
||||
<interface>
|
||||
<name>e1</name>
|
||||
<type>eth</type>
|
||||
</interface>
|
||||
</interfaces>
|
||||
<interfaces-state xmlns="urn:example:interfaces">
|
||||
<interface>
|
||||
<name>e0</name>
|
||||
<admin-status>up</admin-status>
|
||||
<statistics>
|
||||
<in-octets>54326432</in-octets>
|
||||
<in-unicast-pkts>8458765</in-unicast-pkts>
|
||||
</statistics>
|
||||
</interface>
|
||||
<interface>
|
||||
<name>e1</name>
|
||||
<admin-status>down</admin-status>
|
||||
</interface>
|
||||
<interface>
|
||||
<name>e2</name>
|
||||
<admin-status>testing</admin-status>
|
||||
</interface>
|
||||
</interfaces-state>
|
||||
</config>
|
||||
EOF
|
||||
|
||||
# Create configuration
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
|
||||
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||
<CLICON_FEATURE>interfaces:if-mib</CLICON_FEATURE>
|
||||
<CLICON_YANG_MAIN_DIR>$dir</CLICON_YANG_MAIN_DIR>
|
||||
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/example/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_XMLDB_MODSTATE>true</CLICON_XMLDB_MODSTATE>
|
||||
<CLICON_XMLDB_PRETTY>false</CLICON_XMLDB_PRETTY>
|
||||
<CLICON_XML_CHANGELOG>false</CLICON_XML_CHANGELOG>
|
||||
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
||||
# This is 2014 syntax
|
||||
cat <<EOF > $dir/startup_db
|
||||
<config>
|
||||
<modules-state xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library">
|
||||
<module-set-id>42</module-set-id>
|
||||
<module>
|
||||
<name>interfaces</name>
|
||||
<revision>2014-05-08</revision>
|
||||
<namespace>urn:example:interfaces</namespace>
|
||||
</module>
|
||||
</modules-state>
|
||||
<interfaces xmlns="urn:example:interfaces">
|
||||
<interface>
|
||||
<name>e0</name>
|
||||
<type>eth</type>
|
||||
<description>First interface</description>
|
||||
</interface>
|
||||
<interface>
|
||||
<name>e1</name>
|
||||
<type>eth</type>
|
||||
</interface>
|
||||
</interfaces>
|
||||
<interfaces-state xmlns="urn:example:interfaces">
|
||||
<interface>
|
||||
<name>e0</name>
|
||||
<admin-status>up</admin-status>
|
||||
<statistics>
|
||||
<in-octets>54326432</in-octets>
|
||||
<in-unicast-pkts>8458765</in-unicast-pkts>
|
||||
</statistics>
|
||||
</interface>
|
||||
<interface>
|
||||
<name>e1</name>
|
||||
<admin-status>down</admin-status>
|
||||
</interface>
|
||||
<interface>
|
||||
<name>e2</name>
|
||||
<admin-status>testing</admin-status>
|
||||
</interface>
|
||||
</interfaces-state>
|
||||
</config>
|
||||
EOF
|
||||
|
||||
MODSTATE='<modules-state xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library"><module-set-id>0</module-set-id><module><name>clixon-lib</name><revision>2020-04-23</revision><namespace>http://clicon.org/lib</namespace></module><module><name>ietf-inet-types</name><revision>2013-07-15</revision><namespace>urn:ietf:params:xml:ns:yang:ietf-inet-types</namespace></module><module><name>ietf-netconf</name><revision>2011-06-01</revision><namespace>urn:ietf:params:xml:ns:netconf:base:1.0</namespace></module><module><name>ietf-restconf</name><revision>2017-01-26</revision><namespace>urn:ietf:params:xml:ns:yang:ietf-restconf</namespace></module><module><name>ietf-yang-library</name><revision>2016-06-21</revision><namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace></module><module><name>ietf-yang-types</name><revision>2013-07-15</revision><namespace>urn:ietf:params:xml:ns:yang:ietf-yang-types</namespace></module><module><name>interfaces</name><revision>2018-02-20</revision><namespace>urn:example:interfaces</namespace></module></modules-state>'
|
||||
|
||||
XML='<interfaces xmlns="urn:example:interfaces"><interface><name>e0</name><type>eth</type><admin-status>up</admin-status><statistics><in-octets>54326.432</in-octets><in-unicast-pkts>8458765</in-unicast-pkts></statistics><docs><descr>First interface</descr></docs></interface><interface><name>e1</name><type>eth</type><admin-status>down</admin-status></interface></interfaces>'
|
||||
|
||||
ALL="<config>$MODSTATE$XML</config>"
|
||||
|
||||
# -u means trigger example upgrade
|
||||
new "test params: -s startup -f $cfg -- -u"
|
||||
|
||||
# kill old backend (if any)
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err
|
||||
fi
|
||||
new "start backend -s startup -f $cfg -q -- -u"
|
||||
output=$(sudo $clixon_backend -F -D $DBG -s startup -f $cfg -q -- -u)
|
||||
#echo "$output"
|
||||
if [ "$ALL" != "$output" ]; then
|
||||
err "$ALL" "$output"
|
||||
fi
|
||||
|
||||
rm -rf $dir
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue