Re: Telnet.Set Prompt does not take effect

877 views
Skip to first unread message

Heiko Thiery

unread,
Nov 20, 2012, 11:12:23 AM11/20/12
to andreas...@adtran.com, robotframe...@googlegroups.com
Try to set the prompt after opening the connection:

*testcases*
test connection
    open connection         192.168.157.66     # prompt=(#|>)    prompt_is_regexp=true
    set prompt              prompt=(#|>)    prompt_is_regexp=true
    login                   schnutti  putz
      :
      :


2012/11/20 Andreas Kemmler <andreas...@adtran.com>
Hi,

recently we started using robot framework for testing straightforward DSLAM scenarios. One of the first steps is to get device access by trying something like this ...

*settings*
library     Telnet  timeout=5    # prompt=(#|>)  prompt_is_regexp=true

*testcases*
test connection
    set prompt              prompt=(#|>)    prompt_is_regexp=true
    open connection         192.168.157.66     # prompt=(#|>)    prompt_is_regexp=true
    login                   schnutti  putz
    execute command         enable
    write                   exit
    close connection


But unfortunately this fails and the log is telling ...

14:42:59.535  INFO  enable
14:42:59.535  FAIL  Prompt is not set
14:42:59.535
 DEBUG  Traceback (most recent call last): File "D:\akemmler\python\lib\site-packages\robot\libraries\Telnet.py", line 457, in execute_command return self.read_until_prompt(loglevel) File "D:\akemmler\python\lib\site-packages\robot\libraries\Telnet.py", line 434, in read_until_prompt raise RuntimeError('Prompt is not set')

The testcase fails with the message "Prompt is not set" coming from Telnet library, but we did call "Telnet.Set Prompt" indeed as shown above.
It works fine if we either pass the prompt settings within library import statement or within the open connection keyword, see commented out parts above. So what goes wrong if we use "set prompt" instead ?

Using "Telnet.Set Prompt" would be useful if there are several connections to different devices with different prompts at the same time unless "Telnet.Switch Connection" would also change the used prompt. But this is probably not the case, isn't it ?

Andreas

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/robotframework-users/-/HFxYIhXo9ckJ.
To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.

Andreas Kemmler

unread,
Nov 21, 2012, 9:10:27 AM11/21/12
to robotframe...@googlegroups.com, andreas...@adtran.com
This does not help, login at test system succeeds and prompt settings seem to be correct now, but Telnet.Login keyword fails anyway:

No match found for 'prompt=(#|>)' in 5 seconds

Unfortunately I am not familiar with Python and therefore I do not really understand what is going on there in Telnet library, but I did put some prints in the library code to see what is called and what is currently self._prompt:

def set_prompt(self, prompt, prompt_is_regexp=False):
        ...
        print >> sys.stderr, 'setting ... self prompt is {0},{1}'.format(self._prompt[0], self._prompt[1])
        return old

def _prompt_is_set(self):
        print >> sys.stderr, 'checking ... self prompt is {0},{1}'.format(self._prompt[0], self._prompt[1])
        return self._prompt[0] is not None


The results are surprising. Before TC starts there are always about 15 (!) consecutive prints "setting ... self prompt is None,False".
If we set the prompt by library import statement or by open connection keyword then in both cases the test succeeds and we get:

setting ... self prompt is <_sre.SRE_Pattern object at 0x027963E0>,True
setting ... self prompt is None,False
checking ... self prompt is <_sre.SRE_Pattern object at 0x027963E0>,True
checking ... self prompt is <_sre.SRE_Pattern object at 0x027963E0>,True
checking ... self prompt is <_sre.SRE_Pattern object at 0x027963E0>,True


test connection                                                       | PASS |

Hmm, I do not really understand here why prompt setting is undone and why nevertheless checking succeeds anyway !?
If we use neither prompt setting by import statement nor by open connection keyword but by using the set prompt keyword instead then we get:

setting ... self prompt is None,False
setting ... self prompt is None,False
setting ... self prompt is <_sre.SRE_Pattern object at 0x027112F0>,True
setting ... self prompt is None,False
checking ... self prompt is None,False
checking ... self prompt is None,False

test connection                                                       | FAIL |
Prompt is not set

Well, we had intermediately at least one valid prompt which was anyhow overwritten afterwards like above. But now the check function tells the truth and the test fails.
Last but not least the result of your proposal:

setting ... self prompt is None,False
setting ... self prompt is None,False
setting ... self prompt is <_sre.SRE_Pattern object at 0x026E1F50>,True
checking ... self prompt is <_sre.SRE_Pattern object at 0x026E1F50>,True
checking ... self prompt is <_sre.SRE_Pattern object at 0x026E1F50>,True

test connection                                                       | FAIL |
No match found for 'prompt=(#|>)' in 5 seconds


Well, the debug prints look better now than in all the other tries before, but nevertheless the testcase fails although the prompt seems to be set correctly.

Andreas


2012/11/20 Andreas Kemmler <andreas...@adtran.com>
To unsubscribe from this group, send email to robotframework-users+unsub...@googlegroups.com.

Heiko Thiery

unread,
Nov 21, 2012, 2:04:54 PM11/21/12
to andreas...@adtran.com, robotframe...@googlegroups.com
Maybe your prompt is not set correctly. try this:

set prompt              prompt=#|>


2012/11/21 Andreas Kemmler <andreas...@adtran.com>

To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.

Andreas Kemmler

unread,
Nov 22, 2012, 5:50:42 AM11/22/12
to robotframe...@googlegroups.com, andreas...@adtran.com
The parentheses are not the problem, but the named argument because the argument 'prompt' has no default value.

def set_prompt(self, prompt, prompt_is_regexp=False)

Things like this are very very very hard to recognize for Robot beginners like me. My keyword call was:
          
                   *bad*                *good*

set prompt          prompt=(#|>)        prompt_is_regexp=true


This does not work like expected, set_prompt() is called here with 'prompt=(#|>)' and 'true'. Of course that is not what we want, instead we have to use:

                    *good*              *good*
set prompt          (#|>)               prompt_is_regexp=true


In contrast using "library  Telnet  prompt=(#|>)" as well as "open connection  prompt=(#|>)" works fine because in these cases the prompt argument has a default value (which is None of course).

You were right, that the call to "set prompt" must be done after opening the connection. Doing this before opening the connection will set the prompt in any dummy instance of class TelnetConnection and will never take effect. Obviously this dummy also caused the suspicious prints "setting ... self prompt is None,False" after the prompt was set in the successful examples recently posted. Maybe the implementation works rather with "copy instance" instead of "reference instance", I do not know. 

Andreas  


2012/11/21 Andreas Kemmler <andreas...@adtran.com>


2012/11/20 Andreas Kemmler <andreas...@adtran.com>

To unsubscribe from this group, send email to robotframework-users+unsubscrib...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.

Heiko Thiery

unread,
Nov 25, 2012, 1:33:16 PM11/25/12
to andreas...@adtran.com, robotframe...@googlegroups.com
But now with figuring out that you can not use named argument for prompt in the open connection keyword you solved your problem? is that right?

Heiko

2012/11/22 Andreas Kemmler <andreas...@adtran.com>
o

Andreas Kemmler

unread,
Nov 26, 2012, 4:51:24 AM11/26/12
to robotframe...@googlegroups.com, andreas...@adtran.com
Yes, it is.

Ironically I have learned while debugging the problem that there are no needs for us to use "set prompt" because a prompt which is passed by keyword "open connection" will be bound to the new connection instance and is not lost if the current connection is intermediately switched to another one. There are two prompts in Robot's Telnet library:

Telnet::_prompt
TelnetConnection::_prompt


Telnet::_prompt is set by library import statement only in Telnet's constructor while TelnetConnection::_prompt is set by class TelnetConnection constructor as well as by member function TelnetConnection::set_prompt. Without having a current connection a call to set_prompt does absolutely nothing.

If I would have read the documentation carefully at the beginning I could have known this already ....

"Set Prompt | Sets the prompt used in this connection to prompt."

Little by little one goes far.

Andreas

Heiko Thiery

unread,
Nov 26, 2012, 7:22:43 AM11/26/12
to andreas...@adtran.com, robotframe...@googlegroups.com
Ok, that is also new for me. One other thing to be mentioned:

You can alos get the previous set promt as return value and reset to the origin later:

e.g.

${oldPrompt}=  Set Prompt  #|>
... to anything here
Set Prompt  ${oldPrompt}

Maybe this helps ...


2012/11/26 Andreas Kemmler <andreas...@adtran.com>

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.

To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages