コード例 #1
0
def Init_Also(Util_only):
    "This is the 3rd Init stage, done after getopts, etc"
    "usually called at the end of &main::Init"

    if Globals.Debug:
        print("Debug Quiet Verbose", Globals.Debug, Globals.Quiet,
              Globals.Verbose)

    Util.Show_INC
    #our $GUI = ($ENV{DISPLAY} eq '') ? 0 : 1;        # !!! but what about Win32?
    Globals.GUI = 0

    #!!! we can probably lose this test, since disty.pm is the only declarer
    #     of $Util_Only, since no one else uses Init.pm!
    if not Globals.Util_only:  # Session = '' ...
        if not Globals.SessionForce:
            Stats.Session('next')  # Sets the next Session No.
        else:
            Globals.Stats['Session'] = Globals.Session
            Pid = Stats.Session('read')
            # Returns 0 if available
            # check the process table ...
            if Globals.Pid and not Globals.Pid == Globals.Stats[
                    'PID'] or Is_Running(GLobals.Pid, 1):
                # The requested session is already running!
                if not Globals.SessionForce:
                    Exit(107, "Session %i start declined" % Globals.Session)
                Print_Log(11, "Forcing session %i" % Session)
            Stats.Session('write')  # Tags the Session.
        if not os.path.isdir(Globals.FileTmpDir):
            try:
                os.mkdir(Globals.FileTmpDir)
            except:
                exit("Unable to Create tmp dir %s" % Globals.FileTmpDir)
        Globals.FileTmpDir += Globals.PathSep + 's' + str(
            Globals.Stats['Session'])
        if not os.path.isdir(Globals.FileTmpDir):
            try:
                os.mkdir(Globals.FileTmpDir)
            except:
                exit("Unable to Create tmp dir %s" % Globals.FileTmpDir)
        Logs.Arc_Logs(Globals.FileTmpDir, '_logs')
        os.umask(0)
        Arc_File = "2arc2_logs_" + str(Util.PT_Date(time.time(), 5))
        try:
            if Globals.Verbose:
                print("Init_Also Creating arc file %s " %
                      join(Globals.FileTmpDir, Arc_File))
            fh = open(join(Globals.FileTmpDir, Arc_File), "w")
            #close(fh)
        except:
            exit("Unable to create Arc_File %s" %
                 join(Globals.FileTmpDir, Arc_File))

    # Set up log files...
    Log_Str = ''
    Globals.XLog = join(Globals.FileTmpDir, Globals.Main) + r".log"
    #!!!    &Read_Version;
    Msg = Get_Release_Info  # Sets $Version, etc or Aborts on error!
    if not Globals.Quiet: print("\n\n")
    if Globals.Stats['Session']:
        Log_Str += "Session " + str(Globals.Stats['Session']) + ": "
    Log_Str += "Starting %s version %s at %s" % (
        Globals.Main, Globals.TestData['Ver'], Util.PT_Date(time.time(), 2))
    Globals.Erc = Logs.Print_Log(1, Log_Str)
    Log_Str = ''
    if Globals.Erc: Util.Exit(3, "(%s)" % Globals.Xlog)
    Logs.Print_Log(
        11, "This PID = %s, ShellPID = %s" %
        (Globals.Stats['PID'], Globals.Stats['PPID']))
    if Globals.Debug: print("Init_also GP_Path %s" % Globals.GP_Path)
    Logs.Print_Log(11, 'path = ' + Globals.GP_Path)
    #for Module in  sys.modules['os'] :
    #Vers = Globals.CMtestVersion[FileOp.fnstrip(sys.modules['os'], 7)]
    #Module  = sys.modules['OS']  #Value (Full path / filename)
    #if Module[0:1] == '.' :
    #Module = join(os.getcwd(),Module)
    #Log_Str = "Lib: " + Module
    #if Vers == '' : Log_Str += "\t[Ver: %s]" % Vers
    #if not str.find(Module, "python") : Print_Log (11, Log_Str)
    #IncAge = time.time() - stat.st_mtime(Module)
    #if IncAge < 1000 : Print_Log (1, "Using new Module")

    Log_Str = ''

    if not Util_only:  # Required for test oriented scripts only ...
        Util.Abort('clear')
        # Remove any lurking abort flags
        Globals.Stats['Status'] = 'UserID'
        Globals.Stats['Power'] = 0  #Power supply on count
        Stats.Update_All()
        if Globals.GlobalVar['UserID_Check'] == 1:
            UserID_tmp = ''
            if Globals.CurrentUserID == 'none':
                Globals.CurrentUserID = Util.Ask_User(
                    'text16', 'UserID', 'Please enter your UserID#')
            UserID_tmp = bcrypt.hashpw(
                Globals.CurrentUserID.encode('utf-8'), bcrypt.gensalt(
                ))  # Still need to figure out key in python $Key;
            if Globals.Debug:
                print("Init user password hash is : %s" % UserID_tmp)
            UID_Check(UserID_tmp)  #Exit on fail!  Use adduser.pl ...
            Globals.Stats['UserID'] = UserID

        Globals.Stats['Status'] = 'Menu'
        Stats.Update_All()

        Globals.Comm_Log = join(Globals.FileTmpDir, "Comm.log")
        # system "rm -f $Comm_Log";        # OR
        #        &Rotate_Log ($Comm_Log, 10);
        # Aborts on error!
        Util.Abort('check')  # Make sure there isn't an ABORT flag lurking

        # Figure the UUT_IP address ...

        IPA = Globals.GlobalVar['UUT_IP_Base'].split(r".")
        IPAint = int(IPA[3])
        UUT_IP_Top = IPAint + int(
            Globals.GlobalVar['UUT_IP_Range']) - 1  # Highest sub allowed
        IPAint += int(Globals.Stats['Session']) - 1  # 1 per session or
        if IPAint > UUT_IP_Top:
            Exit(28, "No IP addr available for this session")
        Globals.UUT_IP = "%s.%s.%s.%s" % (IPA[0], IPA[1], IPA[2], IPAint)
        IPAint += 1  ##$IPA[3]++;  There is a possibility of conflict, but we shuld end up using 2 session if the second IP is used.
        if IPAint > UUT_IP_Top:
            Exit(28, "No Secondary IP addr available for this session")
        Globals.UUT_IP_SEC = "%s.%s.%s.%s" % (IPA[0], IPA[1], IPA[2], IPAint)

        Logs.Print_Log(11, "UUT_IP  = %s" % Globals.UUT_IP)
        Logs.Print_Log(11, "CmdFilePath = %s" % Globals.CmdFilePath)
        # Assign the output file ...
        Globals.Out_File = join(Globals.FileTmpDir,
                                Globals.Out_File)  # Default is cmtest.xml
        try:
            os.remove(Out_File)
        except:
            pass
        Logs.Print_Out_XML_Tag('Test')
        Globals.Erc = 0
        Stats.Update_All

        PT_Log = join(Globals.FileTmpDir, "Expect.log")
        try:
            os.remove(PT_Log)
        except:
            pass
    return