Review at  https://gerrit.osmocom.org/6037

Osmocom_VTY_Functions: Make prompt configurable

We want to use this code also for OsmoMSC testing, so let's make the
prefix configurable as module parameter.

Change-Id: Iec846227e88b3dc0d3be9474b8b926719161c9ee
---
M library/Osmocom_VTY_Functions.ttcn
1 file changed, 42 insertions(+), 33 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/37/6037/1

diff --git a/library/Osmocom_VTY_Functions.ttcn 
b/library/Osmocom_VTY_Functions.ttcn
index 1215e0d..eb51a03 100644
--- a/library/Osmocom_VTY_Functions.ttcn
+++ b/library/Osmocom_VTY_Functions.ttcn
@@ -1,58 +1,67 @@
 module Osmocom_VTY_Functions {
        import from TELNETasp_PortType all;
 
-       /* permitted prompts on VTY */
-       const charstring NORMAL_PROMPT := "OpenBSC> ";
-       const charstring ENABLE_PROMPT := "OpenBSC# ";
-       const charstring CONFIG_PROMPT := "OpenBSC(*)\#";
-       template charstring t_vty_unknown := pattern "*% Unknown command.";
+       modulepar {
+               charstring mp_prompt_prefix := "OpenBSC";
+       }
 
-       const ASP_TelnetDynamicConfig vty_prompt[3] := {
-               {
-                       prompt := {
-                               id := 1,
-                               prompt := NORMAL_PROMPT,
-                               has_wildcards := false
-                       }
-               }, {
-                       prompt := {
-                               id := 2,
-                               prompt := ENABLE_PROMPT,
-                               has_wildcards := false
-                       }
-               }, {
-                       prompt := {
-                               id := 3,
-                               prompt := CONFIG_PROMPT,
-                               has_wildcards := true
-                       }
-               }
-       };
+       const charstring VTY_VIEW_SUFFIX := "> ";
+       const charstring VTY_ENABLE_SUFFIX := "# ";
+       const charstring VTY_CFG_SUFFIX := "(*)";
+
+       template charstring t_vty_unknown := pattern "*% Unknown command.";
 
        /* configure prompts in TELNETasp module */
        function f_vty_set_prompts(TELNETasp_PT pt) {
+               var ASP_TelnetDynamicConfig vty_prompt[3] := {
+                       {
+                               prompt := {
+                                       id := 1,
+                                       prompt := mp_prompt_prefix & 
VTY_VIEW_SUFFIX,
+                                       has_wildcards := false
+                               }
+                       }, {
+                               prompt := {
+                                       id := 2,
+                                       prompt := mp_prompt_prefix & 
VTY_ENABLE_SUFFIX,
+                                       has_wildcards := false
+                               }
+                       }, {
+                               prompt := {
+                                       id := 3,
+                                       prompt := mp_prompt_prefix & 
VTY_CFG_SUFFIX,
+                                       has_wildcards := true
+                               }
+                       }
+               };
+
                /* set some configuration that isn't possible to express
                 * in the config file due to syntactic restrictions (Who 
invents config
                 * files that don't permit regular expressions? */
                for (var integer i := 0; i < sizeof(vty_prompt); i:= i + 1) {
-                       pt.send(vty_prompt[i])
+                       log(vty_prompt[i]);
+                       pt.send(vty_prompt[i]);
                }
        }
 
        /* wait for any of the permitted prompts; buffer + return all 
intermediate output */
        function f_vty_wait_for_prompt(TELNETasp_PT pt) return charstring {
-               template charstring config_pattern := pattern CONFIG_PROMPT;
                var charstring rx, buf := "";
                timer T := 2.0;
 
                T.start;
                alt {
-                       [] pt.receive(NORMAL_PROMPT) { };
-                       [] pt.receive(ENABLE_PROMPT) { };
-                       [] pt.receive(config_pattern) { };
-                       [] pt.receive(t_vty_unknown) { testcase.stop(fail, 
"VTY: Unknown Command") };
+                       [] pt.receive(mp_prompt_prefix & VTY_VIEW_SUFFIX) { };
+                       [] pt.receive(mp_prompt_prefix & VTY_ENABLE_SUFFIX) { };
+                       [] pt.receive(pattern mp_prompt_prefix & 
VTY_CFG_SUFFIX) { };
+                       [] pt.receive(t_vty_unknown) {
+                               testcase.stop(fail, "VTY: Unknown Command");
+                               };
                        [] pt.receive(charstring:?) -> value rx { buf := buf & 
rx; repeat };
-                       [] T.timeout { setverdict(fail, "VTY Timeout for 
prompt"); return ""};
+                       [] T.timeout {
+                               setverdict(fail, "VTY Timeout for prompt");
+                               self.stop;
+                               };
                }
                T.stop;
                return buf;

-- 
To view, visit https://gerrit.osmocom.org/6037
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iec846227e88b3dc0d3be9474b8b926719161c9ee
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <[email protected]>

Reply via email to