Пример #1
0
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()
    print(pa)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    print(pa.cmdprompt)
    print(pa.iterations)
    print(pa.porttype)
    print(pa.email)
    print("@" * 40)
    print("@" * 40)
    # sys.exit()
    ###################################################################################################################
    ###################################################################################################################
    #
    # 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
    #
    ###################################################################################################################
    ###################################################################################################################
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr)

    # cons_info = sw_matrix_tools.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   = sw_matrix_tools.pwr_pole_info(pa.chassis_name)
    usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name)
    user_name = usr_pass[0]
    usr_psswd = usr_pass[1]

    ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name)

    ###################################################################################################################
    #
    # connect via telnet:
    # if you want to connect to the console it is available in anturlar and an example is available below
    #
    #
    ###################################################################################################################

    # Config_up_down_compare.main()

    # cons_out = anturlar.fos_cmd("firmwareshow")                          # send any command with anturlar.fos_cmd
    # print("\r\n")
    # liabhar.JustSleep(5)                                                 # sleep without printing anything
    # print(cons_out)
    # print("now closing telnet session ") 
    # #anturlar.close_tel()                                                 ####  close the telnet session

    ###################################################################################################################
    #
    #   connect via console example and other "send command" commands
    #
    #
    ###################################################################################################################

    # tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)   # connect to console w/o parser info
    # cons_out = anturlar.fos_cmd("firmwareshow")
    # cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)                 # hange to the fid given on the command
    # tn = anturlar.connect_console(console_ip,console_port)                 # use the console ip and console port info
    # cons_out = anturlar.fos_cmd("switchshow")                              # send a command via the console
    # cons_out = cofra.power_cycle(power_pole_info)                          # powercycle switch w switchmatrix.csv file
    # liabhar.JustSleep(30)                                                  # wait for the switch to boot
    # cons_out = anturlar.send_cmd_console("\r\n")                           # end some commands to the console
    # cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid)        # send some commands to the console
    # cons_out = anturlar.send_cmd_console("firmwareshow")                   # send some commands to the console
    # capture = cofra.cfgupload("10.38.35.131", "ftp1", "ftp2")              # send a cfgupload file to a ftp server
    # liabhar.count_down(5)                                                  ####  set and observe a count down timer

    ###################################################################################################################
    ###################################################################################################################
    #
    #  This starts the template for configshow output comparison (after some type of switch operation).
    #  First snippet of code simply opens a connection, changes to requested fid, sends output of configshow to a
    #  file
    ###################################################################################################################
    ###################################################################################################################
    tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd)
    # cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)
    dt = liabhar.dateTimeStuff()  # create the object for date and time stuff
    date_is = dt.current_no_dash_at_end()  # get the current time for file naming purposes
    # print("\n\nDate is %s" % date_is)

    liabhar.count_down(3)  # count down to the next command
    # configup_cmd = ("configupload -all -p ftp %s,%s,/configs/%s.txt,%s") % ("172.16.114.67","ftp1",/
    # ipaddr_switch,"ftp2")
    f = "%s%s%s%s" % ("logs/Configupload_test_case_file_ORIG", "_" + ipaddr_switch + "_", date_is, ".txt")
    ff = liabhar.FileStuff(f, 'w+b')  # open the log file for writing
    header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", "  sw_info ipaddr  ", ipaddr_switch,
                           "\n==============================\n\n")  # write a header line at top of file
    ff.write(header)
    ff.write(anturlar.fos_cmd("configshow"))
    # ff.write("THE END")
    ff.close()  # close this file for comparison later
    # g = open(f, "r")
    # lines = g.readlines()
    # g.close()
    # ff = liabhar.FileStuff(f, 'w+b')
    # for l in lines:
    #     if " date = " not in l:
    #         ff.write(l)
    # ff.close()

    ##################################################################################################################
    ##################################################################################################################
    #
    #  do anything else you want to try (small sample of examples):
    #  anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
    #  anturlar.fos_cmd("cfgenable")
    #  anturlar.fos_cmd("switchdisable")
    #  anturlar.fos_cmd("switchenable")
    #
    #  In the below snippet we run tsclockerver: anturlar.fos_cmd("tsclockserver 10.38.2.80;\
    #  tstimezone America/Denver")
    #  Then grab output of configshow, drop into a file and compare that with original
    #
    ##################################################################################################################
    ##################################################################################################################

    # tn = cofra.clear_stats()
    # print(pa.porttype)
    # #sys.exit()
    # porttype = pa.porttype
    # print(porttype)
    # PortFlapper.main(porttype)
    #############################################################################################
    si = anturlar.SwitchInfo()
    fi = anturlar.FabricInfo()
    fabric_check = fi.fabric_members()
    f_ports = si.f_ports()
    e_ports = si.e_ports()
    print("\n\n\n\n")
    print(f_ports)
    print(e_ports)
    print("\n\n\n\n")
    if pa.porttype == "eports":
        ports = e_ports
    else:
        ports = f_ports

    # try: 
    #     tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd)
    # except OSError:
    #     print("Switch %s not available" % i) 
    g = pa.iterations
    while g > 0:
        for i in ports:
            slot = i[0]
            port = i[1]
            if slot:
                anturlar.fos_cmd("portdisable %s/%s" % (slot, port))
                liabhar.count_down(15)
                anturlar.fos_cmd("portenable %s/%s" % (slot, port))
                liabhar.count_down(15)
            else:
                anturlar.fos_cmd("portdisable %s" % port)
                liabhar.count_down(15)
                anturlar.fos_cmd("portenable %s" % port)
                liabhar.count_down(15)
        fabric_check1 = fi.fabric_members()
        if fabric_check != fabric_check1:
            print("WTF")
            # email_sender_html(you, me, subj, html_to_send, htmlfile_path = "" )
            liabhar.email_sender_html(pa.email, pa.email, "portflapper failed",
                                      "portflapper failed", "")
            anturlar.close_tel()
            sys.exit(0)
        else:
            c = "%s%s%s%s" % ("logs/Configupload_test_case_file_COMPARE", "_" + ipaddr_switch + "_", date_is, ".txt")
            cc = liabhar.FileStuff(c, 'w+b')  # open the log file for writing
            header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", "  sw_info ipaddr  ", ipaddr_switch,
                                   "\n==============================\n\n")  # write a header line at top of file
            cc.write(header)
            cc.write(anturlar.fos_cmd("configshow"))
            # ff.write("THE END")
            cc.close()
            # x = open(c, "r")
            # lines = x.readlines()
            # x.close()
            # cc = liabhar.FileStuff(f, 'w+b')
            # for l in lines:
            #     if " date = " not in l:
            #         cc.write(l)
            # cc.close()
            diff_f = liabhar.file_diff(f, c)
            print(diff_f)
            g = g - 1
            print(g)
            if not diff_f:
                liabhar.email_sender_html(pa.email, pa.email,
                                          "PF_configshow_compare failed a checkpoint", "PF_configshow_compare failed"
                                          "a checkpoint. Support Save and trace dump transferred", "")
                cofra.DoSupportsave("172.16.114.67", "ftp1", "ftp2", pa.chassis_name)
                anturlar.close_tel()
                sys.exit(0)
    # diff_f = liabhar.file_diff(f, f1)
    print("#" * 80)
    print("#" * 80)
    print("#" * 80)
    print("#" * 80)
    print("Result ")
    print(diff_f)
    liabhar.email_sender_html(pa.email, pa.email, "PF_configshow_compare passed", "PF_configshow_compare passed",
                              "")

    return True
