Example #1
0
    def testCheckWatchdog(self):
        idList = []
        compNameDict = {}
        compIdDict = {}
        addrDict = {}
        portDict = {}
        dataDict = {}

        nextId = 1
        for comp in ('stringHub#0', 'stringHub#10', 'inIceTrigger#0',
                     'simpleTrigger#0', 'iceTopTrigger#0', 'amandaTrigger#0',
                     'globalTrigger#0', 'eventBuilder#0',
                     'secondaryBuilders#0'):
            pound = comp.find('#')
            compName = comp[:pound]
            compId = int(comp[pound + 1:])

            mbeans = self.__buildBeans(TestRunWatchdog.COMP_BEANS, comp)

            client = MockRPCClient(mbeans)

            id = nextId
            nextId += 1

            idList.append(id)
            compNameDict[id] = compName
            compIdDict[id] = compId
            addrDict[id] = 'localhost'
            portDict[id] = 100 + id
            dataDict[id] = MockData(id, compName, compId, None, None, client)

        appender = MockAppender('log')

        wd = MockWatchdog(DAQLog(appender), 60.0, idList, compNameDict,
                          compIdDict, addrDict, portDict, dataDict)

        self.failIf(wd.inProgress(), 'Watchdog should not be in progress')
        self.failIf(wd.isDone(), 'Watchdog should not be done')
        self.failIf(wd.isHealthy(), 'Watchdog should not be healthy')
        self.failIf(wd.caughtError(), 'Watchdog should not have error')
        appender.checkStatus(10)

        for n in range(2):
            for id in dataDict:
                dataDict[id].updateMBeanData()
            self.__runThread(wd, appender)
Example #2
0
    def createClient(self, name, num, host, port, mbeanPort, connectors):
        key = '%s#%d' % (name, num)
        key = 'server'
        if not MostlyCnCServer.APPENDERS.has_key(key):
            MostlyCnCServer.APPENDERS[key] = MockAppender('Mock-%s' % key)

        return MostlyDAQClient(name, num, host, port, mbeanPort, connectors,
                               MostlyCnCServer.APPENDERS[key])
Example #3
0
    def __createLoggers(self, dr):
        appender = MockAppender('main')
        dr.setFileAppender(appender)

        catchall = self.__logFactory.createLog('catchall', DAQPort.CATCHALL,
                                               False)
        StubbedDAQRun.setLogSocketServer(catchall)

        return (appender, catchall)
Example #4
0
class MockServer(CnCServer):
    APPENDER = MockAppender('server')

    def __init__(self,
                 clusterConfigObject=None,
                 copyDir=None,
                 runConfigDir=None,
                 spadeDir=None,
                 logPort=None,
                 livePort=None,
                 forceRestart=False,
                 clientLog=None,
                 logFactory=None):
        self.__clusterConfig = clusterConfigObject
        self.__clientLog = clientLog
        self.__logFactory = logFactory

        super(MockServer, self).__init__(copyDir=copyDir,
                                         runConfigDir=runConfigDir,
                                         spadeDir=spadeDir,
                                         logIP='localhost',
                                         logPort=logPort,
                                         liveIP='localhost',
                                         livePort=livePort,
                                         forceRestart=forceRestart,
                                         testOnly=True)

    def createClient(self, name, num, host, port, mbeanPort, connectors):
        return TinyClient(name, num, host, port, mbeanPort, connectors)

    def createCnCLogger(self, quiet):
        return MockCnCLogger(MockServer.APPENDER, quiet)

    def createRunset(self, runConfig, compList, logger):
        return MockRunSet(self,
                          runConfig,
                          compList,
                          logger,
                          clientLog=self.__clientLog)

    def getClusterConfig(self):
        return self.__clusterConfig

    def openLogServer(self, port, logDir):
        if self.__logFactory is None:
            raise Exception("MockServer log factory has not been set")
        return self.__logFactory.createLog("catchall",
                                           port,
                                           expectStartMsg=False,
                                           startServer=False)

    def saveCatchall(self, runDir):
        pass

    def startLiveThread(self):
        return None
Example #5
0
    def testCreateWatchdogBadComp(self):
        id = 43
        name = 'foo'
        compId = 83

        idList = [
            id,
        ]
        compNameDict = {id: name}
        compIdDict = {id: compId}
        addrDict = {id: 'xxx'}
        portDict = {id: 543}
        dataDict = {id: None}

        appender = MockAppender('log')
        appender.addExpectedExact("Couldn't create watcher for unknown" +
                                  ' component #%d type %s#%d' %
                                  (id, name, compId))

        wd = MockWatchdog(DAQLog(appender), None, idList, compNameDict,
                          compIdDict, addrDict, portDict, dataDict)
