cisco_ap_ctl.py lf_cisco_dfs.py : debugging reading AP over serial

This commit is contained in:
Chuck SmileyRekiere
2021-02-11 20:05:13 -07:00
parent 2b4071d985
commit 134a821a56
2 changed files with 29 additions and 27 deletions

View File

@@ -84,6 +84,16 @@ class FileAdapter(object):
def main():
global logfile
AP_ESCAPE = "Escape character is '^]'."
AP_USERNAME = "Username:"
AP_PASSWORD = "Password:"
AP_EN = "en"
AP_MORE = "--More--"
AP_EXIT = "exit"
LF_PROMPT = "$"
CR = "\r\n"
parser = argparse.ArgumentParser(description="Cisco AP Control Script")
parser.add_argument("-a", "--prompt", type=str, help="ap prompt")
@@ -135,6 +145,9 @@ def main():
egg = SerialSpawn(ser)
egg.logfile = FileAdapter(logg)
time.sleep(1)
egg.sendline(CR)
time.sleep(1)
elif (scheme == "ssh"):
if (port is None):
port = 22
@@ -159,14 +172,6 @@ def main():
AP_PROMPT = "{}>".format(args.prompt)
AP_HASH = "{}#".format(args.prompt)
AP_ESCAPE = "Escape character is '^]'."
AP_USERNAME = "Username:"
AP_PASSWORD = "Password:"
AP_EN = "en"
AP_MORE = "--More--"
AP_EXIT = "exit"
LF_PROMPT = "$"
CR = "\r\n"
time.sleep(0.1)
logged_in = False
loop_count = 0
@@ -174,44 +179,44 @@ def main():
loop_count += 1
i = egg.expect_exact([AP_ESCAPE,AP_PROMPT,AP_HASH,AP_USERNAME,AP_PASSWORD,AP_MORE,LF_PROMPT,pexpect.TIMEOUT],timeout=5)
if i == 0:
logg.info("Expect: {} i: {} loop_count: {}before: {} after: {}".format(AP_ESCAPE,i,egg.before,egg.after))
logg.info("Expect: {} i: {} before: {} after: {}".format(AP_ESCAPE,i,egg.before,egg.after))
egg.sendline(CR) # Needed after Escape or should just do timeout and then a CR?
sleep(0.4)
sleep(1)
if i == 1:
logg.info("Expect: {} i: {} before: {} after: {}".format(AP_PROMPT,i,egg.before,egg.after))
egg.sendline(AP_EN)
sleep(0.4)
sleep(1)
if i == 2:
logg.info("Expect: {} i: {} before: {} after: {}".format(AP_HASH,i,egg.before,egg.after))
logged_in = True
sleep(0.4)
sleep(1)
if i == 3:
logg.info("Expect: {} i: {} before: {} after: {}".format(AP_USERNAME,i,egg.before,egg.after))
egg.sendline(args.user)
sleep(0.4)
sleep(1)
if i == 4:
logg.info("Expect: {} i: {} before: {} after: {}".format(AP_PASSWORD,i,egg.before,egg.after))
egg.sendline(args.passwd)
sleep(0.4)
sleep(1)
if i == 5:
logg.info("Expect: {} i: {} before: {} after: {}".format(AP_MORE,i,egg.before,egg.after))
if (scheme == "serial"):
egg.sendline("r")
else:
egg.sendcontrol('c')
sleep(0.4)
sleep(1)
# for Testing serial connection using Lanforge
if i == 6:
logg.info("Expect: {} i: {} before: {} after: {}".format(LF_PROMPT,i,egg.before.decode('utf-8', 'ignore'),egg.after.decode('utf-8', 'ignore')))
if (loop_count < 3):
egg.send("ls -lrt")
sleep(0.4)
sleep(1)
if (loop_count > 4):
logged_in = True # basically a test mode using lanforge serial
if i == 7:
logg.info("Expect: {} i: {} before: {} after: {}".format("Timeout",i,egg.before,egg.after))
egg.sendline(CR)
sleep(0.4)
sleep(1)
if (args.action == "powercfg"):
@@ -246,8 +251,8 @@ def main():
else: # no other command at this time so send the same power command
#logg.info("no action so execute: show controllers dot11Radio 1 powercfg | g T1")
logg.info("no action so execute: show log")
egg.sendline('show log')
logg.info("no action")
'''egg.sendline('show log')
egg.expect([pexpect.TIMEOUT], timeout=3) # do not delete this allows for subprocess to see output
print(egg.before.decode('utf-8', 'ignore')) # do not delete this allows for subprocess to see output
@@ -259,7 +264,7 @@ def main():
if i == 1:
if (scheme != "serial"):
logg.info("send cntl c anyway, received timeout")
egg.sendcontrol('c')
egg.sendcontrol('c')'''
i = egg.expect_exact([AP_PROMPT,AP_HASH,pexpect.TIMEOUT],timeout=1)
if i == 0:

View File

@@ -2335,7 +2335,7 @@ Sample script
logg.info("cisco_ap_ctl.py: clear log")
# TODO remove position dependence if in tree
ap_info= subprocess.run(["./../cisco_ap_ctl.py", "--scheme", ap_dict['ap_scheme'], "--prompt", ap_dict['ap_prompt'],"--dest", ap_dict['ap_ip'], "--port", ap_dict["ap_port"],
"--user", ap_dict['ap_user'], "--passwd", ap_dict['ap_pw'],"--tty", ap_dict['ap_tty'],"--baud", ap_dict['ap_baud'],"--action", "clear_log"],stdout=subprocess.PIPE)
"--user", ap_dict['ap_user'], "--passwd", ap_dict['ap_pw'],"--tty", ap_dict['ap_tty'],"--baud", ap_dict['ap_baud'],"--action", "clear_log"],capture_output=False, check=True)#stdout=subprocess.PIPE)
try:
pss = ap_info.stdout.decode('utf-8', 'ignore')
except:
@@ -2355,7 +2355,7 @@ Sample script
logg.info("cisco_ap_ctl.py: show log")
# TODO remove position dependence if in tree
ap_info= subprocess.run(["./../cisco_ap_ctl.py", "--scheme", ap_dict['ap_scheme'], "--prompt", ap_dict['ap_prompt'],"--dest", ap_dict['ap_ip'], "--port", ap_dict["ap_port"],
"--user", ap_dict['ap_user'], "--passwd", ap_dict['ap_pw'],"--tty", ap_dict['ap_tty'],"--baud", ap_dict['ap_baud'],"--action", "show_log"],stdout=subprocess.PIPE)
"--user", ap_dict['ap_user'], "--passwd", ap_dict['ap_pw'],"--tty", ap_dict['ap_tty'],"--baud", ap_dict['ap_baud'],"--action", "show_log"],capture_output=False, check=True) #stdout=subprocess.PIPE
try:
pss = ap_info.stdout.decode('utf-8', 'ignore')
except:
@@ -2369,7 +2369,6 @@ Sample script
logg.info("# Unable to commicate to AP error code: {} output {}".format(process_error.returncode, process_error.output))
logg.info("####################################################################################################")
logg.info(pss)
exit(1)
cisco.controller_enable_ap()
# need to actually check the CAC timer
@@ -2380,7 +2379,7 @@ Sample script
logg.info("DFS 5ghz channel {} being set wait CAC time 60, 2.4 ghz: {} : ".format(__chan_5ghz_set, __chan_24ghz_set))
# read AP to verify CAC timer set
# will need to use time to verify CAC from AP - need in results
cac_sleeptime = "65"
cac_sleeptime = "5" # 65
logg.info("CAC start sleeptime: {}".format(cac_sleeptime))
time.sleep(int(cac_sleeptime))
logg.info("CAC done sleeptime: {}".format(cac_sleeptime))
@@ -2400,7 +2399,7 @@ Sample script
logg.info("cisco_ap_ctl.py: read for CAC timer and CAC_EXPIRY_EVT")
# TODO remove position dependence if in tree
ap_info= subprocess.run(["./../cisco_ap_ctl.py", "--scheme", ap_dict['ap_scheme'], "--prompt", ap_dict['ap_prompt'],"--dest", ap_dict['ap_ip'], "--port", ap_dict["ap_port"],
"--user", ap_dict['ap_user'], "--passwd", ap_dict['ap_pw'],"--tty", ap_dict['ap_tty'],"--baud", ap_dict['ap_baud'],"--action", "show_log"],stdout=subprocess.PIPE)
"--user", ap_dict['ap_user'], "--passwd", ap_dict['ap_pw'],"--tty", ap_dict['ap_tty'],"--baud", ap_dict['ap_baud'],"--action", "show_log"],capture_output=True, check=True)
try:
pss = ap_info.stdout.decode('utf-8', 'ignore')
except:
@@ -2516,7 +2515,6 @@ Sample script
logg.info("3504 test_parameters cc_dbm: read : {}".format(cc_dbm))
logg.info("3504 test_parameters cc_ch: read : {}".format(cc_ch))
break
exit(1)
######################################################
# end of cisco controller code no change to controller
######################################################
@@ -2652,7 +2650,6 @@ Sample script
exit(1)
client_density = ip_var_test.station_bringup()
cisco.verify_controller(client_density)
ip_var_test.start(False, False)
ip_var_test.stop()
if not ip_var_test.passes():