Пример #2
0
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)
    print(pa)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    print(pa.cmdprompt)
    print(pa.iterations)
    print(pa.porttype)
    print("@"*40)
    print("@"*40)
    #sys.exit()
#######################################################################################################################
#######################################################################################################################
####
#### 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
####
#######################################################################################################################
#######################################################################################################################
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr)
        
    cons_info         = sw_matrix_tools.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   = sw_matrix_tools.pwr_pole_info(pa.chassis_name)    
    usr_pass          = sw_matrix_tools.get_user_and_pass(pa.chassis_name)
    user_name         = usr_pass[0]
    usr_psswd         = usr_pass[1]
    
    ipaddr_switch     = sw_matrix_tools.get_ip_from_file(pa.chassis_name)
 
 ######################################################################################################################
 ######################################################################################################################
 ####
 ####   connect via telnet:
 ####   if you want to connect to the console it is available in anturlar and an example is available below
 ####
 ####
 ######################################################################################################################
 ######################################################################################################################
 ####   Config_up_down_compare.main()

    #cons_out = anturlar.fos_cmd("firmwareshow")                          ####   send any command with anturlar.fos_cmd
    #print("\r\n")
    #liabhar.JustSleep(5)                                                ####   sleep without printing anything
    #print(cons_out)
    # print("now closing telnet session ") 
    # #anturlar.close_tel()                                                 ####  close the telnet session
#######################################################################################################################   
#######################################################################################################################
####
####   connect via console example and other "send command" commands
####    
####
#######################################################################################################################
#######################################################################################################################
    #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)   ####  connect to console w/o parser info
    #cons_out = anturlar.fos_cmd("firmwareshow")
    #cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)                 ####  change to the fid given on the command  
    #tn = anturlar.connect_console(console_ip,console_port)                 ####  use the console ip and console port info
    #cons_out = anturlar.fos_cmd("switchshow")                              ####  send a command via the console
    #cons_out = cofra.power_cycle(power_pole_info)                          ####  powercycle switch via switchmatrix.csv file
    #liabhar.JustSleep(30)                                                  ####  wait for the switch to boot
    #cons_out = anturlar.send_cmd_console("\r\n")                           ####  send some commands to the console
    #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid)        ####  send some commands to the console
    #cons_out = anturlar.send_cmd_console("firmwareshow")                   ####  send some commands to the console
    #capture = cofra.cfgupload("10.38.35.131", "ftp1", "ftp2")              ####  send a cfgupload file to a ftp server
    #liabhar.count_down(5)                                                  ####  set and observe a count down timer