Example #6
0
    def testCreate(self):
        addr = 'foo'
        port = 678

        client = MockRPCClient(addr, port, None)

        name = 'xyz'
        daqId = 515

        MockMoni.setRPCClient(name, daqId, client)

        moniPath = 'x'

        appender = MockAppender('log')
        appender.addExpectedExact(
            ('Creating moni output file %s/%s-%d.moni' + ' (remote is %s:%d)')
            % (moniPath, name, daqId, addr, port))

        compId = 1

        MockMoni(DAQLog(appender), moniPath, (compId, ), {
            compId: name,
        }, {
            compId: daqId,
        }, {
            compId: addr,
        }, {
            compId: port,
        })

        appender.checkStatus(10)
Example #7
0
    def testCreateWatchdogBadBean(self):
        id = 43
        name = 'eventBuilder'
        compId = 83

        comp = '%s#%d' % (name, compId)
        mbeans = self.__buildBeans({name: []}, comp)

        idList = [
            id,
        ]
        compNameDict = {id: name}
        compIdDict = {id: compId}
        addrDict = {id: 'xxx'}
        portDict = {id: 543}
        dataDict = {id: None}

        appender = MockAppender('log')
        appender.addExpectedRegexp(r"Couldn't create watcher for component" +
                                   r' #%d type %s#%d: .*' % (id, name, compId))

        wd = MockWatchdog(DAQLog(appender), None, idList, compNameDict,
                          compIdDict, addrDict, portDict, dataDict)
Example #8
0
class MockServer(DAQServer):
    APPENDER = MockAppender('server')

    def __init__(self, logPort, livePort):
        super(MockServer, self).__init__(logIP='localhost',
                                         logPort=logPort,
                                         liveIP='localhost',
                                         livePort=livePort,
                                         testOnly=True)

    def createClient(self, name, num, host, port, mbeanPort, connectors):
        return TinyClient(name, num, host, port, mbeanPort, connectors)

    def createCnCLogger(self, quiet):
        return MockCnCLogger(MockServer.APPENDER, quiet)
Example #9
0
    def testSingleBean(self):
        mbeans = {'abean': {'a': 1, 'b': 2}}

        addr = 'foo'
        port = 678

        client = MockRPCClient(addr, port, mbeans)

        name = 'xyz'
        daqId = 515

        MockMoni.setRPCClient(name, daqId, client)

        moniPath = 'x'

        appender = MockAppender('log')
        appender.addExpectedExact(
            ('Creating moni output file %s/%s-%d.moni' + ' (remote is %s)') %
            (moniPath, name, daqId, str(client)))

        compId = 1

        moni = MockMoni(DAQLog(appender), moniPath, (compId, ), {
            compId: name,
        }, {
            compId: daqId,
        }, {
            compId: addr,
        }, {
            compId: port,
        })

        appender.checkStatus(10)

        badId = compId + 1
        badBean = 'xxx'
        badFld = 'yyy'

        try:
            moni.getSingleBeanField(badId, badBean, badFld)
            self.fail('Should have failed due to bogus ID')
        except BeanFieldNotFoundException, e:
            self.assertEquals(str(e), 'Component %d not found' % badId,
                              'Unexpected error: ' + str(e))
