def testBuildMissingOneOutput(self): mgr = DAQPool() compList = [] comp = MockComponent('fooHub', 0) comp.addOutput('aaa') comp.addInput('xxx', 123) compList.append(comp) comp = MockComponent('bar', 0) comp.addInput('aaa', 456) compList.append(comp) self.assertEqual(len(mgr.pool), 0) nameList = [] for c in compList: mgr.add(c) nameList.append(c.name) self.assertEqual(len(mgr.pool), len(compList)) logger = MockLogger('main') self.assertRaises(ValueError, mgr.makeRunset, nameList, logger) self.assertEqual(len(mgr.pool), len(compList)) for c in compList: mgr.remove(c) self.assertEqual(len(mgr.pool), 0) logger.checkStatus(10)
def testSet(self): compList = [] compList.append(MockComponent('foo', 1)) compList.append(MockComponent('bar', 2)) compList[0].setConfigureWait(2) self.runTests(compList, 2)
def testAddRemove(self): mgr = DAQPool() compList = [] comp = MockComponent('foo', 0) compList.append(comp) comp = MockComponent('bar', 0) compList.append(comp) self.assertEqual(mgr.numUnused(), 0) self.assertEqual(mgr.numComponents(), 0) for c in compList: mgr.add(c) self.assertEqual(mgr.numUnused(), len(compList)) self.assertEqual(mgr.numComponents(), len(compList)) for c in compList: mgr.remove(c) self.assertEqual(mgr.numUnused(), 0) self.assertEqual(mgr.numComponents(), 0)
def testRestartExtraComp(self): compList = self.__buildCompList( ("sleepy", "sneezy", "happy", "grumpy", "doc", "dopey", "bashful")) runConfig = FakeRunConfig("XXXrunCfgXXX") logger = MockLogger('foo#0') runset = MyRunSet(MyParent(), runConfig, compList, logger) extraComp = MockComponent("queen", 10) longList = compList[:] longList.append(extraComp) baseName = "failCluCfg" clusterCfg = self.__buildClusterConfig(longList, baseName) logger.addExpectedExact("Cannot remove component %s from RunSet #%d" % (extraComp.fullName(), runset.id())) errMsg = None for c in longList: if errMsg is None: errMsg = "Cycling components [" + c.fullName() else: errMsg += ", " + c.fullName() if errMsg is not None: errMsg += "]" logger.addExpectedExact(errMsg) runset.restartComponents(longList, clusterCfg, None, None, None, None, False, False, False)
def __buildCompList(self, nameList): compList = [] num = 1 for name in nameList: c = MockComponent(name, num) c.setOrder(num) compList.append(c) num += 1 return compList
def testEmpty(self): mgr = DAQPool() runset = mgr.findRunset(1) self.failIf(runset is not None, 'Found set in empty manager') mgr.remove(MockComponent('foo', 0))
def testConnection(self): compName = 'abc' compId = 123 compHost = 'foo' comp = MockComponent(compName, compId, compHost) connType = 'xyz' connPort = 987 conn = Connector(connType, True, connPort) ctn = Connection(conn, comp) expStr = '%s:%s#%d@%s:%d' % (connType, compName, compId, compHost, connPort) self.assertEquals(expStr, str(ctn), 'Expected "%s", not "%s"' % (expStr, str(ctn))) cMap = ctn.getMap() self.checkConnectionMap(connType, cMap, 'type') self.checkConnectionMap(compName, cMap, 'compName') self.checkConnectionMap(compId, cMap, 'compNum') self.checkConnectionMap(compHost, cMap, 'host') self.checkConnectionMap(connPort, cMap, 'port')
def testBuildMissingOneInput(self): self.__runConfigDir = tempfile.mkdtemp() mgr = MyDAQPool() compList = [] outputName = "xxx" comp = MockComponent('fooHub', 0) comp.addOutput('aaa') compList.append(comp) comp = MockComponent('bar', 0) comp.addInput('aaa', 123) comp.addOutput(outputName) compList.append(comp) self.assertEqual(mgr.numComponents(), 0) for c in compList: mgr.add(c) self.assertEqual(mgr.numComponents(), len(compList)) runConfig = self.__createRunConfigFile(compList) logger = MockLogger('main') logger.addExpectedExact("Loading run configuration \"%s\"" % runConfig) logger.addExpectedExact("Loaded run configuration \"%s\"" % runConfig) try: mgr.makeRunset(self.__runConfigDir, runConfig, 0, logger, forceRestart=False, strict=False) self.fail("makeRunset should not succeed") except ConnectionException, ce: if str(ce).find("No inputs found for %s outputs" % outputName) < 0: raise ce
def connect(self, inputs): cDict = {} for data in inputs: comp = MockComponent(data[0], data[1], data[2]) for cData in data[3:]: conn = Connector(cData[0], cData[1], cData[2]) if not cDict.has_key(conn.type): cDict[conn.type] = ConnTypeEntry(conn.type) cDict[conn.type].add(conn, comp) return cDict
def testBuildReturnSet(self): self.__runConfigDir = tempfile.mkdtemp() mgr = MyDAQPool() compList = [] comp = MockComponent('fooHub', 0) comp.addOutput('aaa') compList.append(comp) comp = MockComponent('bar', 0) comp.addInput('aaa', 1234) compList.append(comp) self.assertEqual(mgr.numComponents(), 0) for c in compList: mgr.add(c) self.assertEqual(mgr.numComponents(), len(compList)) runConfig = self.__createRunConfigFile(compList) logger = MockLogger('main') logger.addExpectedExact("Loading run configuration \"%s\"" % runConfig) logger.addExpectedExact("Loaded run configuration \"%s\"" % runConfig) logger.addExpectedRegexp("Built runset #\d+: .*") runset = mgr.makeRunset(self.__runConfigDir, runConfig, 0, logger, forceRestart=False, strict=False) self.assertEqual(mgr.numComponents(), 0) found = mgr.findRunset(runset.id()) self.failIf(found is None, "Couldn't find runset #%d" % runset.id()) mgr.returnRunset(runset, logger) self.assertEqual(mgr.numComponents(), len(compList)) for c in compList: mgr.remove(c) self.assertEqual(mgr.numComponents(), 0) logger.checkStatus(10)
def testBuildReturnSet(self): mgr = DAQPool() compList = [] comp = MockComponent('fooHub', 0) comp.addOutput('aaa') compList.append(comp) comp = MockComponent('bar', 0) comp.addInput('aaa', 1234) compList.append(comp) self.assertEqual(len(mgr.pool), 0) nameList = [] for c in compList: mgr.add(c) nameList.append(c.name) self.assertEqual(len(mgr.pool), len(compList)) logger = MockLogger('main') runset = mgr.makeRunset(nameList, logger) self.assertEqual(len(mgr.pool), 0) found = mgr.findRunset(runset.id) self.failIf(found is None, "Couldn't find runset #" + str(runset.id)) mgr.returnRunset(runset) self.assertEqual(len(mgr.pool), len(compList)) for c in compList: mgr.remove(c) self.assertEqual(len(mgr.pool), 0) logger.checkStatus(10)
def testStartRun(self): mgr = DAQPool() a = MockComponent('aHub', 0) a.addOutput('ab') b = MockComponent('b', 0) b.addInput('ab', 123) b.addOutput('bc') c = MockComponent('c', 0) c.addInput('bc', 456) compList = [c, a, b] self.assertEqual(len(mgr.pool), 0) nameList = [] for c in compList: mgr.add(c) nameList.append(c.name) self.assertEqual(len(mgr.pool), len(compList)) logger = MockLogger('main') runset = mgr.makeRunset(nameList, logger) self.assertEqual(len(mgr.pool), 0) self.assertEqual(len(runset.set), len(compList)) runset.configure('abc') ordered = True prevName = None for s in runset.set: if not prevName: prevName = s.name elif prevName > s.name: ordered = False self.failIf(ordered, 'Runset sorted before startRun()') runset.startRun(1) ordered = True prevName = None for s in runset.set: if not prevName: prevName = s.name elif prevName < s.name: ordered = False self.failUnless(ordered, 'Runset was not sorted by startRun()') runset.stopRun() ordered = True prevName = None for s in runset.set: if not prevName: prevName = s.name elif prevName > s.name: ordered = False self.failUnless(ordered, 'Runset was not reversed by stopRun()') mgr.returnRunset(runset) self.assertEqual(runset.id, None) self.assertEqual(runset.configured, False) self.assertEqual(runset.runNumber, None) self.assertEqual(len(mgr.pool), len(compList)) self.assertEqual(len(runset.set), 0) logger.checkStatus(10)
def testBuildMultiMissing(self): mgr = DAQPool() compList = [] comp = MockComponent('fooHub', 0) comp.addInput('xxx', 123) compList.append(comp) comp = MockComponent('bar', 0) comp.addOutput('xxx') compList.append(comp) comp = MockComponent('feeHub', 0) comp.addInput('xxx', 456) compList.append(comp) comp = MockComponent('baz', 0) comp.addOutput('xxx') compList.append(comp) self.assertEqual(len(mgr.pool), 0) nameList = [] for c in compList: mgr.add(c) nameList.append(c.name) self.assertEqual(len(mgr.pool), len(compList)) logger = MockLogger('main') try: mgr.makeRunset(nameList, logger) self.fail('Unexpected success') except ValueError: pass except: self.fail('Unexpected exception') self.assertEqual(len(mgr.pool), len(compList)) for c in compList: mgr.remove(c) self.assertEqual(len(mgr.pool), 0) logger.checkStatus(10)
def testMonitorClients(self): self.__runConfigDir = tempfile.mkdtemp() mgr = MyDAQPool() compList = [] fooHub = MockComponent('fooHub', 0) fooHub.addOutput('conn') compList.append(fooHub) barComp = MockComponent('bar', 0) barComp.addInput('conn', 123) compList.append(barComp) bazComp = MockComponent('baz', 0) bazComp.addInput('conn', 456) compList.append(bazComp) self.assertEqual(mgr.numComponents(), 0) for c in compList: mgr.add(c) self.assertEqual(mgr.numComponents(), len(compList)) cnt = mgr.monitorClients() self.assertEqual(cnt, len(compList)) for c in compList: self.assertEqual(c.monitorCount(), 1) fooHub.setMonitorState(DAQClient.STATE_DEAD) bazComp.setMonitorState(DAQClient.STATE_MISSING) self.assertEqual(mgr.numComponents(), len(compList)) cnt = mgr.monitorClients() self.assertEqual(cnt, 1) self.assertEqual(mgr.numComponents(), 2) for c in compList: self.assertEqual(c.monitorCount(), 2)
def testStartRun(self): self.__runConfigDir = tempfile.mkdtemp() mgr = MyDAQPool() a = MockComponent('aHub', 0) a.addOutput('ab') b = MockComponent('b', 0) b.addInput('ab', 123) b.addOutput('bc') c = MockComponent('c', 0) c.addInput('bc', 456) compList = [c, a, b] self.assertEqual(mgr.numComponents(), 0) for c in compList: mgr.add(c) self.assertEqual(mgr.numComponents(), len(compList)) runConfig = self.__createRunConfigFile(compList) logger = MockLogger('main') logger.addExpectedExact("Loading run configuration \"%s\"" % runConfig) logger.addExpectedExact("Loaded run configuration \"%s\"" % runConfig) logger.addExpectedRegexp("Built runset #\d+: .*") runset = mgr.makeRunset(self.__runConfigDir, runConfig, 0, logger, forceRestart=False, strict=False) self.assertEqual(mgr.numComponents(), 0) self.assertEqual(runset.size(), len(compList)) self.__checkRunsetState(runset, 'ready') clusterName = "cluster-foo" dashLog = runset.getLog("dashLog") dashLog.addExpectedRegexp(r"Version info: \S+ \d+ \S+ \S+ \S+ \S+" + r" \d+\S*") dashLog.addExpectedExact("Run configuration: %s" % runConfig) dashLog.addExpectedExact("Cluster configuration: %s" % clusterName) self.__checkRunsetState(runset, 'ready') runNum = 1 moniType = RunOption.MONI_TO_NONE logger.addExpectedExact("Starting run #%d with \"%s\"" % (runNum, clusterName)) dashLog.addExpectedExact("Starting run %d..." % runNum) global ACTIVE_WARNING if not LIVE_IMPORT and not ACTIVE_WARNING: ACTIVE_WARNING = True dashLog.addExpectedExact("Cannot import IceCube Live code, so" + " per-string active DOM stats wil not" + " be reported") versionInfo = { "filename": "fName", "revision": "1234", "date": "date", "time": "time", "author": "author", "release": "rel", "repo_rev": "1repoRev", } spadeDir = "/tmp" copyDir = None runset.startRun(runNum, clusterName, moniType, versionInfo, spadeDir, copyDir) self.__checkRunsetState(runset, 'running') numEvts = 0 numSecs = 0 numMoni = 0 numSN = 0 numTcals = 0 dashLog.addExpectedExact("%d physics events collected in %d seconds" % (numEvts, numSecs)) dashLog.addExpectedExact("%d moni events, %d SN events, %d tcals" % (numMoni, numSN, numTcals)) dashLog.addExpectedExact("Run terminated SUCCESSFULLY.") self.failIf(runset.stopRun(), "stopRun() encountered error") self.__checkRunsetState(runset, 'ready') mgr.returnRunset(runset, logger) self.assertEqual(runset.id(), None) self.assertEqual(runset.configured(), False) self.assertEqual(runset.runNumber(), None) self.assertEqual(mgr.numComponents(), len(compList)) self.assertEqual(runset.size(), 0) logger.checkStatus(10)