#######################################################################################################################
#######################################################################################################################
####
####  This starts the template for configshow output comparison (after some type of switch operation).
####  First snippet of code simply opens a connection, changes to requested fid, sends output of configshow to a file.
####
#######################################################################################################################
#######################################################################################################################
    tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)
    cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)  
    dt = liabhar.dateTimeStuff()                                        #### create the object for date and time stuff
    date_is = dt.current_no_dash_at_end()                               #### get the current time for file naming purposes
    #print("\n\nDate is %s" % date_is)
    
    liabhar.count_down(3)                                               ####   count down to the next command 
    #configup_cmd = ("configupload -all -p ftp %s,%s,/configs/%s.txt,%s") % ("10.38.35.131","ftp1", ipaddr_switch, "ftp2")
    f = "%s%s%s%s"%("logs/NameServer_test_case_file","_"+ipaddr_switch+"_",date_is,".txt")
    f1 = "%s%s%s%s"%("logs/NameServer_test_case_file_compare","_"+ipaddr_switch+"_",date_is,".txt")
    ff = liabhar.FileStuff(f, 'w+b')                                    #### open the log file for writing       
    #header = "%s%s%s%s" % ("\nNAMESERVER CAPTURE FILE \n", "  sw_info ipaddr  ",ipaddr_switch,"\n==============================\n\n") #### write a header line at top of file
    header = "%s%s%s%s" % ("\nNAMESERVER CAPTURE FILE \n", "  sw_info ipaddr  ",ipaddr_switch, "\n==============================\n\n")
    ff.write(header)
    ff.write(anturlar.fos_cmd("nsshow"))
    ff.write(anturlar.fos_cmd("nsallshow"))
    ff.write(anturlar.fos_cmd("configshow"))
    ff.close()
    g = open(f, "r")
    lines = g.readlines()
    g.close()
    ff = liabhar.FileStuff(f, 'w+b')
    for l in lines:
        if " date = " not in l:
            ff.write(l)
    ff.close()                                                          #### close this file for comparison later

#######################################################################################################################
#######################################################################################################################
####
####  do anything else you want to try (small sample of examples):
####  anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
####  anturlar.fos_cmd("cfgenable")
####  anturlar.fos_cmd("switchdisable")
####  anturlar.fos_cmd("switchenable")
####
####  In the below snippet we run tsclockerver: anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
####  Then grab output of configshow, drop into a file and compare that with original
####
#######################################################################################################################
#######################################################################################################################

    # tn = cofra.clear_stats()
    # print(pa.porttype)
    # #sys.exit()
    # porttype = pa.porttype
    # print(porttype)
    # PortFlapper.main(porttype)
#############################################################################################
    si = anturlar.SwitchInfo()
    fi = anturlar.FabricInfo()
    fabric_check =  fi.fabric_members()
    f_ports = si.f_ports()
    e_ports = si.e_ports()
    if pa.porttype == "eports":
        ports = e_ports
        print("\n\n\n\n")
        print(e_ports)
    else:
        ports = f_ports
        print("\n\n\n\n")
        print(f_ports)
    i = ipaddr_switch
    
    # try: 
    #     tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd)
    # except OSError:
    #     print("Switch %s not available" % i) 
    nos = si.nos_check()
    if not nos:
        h = pa.iterations
        for i in range(h):
            print("\n\nWe are on loop number:")
            print(i+1)
            print("\n\n")
            for i in ports:
                slot = i[0]
                port = i[1]
                if slot:
                    anturlar.fos_cmd("portdisable %s/%s" % (slot, port))
                    liabhar.count_down(5)
                    anturlar.fos_cmd("portenable %s/%s" % (slot, port))
                    liabhar.count_down(5)
                else:
                    anturlar.fos_cmd("portdisable %s" % (port))
                    liabhar.count_down(5)
                    anturlar.fos_cmd("portenable %s" % (port))
                    liabhar.count_down(5)
            #g = g-1
            fabric_check1 =  fi.fabric_members()
            if fabric_check != fabric_check1:
                print ("WTF")
                #email_sender_html(you, me, subj, html_to_send, htmlfile_path = "" )
                liabhar.email_sender_html("*****@*****.**","*****@*****.**","NS_portflapper failed becasue of Fabric Check","NS_portflapper failed because of Fabric Check","")
                anturlar.close_tel()
                sys.exit()
            ff = liabhar.FileStuff(f1, 'w+b')  #### reset the log file
            #header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", "  sw_info ipaddr  ",ipaddr_switch, "\n==============================\n\n")
            header = "%s%s%s%s" % ("\nNAMESERVER CAPTURE FILE \n", "  sw_info ipaddr  ",ipaddr_switch, "\n==============================\n\n")
            ff.write(header)
            ff.write(anturlar.fos_cmd("nsshow"))
            ff.write(anturlar.fos_cmd("nsallshow"))
            ff.write(anturlar.fos_cmd("configshow"))
            ff.close()
            g = open(f1,"r")
            lines = g.readlines()
            g.close()
            ff = liabhar.FileStuff(f1, 'w+b')
            for l in lines:
                if " date = " not in l:
                    ff.write(l)            
            ff.close()
            diff_f  = liabhar.file_diff(f,f1)
            print(diff_f)
            if not diff_f:
                liabhar.email_sender_html("*****@*****.**","*****@*****.**","NS_portflapper failed a checkpoint","NS_portflapper failed a checkpoint","")
                sys.exit()
    else:
        print("\n"+"@"*40)
        print('\nTHIS IS A NOS SWITCH> SKIPPING')
        print("\n"+"@"*40)
        liabhar.email_sender_html("*****@*****.**","*****@*****.**","NS_portflapper failed becasue of NOS Check","NS_portflapper failed because of NOS Check","")
        sys.exit()
    anturlar.close_tel()
    print("#"*80)
    print("#"*80)
    print("#"*80)
    print("#"*80)
    print("Result ")
    print(diff_f)
    liabhar.email_sender_html("*****@*****.**","*****@*****.**","NS_portflapper passed","NS_portflapper passed","")

    return(True)
    sys.exit()