Example #10
0
class CnCLoggerTest(unittest.TestCase):
    def createLog(self, name, port, expectStartMsg=True):
        return self.__logFactory.createLog(name, port, expectStartMsg)

    def setUp(self):
        self.__logFactory = SocketReaderFactory()

        self.__appender = MockAppender('mock')

    def tearDown(self):
        self.__logFactory.tearDown()

        self.__appender.checkStatus(10)

    def testOpenReset(self):
        dc = CnCLogger(self.__appender, True)

        logPort = 12345

        logObj = self.createLog('file', logPort)

        dc.openLog('localhost', logPort, None, None)
        self.assertEqual(dc.getLogHost(), 'localhost')
        self.assertEqual(dc.getLogPort(), logPort)
        self.assertEqual(dc.getLiveHost(), None)
        self.assertEqual(dc.getLivePort(), None)

        logObj.checkStatus(1000)

        dc.resetLog()
        self.failIf(dc.getLogHost() is not None, 'logIP was not cleared')
        self.failIf(dc.getLogPort() is not None, 'logPort was not cleared')

        logObj.checkStatus(1000)

    def testOpenResetLive(self):
        dc = CnCLogger(self.__appender, True)

        livePort = 6789

        liveObj = self.createLog('live', livePort, False)

        dc.openLog(None, None, 'localhost', livePort)
        self.assertEqual(dc.getLogHost(), None)
        self.assertEqual(dc.getLogPort(), None)
        self.assertEqual(dc.getLiveHost(), 'localhost')
        self.assertEqual(dc.getLivePort(), livePort)

        liveObj.checkStatus(1000)

        dc.resetLog()
        self.failIf(dc.getLiveHost() is not None, 'liveIP was not cleared')
        self.failIf(dc.getLivePort() is not None, 'livePort was not cleared')

        liveObj.checkStatus(1000)

    def testOpenResetBoth(self):
        dc = CnCLogger(self.__appender, True)

        logPort = 12345
        livePort = 6789

        logObj = self.createLog('file', logPort)
        liveObj = self.createLog('live', livePort, False)

        dc.openLog('localhost', logPort, 'localhost', livePort)
        self.assertEqual(dc.getLogHost(), 'localhost')
        self.assertEqual(dc.getLogPort(), logPort)
        self.assertEqual(dc.getLiveHost(), 'localhost')
        self.assertEqual(dc.getLivePort(), livePort)

        logObj.checkStatus(1000)
        liveObj.checkStatus(1000)

        dc.resetLog()
        self.failIf(dc.getLogHost() is not None, 'logIP was not cleared')
        self.failIf(dc.getLogPort() is not None, 'logPort was not cleared')
        self.failIf(dc.getLiveHost() is not None, 'liveIP was not cleared')
        self.failIf(dc.getLivePort() is not None, 'livePort was not cleared')

        logObj.checkStatus(1000)
        liveObj.checkStatus(1000)

    def testOpenClose(self):
        dc = CnCLogger(self.__appender, True)

        logHost = 'localhost'
        logPort = 12345

        logObj = self.createLog('file', logPort)

        dc.openLog(logHost, logPort, None, None)
        self.assertEqual(dc.getLogHost(), logHost)
        self.assertEqual(dc.getLogPort(), logPort)
        self.assertEqual(dc.getLiveHost(), None)
        self.assertEqual(dc.getLivePort(), None)

        logObj.addExpectedTextRegexp('End of log')

        dc.closeLog()
        self.failIf(dc.getLogHost() is not None, 'logIP was not cleared')
        self.failIf(dc.getLogPort() is not None, 'logPort was not cleared')
        self.failIf(dc.getLiveHost() is not None, 'liveIP was not cleared')
        self.failIf(dc.getLivePort() is not None, 'livePort was not cleared')

    def testOpenCloseLive(self):
        dc = CnCLogger(self.__appender, True)

        liveHost = 'localhost'
        livePort = 6789

        liveObj = self.createLog('live', livePort, False)

        dc.openLog(None, None, liveHost, livePort)
        self.assertEqual(dc.getLogHost(), None)
        self.assertEqual(dc.getLogPort(), None)
        self.assertEqual(dc.getLiveHost(), liveHost)
        self.assertEqual(dc.getLivePort(), livePort)

        liveObj.addExpectedTextRegexp('End of log')

        dc.closeLog()
        self.failIf(dc.getLogHost() is not None, 'logIP was not cleared')
        self.failIf(dc.getLogPort() is not None, 'logPort was not cleared')
        self.failIf(dc.getLiveHost() is not None, 'liveIP was not cleared')
        self.failIf(dc.getLivePort() is not None, 'livePort was not cleared')

    def testOpenCloseBoth(self):
        dc = CnCLogger(self.__appender, True)

        logHost = 'localhost'
        logPort = 12345
        liveHost = 'localhost'
        livePort = 6789

        logObj = self.createLog('file', logPort)
        liveObj = self.createLog('live', livePort, False)

        dc.openLog(logHost, logPort, liveHost, livePort)
        self.assertEqual(dc.getLogHost(), logHost)
        self.assertEqual(dc.getLogPort(), logPort)
        self.assertEqual(dc.getLiveHost(), liveHost)
        self.assertEqual(dc.getLivePort(), livePort)

        logObj.addExpectedTextRegexp('End of log')
        liveObj.addExpectedTextRegexp('End of log')

        dc.closeLog()
        self.failIf(dc.getLogHost() is not None, 'logIP was not cleared')
        self.failIf(dc.getLogPort() is not None, 'logPort was not cleared')
        self.failIf(dc.getLiveHost() is not None, 'liveIP was not cleared')
        self.failIf(dc.getLivePort() is not None, 'livePort was not cleared')

    def testLogFallback(self):
        dc = CnCLogger(self.__appender, True)

        dfltHost = 'localhost'
        dfltPort = 11111

        dfltObj = self.createLog('dflt', dfltPort)

        logHost = 'localhost'
        logPort = 12345

        logObj = self.createLog('file', logPort)

        dc.openLog(dfltHost, dfltPort, None, None)
        self.assertEqual(dc.getLogHost(), dfltHost)
        self.assertEqual(dc.getLogPort(), dfltPort)

        dfltObj.checkStatus(1000)

        dc.openLog(logHost, logPort, None, None)
        self.assertEqual(dc.getLogHost(), logHost)
        self.assertEqual(dc.getLogPort(), logPort)

        logObj.checkStatus(1000)

        logObj.addExpectedTextRegexp('End of log')
        dfltObj.addExpectedText('Reset log to %s:%d' % (dfltHost, dfltPort))

        dc.closeLog()
        self.assertEqual(dc.getLogHost(), dfltHost)
        self.assertEqual(dc.getLogPort(), dfltPort)

        logObj.checkStatus(1000)

        dfltObj.checkStatus(1000)

        newHost = 'localhost'
        newPort = 45678

        newObj = self.createLog('new', newPort)

        dc.openLog(newHost, newPort, None, None)
        self.assertEqual(dc.getLogHost(), newHost)
        self.assertEqual(dc.getLogPort(), newPort)

        dfltObj.checkStatus(1000)

        newObj.checkStatus(1000)

        newObj.addExpectedTextRegexp('End of log')
        dfltObj.addExpectedText('Reset log to %s:%d' % (dfltHost, dfltPort))

        dc.closeLog()
        self.assertEqual(dc.getLogHost(), dfltHost)
        self.assertEqual(dc.getLogPort(), dfltPort)

        newObj.checkStatus(1000)

        dfltObj.checkStatus(1000)

        dfltObj.addExpectedTextRegexp('End of log')

        dc.closeLog()
        self.assertEqual(dc.getLogHost(), None)
        self.assertEqual(dc.getLogPort(), None)

        dfltObj.checkStatus(1000)

    def testLogFallbackSwitch(self):
        dc = CnCLogger(self.__appender, True)

        dfltHost = 'localhost'
        dfltPort = 11111

        dfltObj = self.createLog('dflt', dfltPort)

        liveHost = 'localhost'
        livePort = 6789

        liveObj = self.createLog('live', livePort, False)

        dc.openLog(dfltHost, dfltPort, None, None)
        self.assertEqual(dc.getLogHost(), dfltHost)
        self.assertEqual(dc.getLogPort(), dfltPort)
        self.assertEqual(dc.getLiveHost(), None)
        self.assertEqual(dc.getLivePort(), None)

        dfltObj.checkStatus(1000)

        dc.openLog(None, None, liveHost, livePort)
        self.assertEqual(dc.getLogHost(), None)
        self.assertEqual(dc.getLogPort(), None)
        self.assertEqual(dc.getLiveHost(), liveHost)
        self.assertEqual(dc.getLivePort(), livePort)

        liveObj.checkStatus(1000)

        liveObj.addExpectedTextRegexp('End of log')
        dfltObj.addExpectedText('Reset log to %s:%d' % (dfltHost, dfltPort))

        dc.closeLog()
        self.assertEqual(dc.getLogHost(), dfltHost)
        self.assertEqual(dc.getLogPort(), dfltPort)
        self.assertEqual(dc.getLiveHost(), None)
        self.assertEqual(dc.getLivePort(), None)

        liveObj.checkStatus(1000)

        dfltObj.checkStatus(1000)

        newHost = 'localhost'
        newPort = 45678

        newObj = self.createLog('new', newPort)

        dc.openLog(newHost, newPort, None, None)
        self.assertEqual(dc.getLogHost(), newHost)
        self.assertEqual(dc.getLogPort(), newPort)

        dfltObj.checkStatus(1000)

        newObj.checkStatus(1000)

        newObj.addExpectedTextRegexp('End of log')
        dfltObj.addExpectedText('Reset log to %s:%d' % (dfltHost, dfltPort))

        dc.closeLog()
        self.assertEqual(dc.getLogHost(), dfltHost)
        self.assertEqual(dc.getLogPort(), dfltPort)

        newObj.checkStatus(1000)

        dfltObj.checkStatus(1000)

        dfltObj.addExpectedTextRegexp('End of log')

        dc.closeLog()
        self.assertEqual(dc.getLogHost(), None)
        self.assertEqual(dc.getLogPort(), None)

        dfltObj.checkStatus(1000)
