예제 #1
0
파일: Logs.py 프로젝트: white111/CMtestpy
def Log_Error(Msg):
    "An error just occured, log it!"

    Globals.TestData['TOLF'] = int(
        time.time())  #epoch time;      # Time of Last Failure
    Globals.Errors[0] += 1
    Globals.Errors[1] += 1
    Globals.TestData['TEC'] += 1
    Globals.Stats['Result'] = 'FAIL'

    if Globals.TestData['TTF'] == '':  # Only the first time
        Globals.TestData[
            'TTF'] = Globals.TestData['TOLF'] - Globals.Stats['TimeStamp']

    Stats.Update_All
    Util.ASCIIColor('red')
    Print_Log(2, 'Log_Error: ' + Msg)
    #Added JSW 051906 Adding Error Messages to XML file
    Print_Out_XML_Tag("Error")
    Print_Out('		Log_Error: ' + Msg)
    Print_Out_XML_Tag()
    Util.ASCIIColor('reset')
    if (Globals.Exit_On_Error):
        Exit_On_Error_Count -= 1
        # THis must be Erc=0 to avoid dancing forever with $Exit
        #&Exit (0, "Exit_On_Error") if $Exit_On_Error_Count < 1;
        if (Globals.Exit_On_Error_Count < 1):  # if Error count reached Exit
            Print_Log(2, 'Exit on too Many Errors ')
            #&Exit (0, "Exit_On_Error");
            Final()

    return (0)
예제 #2
0
def main():

    #Globals.Myglobals()
    #import Globals
    print(Globals.Debug)
    #print("My Debug = %i" % Debug)
    print(globals())
    #Debug flag

    #global Debug
    #Debug = 1
    #global Verbose
    #global Menu1
    #global session
    #global Cfg_File
    #global Tmp
    #global CmdFilePath
    #global Version
    #global Session
    #global SessionForce
    #global CMPipe; CMPipe=os.getenv('CmTest_Release_Pipe', "No_Pipe")
    #global UserID
    #global Out_File
    #global Loop_overide
    #global shucks; shucks = 0
    #global GlobalVar
    #print (global())
    #Get input from command line
    usage = "usage: %prog session#"
    parser = OptionParser(usage)
    parser.add_option("-d",
                      "--debug",
                      action="count",
                      dest="Debug",
                      default=0,
                      help="Turn on Debug Stetments")
    parser.add_option("-v",
                      "--verbose",
                      action="count",
                      dest="Verbose",
                      default=0,
                      help="Turn on more output")
    parser.add_option(
        "-B",
        "--Batch",
        dest="Menu1",
        default="",
        help="Batch Mode - no Menu prompt, does not support multi level menu")
    parser.add_option("-s",
                      "--session",
                      dest="Session",
                      type="int",
                      default=0,
                      help="Set Sesion #, Default is first avaiable")
    parser.add_option("-L",
                      "--Loop",
                      dest="Loop",
                      type="int",
                      default=0,
                      help="Overide all Loop counts(seconds)")
    parser.add_option("-F",
                      "--Force",
                      dest="Force",
                      type="int",
                      default=0,
                      help="Force Session #")
    parser.add_option("-r",
                      "--regress",
                      dest="Regress",
                      default="null",
                      help="Directly execute a subroutine")
    parser.add_option("-U",
                      "--User",
                      dest="User",
                      default="None",
                      help="Set User ID")
    parser.add_option(
        "-O",
        "--Output",
        dest="Output",
        default=r"cmtest.xml",
        help="Set Output XML file, will default to tmp/cmtest.xml")
    (options, args) = parser.parse_args()
    #if not options.Session :
    #parser.error("-s session# required")
    Globals.Debug += options.Debug
    Globals.Verbose += options.Verbose
    Globals.Menu1 = options.Menu1
    Globals.Regress = options.Regress
    Globals.Session = options.Session
    Globals.SessionForce = options.Force
    Globals.Force = options.Force
    Globals.CurrentUserID = options.User
    Globals.Out_File = options.Output
    Globals.Loop_overide = options.Loop

    OS = os.name
    if os.name == "nt":
        Globals.OS = "NT"
    else:
        Globals.OS = "Linux"
    if Globals.Debug: print("Detected OS: %s " % Globals.OS)

    #Get our base directory and find the Station Config File
    File = os.path.abspath(__file__)
    Globals.GP_Path = FileOp.fnstrip(File, 1)
    PPATH = FileOp.fnstrip(File, 1)
    if Globals.Debug: print("OS path detected is: %s " % Globals.GP_Path)
    if Globals.GP_Path == '': Globals.GP_Path = ".."

    if Globals.OS == "NT":
        Globals.Cfg_File = join(Globals.GP_Path, "cfgfiles",
                                "testctrl.defaults.cfg")
        #Globals[LogPath] = "\Logs"
        TmpDir = expanduser("~")

    else:
        Globals.Cfg_File = '/usr/local/cmtest/testctrl.cfg'
        #Globals[LogPath] = r"/var/local/cmtest/logs"
        TmpDir = expanduser("~") + "/tmp"

    if Globals.Debug: print("Config path detected is: %s " % Globals.Cfg_File)
    #if OS == 'nt':
    #Cfg_File = PPath + "/" + "cfgfiles/testctrl.defaults.cfg"
    #Tmp = os.getenv('TMP', "NO_TMP")
    #else :
    #Cfg_File = r'/usr/local/cmtest/testctrl.cfg'
    #Tmp = os.getenv(expanduser("~") + "/tmp", "NO_TMP")

    Globals.CmdFilePath = r"../" + PPATH + r"/cmdfiles"

    Util.ASCIIColor('reset')

    _Init()
    GUI = 0
    # uneeded Perl &GUI_Init if $GUI;
    Quiet = 0
    # Don't allow since we only have a char menu right now
    shucks = 0
    try:
        Menu.Menu_main()  # Bring up menu and start excution
    except KeyboardInterrupt:
        print("Shutdown requested...exiting")
        _catch_zap()
    except Exception:
        traceback.print_exc(file=sys.stdout)
        sys.exit(0)

    if not Quiet: print("done\n")
    Util.Exit(0)
