summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2013-09-02 13:17:16 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-09-02 20:25:35 +0200
commit0ae92a950a321835c6693e381e131df38febab2a (patch)
treebacb84b469c72c18bb63498b4a697a5fcd56464f
parent190acf6fd03f7f9a92b3e0044abf455b8a465c33 (diff)
vty: Use generic 'end' and 'exit' commands
Add bsc_install_default() and replace all install_default() This patch adds bsc_install_default() which calls install_default() and add 'exit' and 'end'. All other calls to install_default() are replaced by calls to bsc_install_default(). Since 'exit' and 'end' are now added automatically to each node, the explicit registrations of these commands are removed by this patch, too. The related tests succeed now without work-arounds (except for the 'config' node itself which is part of libosmocore).
-rw-r--r--openbsc/include/openbsc/vty.h2
-rw-r--r--openbsc/src/gprs/gb_proxy_vty.c4
-rw-r--r--openbsc/src/gprs/sgsn_vty.c4
-rw-r--r--openbsc/src/libbsc/abis_nm_vty.c3
-rw-r--r--openbsc/src/libbsc/abis_om2000_vty.c3
-rw-r--r--openbsc/src/libbsc/bsc_vty.c16
-rw-r--r--openbsc/src/libcommon/common_vty.c10
-rw-r--r--openbsc/src/libmgcp/mgcp_vty.c8
-rw-r--r--openbsc/src/libmsc/smpp_vty.c4
-rw-r--r--openbsc/src/libmsc/vty_interface_layer3.c4
-rw-r--r--openbsc/src/osmo-bsc/osmo_bsc_vty.c4
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_vty.c12
-rw-r--r--openbsc/tests/vty_test_runner.py24
13 files changed, 35 insertions, 63 deletions
diff --git a/openbsc/include/openbsc/vty.h b/openbsc/include/openbsc/vty.h
index 183fc25..f74516a 100644
--- a/openbsc/include/openbsc/vty.h
+++ b/openbsc/include/openbsc/vty.h
@@ -42,6 +42,8 @@ enum bsc_vty_node {
extern int bsc_vty_is_config_node(struct vty *vty, int node);
extern void bsc_replace_string(void *ctx, char **dst, const char *newstr);
+void bsc_install_default(enum node_type node);
+
struct log_info;
int bsc_vty_init(const struct log_info *cat);
int bsc_vty_init_extra(void);
diff --git a/openbsc/src/gprs/gb_proxy_vty.c b/openbsc/src/gprs/gb_proxy_vty.c
index bfa1f3b..63546d3 100644
--- a/openbsc/src/gprs/gb_proxy_vty.c
+++ b/openbsc/src/gprs/gb_proxy_vty.c
@@ -82,9 +82,7 @@ int gbproxy_vty_init(void)
install_element(CONFIG_NODE, &cfg_gbproxy_cmd);
install_node(&gbproxy_node, config_write_gbproxy);
- install_default(GBPROXY_NODE);
- install_element(GBPROXY_NODE, &ournode_exit_cmd);
- install_element(GBPROXY_NODE, &ournode_end_cmd);
+ bsc_install_default(GBPROXY_NODE);
install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd);
return 0;
diff --git a/openbsc/src/gprs/sgsn_vty.c b/openbsc/src/gprs/sgsn_vty.c
index a4ba280..8106b7d 100644
--- a/openbsc/src/gprs/sgsn_vty.c
+++ b/openbsc/src/gprs/sgsn_vty.c
@@ -418,9 +418,7 @@ int sgsn_vty_init(void)
install_element(CONFIG_NODE, &cfg_sgsn_cmd);
install_node(&sgsn_node, config_write_sgsn);
- install_default(SGSN_NODE);
- install_element(SGSN_NODE, &ournode_exit_cmd);
- install_element(SGSN_NODE, &ournode_end_cmd);
+ bsc_install_default(SGSN_NODE);
install_element(SGSN_NODE, &cfg_sgsn_bind_addr_cmd);
install_element(SGSN_NODE, &cfg_ggsn_remote_ip_cmd);
//install_element(SGSN_NODE, &cfg_ggsn_remote_port_cmd);
diff --git a/openbsc/src/libbsc/abis_nm_vty.c b/openbsc/src/libbsc/abis_nm_vty.c
index fd60210..5db667d 100644
--- a/openbsc/src/libbsc/abis_nm_vty.c
+++ b/openbsc/src/libbsc/abis_nm_vty.c
@@ -183,8 +183,7 @@ int abis_nm_vty_init(void)
install_element(ENABLE_NODE, &oml_classnum_inst_cmd);
install_node(&oml_node, dummy_config_write);
- install_default(OML_NODE);
- install_element(OML_NODE, &ournode_exit_cmd);
+ bsc_install_default(OML_NODE);
install_element(OML_NODE, &oml_chg_adm_state_cmd);
install_element(OML_NODE, &oml_opstart_cmd);
diff --git a/openbsc/src/libbsc/abis_om2000_vty.c b/openbsc/src/libbsc/abis_om2000_vty.c
index 3df005b..eb8f4d5 100644
--- a/openbsc/src/libbsc/abis_om2000_vty.c
+++ b/openbsc/src/libbsc/abis_om2000_vty.c
@@ -445,8 +445,7 @@ int abis_om2k_vty_init(void)
install_element(ENABLE_NODE, &om2k_classnum_inst_cmd);
install_node(&om2k_node, dummy_config_write);
- install_default(OM2K_NODE);
- install_element(OM2K_NODE, &ournode_exit_cmd);
+ bsc_install_default(OM2K_NODE);
install_element(OM2K_NODE, &om2k_reset_cmd);
install_element(OM2K_NODE, &om2k_start_cmd);
install_element(OM2K_NODE, &om2k_status_cmd);
diff --git a/openbsc/src/libbsc/bsc_vty.c b/openbsc/src/libbsc/bsc_vty.c
index 45df90f..5748945 100644
--- a/openbsc/src/libbsc/bsc_vty.c
+++ b/openbsc/src/libbsc/bsc_vty.c
@@ -3002,9 +3002,7 @@ int bsc_vty_init(const struct log_info *cat)
install_element(CONFIG_NODE, &cfg_net_cmd);
install_node(&net_node, config_write_net);
- install_default(GSMNET_NODE);
- install_element(GSMNET_NODE, &ournode_exit_cmd);
- install_element(GSMNET_NODE, &ournode_end_cmd);
+ bsc_install_default(GSMNET_NODE);
install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
@@ -3040,9 +3038,7 @@ int bsc_vty_init(const struct log_info *cat)
install_element(GSMNET_NODE, &cfg_bts_cmd);
install_node(&bts_node, config_write_bts);
- install_default(BTS_NODE);
- install_element(BTS_NODE, &ournode_exit_cmd);
- install_element(BTS_NODE, &ournode_end_cmd);
+ bsc_install_default(BTS_NODE);
install_element(BTS_NODE, &cfg_bts_type_cmd);
install_element(BTS_NODE, &cfg_description_cmd);
install_element(BTS_NODE, &cfg_no_description_cmd);
@@ -3102,9 +3098,7 @@ int bsc_vty_init(const struct log_info *cat)
install_element(BTS_NODE, &cfg_trx_cmd);
install_node(&trx_node, dummy_config_write);
- install_default(TRX_NODE);
- install_element(TRX_NODE, &ournode_exit_cmd);
- install_element(TRX_NODE, &ournode_end_cmd);
+ bsc_install_default(TRX_NODE);
install_element(TRX_NODE, &cfg_trx_arfcn_cmd);
install_element(TRX_NODE, &cfg_description_cmd);
install_element(TRX_NODE, &cfg_no_description_cmd);
@@ -3116,9 +3110,7 @@ int bsc_vty_init(const struct log_info *cat)
install_element(TRX_NODE, &cfg_ts_cmd);
install_node(&ts_node, dummy_config_write);
- install_default(TS_NODE);
- install_element(TS_NODE, &ournode_exit_cmd);
- install_element(TS_NODE, &ournode_end_cmd);
+ bsc_install_default(TS_NODE);
install_element(TS_NODE, &cfg_ts_pchan_cmd);
install_element(TS_NODE, &cfg_ts_pchan_compat_cmd);
install_element(TS_NODE, &cfg_ts_tsc_cmd);
diff --git a/openbsc/src/libcommon/common_vty.c b/openbsc/src/libcommon/common_vty.c
index 7aca4ca..0bf43b0 100644
--- a/openbsc/src/libcommon/common_vty.c
+++ b/openbsc/src/libcommon/common_vty.c
@@ -174,3 +174,13 @@ void bsc_replace_string(void *ctx, char **dst, const char *newstr)
talloc_free(*dst);
*dst = talloc_strdup(ctx, newstr);
}
+
+void bsc_install_default(enum node_type node)
+{
+ install_default (node);
+
+ if (node > CONFIG_NODE) {
+ install_element(node, &ournode_exit_cmd);
+ install_element(node, &ournode_end_cmd);
+ }
+}
diff --git a/openbsc/src/libmgcp/mgcp_vty.c b/openbsc/src/libmgcp/mgcp_vty.c
index 833908a..9421f4f 100644
--- a/openbsc/src/libmgcp/mgcp_vty.c
+++ b/openbsc/src/libmgcp/mgcp_vty.c
@@ -786,9 +786,7 @@ int mgcp_vty_init(void)
install_element(CONFIG_NODE, &cfg_mgcp_cmd);
install_node(&mgcp_node, config_write_mgcp);
- install_default(MGCP_NODE);
- install_element(MGCP_NODE, &ournode_exit_cmd);
- install_element(MGCP_NODE, &ournode_end_cmd);
+ bsc_install_default(MGCP_NODE);
install_element(MGCP_NODE, &cfg_mgcp_local_ip_cmd);
install_element(MGCP_NODE, &cfg_mgcp_bts_ip_cmd);
install_element(MGCP_NODE, &cfg_mgcp_bind_ip_cmd);
@@ -820,9 +818,7 @@ int mgcp_vty_init(void)
install_element(MGCP_NODE, &cfg_mgcp_trunk_cmd);
install_node(&trunk_node, config_write_trunk);
- install_default(TRUNK_NODE);
- install_element(TRUNK_NODE, &ournode_exit_cmd);
- install_element(TRUNK_NODE, &ournode_end_cmd);
+ bsc_install_default(TRUNK_NODE);
install_element(TRUNK_NODE, &cfg_trunk_payload_number_cmd);
install_element(TRUNK_NODE, &cfg_trunk_payload_name_cmd);
install_element(TRUNK_NODE, &cfg_trunk_payload_number_cmd_old);
diff --git a/openbsc/src/libmsc/smpp_vty.c b/openbsc/src/libmsc/smpp_vty.c
index dd9b0c0..bf503f5 100644
--- a/openbsc/src/libmsc/smpp_vty.c
+++ b/openbsc/src/libmsc/smpp_vty.c
@@ -509,7 +509,7 @@ static int config_write_esme(struct vty *v)
int smpp_vty_init(void)
{
install_node(&smpp_node, config_write_smpp);
- install_default(SMPP_NODE);
+ bsc_install_default(SMPP_NODE);
install_element(CONFIG_NODE, &cfg_smpp_cmd);
install_element(SMPP_NODE, &cfg_smpp_port_cmd);
@@ -519,7 +519,7 @@ int smpp_vty_init(void)
install_element(SMPP_NODE, &cfg_no_esme_cmd);
install_node(&esme_node, config_write_esme);
- install_default(SMPP_ESME_NODE);
+ bsc_install_default(SMPP_ESME_NODE);
install_element(SMPP_ESME_NODE, &cfg_esme_passwd_cmd);
install_element(SMPP_ESME_NODE, &cfg_esme_no_passwd_cmd);
install_element(SMPP_ESME_NODE, &cfg_esme_route_pfx_cmd);
diff --git a/openbsc/src/libmsc/vty_interface_layer3.c b/openbsc/src/libmsc/vty_interface_layer3.c
index 79c3457..19c78ea 100644
--- a/openbsc/src/libmsc/vty_interface_layer3.c
+++ b/openbsc/src/libmsc/vty_interface_layer3.c
@@ -975,9 +975,7 @@ int bsc_vty_init_extra(void)
install_element(CONFIG_NODE, &cfg_mncc_int_cmd);
install_node(&mncc_int_node, config_write_mncc_int);
- install_default(MNCC_INT_NODE);
- install_element(MNCC_INT_NODE, &ournode_exit_cmd);
- install_element(MNCC_INT_NODE, &ournode_end_cmd);
+ bsc_install_default(MNCC_INT_NODE);
install_element(MNCC_INT_NODE, &mnccint_def_codec_f_cmd);
install_element(MNCC_INT_NODE, &mnccint_def_codec_h_cmd);
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_vty.c b/openbsc/src/osmo-bsc/osmo_bsc_vty.c
index f6cf1a0..90b0a0c 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_vty.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_vty.c
@@ -609,7 +609,7 @@ int bsc_vty_init_extra(void)
install_element(CONFIG_NODE, &cfg_net_bsc_cmd);
install_node(&bsc_node, config_write_bsc);
- install_default(BSC_NODE);
+ bsc_install_default(BSC_NODE);
install_element(BSC_NODE, &cfg_net_bsc_mid_call_text_cmd);
install_element(BSC_NODE, &cfg_net_bsc_mid_call_timeout_cmd);
install_element(BSC_NODE, &cfg_net_rf_socket_cmd);
@@ -617,7 +617,7 @@ int bsc_vty_init_extra(void)
install_element(BSC_NODE, &cfg_net_no_rf_off_time_cmd);
install_node(&msc_node, config_write_msc);
- install_default(MSC_NODE);
+ bsc_install_default(MSC_NODE);
install_element(MSC_NODE, &cfg_net_bsc_token_cmd);
install_element(MSC_NODE, &cfg_net_bsc_ncc_cmd);
install_element(MSC_NODE, &cfg_net_bsc_mcc_cmd);
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
index b2ec156..9eab574 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
@@ -1192,9 +1192,7 @@ int bsc_nat_vty_init(struct bsc_nat *nat)
/* nat group */
install_element(CONFIG_NODE, &cfg_nat_cmd);
install_node(&nat_node, config_write_nat);
- install_default(NAT_NODE);
- install_element(NAT_NODE, &ournode_exit_cmd);
- install_element(NAT_NODE, &ournode_end_cmd);
+ bsc_install_default(NAT_NODE);
install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
@@ -1235,18 +1233,14 @@ int bsc_nat_vty_init(struct bsc_nat *nat)
install_element(NAT_NODE, &cfg_nat_pgroup_cmd);
install_element(NAT_NODE, &cfg_nat_no_pgroup_cmd);
install_node(&pgroup_node, config_write_pgroup);
- install_default(PGROUP_NODE);
- install_element(PGROUP_NODE, &ournode_exit_cmd);
- install_element(PGROUP_NODE, &ournode_end_cmd);
+ bsc_install_default(PGROUP_NODE);
install_element(PGROUP_NODE, &cfg_pgroup_lac_cmd);
install_element(PGROUP_NODE, &cfg_pgroup_no_lac_cmd);
/* BSC subgroups */
install_element(NAT_NODE, &cfg_bsc_cmd);
install_node(&bsc_node, config_write_bsc);
- install_default(NAT_BSC_NODE);
- install_element(NAT_BSC_NODE, &ournode_exit_cmd);
- install_element(NAT_BSC_NODE, &ournode_end_cmd);
+ bsc_install_default(NAT_BSC_NODE);
install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd);
install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd);
install_element(NAT_BSC_NODE, &cfg_bsc_no_lac_cmd);
diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py
index e91d018..5af59a9 100644
--- a/openbsc/tests/vty_test_runner.py
+++ b/openbsc/tests/vty_test_runner.py
@@ -74,11 +74,6 @@ class TestVTYGenericBSC(TestVTYBase):
except BaseException as e:
sys.stderr.write('Expected and ignored failure: %s\n' % (str(e)))
- def notIgnoredTest(self):
- sys.stderr.write('Going to ignore the next assertion(s) due to known bugs\n')
- return False
-
-
def _testConfigNetworkTree(self):
self.vty.enable()
self.assertTrue(self.vty.verify("configure terminal",['']))
@@ -128,10 +123,7 @@ class TestVTYNITB(TestVTYGenericBSC):
self.assertEquals(self.vty.node(), 'config-smpp')
self.ignoredCheckForEndAndExit()
self.assertTrue(self.vty.verify("exit", ['']))
- if self.notIgnoredTest():
- self.assertEquals(self.vty.node(), 'config')
- else:
- self.assertTrue(self.vty.verify("configure terminal", ['']))
+ self.assertEquals(self.vty.node(), 'config')
self.assertTrue(self.vty.verify("exit", ['']))
self.assertTrue(self.vty.node() is None)
@@ -185,20 +177,14 @@ class TestVTYBSC(TestVTYGenericBSC):
self.ignoredCheckForEndAndExit()
self.assertTrue(self.vty.verify("msc 0", ['']))
self.assertEquals(self.vty.node(), 'config-msc')
- self.ignoredCheckForEndAndExit()
+ self.checkForEndAndExit()
self.assertTrue(self.vty.verify("exit", ['']))
- if self.notIgnoredTest():
- self.assertEquals(self.vty.node(), 'config')
- else:
- self.assertTrue(self.vty.verify("configure terminal", ['']))
+ self.assertEquals(self.vty.node(), 'config')
self.assertTrue(self.vty.verify("bsc", ['']))
self.assertEquals(self.vty.node(), 'config-bsc')
- self.ignoredCheckForEndAndExit()
+ self.checkForEndAndExit()
self.assertTrue(self.vty.verify("exit", ['']))
- if self.notIgnoredTest():
- self.assertEquals(self.vty.node(), 'config')
- else:
- self.assertTrue(self.vty.verify("configure terminal", ['']))
+ self.assertEquals(self.vty.node(), 'config')
self.assertTrue(self.vty.verify("exit", ['']))
self.assertTrue(self.vty.node() is None)