Example #11
0
    def setUp(self):
        self.__logFactory = SocketReaderFactory()

        self.__appender = MockAppender('mock')
Example #12
0
    def createInitialAppender(self):
        if self.__mockAppender is None:
            self.__mockAppender = MockAppender('runlog')

        return self.__mockAppender
Example #13
0
    def createCnCLogger(self, quiet):
        key = 'server'
        if not MostlyCnCServer.APPENDERS.has_key(key):
            MostlyCnCServer.APPENDERS[key] = MockAppender('Mock-%s' % key)

        return MockCnCLogger(MostlyCnCServer.APPENDERS[key], quiet)
Example #14
0
    def createCnCLogger(self, quiet=True):
        key = '%s#%d' % (self.__name, self.__num)
        if not RealComponent.APPENDERS.has_key(key):
            RealComponent.APPENDERS[key] = MockAppender('Mock-%s' % key)

        return MockCnCLogger(RealComponent.APPENDERS[key], quiet)
Example #15
0
    def createLogger(self, quiet=True):
        key = str(self)
        if not RealComponent.APPENDERS.has_key(key):
            RealComponent.APPENDERS[key] = MockAppender('Mock-%s' % key)

        return MockCnCLogger(RealComponent.APPENDERS[key], quiet=quiet)
Example #16
0
    def testDoMoni(self):
        mbeans = {'abean': {'a': 1, 'b': 2}}

        addr = 'foo'
        port = 678

        client = MockRPCClient(addr, port, mbeans)

        name = 'xyz'
        daqId = 515

        MockMoni.setRPCClient(name, daqId, client)

        moniPath = 'x'

        appender = MockAppender('log')
        appender.addExpectedExact(
            ('Creating moni output file %s/%s-%d.moni' + ' (remote is %s)') %
            (moniPath, name, daqId, str(client)))

        compId = 1

        moni = MockMoni(DAQLog(appender), moniPath, (compId, ), {
            compId: name,
        }, {
            compId: daqId,
        }, {
            compId: addr,
        }, {
            compId: port,
        })

        appender.checkStatus(10)

        moni.doMoni()

        tries = 0
        while moni.isActive() and tries < 10:
            time.sleep(0.1)
            tries += 1

        md = MockMoni.getMockData(name, daqId)
        lines = md.getOutputLines()
        self.failUnless(len(lines) > 0, "doMoni didn't print anything")
        self.failUnless(len(lines[0]) > 0, "doMoni printed a blank line")
        self.assertEquals(':', lines[0][-1],
                          'No colon at end of "%s"' % lines[0])

        bean = mbeans.keys()[0]
        prefix = lines[0][0:len(bean) + 2]
        self.assertEquals(
            bean + ': ', prefix,
            'Expected "%s: " at front of "%s"' % (bean, lines[0]))
        expLines = self.__buildLines(mbeans, lines[0][len(prefix):-1])

        self.assertEquals(
            len(expLines), len(lines),
            'Expected %d lines, not %s' % (len(expLines), len(lines)))
        for i in range(len(expLines)):
            self.assertEquals(
                expLines[i], lines[i],
                'Expected line#%d "%s", not "%s"' % (i, expLines[i], lines[i]))

        appender.checkStatus(10)