Пример #3
0
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)
    print(pa)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    print(pa.cmdprompt)
    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
    ####
    #######################################################################################################################
    #######################################################################################################################
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr)

    cons_info = sw_matrix_tools.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 = sw_matrix_tools.pwr_pole_info(pa.chassis_name)
    usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name)
    user_name = usr_pass[0]
    usr_psswd = usr_pass[1]

    ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name)

    ######################################################################################################################
    ######################################################################################################################
    ####
    ####   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 " %
        pa.fid)  ####   change to the fid given on the command
    cons_out = anturlar.fos_cmd(
        "firmwareshow")  ####   send any command with anturlar.fos_cmd
    print("\r\n")
    liabhar.JustSleep(30)  ####   sleep without printing anything
    print("now closing telnet session ")
    anturlar.close_tel()  ####  close the telnet session
    liabhar.JustSleep(30)
    #######################################################################################################################
    #######################################################################################################################
    ####
    ####   connect via console example
    ####
    ####
    #######################################################################################################################
    #######################################################################################################################

    #tn = anturlar.connect_console(console_ip,console_port)          ####  use the console ip and console port info
    #cons_out = anturlar.fos_cmd("switchshow")                       ####  send a command via the console
    #
    ##cons_out = cofra.power_cycle(power_pole_info)                  #### power cycle the switch  using the
    #                                                                ####   Switch Matrix info
    #liabhar.JustSleep(30)                                           ####  wait for the switch to boot
    #
    #
    #cons_out = anturlar.send_cmd_console("\r\n")                        ####  send some commands to the console
    #                                                                    ####
    #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid)     ####
    #cons_out = anturlar.send_cmd_console("firmwareshow")                ####

    #######################################################################################################################
    #######################################################################################################################
    ####
    ####  do anything else you want to try
    ####
    ####
    #######################################################################################################################
    #######################################################################################################################
    dt = liabhar.dateTimeStuff(
    )  #### create the object for date and time stuff
    date_is = dt.current()  #### get the current time
    print(date_is)

    print("Leaving the script\r\n\r\n")
    liabhar.count_down(30)  ####   count down to the next command
