Random command automatic test script | Python implementation under SecureCRT

In the development of command terminal software and communication road development, it is often necessary to test the stability of the terminal. At this time, typing commands through command scripts can save a lot of manpower. Here is an automated test script implemented by python under SecureCRT terminal simulation software. You can randomly select commands from the command list for testing, and have the functions of setting sleep time and overtime discovery.

# $language ="python"
# $interface="1.0"

# This automatically generated script may need to be
# edited in order to work correctly.import time
import math
import random

start_time = time.time()
end_time = time.time()
cmd ="show sw"
cmd_list =['show interface switchport xge 1/0/20','show vlan all','show arp all','show mac-address all','show trap message filter level 1']
cmd_list_len =len(cmd_list)-1
time_sleep =0.1
time_out =30

def Main():
 crt.Screen.Send("co te\r\n")
 crt.Screen.Send("int xge 1/0/6\r\n")while True:
  end_time = time.time()
  crt.Screen.Synchronous = False
  # crt.Screen.Send(cmd)
  CmdNum = random.randint(0,cmd_list_len)
  crt.Screen.Send(cmd_list[CmdNum])
  crt.Screen.Send("\r\n")
  running_time = end_time - start_time
  running_min = math.ceil(running_time /60)-1if(crt.Screen.WaitForCursor(time_out)):
   # crt.Screen.Send("\r\n")
   # crt.Screen.Send("\r\n")
   # crt.Screen.Send("\r\n")
   # crt.Screen.Send("\r\n")
   # crt.Screen.Send("\r\n")if CmdNum ==10:
    time.sleep(10)else:
    time.sleep(time_sleep)
   # time.sleep(100/(running_time /1000))else:        
   msg ="No response after timeout, run report:\n"+ \
    " running time : "+str( running_min )+" min "+str(running_time - running_min *60- time_out)+" s "+"\n"+ \
    " start ms        : "+str(start_time)+"\n"+ \
    " ent ms          : "+str(end_time)+"\n"
   crt.Dialog.MessageBox(msg,"session",64|2)Main()

Author: Frytea
Title: Random command automatic test script | Python implementation under SecureCRT
Link: https://blog.frytea.com/archives/485/
Copyright: This work by TL-Song is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Recommended Posts

Random command automatic test script | Python implementation under SecureCRT
Python implementation of AI automatic matting example analysis
Random command automatic test script | Python implementation under SecureCRT
Python MySQLd under Ubuntu
[python] python2 and python3 under ubuntu
Install python environment under Linux
Python3 script programming commonly used.md
Python waterfall line indicator writing example
Python Chinese encoding setting under ubuntu
Install Python3 and ansible under CentOS8
Install Python3 and Py under CentOS7