Example #17
0
class CnCLoggerTest(unittest.TestCase):
    def createLog(self, name, port):
        return self.__logFactory.createLog(name, port, False)

    def setUp(self):
        self.__logFactory = SocketReaderFactory()

        self.__appender = MockAppender("mock")

    def tearDown(self):
        try:
            self.__logFactory.tearDown()
        except:
            traceback.print_exc()

        self.__appender.checkStatus(10)

    def testOpenReset(self):
        dfltHost = "localhost"
        dfltPort = 54321

        dfltObj = self.createLog("dflt", dfltPort)

        logHost = "localhost"
        logPort = 12345

        logObj = self.createLog("file", logPort)

        for xl in (False, True):
            dc = CnCLogger(self.__appender, quiet=True, extraLoud=xl)

            # set up default logger
            dc.openLog(None, None, dfltHost, dfltPort)

            logObj.addExpectedText("Start of log at LOG=log(%s:%d)" %
                                   (logHost, logPort))

            dc.openLog(logHost, logPort, None, None)
            self.assertEqual(dc.logHost(), logHost)
            self.assertEqual(dc.logPort(), logPort)
            self.assertEqual(dc.liveHost(), None)
            self.assertEqual(dc.livePort(), None)

            logObj.checkStatus(1000)
            dfltObj.checkStatus(1000)

            if xl:
                dfltObj.addExpectedText("Reset log to LOG=live(%s:%d)" %
                                        (dfltHost, dfltPort))

            dc.resetLog()
            self.failIf(dc.logHost() is not None, "logIP was not cleared")
            self.failIf(dc.logPort() is not None, "logPort was not cleared")
            self.assertEqual(
                dc.liveHost(), dfltHost,
                "liveHost should be %s, not %s" % (dfltHost, dc.liveHost()))
            self.assertEqual(
                dc.livePort(), dfltPort,
                "livePort should be %s, not %s" % (dfltPort, dc.livePort()))

            logObj.checkStatus(1000)
            dfltObj.checkStatus(1000)

    def testOpenResetLive(self):
        dfltHost = "localhost"
        dfltPort = 54321

        dfltObj = self.createLog("dflt", dfltPort)

        liveHost = "localhost"
        livePort = 6789

        liveObj = self.createLog("live", livePort)

        for xl in (False, True):
            dc = CnCLogger(self.__appender, quiet=True, extraLoud=xl)

            dfltObj.addExpectedText("Start of log at LOG=log(%s:%d)" %
                                    (dfltHost, dfltPort))

            # set up default logger
            dc.openLog(dfltHost, dfltPort, None, None)

            dfltObj.checkStatus(1000)
            liveObj.checkStatus(1000)

            dc.openLog(None, None, liveHost, livePort)
            self.assertEqual(dc.logHost(), None)
            self.assertEqual(dc.logPort(), None)
            self.assertEqual(dc.liveHost(), liveHost)
            self.assertEqual(dc.livePort(), livePort)

            dfltObj.checkStatus(1000)
            liveObj.checkStatus(1000)

            if xl:
                dfltObj.addExpectedText("Reset log to LOG=log(%s:%d)" %
                                        (dfltHost, dfltPort))

            dc.resetLog()
            self.assertEqual(
                dc.logHost(), dfltHost,
                "logHost should be %s, not %s" % (dfltHost, dc.logHost()))
            self.assertEqual(
                dc.logPort(), dfltPort,
                "logPort should be %s, not %s" % (dfltPort, dc.logPort()))
            self.failIf(dc.liveHost() is not None, "liveIP was not cleared")
            self.failIf(dc.livePort() is not None, "livePort was not cleared")

            liveObj.checkStatus(1000)
            dfltObj.checkStatus(1000)

    def testOpenResetBoth(self):
        dfltHost = "localhost"
        dfltLog = 54321
        dfltLive = 9876

        dLogObj = self.createLog("dLog", dfltLog)
        dLiveObj = self.createLog("dLive", dfltLive)

        host = "localhost"
        logPort = 12345
        livePort = 6789

        logObj = self.createLog("file", logPort)
        liveObj = self.createLog("live", livePort)

        for xl in (False, True):
            dc = CnCLogger(self.__appender, quiet=True, extraLoud=xl)

            dLogObj.addExpectedText(
                ("Start of log at LOG=log(%s:%d)" + " live(%s:%d)") %
                (dfltHost, dfltLog, dfltHost, dfltLive))

            # set up default logger
            dc.openLog(dfltHost, dfltLog, dfltHost, dfltLive)

            dLogObj.checkStatus(1000)
            dLiveObj.checkStatus(1000)
            logObj.checkStatus(1000)
            liveObj.checkStatus(1000)

            logObj.addExpectedText(
                ("Start of log at LOG=log(%s:%d)" + " live(%s:%d)") %
                (host, logPort, host, livePort))

            dc.openLog(host, logPort, host, livePort)
            self.assertEqual(dc.logHost(), host)
            self.assertEqual(dc.logPort(), logPort)
            self.assertEqual(dc.liveHost(), host)
            self.assertEqual(dc.livePort(), livePort)

            dLogObj.checkStatus(1000)
            dLiveObj.checkStatus(1000)
            logObj.checkStatus(1000)
            liveObj.checkStatus(1000)

            if xl:
                dLogObj.addExpectedText(
                    ("Reset log to LOG=log(%s:%d)" + " live(%s:%d)") %
                    (dfltHost, dfltLog, dfltHost, dfltLive))
                dLiveObj.addExpectedLiveMoni(
                    "log", "Reset log to" + " LOG=log(%s:%d) live(%s:%d)" %
                    (dfltHost, dfltLog, dfltHost, dfltLive))

            dc.resetLog()
            self.assertEqual(
                dc.logHost(), dfltHost,
                "logHost should be %s, not %s" % (dfltHost, dc.logHost()))
            self.assertEqual(
                dc.logPort(), dfltLog,
                "logPort should be %s, not %s" % (dfltLog, dc.logPort()))
            self.assertEqual(
                dc.liveHost(), dfltHost,
                "liveHost should be %s, not %s" % (dfltHost, dc.liveHost()))
            self.assertEqual(
                dc.livePort(), dfltLive,
                "livePort should be %s, not %s" % (dfltLive, dc.livePort()))

            logObj.checkStatus(1000)
            liveObj.checkStatus(1000)
            dLogObj.checkStatus(1000)
            dLiveObj.checkStatus(1000)

    def testOpenClose(self):
        dfltHost = "localhost"
        dfltLog = 54321
        dfltLive = 9876

        dLogObj = self.createLog("dLog", dfltLog)
        dLiveObj = self.createLog("dLive", dfltLive)

        logHost = "localhost"
        logPort = 12345

        logObj = self.createLog("file", logPort)

        for xl in (False, True):
            dc = CnCLogger(self.__appender, quiet=True, extraLoud=xl)

            dLogObj.addExpectedText(
                ("Start of log at LOG=log(%s:%d)" + " live(%s:%d)") %
                (dfltHost, dfltLog, dfltHost, dfltLive))

            # set up default logger
            dc.openLog(dfltHost, dfltLog, dfltHost, dfltLive)

            dLogObj.checkStatus(1000)
            dLiveObj.checkStatus(1000)

            logObj.addExpectedText("Start of log at LOG=log(%s:%d)" %
                                   (logHost, logPort))

            dc.openLog(logHost, logPort, None, None)
            self.assertEqual(dc.logHost(), logHost)
            self.assertEqual(dc.logPort(), logPort)
            self.assertEqual(dc.liveHost(), None)
            self.assertEqual(dc.livePort(), None)

            logObj.checkStatus(1000)
            dLogObj.checkStatus(1000)
            dLiveObj.checkStatus(1000)

            if xl:
                logObj.addExpectedText("End of log")
                dLogObj.addExpectedText(
                    ("Reset log to LOG=log(%s:%d)" + " live(%s:%d)") %
                    (dfltHost, dfltLog, dfltHost, dfltLive))
                dLiveObj.addExpectedLiveMoni(
                    "log", "Reset log to" + " LOG=log(%s:%d) live(%s:%d)" %
                    (dfltHost, dfltLog, dfltHost, dfltLive))

            dc.closeLog()
            self.assertEqual(
                dc.logHost(), dfltHost,
                "logHost should be %s, not %s" % (dfltHost, dc.logHost()))
            self.assertEqual(
                dc.logPort(), dfltLog,
                "logPort should be %s, not %s" % (dfltLog, dc.logPort()))
            self.assertEqual(
                dc.liveHost(), dfltHost,
                "liveHost should be %s, not %s" % (dfltHost, dc.liveHost()))
            self.assertEqual(
                dc.livePort(), dfltLive,
                "livePort should be %s, not %s" % (dfltLive, dc.livePort()))

            logObj.checkStatus(1000)
            dLogObj.checkStatus(1000)
            dLiveObj.checkStatus(1000)

    def testOpenCloseLive(self):
        dfltHost = "localhost"
        dfltLog = 54321
        dfltLive = 9876

        dLogObj = self.createLog("dLog", dfltLog)
        dLiveObj = self.createLog("dLive", dfltLive)

        liveHost = "localhost"
        livePort = 6789

        liveObj = self.createLog("live", livePort)

        for xl in (False, True):
            dc = CnCLogger(self.__appender, quiet=True, extraLoud=xl)

            dLogObj.addExpectedText(
                ("Start of log at LOG=log(%s:%d)" + " live(%s:%d)") %
                (dfltHost, dfltLog, dfltHost, dfltLive))

            # set up default logger
            dc.openLog(dfltHost, dfltLog, dfltHost, dfltLive)

            dLogObj.checkStatus(1000)
            dLiveObj.checkStatus(1000)

            dc.openLog(None, None, liveHost, livePort)
            self.assertEqual(dc.logHost(), None)
            self.assertEqual(dc.logPort(), None)
            self.assertEqual(dc.liveHost(), liveHost)
            self.assertEqual(dc.livePort(), livePort)

            liveObj.checkStatus(1000)
            dLogObj.checkStatus(1000)
            dLiveObj.checkStatus(1000)

            if xl:
                liveObj.addExpectedText("End of log")
                dLogObj.addExpectedText(
                    ("Reset log to LOG=log(%s:%d)" + " live(%s:%d)") %
                    (dfltHost, dfltLog, dfltHost, dfltLive))
                dLiveObj.addExpectedLiveMoni(
                    "log", "Reset log to" + " LOG=log(%s:%d) live(%s:%d)" %
                    (dfltHost, dfltLog, dfltHost, dfltLive))

            dc.closeLog()
            self.assertEqual(
                dc.logHost(), dfltHost,
                "logHost should be %s, not %s" % (dfltHost, dc.logHost()))
            self.assertEqual(
                dc.logPort(), dfltLog,
                "logPort should be %s, not %s" % (dfltLog, dc.logPort()))
            self.assertEqual(
                dc.liveHost(), dfltHost,
                "liveHost should be %s, not %s" % (dfltHost, dc.liveHost()))
            self.assertEqual(
                dc.livePort(), dfltLive,
                "livePort should be %s, not %s" % (dfltLive, dc.livePort()))

            liveObj.checkStatus(1000)
            dLogObj.checkStatus(1000)
            dLiveObj.checkStatus(1000)

    def testOpenCloseBoth(self):
        dfltHost = "localhost"
        dfltLog = 54321
        dfltLive = 9876

        dLogObj = self.createLog("dLog", dfltLog)
        dLiveObj = self.createLog("dLive", dfltLive)

        logHost = "localhost"
        logPort = 12345
        liveHost = "localhost"
        livePort = 6789

        logObj = self.createLog("file", logPort)
        liveObj = self.createLog("live", livePort)

        for xl in (False, True):
            dc = CnCLogger(self.__appender, quiet=True, extraLoud=xl)

            dLogObj.addExpectedText(
                ("Start of log at LOG=log(%s:%d)" + " live(%s:%d)") %
                (dfltHost, dfltLog, dfltHost, dfltLive))

            # set up default logger
            dc.openLog(dfltHost, dfltLog, dfltHost, dfltLive)

            dLogObj.checkStatus(1000)
            dLiveObj.checkStatus(1000)

            logObj.addExpectedText(
                ("Start of log at LOG=log(%s:%d)" + " live(%s:%d)") %
                (logHost, logPort, liveHost, livePort))

            dc.openLog(logHost, logPort, liveHost, livePort)
            self.assertEqual(dc.logHost(), logHost)
            self.assertEqual(dc.logPort(), logPort)
            self.assertEqual(dc.liveHost(), liveHost)
            self.assertEqual(dc.livePort(), livePort)

            if xl:
                logObj.addExpectedTextRegexp("End of log")
                liveObj.addExpectedTextRegexp("End of log")
                dLogObj.addExpectedText(
                    ("Reset log to LOG=log(%s:%d)" + " live(%s:%d)") %
                    (dfltHost, dfltLog, dfltHost, dfltLive))
                dLiveObj.addExpectedLiveMoni(
                    "log", "Reset log to" + " LOG=log(%s:%d) live(%s:%d)" %
                    (dfltHost, dfltLog, dfltHost, dfltLive))

            dc.closeLog()
            self.assertEqual(
                dc.logHost(), dfltHost,
                "logHost should be %s, not %s" % (dfltHost, dc.logHost()))
            self.assertEqual(
                dc.logPort(), dfltLog,
                "logPort should be %s, not %s" % (dfltLog, dc.logPort()))
            self.assertEqual(
                dc.liveHost(), dfltHost,
                "liveHost should be %s, not %s" % (dfltHost, dc.liveHost()))
            self.assertEqual(
                dc.livePort(), dfltLive,
                "livePort should be %s, not %s" % (dfltLive, dc.livePort()))

            logObj.checkStatus(1000)
            liveObj.checkStatus(1000)
            dLogObj.checkStatus(1000)
            dLiveObj.checkStatus(1000)