Пример #4
0
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)
    print(pa)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    print(pa.cmdprompt)
    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
    ####
    #######################################################################################################################
    #######################################################################################################################
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr)

    cons_info = sw_matrix_tools.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 = sw_matrix_tools.pwr_pole_info(pa.chassis_name)
    usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name)
    user_name = usr_pass[0]
    usr_psswd = usr_pass[1]

    ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name)

    ######################################################################################################################
    ######################################################################################################################
    ####
    ####   connect via telnet:
    ####   if you want to connect to the console it is available in anturlar and an example below
    ####
    ####
    ######################################################################################################################
    ######################################################################################################################
    ####   Config_up_down_compare.main()

    # cons_out = anturlar.fos_cmd("firmwareshow")                          ####   send any command with anturlar.fos_cmd
    # print("\r\n")
    # liabhar.JustSleep(5)                                                ####   sleep without printing anything
    # print("now closing telnet session ")
    # #anturlar.close_tel()                                                 ####  close the telnet session
    #######################################################################################################################
    #######################################################################################################################
    ####
    ####   connect via console example and other "send command" commands
    ####
    ####
    #######################################################################################################################
    #######################################################################################################################
    #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)   ####  connect to console w/o parser info
    #cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)                 ####  change to the fid given on the command
    #tn = anturlar.connect_console(console_ip,console_port)                 ####  use the console ip and console port info
    #cons_out = anturlar.fos_cmd("switchshow")                              ####  send a command via the console
    #cons_out = cofra.power_cycle(power_pole_info)                          ####  powercycle switch via switchmatrix.csv file
    #liabhar.JustSleep(30)                                                  ####  wait for the switch to boot
    #cons_out = anturlar.send_cmd_console("\r\n")                           ####  send some commands to the console
    #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid)        ####  send some commands to the console
    #cons_out = anturlar.send_cmd_console("firmwareshow")                   ####  send some commands to the console
    #capture = cofra.cfgupload("10.38.35.131", "ftp1", "ftp2")              ####  send a cfgupload file to a ftp server
    #liabhar.count_down(5)                                                  ####  set and observe a count down timer

    #######################################################################################################################
    #######################################################################################################################
    ####
    ####  This starts the template for configshow output comparison (after some type of switch operation).
    ####  First snippet of code simply opens a connection, changes to requested fid, sends output of configshow to a file.
    ####
    #######################################################################################################################
    #######################################################################################################################
    tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd)
    cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)
    dt = liabhar.dateTimeStuff(
    )  #### create the object for date and time stuff
    date_is = dt.current_no_dash_at_end(
    )  #### get the current time for file naming purposes
    #print("\n\nDate is %s" % date_is)

    liabhar.count_down(5)  ####   count down to the next command
    #configup_cmd = ("configupload -all -p ftp %s,%s,/configs/%s.txt,%s") % ("10.38.35.131","ftp1", ipaddr_switch, "ftp2")
    f = "%s%s%s%s" % ("logs/Configupload_test_case_file", ipaddr_switch,
                      date_is, ".txt")
    ff = liabhar.FileStuff(f, 'w+b')  #### open the log file for writing
    header = "%s%s%s%s" % (
        "\nCONFIGUPLOAD CAPTURE FILE \n", "  sw_info ipaddr  ", ipaddr_switch,
        "\n==============================\n\n"
    )  #### write a header line at top of file
    ff.write(header)
    #cons_out = anturlar.fos_cmd (configup_cmd)
    ff.write(anturlar.fos_cmd("configshow"))
    ff.close()  #### close this file for comparison later
    #######################################################################################################################
    #######################################################################################################################
    ####
    ####  do anything else you want to try (small sample of examples):
    ####  anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
    ####  anturlar.fos_cmd("cfgenable")
    ####  anturlar.fos_cmd("switchdisable")
    ####  anturlar.fos_cmd("switchenable")
    ####
    ####  In the below snippet we run tsclockerver: anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
    ####  Then grab output of configshow, drop into a file and compare that with original
    ####
    #######################################################################################################################
    #######################################################################################################################

    anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
    date_is = dt.current_no_dash_at_end()
    f1 = "%s%s%s%s" % ("logs/Configupload_test_case_file", ipaddr_switch,
                       date_is, ".txt")
    ff = liabhar.FileStuff(f1, 'w+b')  #### reset the log file
    header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n",
                           "  sw_info ipaddr  ", ipaddr_switch,
                           "\n==============================\n\n")
    ff.write(header)
    #cons_out = anturlar.fos_cmd (configup_cmd)
    ff.write(anturlar.fos_cmd("configshow"))
    ff.close()

    diff_f = liabhar.file_diff(f, f1)
    print("#" * 80)
    print("#" * 80)
    print("#" * 80)
    print("#" * 80)
    print("Result ")
    print(diff_f)

    #return(cons_out)
    return (True)
Пример #5
0
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)
Пример #6
0
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)
    print(pa)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    print(pa.cmdprompt)
    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
####
#######################################################################################################################
#######################################################################################################################
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr)
        
    cons_info         = sw_matrix_tools.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   = sw_matrix_tools.pwr_pole_info(pa.chassis_name)    
    usr_pass          = sw_matrix_tools.get_user_and_pass(pa.chassis_name)
    user_name         = usr_pass[0]
    usr_psswd         = usr_pass[1]
    
    ipaddr_switch     = sw_matrix_tools.get_ip_from_file(pa.chassis_name)
 
 ######################################################################################################################
 ######################################################################################################################
 ####
 ####   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 " % pa.fid)               ####   change to the fid given on the command 
    cons_out = anturlar.fos_cmd("firmwareshow")                          ####   send any command with anturlar.fos_cmd
    print("\r\n")
    liabhar.JustSleep(30)                                                ####   sleep without printing anything
    print("now closing telnet session ") 
    anturlar.close_tel()                                                 ####  close the telnet session
    liabhar.JustSleep(30)
#######################################################################################################################   
#######################################################################################################################
####
####   connect via console example
####    
####
#######################################################################################################################
#######################################################################################################################
 
    #tn = anturlar.connect_console(console_ip,console_port)          ####  use the console ip and console port info
    #cons_out = anturlar.fos_cmd("switchshow")                       ####  send a command via the console
    #
    ##cons_out = cofra.power_cycle(power_pole_info)                  #### power cycle the switch  using the
    #                                                                ####   Switch Matrix info
    #liabhar.JustSleep(30)                                           ####  wait for the switch to boot
    #
    #
    #cons_out = anturlar.send_cmd_console("\r\n")                        ####  send some commands to the console
    #                                                                    ####
    #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid)     ####
    #cons_out = anturlar.send_cmd_console("firmwareshow")                ####


#######################################################################################################################
#######################################################################################################################
####
####  do anything else you want to try
####
####
#######################################################################################################################
#######################################################################################################################
    dt = liabhar.dateTimeStuff()                         #### create the object for date and time stuff
    date_is = dt.current()                               #### get the current time
    print(date_is)
    
    print("Leaving the script\r\n\r\n")
    liabhar.count_down(30)                               ####   count down to the next command 
Пример #7
0
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)
    print(pa)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    print(pa.cmdprompt)
    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
