def main(): global tn #### varable for telnet session ####################################################################################################################### #### #### #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) print(pa.cmdprompt) print("@" * 40) ################################################################################################################### ################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### if pa.ipaddr: print("do IP steps") pa.chassis_name = console_info_from_ip(pa.ipaddr) cons_info = console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = get_ip_from_file(pa.chassis_name) steps_to_run = pa.steps fid_to_compare = 128 fid_to_compare = pa.fid ################################################################################################################### #### if the user does not enter a value for which steps to run prompt for user input value #### if not steps_to_run: # pa.start = user_start() steps_to_run = pa.start = user_start() tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) ################################################################################################################### #### #### configure some settings that are not defualt to confirm they remain after disruptions #### cons_out = send_cmd("creditrecovmode --cfg onLrThresh") cons_out = send_cmd("creditrecovmode --cfg onLrThresh -lrthreshold 7") cons_out = send_cmd("creditrecovmode --fe_crdloss off") cons_out = send_cmd("creditrecovmode --be_crdloss off") cons_out = send_cmd("creditrecovmode --be_losync off") cons_out = send_cmd("creditrecovmode --fault edgeblade") ################################################################################################################### #### #### capture teh configuration file if the user selected 1 or 3 #### if steps_to_run == 1 or steps_to_run == 3: # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") switch_info = capture_switch_info("compare_orig", fid_to_compare) ################################################################################################################### #### path to the first file to compare # switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % pa.ipaddr #switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch switch_data_0 = "/home/runfromhere/logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch liabhar.JustSleep(10) ################################################################################################################### ################################################################################################################### ################################################################################################################### #### #### do configupload or other test steps here #### make other changes here before configupload or other commands #### ################################################################################################################### #### #### REBOOT and RECONNECT WAIT 60 SECONDS and CONTINUE #### print("START Switch Update Class") liabhar.JustSleep(10) pp = cofra.SwitchUpdate() # tn = pp.reboot_reconnect() # liabhar.count_down(60) ################################################################################################################### #### #### hafailover or hareboot on pizza box #### call the failover function from cofra and send the number of failovers #### print("START HA FAILOVER") liabhar.JustSleep(10) tn = cofra.ha_failover(100) liabhar.count_down(600) ################################################################################################################### #### #### power cycle slots #### ss = anturlar.SwitchInfo() slot_list = ss.blades(True) #### skip if switch is a pizza box # if "not a d" not in slot_list: # pc_result = slot_pwr_cycle(slot_list) # else: # print("NOT A DIRECTOR SO PASSING SLOT POWER CYCLE TEST") # #### #### #### other interuptions #### #### ################################################################################################################### ################################################################################################################### ################################################################################################################### if steps_to_run == 2 or steps_to_run == 3: liabhar.JustSleep(10) liabhar.count_down(360) # cons_out = anturlar.fos_cmd("setcontext 128") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") switch_info = capture_switch_info("compare", fid_to_compare) ################################################################################################################### #### path to the second file to compare switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch liabhar.cls() #### compare the two files print("#" * 80) print("#" * 80) print("#######") print("####### @@@@@ @@@@@ @@@@@ @ @ @ @@@@@ @ ") print("####### @ @ @ @ @ @ @ @ @ ") print("####### @@@ @@@@ @@@@ @ @ @ @ @ ") print("####### @ @ @ @ @ @ @ @ ") print("####### @ @ @@@@@ @@@@@ @@@ @@@@@ @ @ ") print("#" * 80) print("#" * 80) diff_f = liabhar.file_diff(switch_data_0, switch_data_1) print("#" * 80) print("#" * 80) print("#" * 80) print("#" * 80) print("Result ") print(diff_f) ################################################################################################################### #### put additional commands here before disconnecting from telnet #### # cons_out = anturlar.fos_cmd("mapsdb --show all") # print(cons_out) # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") #cons_out = anturlar.fos_cmd("mapspolicy --enable Nervio") anturlar.close_tel() dt = liabhar.dateTimeStuff() date_is = dt.current() print(date_is) print(type(steps_to_run)) print(steps_to_run)
def chck_a(): #global tn si = anturlar.SwitchInfo() does_allow_xisl = si.allow_xisl() show_all_ports = si.all_ports() show_all_ports_fc = si.all_ports_fc_only() base_y_n = si.base_check() blade_8G = si.blade_search_8GB() blades = si.blades() blade_blank = si.blank_type() fid_now = si.currentFID() chass_name = si.chassisname() dport = si.d_ports() dflt_switch = si.default_switch() dir_y_n = si.director() disbled_ports = si.disabled_ports() eports = si.e_ports() exports = si.ex_ports() vexports = si.vex_ports() fports = si.f_ports() fans = si.fan_count() fcr_y_n = si.fcr_enabled() gports = si.g_ports() lic_lst = si.getLicense() sw_ip = si.ipaddress() lport = si.loopback() ls_lst = si.ls() ls_crnt = si.ls_now() nports = si.n_ports() pdports = si.persistent_disabled_ports() sensors_lst_t = si.sensor_t_f_ps("t") sensors_lst_t = si.sensor_t_f_ps("f") sensors_lst_t = si.sensor_t_f_ps("ps") sfpinfo = si.sfp_info() sports = si.sim_ports() swstate = si.switch_state() sw_id = si.switch_id() sw_name = si.switch_name() sw_status = si.switch_status() ### fcr info sw_type = si.switch_type() sw_sync = si.synchronized() sw_tmp = si.temp_sensors() vf_y_n = si.vf_enabled() #### Fabric fi = anturlar.FabricInfo() sid_nums = fi.sid_numbers() sw_cnt = fi.switch_count() ipv4_lst = fi.ipv4_list() print("$"*80) print(ipv4_lst) print("@"*80) ipv4_fcr = fi.ipv4_plus_fcr_list('root','password') print("$"*80) print(ipv4_fcr) print("@"*80) fab_name = fi.name() fab_all = fi.all_info() fab_memb = fi.fabric_members() fab_zone = fi.zone_info() ##### FCIP info # fc = anturlar.FcipInfo() fc_ge_ports = fc.all_online_ge_ports() fc_ge_ports_dble = fc.all_ge_port_disabled() fc_vex_ports = fc.vex_ports() fc_ex_ports = fc.ex_ports() fc_ge_ports = fc.ge_ports() #### DATE TIME STUFF #### dt = liabhar.dateTimeStuff() crrnt_date = dt.current() time_stamp = dt.stamp() time_simple = dt.simple() #### other stuff print("\r\n"*5) print(crrnt_date) print(time_stamp) print(time_simple) liabhar.cls() liabhar.count_down(3) some_string_0 = "this is to compare different text strings" some_string_1 = "this is to compare diff erent text strings" some_string_2 = "this is to compare different text strings" case_1_diff = liabhar.diff_compare(some_string_0, some_string_1) case_2_diff = liabhar.diff_compare(some_string_0, some_string_2) print("result of case 1 diff test %s " % case_1_diff ) print("result of case 2 diff test %s " % case_2_diff ) this_pltfrm_is = liabhar.platform() print("this platform is %s " % this_pltfrm_is ) print(liabhar.random_number()) print(liabhar.random_number_int(23)) #### COFRA bld_port_map_info = cofra.bladeportmap_Info(3) port_stats_0 = cofra.PortStats() fid_to_check = "24" fids_0 = cofra.fids_check(fid_to_check) print("THIS IS FID CHECK %s is on the switch %s " % (fid_to_check, fids_0 )) print("Blade Port Map Info ") print(bld_port_map_info) print("PORT STATS ") print(port_stats_0) clr_stats = cofra.clear_stats()
def main(): global tn #### varable for telnet session ####################################################################################################################### #### #### #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) #print(pa.chassis_name) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) #print(pa.firmware) print(pa.cmdprompt) print("@"*40) ################################################################################################################### ################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### if pa.ipaddr: print("do IP steps") pa.chassis_name = console_info_from_ip(pa.ipaddr) cons_info = console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = get_ip_from_file(pa.chassis_name) steps_to_run = pa.steps fid_to_compare = 128 ################################################################################################################### #### if the user does not enter a value for which steps to run prompt for user input value #### if not steps_to_run: #pa.start = user_start() steps_to_run = pa.start = user_start() tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) ################################################################################################################### #### #### configure some settings that are not defualt to confirm they remain after disruptions #### cons_out = send_cmd("creditrecovmode --cfg onLrThresh") cons_out = send_cmd("creditrecovmode --fe_crdloss off") cons_out = send_cmd("creditrecovmode --be_crdloss off") cons_out = send_cmd("creditrecovmode --be_losync off") cons_out = send_cmd("creditrecovmode --fault edgeblade") ################################################################################################################### #### #### capture the configuration file if the user selected 1 or 3 #### switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch if steps_to_run == 1 or steps_to_run == 3: #cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") #cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") #switch_info_orig = capture_switch_info("compare_orig", fid_to_compare) ###### File to compare before operations switch_data_0 = ("logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch) ################################################################################################################### #### path to the first file to compare #switch_data_0 = ("logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch) switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch liabhar.JustSleep(10) ################################################################################################################### #### this is how to reconnect with telnet #print("reconnect via telnet") #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,"fibranne") ################################################################################################################### ################################################################################################################### ################################################################################################################### #### #### do configupload or other test steps here #### make other changes here before configupload or other commands #### ################################################################################################################### #### #### hafailover or hareboot on pizza box #### call the failover function from cofra and send the number of failovers #### g = pa.iterations while g > 0: tn = cofra.ha_failover(g) liabhar.count_down(120) #switch_info_compare = capture_switch_info("compare", fid_to_compare) ###### File to compare after operations switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch diff_f = liabhar.file_diff(switch_data_0, switch_data_1) print(diff_f) g = g-1 if not diff_f: liabhar.email_sender_html("*****@*****.**","*****@*****.**","NS_portflapper failed a checkpoint","NS_portflapper failed a checkpoint","") sys.exit() ################################################################################################################### #### #### power cycle slots #### #ss = anturlar.SwitchInfo() #slot_list = ss.blades(True) #### skip if switch is a pizza box #if "not a d" not in slot_list: # pc_result = slot_pwr_cycle(slot_list) #else: # print("NOT A DIRECTOR SO PASSING SLOT POWER CYCLE TEST") # #### #### #### other interuptions #### #### ################################################################################################################### ################################################################################################################### ################################################################################################################### if steps_to_run == 2 or steps_to_run == 3: liabhar.JustSleep(10) #liabhar.count_down(360) #cons_out = anturlar.fos_cmd("setcontext 128") #cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") #cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") ################################################################################################################### #### path to the second file to compare switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch liabhar.cls() print("#"*80) print("#"*80) print("#######") print("####### @@@@@ @@@@@ @@@@@ @ @ @ @@@@@ @ ") print("####### @ @ @ @ @ @ @ @ @ ") print("####### @@@ @@@@ @@@@ @ @ @ @ @ ") print("####### @ @ @ @ @ @ @ @ ") print("####### @ @ @@@@@ @@@@@ @@@ @@@@@ @ @ ") print("#"*80) print("#"*80) diff_f = liabhar.file_diff(switch_data_0, switch_data_1) print("#"*80) print("#"*80) print("#"*80) print("#"*80) print("Result ") print(diff_f) ################################################################################################################### #### put additional commands here before disconnecting from telnet #### #cons_out = anturlar.fos_cmd("mapsdb --show all") #print(cons_out) cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") #cons_out = anturlar.fos_cmd("mapspolicy --enable Nervio") anturlar.close_tel() dt = liabhar.dateTimeStuff() date_is = dt.current() print(date_is) liabhar.email_sender_html("*****@*****.**","*****@*****.**","HA_Failover passed","HA_Failover passed","")
def main(): ########################################################################### #### the module will start a suite of test #### #### 1. start from the command line - parse the args #### 2. determine if switch or fabric test - user input default to switch #### 3. determine which test case to run - read from a config file #### 4. start each test case in a seperate process #### 5. return the results of the complete suite -- need to wait for each #### process to exit ( each test case to complete ) #### #### ############################################################################### #### Step 1 #### parse of the command line is done when the test is started #### ############################################################################### #### confirm you are in your $HOME directory #### if not move to the user HOME directory and continue #### #### #### global tn liabhar.cls() print("@"*80) print("@"*80) print("@"*80) print("@"*80) cwd = os.getcwd() path = os.path.join(cwd,"logs") if os.path.exists(path): pass ##liabhar.count_down(1) else: print("\n\nChanging to your HOME directory\n\n") homepath = os.getenv('HOME') os.chdir(homepath) cwd = os.getcwd() print(cwd) pa = liabhar.parse_args(sys.argv) #print(pa) ########################################################################### #### if no password ask the user for the password #### ########################################################################### pw = "password" if not pa.password: pw = getpass.getpass() ############################################################################### #### Step 2 #### #### is the testing switch only or fabric wide #### #### the variable is in the parse args fabwide 0 = switch only #### ############################################################################### #print("#"*80) #print("#"*80) if pa.fabwide == False: print(" Testing in switch mode") else: print(" Testing in fabric wide mode") ############################################################################### #### Step 3 #### #### what test case do i run -- read a config file #### #### the file is in logs/config or logs still open question #### ############################################################################### #suite_name = pa.suite cw_config_file_name = "%s%s%s"%("ini/",pa.suite,".txt") fileIN = open( cw_config_file_name, 'rb') testcaselist = [] #print("Running the following Test Cases") #print("#"*32) for line in fileIN: line = str(line.strip(), encoding='utf8') line = line.split(" ") #for j in line: #print("list item %s "%j ) if line[0] == 'Y': testcaselist.append(line) #print("test case list \n") #print(testcaselist) #print("#"*80) #print("#"*80) ########################################################################### #### Step 4 #### #### Start the appropriate test to each switch or Fabrica Wide or #### #### or read the file for a list of IP. #### #### #### ########################################################################### #### take the testcaselist if pa.fabwide: conn_value = anturlar.connect_tel(pa, pw ) si = anturlar.SwitchInfo fabi = anturlar.FabricInfo(pa.fid) fablist = fabi.ipv4_plus_fcr_list(pa.user,pw) anturlar.close_tel() time.sleep(1) liabhar.cls() print("@"*60) print("@"*60) print("\n FABRIC LIST OF IP TO BE TESTED : ") print("-"*60) for ip in fablist: print(" %s" % ip) header(pa, testcaselist) user_start() for ip in fablist: #print("\n\n\n\n%s"%ip) pa.ip = ip p = Process(target=testprocess, args=(pa, testcaselist, pw)) p.daemon = False p.start() elif pa.ipfile: pass else: header(pa,testcaselist) user_start() p = Process(target=testprocess, args=(pa, testcaselist, pw)) #p.daemon = True #### use True value all child process will stop when the main process stops p.daemon = False #### this will run in the background even if this script finishes p.start() time.sleep(0.1) #print("\nprocess exit code is %s"%p.exitcode) #time.sleep(5.1) #print("\nprocess exit code is %s"%p.exitcode) print("\n\n TESTING STARTED IN ANOTHER CONNECTION ") print(" EXITING THIS CONNECTION") print("@"*80) print("@"*80) print("@"*80) print("@"*80)
def main(): global tn #### varable for telnet session ####################################################################################################################### #### #### #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) #print(pa.chassis_name) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) #print(pa.firmware) print(pa.cmdprompt) print("@"*40) ################################################################################################################### ################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### if pa.ipaddr: print("do IP steps") pa.chassis_name = console_info_from_ip(pa.ipaddr) cons_info = console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = get_ip_from_file(pa.chassis_name) steps_to_run = pa.steps ################################################################################################################### #### if the user does not enter a value for which steps to run prompt for user input value #### if not steps_to_run: #pa.start = user_start() steps_to_run = pa.start = user_start() tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) if steps_to_run == 1 or steps_to_run == 3: #cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") switch_info = cofra.get_info_from_the_switch("compare_orig") #switch_data_0 = "logs/Switch_Info_for_playback_",pa.ipaddr,".orig.txt" # this failed the compare # the because it sees it # as a tuple ################################################################################################################### #### path to the first file to compare switch_data_0 = "logs/Switch_Info_%s_compare_orig.txt" % pa.ipaddr liabhar.JustSleep(10) ################################################################################################################### #### this is how to reconnect with telnet #print("reconnect via telnet") #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,"fibranne") ########################################################################### #### do configupload or other test steps here ########################################################################### #### if steps_to_run == 2 or steps_to_run == 3: liabhar.JustSleep(10) cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_conservative_policy") switch_info = cofra.get_info_from_the_switch("compare") ################################################################################################################### #### path to the second file to compare switch_data_1 = "logs/Switch_Info_%s_compare.txt" % pa.ipaddr liabhar.cls() #### compare the two files diff_f = liabhar.file_diff(switch_data_0,switch_data_1) print("#"*80) print("#"*80) print("#"*80) print("#"*80) print("Result ") print(diff_f) ################################################################################################################### #### put additional commands here before disconnecting from telnet #### #cons_out = anturlar.fos_cmd("mapsdb --show all") print(cons_out) anturlar.close_tel() dt = liabhar.dateTimeStuff() date_is = dt.current() print(date_is)
def main(): global tn ####################################################################################################################### #### #### start with parsing the command line #### #### use the procedures parent_parser and parse_args #### to determine the command line switches #### ####################################################################################################################### pa = parse_args(sys.argv) if pa.verbose: print("@"*40) print("#"*40) print(pa) print(pa.file) print(pa.quiet) print(pa.verbose) print("#"*40) print("@"*40) ####################################################################################################################### ####################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### #### then get the info from the SwitchMatrix file using the Chassis Name #### #### Type,Chassisname,IP Address,Username,Password,Console1 IP,Console1 Port,Console2 IP,Console2 Port, #### Power1 IP,Power1 Port,Power2 IP,Power2 Port,Power3 IP,Power3 Port,Power4 IP,Power4 Port, #### KVM IP,KVM Port,Web Username,Web Password,Admin Password #### ####################################################################################################################### ####################################################################################################################### reg_list = get_info_from_flow_file(pa.file) if pa.verbose: print("\n\ninfo from flow reg file\n\n") print(reg_list) #### this is common steps to get the information from a csv file #### for this test we only need the chassis name and fid for i in range(0,len(reg_list),2): chass_1 = reg_list[i] target_fid = reg_list[i+1] print("chassname is %s " % chass_1) print("target fid is %s " % target_fid) #chass_1 = reg_list[0] #target_fid = reg_list[1] #cons_info = sw_matrix_tools.console_info(chass_1) #console_ip = cons_info[0] #console_port = cons_info[1] #console_ip_bkup = cons_info[2] #console_port_bkup = cons_info[3] power_pole_info = sw_matrix_tools.pwr_pole_info(chass_1) usr_pass = sw_matrix_tools.get_user_and_pass(chass_1) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = sw_matrix_tools.get_ip_from_file(chass_1) ###################################################################################################################### ###################################################################################################################### #### #### connect via telnet #### if you want to connect to the console it is available in anturlar and an example below #### #### ###################################################################################################################### ###################################################################################################################### tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) cons_out = anturlar.fos_cmd("setcontext %s " % target_fid) #### change to the fid given on the command firmware_ver = anturlar.fos_cmd("firmwareshow") #### send any command with anturlar.fos_cmd flow = anturlar.FlowV() date_is = get_time_stamp() header = "%s" % ("\nFlow Regression Log \n") #### write a header line at top of file seperator = "%s" % ("="*80) write_to_results_file("\r\n\r\n",ipaddr_switch,date_is) write_to_results_file(header,ipaddr_switch,date_is) write_to_results_file(ipaddr_switch,ipaddr_switch,date_is) write_to_results_file(firmware_ver,ipaddr_switch,date_is) write_to_results_file(seperator,ipaddr_switch,date_is) write_to_results_file(seperator,ipaddr_switch,date_is) #### get the list of flows on the switch flow_all_fport = flow.get_flow_details() #### change the list to a string a = str(flow_all_fport) write_to_results_file(a,ipaddr_switch,date_is) liabhar.cls() ####################################################################################################################### ####################################################################################################################### #### #### ####################################################################################################################### cons_out = anturlar.fos_cmd("fosexec --fid all -cmd 'flow --deact all'") cons_out = anturlar.fos_cmd("flow --deact all") cons_out = anturlar.fos_cmd("echo y | flow --delete all -force") #### remove all flows cons_out = anturlar.fos_cmd("flow --act sys_mon_all_fports") liabhar.JustSleep(360) stats = flow.get_egr_stats("sys_mon_all_fports") liabhar.JustSleep(120) write_to_results_file(stats,ipaddr_switch,date_is) result = look_for_zero(stats) #### print the result to a file #### write_pass_fail_to_file(result,ipaddr_switch,date_is) print("@"*80) print("#"*80) print(result) print("#"*80) print("@"*80) cons_out = anturlar.fos_cmd("flow --deact all") #### find the SID DID pairs and create each monitor #### ras = re.compile('\|([0-9a-f]{1,4})\s+\|([0-9a-f]{6})\|([0-9a-f]{6})') ingr_sid_did_list = ras.findall(stats) if pa.verbose: print("LIST OF FLOWS \n") print(stats) print("regex ") print(ingr_sid_did_list) name_number = 0 for ingr_p, sid, did in ingr_sid_did_list: print(ingr_p) print(sid) print(did) print("\n") cons_out = anturlar.fos_cmd("flow --create regress_flow_a%s -fea mon -ingrport %s -srcdev %s -dstdev %s -noact " % (name_number,ingr_p,sid,did)) cons_out = anturlar.fos_cmd("flow --create regress_flow_b%s -fea mon -ingrport %s -dstdev %s -noact " % (name_number,ingr_p,did)) cons_out = anturlar.fos_cmd("flow --create regress_flow_c%s -fea mon -ingrport %s -srcdev %s -noact " % (name_number,ingr_p,sid)) cons_out = anturlar.fos_cmd("flow --create regress_flow_d%s -fea mon -ingrport %s -srcdev '*' -dstdev %s -noact " % (name_number,ingr_p,did)) cons_out = anturlar.fos_cmd("flow --create regress_flow_e%s -fea mon -ingrport %s -srcdev %s -dstdev '*' -noact " % (name_number,ingr_p,sid)) cons_out = anturlar.fos_cmd("flow --create regress_flow_f%s -fea mon -egrport %s -srcdev %s -dstdev %s -noact " % (name_number,ingr_p,did,sid)) cons_out = anturlar.fos_cmd("flow --create regress_flow_g%s -fea mon -egrport %s -srcdev %s -noact " % (name_number,ingr_p,did)) cons_out = anturlar.fos_cmd("flow --create regress_flow_h%s -fea mon -egrport %s -dstdev %s -noact " % (name_number,ingr_p,sid)) name_number += 1 flow_all = flow.get_nondflt_flows() if pa.verbose: verb_list_print(flow_all) for f in flow_all: cons_out = anturlar.fos_cmd("flow --act %s " % f) #### get the current flow #egrp_flow = flow.get_active_flows() #e = egrp_flow[0] liabhar.JustSleep(120) stats = flow.get_egr_stats(f) liabhar.JustSleep(120) write_to_results_file(stats,ipaddr_switch,date_is) result = look_for_zero(stats) #### print the result to a file #### write_pass_fail_to_file(result,ipaddr_switch,date_is) print("@"*80) print("#"*80) print(result) print("#"*80) print("@"*80) cons_out = anturlar.fos_cmd("flow --deact all") #### close the telnet session ############################# anturlar.close_tel() #### close the telnet session #liabhar.JustSleep(30) return(True)
def main(): global tn #### varable for telnet session ####################################################################################################################### #### #### #### ####################################################################################################################### pa = parse_args(sys.argv) print(pa) #print(pa.chassis_name) print(pa.ipaddr) print(pa.quiet) print(pa.verbose) #print(pa.firmware) print(pa.cmdprompt) print("@"*40) ################################################################################################################### ################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### then get the info from the SwitchMatrix file using the Chassis Name #### #### #### if pa.ipaddr: print("do IP steps") pa.chassis_name = console_info_from_ip(pa.ipaddr) cons_info = console_info(pa.chassis_name) console_ip = cons_info[0] console_port = cons_info[1] console_ip_bkup = cons_info[2] console_port_bkup = cons_info[3] power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = get_ip_from_file(pa.chassis_name) steps_to_run = pa.steps fid_to_compare = 128 ### later we will capture info for all fids ################################################################################################################### #### if the user does not enter a value for which steps to run prompt for user input value #### if not steps_to_run: #pa.start = user_start() steps_to_run = pa.start = user_start() tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd) ################################################################################################################### #### #### configure some settings that are not defualt to confirm they remain after disruptions #### cons_out = send_cmd("creditrecovmode --cfg onLrThresh") cons_out = send_cmd("creditrecovmode --cfg onLrThresh -lrtthreshold 7") cons_out = send_cmd("creditrecovmode --fe_crdloss off") cons_out = send_cmd("creditrecovmode --be_crdloss off") cons_out = send_cmd("creditrecovmode --be_losync off") cons_out = send_cmd("creditrecovmode --fault edgeblade") ################################################################################################################### #### #### capture teh configuration file if the user selected 1 or 3 #### if steps_to_run == 1 or steps_to_run == 3: switch_info = capture_switch_info("compare_orig", fid_to_compare) ################################################################################################################### #### path to the first file to compare #switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % pa.ipaddr switch_data_0 = "logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch liabhar.JustSleep(10) ################################################################################################################### ################################################################################################################### ################################################################################################################### #### #### do configupload or other test steps here #### make other changes here before configupload or other commands #### ################################################################################################################### #### #### #### pp = cofra.SwitchUpdate() ################################################################################################################### #### #### #### #### cd = cofra.cfgupload(pa.ftp_ipaddress, pa.ftp_username,pa.ftp_password,pa.config_path) liabhar.count_down(120) mc = make_changes() cdd = cofra.cfgdownload(pa.ftp_ipaddress, pa.ftp_username,pa.ftp_password,cd) liabhar.count_down(360) ################################################################################################################### #### #### #### #### #### #### #### other actions here #### #### ################################################################################################################### ################################################################################################################### ################################################################################################################### if steps_to_run == 2 or steps_to_run == 3: # liabhar.JustSleep(10) liabhar.count_down(60) switch_info = capture_switch_info("compare", fid_to_compare) ################################################################################################################### #### path to the second file to compare switch_data_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch liabhar.cls() #### compare the two files print("#"*80) print("#"*80) print("#######") print("####### @@@@@ @@@@@ @@@@@ @ @ @ @@@@@ @ ") print("####### @ @ @ @ @ @ @ @ @ ") print("####### @@@ @@@@ @@@@ @ @ @ @ @ ") print("####### @ @ @ @ @ @ @ @ ") print("####### @ @ @@@@@ @@@@@ @@@ @@@@@ @ @ ") print("#"*80) print("#"*80) diff_f = liabhar.file_diff(switch_data_0,switch_data_1) print("#"*80) print("#"*80) print("#"*80) print("#"*80) print("Result ") print(diff_f) ################################################################################################################### #### #### disconnecting from telnet #### ################################################################################################################### anturlar.close_tel()
def main(): global tn # variable for telnet session pa = parse_args() # print(pa) # print(pa.chassis_name) # print(pa.ipaddr) # print(pa.quiet) # print(pa.verbose) # print(pa.firmware) # print(pa.cmdprompt) print("@" * 40) ################################################################################################################### ################################################################################################################### # # if user enter ip address then get the chassisname from the SwitchMatrix file # then get the info from the SwitchMatrix file using the Chassis Name # # # if pa.ipaddr: print("do IP steps") pa.chassis_name = console_info_from_ip(pa.ipaddr) # cons_info = console_info(pa.chassis_name) # console_ip = cons_info[0] # console_port = cons_info[1] # console_ip_bkup = cons_info[2] # console_port_bkup = cons_info[3] # power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = get_ip_from_file(pa.chassis_name) # steps_to_run = pa.steps ################################################################################################################### # if the user does not enter a value for which steps to run prompt for user input value # # if not steps_to_run: # pa.start = user_start() # steps_to_run = pa.start = user_start() tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) ################################################################################################################### # # configure some settings that are not defualt to confirm they remain after disruptions # # cons_out = send_cmd("creditrecovmode --cfg onLrThresh") # cons_out = send_cmd("creditrecovmode --fe_crdloss off") # cons_out = send_cmd("creditrecovmode --be_crdloss off") # cons_out = send_cmd("creditrecovmode --be_losync off") # cons_out = send_cmd("creditrecovmode --fault edgeblade") ################################################################################################################### # # capture the configuration file if the user selected 1 or 3 # # switchdata_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch # if steps_to_run == 1 or steps_to_run == 3: # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") # switch_info_orig = capture_switch_info("compare_orig", fid_to_compare) ###### File to compare before operations # switchdata_0 = ("logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch) ################################################################################################################### # path to the first file to compare # switch_data_0 = ("logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch) # switchdata_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch # liabhar.JustSleep(10) ################################################################################################################### # this is how to reconnect with telnet # print("reconnect via telnet") # tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,"fibranne") ################################################################################################################### ################################################################################################################### ################################################################################################################### # # do configupload or other test steps here # make other changes here before configupload or other commands # ################################################################################################################ # # hafailover or hareboot on pizza box # call the failover function from cofra and send the number of failovers # capture_switch_info("switch_info_orig", pa.fid) # Original File1 # if steps_to_run == 1: # print('\n\nFile written') # sys.exit(0) g = pa.iterations tn = cofra.ha_failover(g) liabhar.count_down(30) capture_switch_info("switch_info_compare", pa.fid) # File to compare after operations orig = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_orig.txt" % ipaddr_switch compare = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_compare.txt" % ipaddr_switch diff_f = liabhar.file_diff(orig, compare, "HA_FAILOVER_DIFFERENCES") print(diff_f) # g = g-1 if not diff_f: liabhar.email_sender_html(pa.email, pa.email, "HA Failover failed a checkpoint", "HA_Failover failed a checkpoint.\ Look in logs for HA_FAILOVER_DIFFERENCES file", "") cofra.DoSupportsave(ftp_ip, ftp_username, ftp_password, pa.chassis_name) print("Support Save captured") sys.exit(0) # g = pa.iterations # print(g) # while g > 0: # tn = cofra.ha_failover(g) # liabhar.count_down(60) # capture_switch_info("switch_info_compare", pa.fid) # File to compare after operations # orig = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_orig.txt" % ipaddr_switch # compare = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_compare.txt" % ipaddr_switch # diff_f = liabhar.file_diff(orig, compare) # print(diff_f) # # g = g-1 # if not diff_f: # liabhar.email_sender_html(pa.email, pa.email, # "HA Failover failed a checkpoint", "HA_Failover failed a checkpoint", "") # cofra.DoSupportsave("172.16.114.67", "ftp1", "ftp2", pa.chassis_name) # sys.exit(1) # g = g - 1 ################################################################################################################### # # power cycle slots # # ss = anturlar.SwitchInfo() # slot_list = ss.blades(True) # skip if switch is a pizza box # if "not a d" not in slot_list: # pc_result = slot_pwr_cycle(slot_list) # else: # print("NOT A DIRECTOR SO PASSING SLOT POWER CYCLE TEST") # # # # other interuptions # # ################################################################################################################### ################################################################################################################### ################################################################################################################### # if steps_to_run == 2 or steps_to_run == 3: liabhar.JustSleep(10) # liabhar.count_down(360) # cons_out = anturlar.fos_cmd("setcontext 128") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") ################################################################################################################### liabhar.cls() print("#" * 80) print("#" * 80) print("#######") print("####### @@@@@ @@@@@ @@@@@ @ @ @ @@@@@ @ ") print("####### @ @ @ @ @ @ @ @ @ ") print("####### @@@ @@@@ @@@@ @ @ @ @ @ ") print("####### @ @ @ @ @ @ @ @ ") print("####### @ @ @@@@@ @@@@@ @@@ @@@@@ @ @ ") print("#" * 80) print("#" * 80) diff_f = liabhar.file_diff(orig, compare) print(diff_f) print('\n\n') print("#" * 80) print("#" * 80) print("#" * 80) print("#" * 80) ################################################################################################################### # put additional commands here before disconnecting from telnet # # cons_out = anturlar.fos_cmd("mapsdb --show all") # print(cons_out) # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") anturlar.close_tel() dt = liabhar.dateTimeStuff() date_is = dt.current() print(date_is) liabhar.email_sender_html (pa.email, pa.email, "HA_Failover passed", "HA_Failover passed", "")
def main(): ########################################################################### #### the module will start a suite of test #### #### 1. start from the command line - parse the args #### 2. determine if switch or fabric test - user input default to switch #### 3. determine which test case to run - read from a config file #### 4. start each test case in a seperate process #### 5. return the results of the complete suite -- need to wait for each #### process to exit ( each test case to complete ) #### #### ############################################################################### #### Step 1 #### parse of the command line is done when the test is started #### ############################################################################### #### confirm you are in your $HOME directory #### if not move to the user HOME directory and continue #### #### #### global tn liabhar.cls() print("@" * 80) print("@" * 80) print("@" * 80) print("@" * 80) cwd = os.getcwd() path = os.path.join(cwd, "logs") if os.path.exists(path): pass ##liabhar.count_down(1) else: print("\n\nChanging to your HOME directory\n\n") homepath = os.getenv('HOME') os.chdir(homepath) cwd = os.getcwd() print(cwd) pa = liabhar.parse_args(sys.argv) #print(pa) ########################################################################### #### if no password ask the user for the password #### ########################################################################### pw = "password" if not pa.password: pw = getpass.getpass() ############################################################################### #### Step 2 #### #### is the testing switch only or fabric wide #### #### the variable is in the parse args fabwide 0 = switch only #### ############################################################################### #print("#"*80) #print("#"*80) if pa.fabwide == False: print(" Testing in switch mode") else: print(" Testing in fabric wide mode") ############################################################################### #### Step 3 #### #### what test case do i run -- read a config file #### #### the file is in logs/config or logs still open question #### ############################################################################### #suite_name = pa.suite cw_config_file_name = "%s%s%s" % ("ini/", pa.suite, ".txt") fileIN = open(cw_config_file_name, 'rb') testcaselist = [] #print("Running the following Test Cases") #print("#"*32) for line in fileIN: line = str(line.strip(), encoding='utf8') line = line.split(" ") #for j in line: #print("list item %s "%j ) if line[0] == 'Y': testcaselist.append(line) #print("test case list \n") #print(testcaselist) #print("#"*80) #print("#"*80) ########################################################################### #### Step 4 #### #### Start the appropriate test to each switch or Fabrica Wide or #### #### or read the file for a list of IP. #### #### #### ########################################################################### #### take the testcaselist if pa.fabwide: conn_value = anturlar.connect_tel(pa, pw) si = anturlar.SwitchInfo fabi = anturlar.FabricInfo(pa.fid) fablist = fabi.ipv4_plus_fcr_list(pa.user, pw) anturlar.close_tel() time.sleep(1) liabhar.cls() print("@" * 60) print("@" * 60) print("\n FABRIC LIST OF IP TO BE TESTED : ") print("-" * 60) for ip in fablist: print(" %s" % ip) header(pa, testcaselist) user_start() for ip in fablist: #print("\n\n\n\n%s"%ip) pa.ip = ip p = Process(target=testprocess, args=(pa, testcaselist, pw)) p.daemon = False p.start() elif pa.ipfile: pass else: header(pa, testcaselist) user_start() p = Process(target=testprocess, args=(pa, testcaselist, pw)) #p.daemon = True #### use True value all child process will stop when the main process stops p.daemon = False #### this will run in the background even if this script finishes p.start() time.sleep(0.1) #print("\nprocess exit code is %s"%p.exitcode) #time.sleep(5.1) #print("\nprocess exit code is %s"%p.exitcode) print("\n\n TESTING STARTED IN ANOTHER CONNECTION ") print(" EXITING THIS CONNECTION") print("@" * 80) print("@" * 80) print("@" * 80) print("@" * 80)
def main(): global tn # variable for telnet session pa = parse_args() # print(pa) # print(pa.chassis_name) # print(pa.ipaddr) # print(pa.quiet) # print(pa.verbose) # print(pa.firmware) # print(pa.cmdprompt) print("@" * 40) ################################################################################################################### ################################################################################################################### # # if user enter ip address then get the chassisname from the SwitchMatrix file # then get the info from the SwitchMatrix file using the Chassis Name # # # if pa.ipaddr: print("do IP steps") pa.chassis_name = console_info_from_ip(pa.ipaddr) # cons_info = console_info(pa.chassis_name) # console_ip = cons_info[0] # console_port = cons_info[1] # console_ip_bkup = cons_info[2] # console_port_bkup = cons_info[3] # power_pole_info = pwr_pole_info(pa.chassis_name) usr_pass = get_user_and_pass(pa.chassis_name) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = get_ip_from_file(pa.chassis_name) # steps_to_run = pa.steps ################################################################################################################### # if the user does not enter a value for which steps to run prompt for user input value # # if not steps_to_run: # pa.start = user_start() # steps_to_run = pa.start = user_start() tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) ################################################################################################################### # # configure some settings that are not defualt to confirm they remain after disruptions # # cons_out = send_cmd("creditrecovmode --cfg onLrThresh") # cons_out = send_cmd("creditrecovmode --fe_crdloss off") # cons_out = send_cmd("creditrecovmode --be_crdloss off") # cons_out = send_cmd("creditrecovmode --be_losync off") # cons_out = send_cmd("creditrecovmode --fault edgeblade") ################################################################################################################### # # capture the configuration file if the user selected 1 or 3 # # switchdata_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch # if steps_to_run == 1 or steps_to_run == 3: # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") # switch_info_orig = capture_switch_info("compare_orig", fid_to_compare) ###### File to compare before operations # switchdata_0 = ("logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch) ################################################################################################################### # path to the first file to compare # switch_data_0 = ("logs/Switch_Info_cudc%s_compare_orig.txt" % ipaddr_switch) # switchdata_1 = "logs/Switch_Info_cudc%s_compare.txt" % ipaddr_switch # liabhar.JustSleep(10) ################################################################################################################### # this is how to reconnect with telnet # print("reconnect via telnet") # tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,"fibranne") ################################################################################################################### ################################################################################################################### ################################################################################################################### # # do configupload or other test steps here # make other changes here before configupload or other commands # ################################################################################################################ # # hafailover or hareboot on pizza box # call the failover function from cofra and send the number of failovers # capture_switch_info("switch_info_orig", pa.fid) # Original File1 # if steps_to_run == 1: # print('\n\nFile written') # sys.exit(0) g = pa.iterations tn = cofra.ha_failover(g) liabhar.count_down(30) capture_switch_info("switch_info_compare", pa.fid) # File to compare after operations orig = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_orig.txt" % ipaddr_switch compare = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_compare.txt" % ipaddr_switch diff_f = liabhar.file_diff(orig, compare, "HA_FAILOVER_DIFFERENCES") print(diff_f) # g = g-1 if not diff_f: liabhar.email_sender_html( pa.email, pa.email, "HA Failover failed a checkpoint", "HA_Failover failed a checkpoint.\ Look in logs for HA_FAILOVER_DIFFERENCES file", "") cofra.DoSupportsave(ftp_ip, ftp_username, ftp_password, pa.chassis_name) print("Support Save captured") sys.exit(0) # g = pa.iterations # print(g) # while g > 0: # tn = cofra.ha_failover(g) # liabhar.count_down(60) # capture_switch_info("switch_info_compare", pa.fid) # File to compare after operations # orig = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_orig.txt" % ipaddr_switch # compare = "/home/runfromhere/logs/Switch_Info_cudc%s_switch_info_compare.txt" % ipaddr_switch # diff_f = liabhar.file_diff(orig, compare) # print(diff_f) # # g = g-1 # if not diff_f: # liabhar.email_sender_html(pa.email, pa.email, # "HA Failover failed a checkpoint", "HA_Failover failed a checkpoint", "") # cofra.DoSupportsave("172.16.114.67", "ftp1", "ftp2", pa.chassis_name) # sys.exit(1) # g = g - 1 ################################################################################################################### # # power cycle slots # # ss = anturlar.SwitchInfo() # slot_list = ss.blades(True) # skip if switch is a pizza box # if "not a d" not in slot_list: # pc_result = slot_pwr_cycle(slot_list) # else: # print("NOT A DIRECTOR SO PASSING SLOT POWER CYCLE TEST") # # # # other interuptions # # ################################################################################################################### ################################################################################################################### ################################################################################################################### # if steps_to_run == 2 or steps_to_run == 3: liabhar.JustSleep(10) # liabhar.count_down(360) # cons_out = anturlar.fos_cmd("setcontext 128") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_aggressive_policy") ################################################################################################################### liabhar.cls() print("#" * 80) print("#" * 80) print("#######") print("####### @@@@@ @@@@@ @@@@@ @ @ @ @@@@@ @ ") print("####### @ @ @ @ @ @ @ @ @ ") print("####### @@@ @@@@ @@@@ @ @ @ @ @ ") print("####### @ @ @ @ @ @ @ @ ") print("####### @ @ @@@@@ @@@@@ @@@ @@@@@ @ @ ") print("#" * 80) print("#" * 80) diff_f = liabhar.file_diff(orig, compare) print(diff_f) print('\n\n') print("#" * 80) print("#" * 80) print("#" * 80) print("#" * 80) ################################################################################################################### # put additional commands here before disconnecting from telnet # # cons_out = anturlar.fos_cmd("mapsdb --show all") # print(cons_out) # cons_out = anturlar.fos_cmd("mapspolicy --enable dflt_base_policy") anturlar.close_tel() dt = liabhar.dateTimeStuff() date_is = dt.current() print(date_is) liabhar.email_sender_html(pa.email, pa.email, "HA_Failover passed", "HA_Failover passed", "")
def main(): global tn ####################################################################################################################### #### #### start with parsing the command line #### #### use the procedures parent_parser and parse_args #### to determine the command line switches #### ####################################################################################################################### pa = parse_args(sys.argv) if pa.verbose: print("@" * 40) print("#" * 40) print(pa) print(pa.file) print(pa.quiet) print(pa.verbose) print("#" * 40) print("@" * 40) ####################################################################################################################### ####################################################################################################################### #### #### if user enter ip address then get the chassisname from the #### SwitchMatrix file #### #### then get the info from the SwitchMatrix file using the Chassis Name #### #### Type,Chassisname,IP Address,Username,Password,Console1 IP,Console1 Port,Console2 IP,Console2 Port, #### Power1 IP,Power1 Port,Power2 IP,Power2 Port,Power3 IP,Power3 Port,Power4 IP,Power4 Port, #### KVM IP,KVM Port,Web Username,Web Password,Admin Password #### ####################################################################################################################### ####################################################################################################################### reg_list = get_info_from_flow_file(pa.file) if pa.verbose: print("\n\ninfo from flow reg file\n\n") print(reg_list) #### this is common steps to get the information from a csv file #### for this test we only need the chassis name and fid for i in range(0, len(reg_list), 2): chass_1 = reg_list[i] target_fid = reg_list[i + 1] print("chassname is %s " % chass_1) print("target fid is %s " % target_fid) #chass_1 = reg_list[0] #target_fid = reg_list[1] #cons_info = sw_matrix_tools.console_info(chass_1) #console_ip = cons_info[0] #console_port = cons_info[1] #console_ip_bkup = cons_info[2] #console_port_bkup = cons_info[3] power_pole_info = sw_matrix_tools.pwr_pole_info(chass_1) usr_pass = sw_matrix_tools.get_user_and_pass(chass_1) user_name = usr_pass[0] usr_psswd = usr_pass[1] ipaddr_switch = sw_matrix_tools.get_ip_from_file(chass_1) ###################################################################################################################### ###################################################################################################################### #### #### connect via telnet #### if you want to connect to the console it is available in anturlar and an example below #### #### ###################################################################################################################### ###################################################################################################################### tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd) cons_out = anturlar.fos_cmd( "setcontext %s " % target_fid) #### change to the fid given on the command firmware_ver = anturlar.fos_cmd( "firmwareshow") #### send any command with anturlar.fos_cmd flow = anturlar.FlowV() date_is = get_time_stamp() header = "%s" % ("\nFlow Regression Log \n" ) #### write a header line at top of file seperator = "%s" % ("=" * 80) write_to_results_file("\r\n\r\n", ipaddr_switch, date_is) write_to_results_file(header, ipaddr_switch, date_is) write_to_results_file(ipaddr_switch, ipaddr_switch, date_is) write_to_results_file(firmware_ver, ipaddr_switch, date_is) write_to_results_file(seperator, ipaddr_switch, date_is) write_to_results_file(seperator, ipaddr_switch, date_is) #### get the list of flows on the switch flow_all_fport = flow.get_flow_details() #### change the list to a string a = str(flow_all_fport) write_to_results_file(a, ipaddr_switch, date_is) liabhar.cls() ####################################################################################################################### ####################################################################################################################### #### #### ####################################################################################################################### cons_out = anturlar.fos_cmd( "fosexec --fid all -cmd 'flow --deact all'") cons_out = anturlar.fos_cmd("flow --deact all") cons_out = anturlar.fos_cmd( "echo y | flow --delete all -force") #### remove all flows cons_out = anturlar.fos_cmd("flow --act sys_mon_all_fports") liabhar.JustSleep(360) stats = flow.get_egr_stats("sys_mon_all_fports") liabhar.JustSleep(120) write_to_results_file(stats, ipaddr_switch, date_is) result = look_for_zero(stats) #### print the result to a file #### write_pass_fail_to_file(result, ipaddr_switch, date_is) print("@" * 80) print("#" * 80) print(result) print("#" * 80) print("@" * 80) cons_out = anturlar.fos_cmd("flow --deact all") #### find the SID DID pairs and create each monitor #### ras = re.compile('\|([0-9a-f]{1,4})\s+\|([0-9a-f]{6})\|([0-9a-f]{6})') ingr_sid_did_list = ras.findall(stats) if pa.verbose: print("LIST OF FLOWS \n") print(stats) print("regex ") print(ingr_sid_did_list) name_number = 0 for ingr_p, sid, did in ingr_sid_did_list: print(ingr_p) print(sid) print(did) print("\n") cons_out = anturlar.fos_cmd( "flow --create regress_flow_a%s -fea mon -ingrport %s -srcdev %s -dstdev %s -noact " % (name_number, ingr_p, sid, did)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_b%s -fea mon -ingrport %s -dstdev %s -noact " % (name_number, ingr_p, did)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_c%s -fea mon -ingrport %s -srcdev %s -noact " % (name_number, ingr_p, sid)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_d%s -fea mon -ingrport %s -srcdev '*' -dstdev %s -noact " % (name_number, ingr_p, did)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_e%s -fea mon -ingrport %s -srcdev %s -dstdev '*' -noact " % (name_number, ingr_p, sid)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_f%s -fea mon -egrport %s -srcdev %s -dstdev %s -noact " % (name_number, ingr_p, did, sid)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_g%s -fea mon -egrport %s -srcdev %s -noact " % (name_number, ingr_p, did)) cons_out = anturlar.fos_cmd( "flow --create regress_flow_h%s -fea mon -egrport %s -dstdev %s -noact " % (name_number, ingr_p, sid)) name_number += 1 flow_all = flow.get_nondflt_flows() if pa.verbose: verb_list_print(flow_all) for f in flow_all: cons_out = anturlar.fos_cmd("flow --act %s " % f) #### get the current flow #egrp_flow = flow.get_active_flows() #e = egrp_flow[0] liabhar.JustSleep(120) stats = flow.get_egr_stats(f) liabhar.JustSleep(120) write_to_results_file(stats, ipaddr_switch, date_is) result = look_for_zero(stats) #### print the result to a file #### write_pass_fail_to_file(result, ipaddr_switch, date_is) print("@" * 80) print("#" * 80) print(result) print("#" * 80) print("@" * 80) cons_out = anturlar.fos_cmd("flow --deact all") #### close the telnet session ############################# anturlar.close_tel() #### close the telnet session #liabhar.JustSleep(30) return (True)
def chck_a(): #global tn si = anturlar.SwitchInfo() does_allow_xisl = si.allow_xisl() show_all_ports = si.all_ports() show_all_ports_fc = si.all_ports_fc_only() base_y_n = si.base_check() blade_8G = si.blade_search_8GB() blades = si.blades() blade_blank = si.blank_type() fid_now = si.currentFID() chass_name = si.chassisname() dport = si.d_ports() dflt_switch = si.default_switch() dir_y_n = si.director() disbled_ports = si.disabled_ports() eports = si.e_ports() exports = si.ex_ports() vexports = si.vex_ports() fports = si.f_ports() fans = si.fan_count() fcr_y_n = si.fcr_enabled() gports = si.g_ports() lic_lst = si.getLicense() sw_ip = si.ipaddress() lport = si.loopback() ls_lst = si.ls() ls_crnt = si.ls_now() nports = si.n_ports() pdports = si.persistent_disabled_ports() sensors_lst_t = si.sensor_t_f_ps("t") sensors_lst_t = si.sensor_t_f_ps("f") sensors_lst_t = si.sensor_t_f_ps("ps") sfpinfo = si.sfp_info() sports = si.sim_ports() swstate = si.switch_state() sw_id = si.switch_id() sw_name = si.switch_name() sw_status = si.switch_status() ### fcr info sw_type = si.switch_type() sw_sync = si.synchronized() sw_tmp = si.temp_sensors() vf_y_n = si.vf_enabled() #### Fabric fi = anturlar.FabricInfo() sid_nums = fi.sid_numbers() sw_cnt = fi.switch_count() ipv4_lst = fi.ipv4_list() print("$" * 80) print(ipv4_lst) print("@" * 80) ipv4_fcr = fi.ipv4_plus_fcr_list('root', 'password') print("$" * 80) print(ipv4_fcr) print("@" * 80) fab_name = fi.name() fab_all = fi.all_info() fab_memb = fi.fabric_members() fab_zone = fi.zone_info() ##### FCIP info # fc = anturlar.FcipInfo() fc_ge_ports = fc.all_online_ge_ports() fc_ge_ports_dble = fc.all_ge_port_disabled() fc_vex_ports = fc.vex_ports() fc_ex_ports = fc.ex_ports() fc_ge_ports = fc.ge_ports() #### DATE TIME STUFF #### dt = liabhar.dateTimeStuff() crrnt_date = dt.current() time_stamp = dt.stamp() time_simple = dt.simple() #### other stuff print("\r\n" * 5) print(crrnt_date) print(time_stamp) print(time_simple) liabhar.cls() liabhar.count_down(3) some_string_0 = "this is to compare different text strings" some_string_1 = "this is to compare diff erent text strings" some_string_2 = "this is to compare different text strings" case_1_diff = liabhar.diff_compare(some_string_0, some_string_1) case_2_diff = liabhar.diff_compare(some_string_0, some_string_2) print("result of case 1 diff test %s " % case_1_diff) print("result of case 2 diff test %s " % case_2_diff) this_pltfrm_is = liabhar.platform() print("this platform is %s " % this_pltfrm_is) print(liabhar.random_number()) print(liabhar.random_number_int(23)) #### COFRA bld_port_map_info = cofra.bladeportmap_Info(3) port_stats_0 = cofra.PortStats() fid_to_check = "24" fids_0 = cofra.fids_check(fid_to_check) print("THIS IS FID CHECK %s is on the switch %s " % (fid_to_check, fids_0)) print("Blade Port Map Info ") print(bld_port_map_info) print("PORT STATS ") print(port_stats_0) clr_stats = cofra.clear_stats()