Example #18
0
 def testInit(self):
     appender = MockAppender('test')
     MostlyDAQClient('foo', 0, 'localhost', 543, 0, [], appender)
Example #19
0
    def buildRunset(self, nodeList):
        if LOUD:
            print '-- Nodes'
            for node in nodeList:
                print node.getDescription()

        nodeLog = {}

        pool = DAQPool()
        port = -1
        for node in nodeList:
            key = '%s#%d' % (node.name, node.num)
            nodeLog[key] = MockAppender('Log-%s' % key)
            pool.add(MockDAQClient(node.name, node.num, None, port, 0,
                                   node.getConnections(), nodeLog[key],
                                   node.outLinks))
            port -= 1

        if LOUD:
            print '-- Pool has ' + str(len(pool.pool)) + ' comps'
            for k in pool.pool.keys():
                print '  ' + str(k)
                for c in pool.pool[k]:
                    print '    ' + str(c)

        numComps = len(pool.pool)

        nameList = []
        for node in nodeList:
            nameList.append(node.name + '#' + str(node.num))

        logger = MockLogger('main')
        runset = pool.makeRunset(nameList, logger)

        chkId = ConnectionTest.EXP_ID
        ConnectionTest.EXP_ID += 1

        self.assertEquals(len(pool.pool), 0)
        self.assertEquals(len(pool.sets), 1)
        self.assertEquals(pool.sets[0], runset)

        self.assertEquals(runset.id, chkId)
        self.assertEquals(len(runset.set), len(nodeList))

        # copy node list
        #
        tmpList = nodeList[:]

        # validate all components in runset
        #
        for comp in runset.set:
            node = None
            for t in tmpList:
                if comp.name == t.name and comp.num == t.num:
                    node = t
                    tmpList.remove(t)
                    break

            self.failIf(not node, 'Could not find component ' + str(comp))

            # copy connector list
            #
            compConn = comp.connectors[:]

            # remove all output connectors
            #
            for typ in node.outLinks:
                conn = None
                for c in compConn:
                    if not c.isInput() and c.type == typ:
                        conn = c
                        compConn.remove(c)
                        break

                self.failIf(not conn, 'Could not find connector ' + typ +
                            ' for component ' + str(comp))

            # remove all input connectors
            #
            for typ in node.inLinks:
                conn = None
                for c in compConn:
                    if c.isInput and c.type == typ:
                        conn = c
                        compConn.remove(c)
                        break

                self.failIf(not conn, 'Could not find connector ' + typ +
                            ' for component ' + str(comp))

            # whine if any connectors are left
            #
            self.assertEquals(len(compConn), 0, 'Found extra connectors in ' +
                              str(compConn))

        # whine if any components are left
        #
        self.assertEquals(len(tmpList), 0, 'Found extra components in ' +
                          str(tmpList))

        if LOUD:
            print '-- SET: ' + str(runset)

        for key in nodeLog:
            nodeLog[key].addExpectedExact('End of log')
        pool.returnRunset(runset)
        self.assertEquals(len(pool.pool), numComps)
        self.assertEquals(len(pool.sets), 0)

        logger.checkStatus(10)

        for key in nodeLog:
            nodeLog[key].checkStatus(10)