####
#######################################################################################################################
#######################################################################################################################
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr)
        
    cons_info         = sw_matrix_tools.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   = sw_matrix_tools.pwr_pole_info(pa.chassis_name)    
    usr_pass          = sw_matrix_tools.get_user_and_pass(pa.chassis_name)
    user_name         = usr_pass[0]
    usr_psswd         = usr_pass[1]
    
    ipaddr_switch     = sw_matrix_tools.get_ip_from_file(pa.chassis_name)
 
 ######################################################################################################################
 ######################################################################################################################
 ####
 ####   connect via telnet:
 ####   if you want to connect to the console it is available in anturlar and an example below
 ####
 ####
 ######################################################################################################################
 ######################################################################################################################
 ####   Config_up_down_compare.main()

    # cons_out = anturlar.fos_cmd("firmwareshow")                          ####   send any command with anturlar.fos_cmd
    # print("\r\n")
    # liabhar.JustSleep(5)                                                ####   sleep without printing anything
    # print("now closing telnet session ") 
    # #anturlar.close_tel()                                                 ####  close the telnet session
#######################################################################################################################   
#######################################################################################################################
####
####   connect via console example and other "send command" commands
####    
####
#######################################################################################################################
#######################################################################################################################
    #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)   ####  connect to console w/o parser info
    #cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)                 ####  change to the fid given on the command  
    #tn = anturlar.connect_console(console_ip,console_port)                 ####  use the console ip and console port info
    #cons_out = anturlar.fos_cmd("switchshow")                              ####  send a command via the console
    #cons_out = cofra.power_cycle(power_pole_info)                          ####  powercycle switch via switchmatrix.csv file
    #liabhar.JustSleep(30)                                                  ####  wait for the switch to boot
    #cons_out = anturlar.send_cmd_console("\r\n")                           ####  send some commands to the console
    #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid)        ####  send some commands to the console
    #cons_out = anturlar.send_cmd_console("firmwareshow")                   ####  send some commands to the console
    #capture = cofra.cfgupload("10.38.35.131", "ftp1", "ftp2")              ####  send a cfgupload file to a ftp server
    #liabhar.count_down(5)                                                  ####  set and observe a count down timer


#######################################################################################################################
#######################################################################################################################
####
####  This starts the template for configshow output comparison (after some type of switch operation).
####  First snippet of code simply opens a connection, changes to requested fid, sends output of configshow to a file.
####
#######################################################################################################################
#######################################################################################################################
    tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)
    cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)  
    dt = liabhar.dateTimeStuff()                                        #### create the object for date and time stuff
    date_is = dt.current_no_dash_at_end()                               #### get the current time for file naming purposes
    #print("\n\nDate is %s" % date_is)
    
    liabhar.count_down(5)                                               ####   count down to the next command 
    #configup_cmd = ("configupload -all -p ftp %s,%s,/configs/%s.txt,%s") % ("10.38.35.131","ftp1", ipaddr_switch, "ftp2")
    f = "%s%s%s%s"%("logs/Configupload_test_case_file",ipaddr_switch,date_is,".txt")
    ff = liabhar.FileStuff(f, 'w+b')                                    #### open the log file for writing       
    header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", "  sw_info ipaddr  ",ipaddr_switch,"\n==============================\n\n")                                 #### write a header line at top of file
    ff.write(header)
    #cons_out = anturlar.fos_cmd (configup_cmd)
    ff.write(anturlar.fos_cmd("configshow"))
    ff.close()                                                          #### close this file for comparison later
#######################################################################################################################
#######################################################################################################################
####
####  do anything else you want to try (small sample of examples):
####  anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
####  anturlar.fos_cmd("cfgenable")
####  anturlar.fos_cmd("switchdisable")
####  anturlar.fos_cmd("switchenable")
####
####  In the below snippet we run tsclockerver: anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
####  Then grab output of configshow, drop into a file and compare that with original
####
#######################################################################################################################
#######################################################################################################################

    
    anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
    date_is = dt.current_no_dash_at_end()
    f1 = "%s%s%s%s"%("logs/Configupload_test_case_file",ipaddr_switch,date_is,".txt")
    ff = liabhar.FileStuff(f1, 'w+b')  #### reset the log file        
    header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", "  sw_info ipaddr  ",ipaddr_switch, "\n==============================\n\n")  
    ff.write(header)
    #cons_out = anturlar.fos_cmd (configup_cmd)
    ff.write(anturlar.fos_cmd("configshow"))
    ff.close()
    
    diff_f  = liabhar.file_diff(f,f1)
    print("#"*80)
    print("#"*80)
    print("#"*80)
    print("#"*80)
    print("Result ")
    print(diff_f)

    #return(cons_out)
    return(True)
