mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-20 20:14:57 +00:00
wifi_ctl_9800_3504.py : auto pep8 white space clean up
Signed-off-by: Chuck SmileyRekiere <chuck.smileyrekiere@candelatech.com>
This commit is contained in:
committed by
shivam
parent
af490281a7
commit
3037eb9e24
@@ -67,6 +67,7 @@ FORMAT = '%(asctime)s %(name)s %(levelname)s: %(message)s'
|
||||
band = "a"
|
||||
egg = None # think "eggpect" Need global scope for recovery
|
||||
|
||||
|
||||
def usage():
|
||||
print("$0 used connect to controller:")
|
||||
print("-d|--dest: destination host")
|
||||
@@ -86,14 +87,18 @@ def usage():
|
||||
print("-h|--help")
|
||||
|
||||
# see https://stackoverflow.com/a/13306095/11014343
|
||||
|
||||
|
||||
class FileAdapter(object):
|
||||
def __init__(self, logger):
|
||||
self.logger = logger
|
||||
|
||||
def write(self, data):
|
||||
# NOTE: data can be a partial line, multiple lines
|
||||
data = data.strip() # ignore leading/trailing whitespace
|
||||
if data: # non-blank
|
||||
self.logger.info(data)
|
||||
|
||||
def flush(self):
|
||||
pass # leave it to logging to flush properly
|
||||
|
||||
@@ -121,7 +126,6 @@ def main():
|
||||
# parser.add_argument("--tag_policy", type=str, help="--tag_policy default-tag-policy", default="RM204-TB2")
|
||||
parser.add_argument("--policy_profile", type=str, help="--policy_profile default-policy-profile", default="default-policy-profile")
|
||||
|
||||
|
||||
parser.add_argument("--action", type=str, help="perform action",
|
||||
choices=["config", "debug_disable_all", "no_logging_console", "line_console_0", "country", "ap_country", "enable", "disable", "summary", "advanced",
|
||||
"cmd", "txPower", "bandwidth", "manual", "auto", "no_wlan", "show_wlan_summary",
|
||||
@@ -140,7 +144,7 @@ def main():
|
||||
user = args.user
|
||||
passwd = args.passwd
|
||||
logfile = args.log
|
||||
if (args.band != None):
|
||||
if (args.band is not None):
|
||||
band = args.band
|
||||
if (band == "abgn"):
|
||||
band = "-abgn"
|
||||
@@ -197,14 +201,13 @@ def main():
|
||||
print("CCP_POLICY_TAG {}".format(CCP_POLICY_TAG))
|
||||
print("CCP_CONFIG_LINE {}".format(CCP_CONFIG_LINE))'''
|
||||
|
||||
|
||||
try:
|
||||
if (scheme == "serial"):
|
||||
# eggspect = pexpect.fdpexpect.fdspan(telcon, logfile=sys.stdout.buffer)
|
||||
import serial
|
||||
from pexpect_serial import SerialSpawn
|
||||
with serial.Serial('/dev/ttyUSB0', 115200, timeout=5) as ser:
|
||||
egg = SerialSpawn(ser);
|
||||
egg = SerialSpawn(ser)
|
||||
egg.logfile = FileAdapter(logg)
|
||||
print("logg {}".format(logg))
|
||||
egg.sendline(NL)
|
||||
@@ -375,7 +378,9 @@ def main():
|
||||
found_escape = False
|
||||
|
||||
if j == 5:
|
||||
logg.info("9800 timed out looking for CCP :{},CCP_EN: {},CCP_CONFIG: {} loop_count {} i {} j {} before {} after {}".format(CCP,CCP_EN,CCP_CONFIG,loop_count,i,j,egg.before,egg.after))
|
||||
logg.info(
|
||||
"9800 timed out looking for CCP :{},CCP_EN: {},CCP_CONFIG: {} loop_count {} i {} j {} before {} after {}".format(
|
||||
CCP, CCP_EN, CCP_CONFIG, loop_count, i, j, egg.before, egg.after))
|
||||
logg.info("9800 Closing the connection and try to re-establish loop_count {} i {} j {}".format(loop_count, i, j))
|
||||
egg.close(force=True)
|
||||
sleep(1)
|
||||
@@ -547,7 +552,6 @@ def main():
|
||||
egg.close(force=True)
|
||||
exit(1)
|
||||
|
||||
|
||||
# 3504 series
|
||||
else:
|
||||
i = egg.expect(["ssword:", "continue connecting (yes/no)?"], timeout=timeout)
|
||||
@@ -735,7 +739,6 @@ def main():
|
||||
logged_in_9800 = False
|
||||
found_escape = False
|
||||
|
||||
|
||||
if i == 1:
|
||||
logg.info("9800 found {} will elevate loging i:{} before {} after {}".format(CCP, i, egg.before, egg.after))
|
||||
egg.sendline("en")
|
||||
@@ -871,7 +874,12 @@ def main():
|
||||
egg.sentline(CR)
|
||||
sleep(0.2)
|
||||
if i == 9:
|
||||
logg.info("9800 Timed out waiting for initial prompt, Log message from controller interfering with expected prompts loop_count: {} i: {} before {} after {}".format(loop_count, i, egg.before,egg.after))
|
||||
logg.info(
|
||||
"9800 Timed out waiting for initial prompt, Log message from controller interfering with expected prompts loop_count: {} i: {} before {} after {}".format(
|
||||
loop_count,
|
||||
i,
|
||||
egg.before,
|
||||
egg.after))
|
||||
logg.info("9800 Closing the connection and try to re-establish, ")
|
||||
egg.close(force=True)
|
||||
sleep(1)
|
||||
@@ -912,9 +920,9 @@ def main():
|
||||
# 3504 series
|
||||
else:
|
||||
egg.sendline(' ')
|
||||
egg.expect('User\:',timeout=3)
|
||||
egg.expect('User\\:', timeout=3)
|
||||
egg.sendline(user)
|
||||
egg.expect('Password\:',timeout=3)
|
||||
egg.expect('Password\\:', timeout=3)
|
||||
egg.sendline(passwd)
|
||||
# if args.prompt in CCP_EN or args.prompt in CCP:
|
||||
# egg.sendline("enable")
|
||||
@@ -936,7 +944,6 @@ def main():
|
||||
command = None
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
sleep(0.1)
|
||||
if args.series == "9800":
|
||||
pass
|
||||
@@ -1176,7 +1183,6 @@ def main():
|
||||
if i == 1:
|
||||
logg.info("did not get the (config)# prompt")
|
||||
|
||||
|
||||
if (args.action == "wireless_tag_policy"):
|
||||
logg.info("send wireless tag policy")
|
||||
egg.sendline("config t")
|
||||
@@ -1370,7 +1376,6 @@ def main():
|
||||
logg.info("send: config wlan disable {}".format(args.wlan))
|
||||
command = "config wlan disable %s" % (args.wlan)
|
||||
|
||||
|
||||
if (args.action == "wlan_qos" and (args.wlan is None)):
|
||||
raise Exception("wlan ID is required")
|
||||
if (args.action == "wlan_qos"):
|
||||
@@ -1405,7 +1410,7 @@ def main():
|
||||
egg.sendline("logout")
|
||||
sleep(0.1)
|
||||
logged_out_9800 = True
|
||||
except:
|
||||
except BaseException:
|
||||
logg.info("9800 exception on logout")
|
||||
sleep(0.1)
|
||||
break
|
||||
@@ -1415,7 +1420,7 @@ def main():
|
||||
egg.sendline("exit")
|
||||
sleep(0.2)
|
||||
logged_out_9800 = True
|
||||
except:
|
||||
except BaseException:
|
||||
logg.info("9800 exception on end")
|
||||
sleep(0.1)
|
||||
if i == 3:
|
||||
@@ -1423,7 +1428,7 @@ def main():
|
||||
try:
|
||||
egg.sendline("end")
|
||||
sleep(0.2)
|
||||
except:
|
||||
except BaseException:
|
||||
logg.info("9800 exception on end")
|
||||
sleep(0.1)
|
||||
if i == 4:
|
||||
@@ -1431,7 +1436,7 @@ def main():
|
||||
try:
|
||||
egg.sendline("end")
|
||||
sleep(0.2)
|
||||
except:
|
||||
except BaseException:
|
||||
logg.info("9800 exception on end")
|
||||
sleep(0.1)
|
||||
if i == 5:
|
||||
@@ -1439,7 +1444,7 @@ def main():
|
||||
try:
|
||||
egg.sendline("end")
|
||||
sleep(0.2)
|
||||
except:
|
||||
except BaseException:
|
||||
logg.info("9800 exception on end")
|
||||
sleep(0.1)
|
||||
if i == 6:
|
||||
@@ -1474,7 +1479,6 @@ def main():
|
||||
egg.expect([pexpect.TIMEOUT], timeout=1)
|
||||
print(egg.before.decode('utf-8', 'ignore'))
|
||||
|
||||
|
||||
command_sent = False
|
||||
loop_count = 0
|
||||
while command_sent == False and loop_count <= 3:
|
||||
@@ -1503,7 +1507,7 @@ def main():
|
||||
logg.info(" Check to see if logging to console is disabled")
|
||||
command_sent = True
|
||||
|
||||
except:
|
||||
except BaseException:
|
||||
logg.info("closing connection logout loop {}".format(CCPROMPT))
|
||||
try:
|
||||
egg.sendline("logout")
|
||||
@@ -1511,11 +1515,10 @@ def main():
|
||||
logg.info("send close to the egg child process")
|
||||
egg.close(force=True)
|
||||
sleep(0.1)
|
||||
except:
|
||||
except BaseException:
|
||||
logg.info("closing connection on logout")
|
||||
|
||||
|
||||
|
||||
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user