def test_init_scheduler_unknown_scheduler(self):
    """ Test AgentRunner with parameters """
    instance = Mock()
    instance.config.scheduling.name = "BAD SCHEDULER"

    co = AgentRunner(instance)
    with self.assertRaisesRegexp(AgentRunnerException, "Scheduling strategies not found"):
      co._init_scheduler()
  def test_init_scheduler_none_scheduler(self):
    """ Test AgentRunner scheduler instanciation """

    instance = Mock()
    instance.config.scheduling.name = None

    co = AgentRunner(instance)
    co._init_scheduler()
    self.assertTrue(co.scheduler.__class__ is SCHEDULERS[None])
  def test_start_no_instance(self):
    """ Test AgentRunner with parameters """
    sched = {"scheduling":{"name": "A SCHEDULER"}}
    instance = None
    mock = Mock()

    co = AgentRunner(instance)

    with self.assertRaisesRegexp(AgentRunnerException, "Can't init a runner for a None module !"):
      co._init_scheduler()
  def test_stop_no_scheduler(self):
    """ Test AgentRunner with parameters """
    sched = {"scheduling":{"name": "A SCHEDULER"}}
    instance = Mock()
    mock = Mock()

    co = AgentRunner(instance)
    co._init_scheduler = mock

    with self.assertRaisesRegexp(AgentRunnerException, "No scheduler found"):
      co.stop()
  def test_start_no_scheduler(self):
    """ Test AgentRunner with parameters """
    instance = Mock()
    mock = Mock()
    instance.config.scheduling.name = "A SCHEDULER"

    co = AgentRunner(instance)
    co._init_scheduler = mock

    with self.assertRaisesRegexp(AgentRunnerException, "No scheduler found"):
      co.start()
  def test_stop_a_scheduler(self):
    """ Test AgentRunner with parameters """
    sched = {"scheduling":{"name": "A SCHEDULER"}}
    mock = Mock()
    mocked_sched = Mock()
    instance = Mock()

    co = AgentRunner(instance)
    co.scheduler = mocked_sched

    co.stop()
    mocked_sched.stop.assert_called_with()
Example #7
0
def main():
  configurator= AgentConfigurator({"folder":"/home/jc", "filename":"clu.conf"})

  configurator.loadfile()
  configurator.loadclasses()
  configurator.initalize_all()

  runners = []
  try:
    for agent in configurator.agents:
      runner = AgentRunner(agent)
      runners.append(runner.start())
    # keep the main thread alive
    while True:
      time.sleep(0.1)
  except KeyboardInterrupt, ex:
    LOGGER.warning("ctrl-C catched, shuting down all threads")
    for runner in runners:
      runner.stop()
      runner.join()