Example #1
0
def test_get_info_for_DB():
    a = []
    for i in sw.get_info_for_DB():
        a.append(i)
    assert isinstance(a[0], dict)
    assert isinstance(a[1], dict)
    assert isinstance(a[2], dict)
def check_all_sansw():
    dicAll = sw.get_info_for_DB()
    try:
        if dicAll:
            for sw_alias in lst_sansw_alias:
                int_total_DB = get_switch_total_db(sw_alias)
                dic_sum_total = dicAll[1]
                dic_sum_total = dic_sum_total[sw_alias]
                int_total_RT = dic_sum_total['PE_Total']
                strIP = dic_sum_total['IP']
                sansw_judge(int_total_RT, int_total_DB, strIP, sw_alias)
    finally:
        db.switch_insert(datetime.datetime.now(), dicAll[0], dicAll[1],
                         dicAll[2])
def sansw_rt_info_to_show():
    """
    @note: SANSW要展示的即时内容(status)
    """
    switch_total = sw.get_info_for_DB()[1]
    lst_sansw_to_show = []
    if switch_total:
        for sansw_alias in switch_total.keys():
            ip = switch_total[sansw_alias]["IP"]
            PE_sum = switch_total[sansw_alias]["PE_Sum"]
            if PE_sum == None:
                PE_sum = []
            PE_total = switch_total[sansw_alias]["PE_Total"]
            warning_level = s.is_Warning(PE_total, tuplThresholdTotal)
            PE_sum.insert(0, ip)
            PE_sum.append(PE_total)
            PE_sum.insert(0, sansw_alias)
            PE_sum.append(warning_level)
            lst_sansw_to_show.append(PE_sum)
        return lst_sansw_to_show
Example #4
0
def main():
    if len(sys.argv) == 1:#用户输入参数是否是本身,如果是
        print(strHelp)#打印帮助
    #OK
    elif sys.argv[1] == 'ptes':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strPTESHelp)
        elif sys.argv[2] == 'all':
            sw.print_porterror_all_formated()
        else:
            if s.is_IP(sys.argv[2]):
                sw.print_porterror_formated(sys.argv[2])
            else:
                print('Please provide correct switch ip...')
    #OK
    elif sys.argv[1] == 'ptcl':#判断执行参数是否为ptcl
        num_argv = len(sys.argv)  #获取参数的个数
        if num_argv == 2 or num_argv > 4:#如果是2个或者大于4个
            print(strPTCLHelp) #打印提示信息
        elif sys.argv[2] == 'all': #如果是3个参数是 all
            sw.clear_all() #调用清除所有交换机端口错误函数
        elif s.is_IP(sys.argv[2]):#如果第3个参数是ip的话,判断是不是ip
            if num_argv == 4:   #判断是否有第4个参数,如果有
                #if _isPort(sys.argv[3]):   错误
                if s.is_port(sys.argv[3]):   #在判断第4个参数是否是正确的端口      
                    sw.clear_one_port(sys.argv[2], sys.argv[3])#调用清除具体ip,端口错误
                else:
                    print('Please provide correct port number...') #请提供正确端口号
            else:
                print(strPTCLHelp) #打印提示
        else:
            print('Please provide correct switch ip...')#请提供正确的交换机ip
    #OK
    elif sys.argv[1] == 'sws':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strSWSHelp)
        elif sys.argv[2] == 'all':
            sw.print_switchshow_all()
        else:
            if s.is_IP(sys.argv[2]):
                sw.print_switchshow(sys.argv[2])
            else:
                print('Please provide correct switch ip...')

    #OK
    elif sys.argv[1] == 'bc':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strBCHelp)
        elif sys.argv[2] == 'all':
            haap.backup_config_all()
        else:
            if s.is_IP(sys.argv[2]):
                haap.backup_config(sys.argv[2])
            else:
                print('Please provide correct engine ip...')

    # get engines' trace files under TraceFolder based on Trace levels
    #trace、primary、seaond
    #OK git Trace   NOT have Primary
    elif sys.argv[1] == 'gt':
        num_argv = len(sys.argv)
        if num_argv > 3:
            trace_level = int(sys.argv[3])
        if num_argv == 2 or num_argv > 4:
            print(strGTHelp)
        elif sys.argv[2] == 'all':
            if num_argv > 3:
                if s.is_trace_level(trace_level):
                    haap.get_trace_all(trace_level)
                else:
                    print('Trace level must be "1" or "2" or "3"')
            else:
                haap.get_trace_all(0)
        elif s.is_IP(sys.argv[2]):
            if num_argv > 3:
                if s.is_trace_level(trace_level):
                    haap.get_trace(sys.argv[2], trace_level)
                else:
                    print('Trace level must be "1" or "2" or "3"')
            else:
                haap.get_trace(sys.argv[2], 0)
        else:
            print('Please provide correct engine ip...')

    # elif sys.argv[1] == 'at':
    #     num_argv = len(sys.argv)
    #     if num_argv > 3:
    #         trace_level = sys.argv[3]
    #     if num_argv == 2 or num_argv > 4:
    #         print(strPTCLHelp)
    #     elif sys.argv[2] == 'all':
    #         if num_argv > 3:
    #             if s.is_trace_level(trace_level):
    #                 haap.analyse_trace_all(trace_level)
    #             else:
    #                 print('Trace Level Must Be "1" or "2" or "3"')
    #         else:
    #             haap.analyse_trace_all(0)
    #     elif s.is_IP(sys.argv[2]):
    #         if num_argv > 3:
    #             if s.is_trace_level(trace_level):
    #                 haap.analyse_trace(sys.argv[2], trace_level)
    #             else:
    #                 print('Trace Level Must Be "1" or "2" or "3"')
    #         else:
    #             haap.analyse_trace(sys.argv[2], 0)
    #     else:
    #         print('Please Provide Correct Engine IP...')
    #OK python Main.py at Trace\2019-00-00
    elif sys.argv[1] == 'at':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strATHelp)
        else:
            if s.is_folder(sys.argv[2]):
                s.TraceAnalyse(sys.argv[2]).run()
            else:
                print('Please provide correct trace folder')
    #OK  python Main.py ec 10.203.1.223 cmd.txt
    elif sys.argv[1] == 'ec':
        if len(sys.argv) != 4:
            print(strECHelp)
        else:
            ip = sys.argv[2]
            command_file = sys.argv[3]
            if not s.is_IP(ip):
                print('Please provide correct engine ip...')
            if not s.is_file(command_file):
                print('File not exists. please provide correct file...')
            haap.execute_multi_commands(ip, command_file)
    #OK  python Main.py fw 10.203.1.223 FW15.9.7.7_OR.bin
    elif sys.argv[1] == 'fw':
        if len(sys.argv) != 4:
            print(strFWHelp)
        else:
            ip = sys.argv[2]
            fw_file = sys.argv[3]
            if not s.is_IP(ip):
                print('Please provide correct engine ip...')
            if not s.is_file(fw_file):
                print('File not exists. please provide correct file...')
            haap.change_firmware(ip, fw_file)
    #OK-
    elif sys.argv[1] == 'sts':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strSTSHelp)
        elif sys.argv[2] == 'all':
            haap.show_stauts_all()
        else:
            if s.is_IP(sys.argv[2]):
                haap.show_stauts(sys.argv[2])
            else:
                print('Please provide correct engine ip...')
    #OK
    elif sys.argv[1] == 'st':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strSTHelp)
        elif sys.argv[2] == 'all':
            haap.set_time_all()
        else:
            if s.is_IP(sys.argv[2]):
                haap.set_time(sys.argv[2])
            else:
                print('Please provide correct engine ip...')
    #OK    
    elif sys.argv[1] == 'stm':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strSTMHelp)
        elif sys.argv[2] == 'all':
            haap.show_time_all()
        else:
            if s.is_IP(sys.argv[2]):
                haap.show_time(sys.argv[2])
            else:
                print('Please provide correct engine ip...')
    #OK
    elif sys.argv[1] == 'pc':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 4:
            print(strPCHelp)
