コード例 #1
0
ファイル: powerSwitcher.py プロジェクト: lyh3/automation
    def __new__(cls, *args, **kwargs):
        if not cls._instancePowerSwitcher:
            cls._instancePowerSwitcher = super(PowerSwitcher, cls).__new__(cls)
            cls._powerSwitch = None
            if args.__len__() > 0:
                logName = 'PowerSwitcher'
                automationlog = AutomationLog(logName)
                logger = automationlog.GetLogger(logName)
                automationlog.TryAddConsole(logName)
                powerSwitch = None
                for key in args[0].keys():
                    try:
                        config = args[0][key]
                        if not config['active']:
                            continue
                        if key == 'DLIPowerSwitch':
                            powerSwitch = DLiPowerSwitch(config, logger)
                        elif key == 'usbPowerSwitch':
                            powerSwitch = UsbPowerSwitch(config, logger)
                        elif key == 'sshClient':
                            powerSwitch = LinuxOSPowerSwitch(config, logger)
                        if powerSwitch is not None:
                            cls._powerSwitch = powerSwitch
                            break
                    except Exception as e:
                        logger.error(str(e))
                        #raise Exception('Failed to initialize PowerSwitcher.\n')

        return cls._instancePowerSwitcher._powerSwitch
コード例 #2
0
 def __init__(self, config, resource, isDefaultTestType=True):
     super(HtmlReportWorkThread, self).__init__()
     self._isDefaultTestType = isDefaultTestType
     self._resource = resource
     logName = self.class_id
     automationlog = AutomationLog(logName)
     self._config = config
     self._logger = automationlog.GetLogger(logName)
     automationlog.TryAddConsole(logName)
     self._client = None
     self._reportHeader = []
     self._reportData = []
     self._powerCycleRequestCount = 0
     self._reportHeader.append(
         '<html xmlns="http://www.w3.org/1999/xhtml">')
     self._reportHeader.append(
         '<body style="background-color:{0};">'.format(
             'rgb(225, 231, 242)'))
     self._reportHeader.append(
         '<table cellspacing="0" cellpadding="0" border="0" style="height: 50px;width: 100%;'
         'background-color:steelblue; font-family:arial,helvetica; '
         'font-size:smaller; font-weight:bold; color:white;border-radius:5px;">'
     )
     self._reportHeader.append('<tr style="border:none;">')
     s = self._config['Client']['ip']
     if s is None:
         s = socket.gethostname()
     self._reportHeader.append(
         '<th align=left style="padding-left:3px;">{0}</th><th>'.format(
             self._resource['ICON']['INTEL_LOGO']))
     self._reportHeader.append(
         'Apache Pass Health Check Report [ {0} ] on system @{1}'.format(
             util.GetCurrentTimestamp(), s))
     self._reportHeader.append('</th></tr></table>')
コード例 #3
0
 def setUp(self):
     self._logname = 'automationTest'
     self._automationlogInstance = AutomationLog(self._logname)
     self._logFilename = self._automationlogInstance.GetFileName()
     self.assertTrue(os.path.isfile(self._logFilename))
     self._logger = self._automationlogInstance.GetLogger(self._logname)
     self._automationlogInstance.TryAddConsole(self._logname)
     self.assertFalse(self._logger is None)
コード例 #4
0
ファイル: archiveDataState.py プロジェクト: lyh3/automation
    def DoWork(self):
        try:
            AutomationLog().Close()
            cwd = os.getcwd()
            for d in ['log', 'report']:
                self._createDirectory('{0}/{1}'.format(cwd, r'archive/'), d)

            for key in self._parentWorkThread.TestResultsDictionary.keys():
                resultFolder = r'{0}/{1}'.format(cwd, r'archive/results')
                for g in [RESULTS.FAILED, RESULTS.SKIPPED]:
                    if self._createDirectory(resultFolder, key):
                        for k, v in self._parentWorkThread.TestResultsDictionary.iteritems(
                        ):
                            ids = [x for x in v if x[x.keys()[0]] == g]
                            if len(ids) > 0:
                                filename = '{0}/{1}/{2}_{3}.txt'.format(
                                    resultFolder, key, g.value,
                                    util.GetCurrentTimestamp(
                                        '%Y-%m-%d-%H-%M-%S'))
                                outFile = open(filename, 'w')
                                for id in ids:
                                    outFile.writelines(id)
                                outFile.flush()
                                pass

            files = os.listdir(cwd)
            for l in [x for x in files if x.endswith('.log')]:
                source = os.path.join(cwd, l)
                target = os.path.join(
                    cwd, r'archive/log/{0}_{1}.log'.format(
                        l.split('.')[0],
                        util.GetCurrentTimestamp('%Y-%m-%d-%H-%M-%S')))
                # TODO : self._movDataFile(source, target)
            htmlFiles = [x for x in files if x.endswith('.html')]
            for l in htmlFiles:
                source = os.path.join(cwd, l)
                target = os.path.join(cwd, r'archive/report/{0}'.format(l))
                self._movDataFile(source, target)

        except Exception as e:
            print(str(e))
