def __getHostfromConfig(self, maxProcess, maxError): lst = config["hosts"] pcList = [] for host in lst: h = Host(host["name"], host["user"], crypto.decrypt(host["pass"])) h.setMaxProcess(maxProcess) h.setMaxErrors(maxError) self.log.debug("Host %s extracted from config file." % h.getHostName()) pcList.append(h) self.log.debug("Total number of hosts is: %i" % len(pcList)) return pcList
class TestHost(unittest.TestCase): def setUp(self): self.host=Host("localhost", "boby", "098334057") def tearDown(self): pass def testCheckHost(self): self.host.checkHost() self.assertTrue(self.host.getStatus() in [Host.States.Available, Host.States.Down], "CheckHost function failed") def testErrors(self): self.host.checkHost() self.host.setMaxErrors(1) self.host.addError() self.assertTrue(self.host.getStatus() == Host.States.Error, "Host errors are not the expected status!!!") self.host.resetErrors() def testaddProcess(self): self.host.checkHost() self.host.setMaxProcess(2) self.host.addProcess() self.assertTrue(self.host.getStatus() == Host.States.Running, "Host process are not reported!!!") def testdelProcess(self): self.host.checkHost() self.host.setMaxProcess(2) self.host.addProcess() self.host.delProcess() self.assertTrue(self.host.getStatus() == Host.States.Available, "Host process are not reported!!!") def testfullProcess(self): self.host.checkHost() self.host.setMaxProcess(1) self.host.addProcess() self.assertTrue(self.host.getStatus() == Host.States.Full, "Host process are not reported!!!") def testdelfromFullProcess(self): self.host.checkHost() self.host.setMaxProcess(2) self.host.addProcess() self.host.addProcess() self.host.delProcess() self.assertTrue(self.host.getStatus() == Host.States.Running, "Host process are not reported!!!")