Пример #8
0
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)
Пример #9
0
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)
    print(pa)
    print(pa.ipaddr)
    print(pa.quiet)
    print(pa.verbose)
    print(pa.cmdprompt)
    print(pa.iterations)
    #print(pa.zone_name_size)
    print("@" * 40)
    print("@" * 40)
    #sys.exit()
    #######################################################################################################################
    #######################################################################################################################
    ####
    #### 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
    ####
    #######################################################################################################################
    #######################################################################################################################
    if pa.ipaddr:
        print("do IP steps")
        pa.chassis_name = sw_matrix_tools.console_info_from_ip(pa.ipaddr)

    cons_info = sw_matrix_tools.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 = sw_matrix_tools.pwr_pole_info(pa.chassis_name)
    usr_pass = sw_matrix_tools.get_user_and_pass(pa.chassis_name)
    user_name = usr_pass[0]
    usr_psswd = usr_pass[1]

    ipaddr_switch = sw_matrix_tools.get_ip_from_file(pa.chassis_name)

    ######################################################################################################################
    ######################################################################################################################
    ####
    ####   connect via telnet:
    ####   if you want to connect to the console it is available in anturlar and an example is available below
    ####
    ####
    ######################################################################################################################
    ######################################################################################################################
    ####   Config_up_down_compare.main()

    #cons_out = anturlar.fos_cmd("firmwareshow")                          ####   send any command with anturlar.fos_cmd
    #print("\r\n")
    #liabhar.JustSleep(5)                                                ####   sleep without printing anything
    #print(cons_out)
    # print("now closing telnet session ")
    # #anturlar.close_tel()                                                 ####  close the telnet session
    #######################################################################################################################
    #######################################################################################################################
    ####
    ####   connect via console example and other "send command" commands
    ####
    ####
    #######################################################################################################################
    #######################################################################################################################
    #tn = anturlar.connect_tel_noparse(ipaddr_switch,user_name,usr_psswd)   ####  connect to console w/o parser info
    #cons_out = anturlar.fos_cmd("firmwareshow")
    #cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)                 ####  change to the fid given on the command
    #tn = anturlar.connect_console(console_ip,console_port)                 ####  use the console ip and console port info
    #cons_out = anturlar.fos_cmd("switchshow")                              ####  send a command via the console
    #cons_out = cofra.power_cycle(power_pole_info)                          ####  powercycle switch via switchmatrix.csv file
    #liabhar.JustSleep(30)                                                  ####  wait for the switch to boot
    #cons_out = anturlar.send_cmd_console("\r\n")                           ####  send some commands to the console
    #cons_out = anturlar.send_cmd_console("setcontext %s " % pa.fid)        ####  send some commands to the console
    #cons_out = anturlar.send_cmd_console("firmwareshow")                   ####  send some commands to the console
    #capture = cofra.cfgupload("10.38.35.131", "ftp1", "ftp2")              ####  send a cfgupload file to a ftp server
    #liabhar.count_down(5)                                                  ####  set and observe a count down timer

    #######################################################################################################################
    #######################################################################################################################
    ####
    ####  This starts the template for configshow output comparison (after some type of switch operation).
    ####  First snippet of code simply opens a connection, changes to requested fid, sends output of configshow to a file.
    ####
    #######################################################################################################################
    #######################################################################################################################
    tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd)
    cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)
    dt = liabhar.dateTimeStuff(
    )  #### create the object for date and time stuff
    date_is = dt.current_no_dash_at_end(
    )  #### get the current time for file naming purposes
    #print("\n\nDate is %s" % date_is)

    liabhar.count_down(3)  ####   count down to the next command
    #configup_cmd = ("configupload -all -p ftp %s,%s,/configs/%s.txt,%s") % ("10.38.35.131","ftp1", ipaddr_switch, "ftp2")
    f = "%s%s%s%s" % ("logs/CLITIZoneOperations_test_case_file",
                      "_" + ipaddr_switch + "_", date_is, ".txt")
    ff = liabhar.FileStuff(f, 'w+b')  #### open the log file for writing
    #header = "%s%s%s%s" % ("\nNAMESERVER CAPTURE FILE \n", "  sw_info ipaddr  ",ipaddr_switch,"\n==============================\n\n") #### write a header line at top of file
    header = "%s%s%s%s" % ("\nCLITIZoneOperations CAPTURE FILE \n",
                           "  sw_info ipaddr  ", ipaddr_switch,
                           "\n==============================\n\n")
    ff.write(header)
    ff.write(anturlar.fos_cmd("nsshow"))
    ff.write(anturlar.fos_cmd("nsallshow"))
    ff.close()
    g = open(f, "r")
    lines = g.readlines()
    g.close()
    ff = liabhar.FileStuff(f, 'w+b')
    for l in lines:
        if " date = " not in l:
            ff.write(l)
    ff.close()  #### close this file for comparison later

    #######################################################################################################################
    #######################################################################################################################
    ####
    ####  do anything else you want to try (small sample of examples):
    ####  anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
    ####  anturlar.fos_cmd("cfgenable")
    ####  anturlar.fos_cmd("switchdisable")
    ####  anturlar.fos_cmd("switchenable")
    ####
    ####  In the below snippet we run tsclockerver: anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
    ####  Then grab output of configshow, drop into a file and compare that with original
    ####
    #######################################################################################################################
    #######################################################################################################################

    # tn = cofra.clear_stats()
    # print(pa.porttype)
    # #sys.exit()
    # porttype = pa.porttype
    # print(porttype)
    # PortFlapper.main(porttype)
    #############################################################################################
    si = anturlar.SwitchInfo()
    fi = anturlar.FabricInfo()
    # fabric_check =  fi.fabric_members()
    cfgsz = anturlar.fos_cmd("cfgsize")
    # cfgshow = anturlar.fos_cmd("cfgshow")
    cfgtransshow = anturlar.fos_cmd("cfgtransshow")
    if "token" in cfgtransshow:
        print("Outstanding transaction in progress. Use cfgtransshow to view.")
        sys.exit()
    # print(fabric_check)
    # print(cfgsz)
    # print(cfgshow)
    # print(cfgtransshow)
    character = "$-^_"
    characters = ["$", "-", "^", "_"]
    size = random.randint(0, 61)
    ti_zonename = (''.join(
        random.choice(string.ascii_letters + string.digits + character)
        for _ in range(size)) + "_TI")
    ti_zonename = "$" + ti_zonename
    print(ti_zonename)
    while ti_zonename[0] in character:
        print("Can't have special characters at the beginning of a zone name")
        ti_zonename = (''.join(
            random.choice(string.ascii_letters + string.digits + character)
            for _ in range(size)) + "_TI")
    print(ti_zonename)
    sys.exit()
    # a = ("time zone --create -t ti %s -p \"1,1:2,2\"" % ti_zonename)
    # print(a)
    anturlar.fos_cmd("zone --create -t ti %s -p \"1,1;2,2\"" % ti_zonename)
    #anturlar.fos_cmd("echo Y | cfgsave")
    # anturlar.fos_cmd("echo Y | cfgsave")
    # anturlar.fos_cmd("cfgshow")

    sys.exit()

    # f_ports = si.f_ports()
    # e_ports = si.e_ports()
    # print("\n\n\n\n")
    # print(f_ports)
    # print(e_ports)
    # print("\n\n\n\n")
    # if pa.porttype == "eports":
    #     ports = e_ports
    # else:
    #     ports = f_ports
    # i = ipaddr_switch

    # try:
    #     tn = anturlar.connect_tel_noparse(i,user_name,usr_psswd)
    # except OSError:
    #     print("Switch %s not available" % i)
    nos = si.nos_check()
    if not nos:
        for i in ports:
            slot = i[0]
            port = i[1]
            if slot:
                anturlar.fos_cmd("portdisable %s/%s" % (slot, port))
                liabhar.count_down(15)
                anturlar.fos_cmd("portenable %s/%s" % (slot, port))
                liabhar.count_down(15)
            else:
                anturlar.fos_cmd("portdisable %s" % (port))
                liabhar.count_down(15)
                anturlar.fos_cmd("portenable %s" % (port))
                liabhar.count_down(15)
        fabric_check1 = fi.fabric_members()
        if fabric_check != fabric_check1:
            print("WTF")
            #email_sender_html(you, me, subj, html_to_send, htmlfile_path = "" )
            liabhar.email_sender_html("*****@*****.**",
                                      "*****@*****.**",
                                      "NS_portflapper failed",
                                      "NS_portflapper failed", "")
            sys.exit()
        anturlar.close_tel()
        #return(True)
    else:
        print("\n" + "@" * 40)
        print('\nTHIS IS A NOS SWITCH> SKIPPING')
        print("\n" + "@" * 40)
        pass
    #anturlar.close_tel()