コード例 #5
0
ファイル: invokeITP.py プロジェクト: lyh3/automation
                for thread in cls._itp.threads:
                    if on:
                        success = 0 ^ thread.cv.resetbreak
                    else:
                        success = 1 ^ thread.cv.resetbreak
                    cls._logInfo('Reset thread {0} to {1} {2}'.format(
                        thread, val, success))
                    results = results and success
            except Exception as e:
                cls._logInfo(
                    'Exception caught when reset break, error = {0}\n'.format(
                        str(e)))
        return results

    @classmethod
    def _logInfo(cls, message):
        with cls._itpMutex:
            return cls._log.info(message)


if __name__ == '__main__':
    from buildingblocks.AutomationLog import AutomationLog
    logName = 'InvokeITP'
    log = AutomationLog(logName)
    invokeITP = InvokeITP(log.GetLogger(logName))
    log.TryAddConsole(logName)
    invokeITP.IsRunning()
    invokeITP.Unlock()
    #invokeITP.TurnSystemOnOrOff(False)
    #invokeITP.TurnSystemOnOrOff(True)
    pass
コード例 #6
0
class TestBuildingblocks(TestCase):
    def setUp(self):
        self._logname = 'automationTest'
        self._automationlogInstance = AutomationLog(self._logname)
        self._logFilename = self._automationlogInstance.GetFileName()
        self.assertTrue(os.path.isfile(self._logFilename))
        self._logger = self._automationlogInstance.GetLogger(self._logname)
        self._automationlogInstance.TryAddConsole(self._logname)
        self.assertFalse(self._logger is None)

    def tearDown(self):
        pass

    def testAutomationLog(self):
        self._logger.info('I am feeling lucky today.')
        if os.path.isfile(self._logFilename):
            try:
                self._automationlogInstance.Close()
                os.remove(self._logFilename)
            except IOError as ex:
                print('Error caugt at tearDown of text_buildingblocks : {}'.
                      format(str(ex)))

    def testAutomationLogGetLogger(self):
        logger = self._automationlogInstance.GetLogger(self._logname)
        self.assertFalse(logger is None)
        self.assertEquals(logger, self._logger)

    def testAutomationCloseLog(self):
        self._automationlogInstance.Close()

    def testPosition(self):
        pos = Position()
        self.assertEquals(0, pos.x)
        self.assertEquals(0, pos.y)
        self.assertEquals(0, pos.z)
        pos.x = pos.y = pos.z = 5
        self.assertEquals(5, pos.x)
        self.assertEquals(5, pos.y)
        self.assertEquals(5, pos.z)

    @expectedFailure
    def testAutomationAddConsoleFail(self):
        self._automationlogInstance.TryAddConsole('')

    def testAutomationLogGetLoggerFail(self):
        logger = self._automationlogInstance.GetLogger(None)
        self.assertTrue(logger is None)
        logger = self._automationlogInstance.GetLogger('')
        self.assertTrue(logger is None)

    def testLengthMetricSucces(self):
        f = LengthMetric()[LengthType.FOOT]
        self.assertEquals(3.28084, f)

    @expectedFailure
    def testLengthMetricSFailedWithWrongIndex(self):
        self.assertRaises(LengthMetric()["Hello"], InvalidArgumentException)

    @expectedFailure
    def testLengthMetricSFailedWithNoneIndex(self):
        self.assertRaises(LengthMetric()[None], InvalidArgumentException)