예제 #3
0
def main():
    usage = "usage: %prog session#"
    parser = OptionParser(usage)
    parser.add_option("-d",
                      "--debug",
                      action="count",
                      dest="Debug",
                      default=0,
                      help="Turn on Debug Stetments")
    parser.add_option("-v",
                      "--verbose",
                      action="count",
                      dest="Verbose",
                      default=0,
                      help="Turn on more output")
    parser.add_option("-c",
                      "--control",
                      dest="Control",
                      default="",
                      help="[ON|OFF|Reboot")
    parser.add_option("-i",
                      "--ip",
                      dest="Ip",
                      default=Globals.GlobalVar['Power_Switch_IP'],
                      help="format IP/Name [ON|OFF|Cycle Outlet Number")
    parser.add_option("-p",
                      "--port",
                      dest="Port",
                      type="int",
                      default=0,
                      help=" Outlet Number")
    parser.add_option("-m",
                      "--monitor",
                      dest="Monitor",
                      type="int",
                      default=0,
                      help="Monitor Power Ports, loop until keypress")

    (options, args) = parser.parse_args()
    #if not options.Session :
    #parser.error("-s session# required")
    Globals.Debug += options.Debug
    Globals.Verbose += options.Verbose
    Control = options.Control
    Ip = options.Ip
    Port = options.Port
    Monitor = options.Monitor

    if Ip:  #check fora valid Ip address/name
        try:
            ipaddress.ip_address(socket.getaddrinfo(Ip, 80)[0][4][0])
        except:
            Util.Exit(0, "Option -i Invalid Ip address or name {}".format(Ip))

    OS = os.name
    if os.name == "nt":
        Globals.OS = "NT"
    else:
        Globals.OS = "Linux"
    if Globals.Debug: print("Detected OS: %s " % Globals.OS)

    #Get our base directory and find the Station Config File
    File = os.path.abspath(__file__)
    Globals.GP_Path = FileOp.fnstrip(File, 1)
    PPATH = FileOp.fnstrip(File, 1)

    if "lib" in Globals.GP_Path:
        Globals.GP_Path, _ = os.path.split(Globals.GP_Path)
    if Globals.GP_Path == '': Globals.GP_Path = ".."
    if Globals.Debug: print("OS path detected is: %s " % Globals.GP_Path)

    if Globals.OS == "NT":
        Globals.Cfg_File = join(Globals.GP_Path, "cfgfiles",
                                "testctrl.defaults.cfg")
        #Globals[LogPath] = "\Logs"
        TmpDir = expanduser("~")

    else:
        Globals.Cfg_File = '/usr/local/cmtest/testctrl.cfg'
        #Globals[LogPath] = r"/var/local/cmtest/logs"
        TmpDir = expanduser("~") + "/tmp"

    if Globals.Debug: print("Config path detected is: %s " % Globals.Cfg_File)
    #if OS == 'nt':
    #Cfg_File = PPath + "/" + "cfgfiles/testctrl.defaults.cfg"
    #Tmp = os.getenv('TMP', "NO_TMP")
    #else :
    #Cfg_File = r'/usr/local/cmtest/testctrl.cfg'
    #Tmp = os.getenv(expanduser("~") + "/tmp", "NO_TMP")

    Globals.CmdFilePath = r"../" + PPATH + r"/cmdfiles"

    Util.ASCIIColor('reset')
    if not os.name == "nt":
        Linux_gbl = 'Ubuntu'
        # Added 3/4/10 to support Ubuntu install
        try:
            with open("/etc/*release", r) as fh:
                for line in fh:
                    if re.search(r"Ubuntu", line): Linux_gbl = 'Ubuntu'
                    elif re.search(r"Fedora", line): Linux_gbl = 'Fedora'
                    elif re.search(r"CentOS", line): Linux_gbl = 'CentOS'
                    else:
                        Linux_gbl = 'unknown'
                        print(
                            "Un-suported linux type found, I am going to die now"
                        )
                        exit()
        except:
            print(
                "Un-suported linux type found, are we Windows? I am going to die now"
            )
            if not Debug: exit()
    #else we are NT
    print("Debug in _Init %i" % Globals.Debug)
    Init.Init_All(0)
    Globals.Erc = 101

    Globals.Erc = 0
    #Init.Init_Also(0)

    pdu = PDU()
    if not Monitor and not Ip: pdu.print_status_with_names()
    if Ip:
        pdu.Ip = Ip
        print("Set PDU IP to: {}".format(pdu.Ip))
        #pdu.get_Ip()
    pdu.print_status_with_names()
    if Control == "on" and Port > 0 and Port < 9:
        print("Turn on Port {}".format(Port))
        pdu.outletnumbers[Port](1)
    elif Control == "off" and Port > 0 and Port < 9:
        pdu.outletnumbers[Port](0)
    elif Control == "reboot" and Port > 0 and Port < 9:
        pdu.outletnumbers[Port](2)
    else:
        Exit(0,
             "Invlaid request for control {} or port {}".formt(Control, Port))

    pdu.print_status_with_names()