#             print(strPTCLHelp) 原
        elif num_argv > 2:
            if sys.argv[2] == 'all':
                haap.periodically_check_all()
                sw.periodically_check_all()
            elif sys.argv[2] == 'haap':
                if num_argv == 3:
                    haap.periodically_check_all()
                elif num_argv > 3:
                    if s.is_IP(sys.argv[3]):
                        haap.periodically_check(sys.argv[3])
                    else:
                        print('Please provide correct engine ip...')
            elif sys.argv[2] == 'sw':
                if num_argv == 3:
                    sw.periodically_check_all()
                elif num_argv > 3:
                    if s.is_IP(sys.argv[3]):
                        sw.periodically_check(sys.argv[3])
                    else:
                        print('Please provide correct SAN switch ip...')
            else:
                print(strPCHelp)
    #OK
    elif sys.argv[1] == 'mnt':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 4:
            print(strMNTHelp)
        elif sys.argv[2] == 'rt':
            m.monitor_rt_1_thread()
        elif sys.argv[2] == 'db':
            m.monitor_db_4_thread()
        else:
            print('rt(realtime) or db(datarase)')
            
    elif sys.argv[1] == 'v':
        print("VersaTEL G1",Version)
    else:
        print(strHelp)
Example #5
0
 def setup_class(self):
     self.act = sw.Action(ip, ssh_port, user, pw, [])
Example #6
0
def test_periodically_check():
    assert sw.periodically_check(ip) == None
Example #7
0
def test_print_switchshow():
    assert sw.print_switchshow(ip) == None
Example #8
0
def test_periodically_check_all():
    assert sw.periodically_check_all() == None
Example #9
0
def test_print_porterror_formated():
    assert sw.print_porterror_formated(ip) == None
Example #10
0
def test_print_switchshow_all():
    assert sw.print_switchshow_all() == None
Example #11
0
def test_clear_one_port():
    assert sw.clear_one_port(ip, 1) == None
Example #12
0
def test_clear_all():
    assert sw.clear_all() == None
Example #13
0
 def setup_class(self):
     self.infodb = sw.InfoForDB('switch0', ip, port)
Example #14
0
 def setup_class(self):
     self.st = sw.Status(ip, ssh_port, user, pw, port)
Example #15
0
import DB
import datetime
import HAAP as haap
import SANSW as sw
try:
    import configparser as cp
except Exception:
    import ConfigParser as cp

cfg = cp.ConfigParser(allow_no_value=True)
cfg.read('config.ini')
time = datetime.datetime.now()
time_ago = time - datetime.timedelta(minutes=1)
timeshow = time.strftime('%Y-%m-%d %H:%M:%S')
Origin, Info = haap.data_for_db()
origin, total, dic = sw.get_info_for_DB()
ip = str(cfg.get('Engines', 'engine0'))
device = 'engine0'
level = 2
warn = 'Engine AH'
confirm = 0


@pytest.mark.mnt
def test_haap_insert():
    assert DB.haap_insert(time, Origin, Info) == None


@pytest.mark.mnt
def test_haap_last_record():
    assert DB.haap_last_record()