Pexpect
Iranna Mathapati
iranna.gani28 at gmail.com
Sat Dec 10 05:33:54 EST 2016
Hi Team,
The fallowing script(function) is working if its in PDB mode(trace line by
line) but same script is not working if its remove/comment PDB and run one
shot.
log.info("Time out expection")
uut_con1 = pexpect.spawn('telnet %s'%power_ip)
uut_con1.logfile = sys.stdout
uut_con1.delaybeforesend = None
time.sleep(30)
uut_con1.send("%s\r" % username)
uut_con1.expect([r"Password:"],timeout=30)
uut_con1.send("%s\r" % pass_word)
time.sleep(30)
uut_con1.send("\r")
uut_con1.expect([r'#?'],timeout=30)
uut_con1.send("power outlets %d off\r"%outlet)
uut_con1.expect([r'wish to turn outlet'],timeout=30)
uut_con1.send("y\r")
uut_con1.send("\r")
uut_con1.expect([r'#?'],timeout=30)
uut_con1.send("power outlets %d on\r"%outlet)
uut_con1.expect([r'wish to turn outlet'],timeout=30)
uut_con1.send("y\r")
uut_con1.send("\r")
uut_con1.expect([r'#?'],timeout=30)
uut_con1.close()
uut_con.close()
time.sleep(300)
check_prompt(self,username,pass_word,dev_ip,dev_port,power_ip,outlet)
*I got fallowing error:*
2016-12-10T02:24:42: %aetest-INFO: Time out expection
Trying 172.31.206.143...
Connected to 172.31.206.143.
Escape character is '^]'.
Login for PX2 CLI
Username: admin
power outlets 21 off
Welcome to PX2 CLI!
Last login: 2001-06-30 11:53:59 EDT [CLI (Telnet) from 172.31.144.6]
#
# power outlets 21 off
yower outlets 21 on outlet 21 off? [y/n] y
power outlets 21 on
# 2016-12-10T02:26:12: %aetest-ERROR: Caught exception during execution:
2016-12-10T02:26:13: %aetest-ERROR: Traceback (most recent call last):
2016-12-10T02:26:13: %aetest-ERROR: File
"/auto/n3k-qa/CODC/rajtamil/pyATS2.7/hlite/eor/systest/scripts/NAT/ATS_CLEAN_N9K.py",
line 354, in connect_devices
2016-12-10T02:26:13: %aetest-ERROR:
check_prompt(self,username,pass_word,dev_ip,dev_port,power_ip,outlet)
2016-12-10T02:26:13: %aetest-ERROR: File
"/auto/n3k-qa/CODC/rajtamil/pyATS2.7/hlite/eor/systest/scripts/NAT/ATS_CLEAN_N9K.py",
line 282, in check_prompt
2016-12-10T02:26:13: %aetest-ERROR: uut_con1.expect([r'wish to turn
outlet'],timeout=30)
2016-12-10T02:26:13: %aetest-ERROR: File
"/auto/n3k-qa/CODC/svanalin/pyats2/lib/python2.7/site-packages/pexpect/spawnbase.py",
line 321, in expect
2016-12-10T02:26:13: %aetest-ERROR: timeout, searchwindowsize, async)
2016-12-10T02:26:13: %aetest-ERROR: File
"/auto/n3k-qa/CODC/svanalin/pyats2/lib/python2.7/site-packages/pexpect/spawnbase.py",
line 345, in expect_list
2016-12-10T02:26:13: %aetest-ERROR: return exp.expect_loop(timeout)
2016-12-10T02:26:13: %aetest-ERROR: File
"/auto/n3k-qa/CODC/svanalin/pyats2/lib/python2.7/site-packages/pexpect/expect.py",
line 107, in expect_loop
2016-12-10T02:26:13: %aetest-ERROR: return self.timeout(e)
2016-12-10T02:26:13: %aetest-ERROR: File
"/auto/n3k-qa/CODC/svanalin/pyats2/lib/python2.7/site-packages/pexpect/expect.py",
line 70, in timeout
2016-12-10T02:26:13: %aetest-ERROR: raise TIMEOUT(msg)
2016-12-10T02:26:13: %aetest-ERROR: TIMEOUT: Timeout exceeded.
2016-12-10T02:26:13: %aetest-ERROR: <pexpect.pty_spawn.spawn object at
0xf686d5ec>
2016-12-10T02:26:13: %aetest-ERROR: command: /usr/bin/telnet
2016-12-10T02:26:13: %aetest-ERROR: args: ['/usr/bin/telnet',
'172.31.206.143']
2016-12-10T02:26:13: %aetest-ERROR: buffer (last 100 chars): ' 21 off?
[y/n] y\r\n\r\npower outlets 21 on\r\n# '
2016-12-10T02:26:13: %aetest-ERROR: before (last 100 chars): ' 21 off?
[y/n] y\r\n\r\npower outlets 21 on\r\n# '
2016-12-10T02:26:13: %aetest-ERROR: after: <class
'pexpect.exceptions.TIMEOUT'>
2016-12-10T02:26:13: %aetest-ERROR: match: None
2016-12-10T02:26:13: %aetest-ERROR: match_index: None
2016-12-10T02:26:13: %aetest-ERROR: exitstatus: None
2016-12-10T02:26:13: %aetest-ERROR: flag_eof: False
2016-12-10T02:26:13: %aetest-ERROR: pid: 9163
2016-12-10T02:26:13: %aetest-ERROR: child_fd: 18
2016-12-10T02:26:13: %aetest-ERROR: closed: False
2016-12-10T02:26:13: %aetest-ERROR: timeout: 30
2016-12-10T02:26:13: %aetest-ERROR: delimiter: <class
'pexpect.exceptions.EOF'>
2016-12-10T02:26:13: %aetest-ERROR: logfile: <open file '<stdout>', mode
'w' at 0xf7712078>
2016-12-10T02:26:13: %aetest-ERROR: logfile_read: None
2016-12-10T02:26:13: %aetest-ERROR: logfile_send: None
2016-12-10T02:26:13: %aetest-ERROR: maxread: 2000
2016-12-10T02:26:13: %aetest-ERROR: ignorecase: False
2016-12-10T02:26:13: %aetest-ERROR: searchwindowsize: None
2016-12-10T02:26:13: %aetest-ERROR: delaybeforesend: None
2016-12-10T02:26:13: %aetest-ERROR: delayafterclose: 0.1
2016-12-10T02:26:13: %aetest-ERROR: delayafterterminate: 0.1
2016-12-10T02:26:13: %aetest-ERROR: searcher: searcher_re:
2016-12-10T02:26:13: %aetest-ERROR: 0: re.compile("wish to turn outlet")
2016-12-10T02:26:13: %aetest-INFO: The result of subsection connect_devices
is => ERRORED
Regards,
Iranna M
More information about the Python-list
mailing list