####################################################################################################################
#anturlar.fos_cmd("tsclockserver 10.38.2.80; tstimezone America/Denver")
#tn = cofra.ha_failover(pa.iterations)
#tn = cofra.power_cycle_iterations(power_pole_info, pa.iterations)

    tn = anturlar.connect_tel_noparse(ipaddr_switch, user_name, usr_psswd)
    cons_out = anturlar.fos_cmd("setcontext %s " % pa.fid)
    date_is = dt.current_no_dash_at_end()
    f1 = "%s%s%s%s" % ("logs/NameServer_test_case_file",
                       "_" + ipaddr_switch + "_", date_is, ".txt")
    ff = liabhar.FileStuff(f1, 'w+b')  #### reset the log file
    #header = "%s%s%s%s" % ("\NAMESERVER CAPTURE FILE \n", "  sw_info ipaddr  ",ipaddr_switch,"\n==============================\n\n")
    #header = "%s%s%s%s" % ("\nCONFIGUPLOAD CAPTURE FILE \n", "  sw_info ipaddr  ",ipaddr_switch, "\n==============================\n\n")
    header = "%s%s%s%s" % ("\nNAMESERVER CAPTURE FILE \n",
                           "  sw_info ipaddr  ", ipaddr_switch,
                           "\n==============================\n\n")
    ff.write(header)
    ff.write(anturlar.fos_cmd("nsshow"))
    ff.write(anturlar.fos_cmd("nsallshow"))
    ff.close()
    g = open(f1, "r")
    lines = g.readlines()
    g.close()
    ff = liabhar.FileStuff(f1, 'w+b')
    for l in lines:
        if " date = " not in l:
            ff.write(l)
    ff.close()

    diff_f = liabhar.file_diff(f, f1)
    print("#" * 80)
    print("#" * 80)
    print("#" * 80)
    print("#" * 80)
    print("Result ")
    print(diff_f)
    liabhar.email_sender_html("*****@*****.**", "*****@*****.**",
                              "NS_portflapper passed", "NS_portflapper passed",
                              "")

    return (True)