Ejemplo n.º 1
0
    def get_trace(self, strBaseFolder, intTraceLevel):
        tn = self._TN_Conn
        connFTP = self._ftp()

        def _get_oddCommand(intTraceLevel):
            oddCMD = odd()
            if intTraceLevel == 1 or intTraceLevel == 2 or intTraceLevel == 3:
                oddCMD['Trace'] = 'ftpprep trace'
                if intTraceLevel == 2 or intTraceLevel == 3:
                    oddCMD['Primary'] = 'ftpprep coredump primary all'
                    if intTraceLevel == 3:
                        oddCMD['Secondary'] = 'ftpprep coredump secondary all'
                return oddCMD
            else:
                print(
                    'Trace level must be: 1 or 2 or 3, please refer "Config.ini" '
                )

        def _get_trace_file(command, strTraceDes):

            # TraceDes = Trace Description
            def _get_trace_name():
                result = tn.exctCMD(command)
                reTraceName = re.compile(r'(ftp_data_\d{8}_\d{6}.txt)')
                strTraceName = reTraceName.search(result)
                if strTraceName:
                    return strTraceName.group()
                else:
                    print('Generate trace "{}" file failed for "{}"'.format(
                        strTraceDes, self._host))

            trace_name = _get_trace_name()
            if trace_name:
                time.sleep(0.1)
                local_name = 'Trace_{}_{}.log'.format(self._host, strTraceDes)
                if connFTP.GetFile('mbtrace', '.', trace_name, local_name):
                    print('Get trace "{:<10}" for "{}" completed ...'.format(
                        strTraceDes, self._host))
                    return True
                else:
                    print('Get trace "{:<10}" for engine "{}" failed!!!\
                        '.format(strTraceDes, self._host))
                #     s.ShowErr(self.__class__.__name__,
                #               sys._getframe().f_code.co_name,
                #               'Get Trace "{:<10}" for Engine "{}" Failed!!!\
                #               '.format(strTraceDes, self._host))

        oddCommand = _get_oddCommand(intTraceLevel)
        lstCommand = list(oddCommand.values())
        lstDescribe = list(oddCommand.keys())

        if s.GotoFolder(strBaseFolder):
            for i in range(len(lstDescribe)):

                _get_trace_file(lstCommand[i], lstDescribe[i])

                time.sleep(0.1)
Ejemplo n.º 2
0
def test_GotoFolder():
    fold = sun.GotoFolder('testa')
    assert fold == True
    if fold:
        try:
            os.chdir('../')
            os.removedirs('testa')
        except:
            pass
Ejemplo n.º 3
0
 def backup(self, strBaseFolder):
     connFTP = self._ftp()
     s.GotoFolder(strBaseFolder)
     lstCFGFile = ['automap.cfg', 'cm.cfg', 'san.cfg']
     for strCFGFile in lstCFGFile:
         if connFTP.GetFile('bin_conf', '.', strCFGFile,
                            'backup_{}_{}'.format(self._host, strCFGFile)):
             print('{} backup completely for {}'.format(
                 strCFGFile.ljust(12), self._host))
             continue
         else:
             print('{} backup failed for {}'.format(
                 strCFGFile.ljust(12), self._host))
             break
         time.sleep(0.25)
Ejemplo n.º 4
0
 def periodic_check(self, lstCommand, strResultFolder, strResultFile):
     s.GotoFolder(strResultFolder)
     if self._SWConn:
         if self._SWConn.exctCMD('chassisshow'):
             with open(strResultFile, 'w') as f:
                 for strCMD in lstCommand:
                     time.sleep(0.2)
                     strResult = self._SWConn.exctCMD(strCMD)
                     if strResult:
                         print(strResult)
                         f.write(strResult)
                     else:
                         strErr = '\n*** Execute command "{}" failed\n'.format(
                             strCMD)
                         print(strErr)
                         f.write(strErr)
Ejemplo n.º 5
0
 def periodic_check(self, lstCommand, strResultFolder, strResultFile):
     if self.AHStatus:
         print("Engine '%s' is at AH status(AH Code %d)" %
               (self.host, self.AHStatus))
         return
     tn = self._TN_Conn
     s.GotoFolder(strResultFolder)
     if tn.exctCMD('\n'):
         with open(strResultFile, 'w') as f:
             for strCMD in lstCommand:
                 time.sleep(0.1)
                 strResult = tn.exctCMD(strCMD)
                 if strResult:
                     print(strResult)
                     f.write(strResult)
                 else:
                     strErr = '\n*** Execute command "{}" failed\n'.format(
                         strCMD)
                     print(strErr)
                     f.write(strErr)