예제 #1
0
    def testStore(self):
        conf = Config()

        servicebot_conf = ServiceBotConfig()
        servicebot_conf.min_duration_seconds = 2
        servicebot_conf.max_duration_seconds = 2
        servicebot_conf.addServiceInfo(
            "Service",
            modulePath() + "/testservices/StoreService.py", 1, 1, 1)

        conf.addSection("SERVICE_BOT", servicebot_conf)

        conf.addTeamInfo("Team1", "127.0.0.1", "127.0.0.0/24")
        conf.addTeamInfo("Team1", "127.0.0.1", "127.0.0.0/24")

        gamestate = GameStateServerInfo("localhost", 4242, "0123456789012345",
                                        "ABCDEFGH")
        conf.setGameStateServerInfo(gamestate)

        scheduler = ServiceTaskScheduler(conf, True)
        scheduler.execute(0)
        results = scheduler.execute(1)
        scheduler.terminateAtRoundEnd()

        for i in range(0, conf.numTeams()):
            for j in range(0, servicebot_conf.numServices()):
                self.assert_(results[i][j].store() == "Worked")
    def testSimpleSchedule(self):
        round = 0
        scheduler = ServiceTaskScheduler(self.conf, True)

        start = time.time()
        results = scheduler.execute(round)
        scheduler.terminateAtRoundEnd()
        end = time.time()

        run_time = end - start
        self.assert_(4.0 < run_time and run_time < 6.0)
        for i in range(0, self.conf.numTeams()):
            for j in range(0, self.servicebot_conf.numServices()):
                self.assert_(results[i][j].status() == ServiceTask.ERROR)
예제 #3
0
    def testSimpleSchedule(self):
        round = 0
        scheduler = ServiceTaskScheduler(self.conf, True)

        start = time.time()
        results = scheduler.execute(round)
        scheduler.terminateAtRoundEnd()
        end = time.time()

        run_time = end - start
        self.assert_(4.0 < run_time and run_time < 6.0)
        for i in range(0, self.conf.numTeams()):
            for j in range(0, self.servicebot_conf.numServices()):
                self.assert_(results[i][j].status() == ServiceTask.ERROR)
    def testStore(self):
        conf = Config()

        servicebot_conf = ServiceBotConfig()
        servicebot_conf.min_duration_seconds = 2
        servicebot_conf.max_duration_seconds = 2
        servicebot_conf.addServiceInfo("Service", modulePath() + "/testservices/StoreService.py", 1, 1, 1)

        conf.addSection("SERVICE_BOT", servicebot_conf)

        conf.addTeamInfo("Team1", "127.0.0.1", "127.0.0.0/24")
        conf.addTeamInfo("Team1", "127.0.0.1", "127.0.0.0/24")

        gamestate = GameStateServerInfo("localhost", 4242, "0123456789012345", "ABCDEFGH")
        conf.setGameStateServerInfo(gamestate)

        scheduler = ServiceTaskScheduler(conf, True)
        scheduler.execute(0)
        results = scheduler.execute(1)
        scheduler.terminateAtRoundEnd()

        for i in range(0, conf.numTeams()):
            for j in range(0, servicebot_conf.numServices()):
                self.assert_(results[i][j].store() == "Worked")
예제 #5
0
class ServiceBot(Process):

	def __init__(self,conf,init=False):
		Process.__init__(self)
		self.conf = conf
		self.servicebot_conf = conf.getSection("SERVICE_BOT")

		self.comm = None
		self.scheduler = None
		self.init = init
		self.logger = conf.buildLogger("ServiceBot")

	def run(self):
		try:
			self.logger.info("=== Starting ===")
			server_info = self.conf.getGameStateServerInfo()
			self.comm = BotCommClient(
				server_info.host,
				server_info.port,
				server_info.key,
				server_info.iv,
				"SERVICE_BOT")
		
			self.scheduler = ServiceTaskScheduler(self.conf,self.init)

			self.comm.start()
			running = True

			while(running):
				msg = self.comm.receive()
				self.logger.debug("recvd msg: %s (%r)" % (msg.type,str(msg.data)))

				if(msg.type == "EXECUTE_ROUND"):
					round = msg.data
					self.logger.info("=== Service Round(%d) Starting ===" % round)
					results = self.scheduler.execute(round)
					result_msg = self.__parseResults(round,results)
					self.comm.send(result_msg)
					self.logger.info("=== Service Round(%d) Ending ===" % round)

				elif(msg.type == "TERMINATE"):
					self.logger.info("Received TERM message from gameserver")
					running = False

				else:
					self.logger.error("Unknown message: %s %s" % (msg.type,str(msg.data)))
					assert(False)

		except KeyboardInterrupt:
			self.logger.warn("Servicebot caught Keyboard Interrupt!")

		finally:
			#cleanup
			self.logger.info("Terminating...")
			self.scheduler.terminate()
			self.comm.kill()
			self.logger.info("Terminated...")
	
	
	def __parseResults(self,round,task_results):
		results = []
		for teamId in xrange(self.conf.numTeams()):
			results.append([])
			for serviceId in xrange(self.servicebot_conf.numServices()):
				task = task_results[teamId][serviceId]

				if(task.status() == ServiceTask.OK):
					results[teamId].append('g')

				elif(task.status() == ServiceTask.INVALID_FLAG):
					results[teamId].append('b')

				else:
					results[teamId].append('e')
		
		return BotMessage("SERVICE_RESULTS",(round,results))
예제 #6
0
class ServiceBot(Process):
    def __init__(self, conf, init=False):
        Process.__init__(self)
        self.conf = conf
        self.servicebot_conf = conf.getSection("SERVICE_BOT")

        self.comm = None
        self.scheduler = None
        self.init = init
        self.logger = conf.buildLogger("ServiceBot")

    def run(self):
        try:
            self.logger.info("=== Starting ===")
            server_info = self.conf.getGameStateServerInfo()
            self.comm = BotCommClient(server_info.host, server_info.port,
                                      server_info.key, server_info.iv,
                                      "SERVICE_BOT")

            self.scheduler = ServiceTaskScheduler(self.conf, self.init)

            self.comm.start()
            running = True

            while (running):
                msg = self.comm.receive()
                self.logger.debug("recvd msg: %s (%r)" %
                                  (msg.type, str(msg.data)))

                if (msg.type == "EXECUTE_ROUND"):
                    round = msg.data
                    self.logger.info("=== Service Round(%d) Starting ===" %
                                     round)
                    results = self.scheduler.execute(round)
                    result_msg = self.__parseResults(round, results)
                    self.comm.send(result_msg)
                    self.logger.info("=== Service Round(%d) Ending ===" %
                                     round)

                elif (msg.type == "TERMINATE"):
                    self.logger.info("Received TERM message from gameserver")
                    running = False

                else:
                    self.logger.error("Unknown message: %s %s" %
                                      (msg.type, str(msg.data)))
                    assert (False)

        except KeyboardInterrupt:
            self.logger.warn("Servicebot caught Keyboard Interrupt!")

        finally:
            #cleanup
            self.logger.info("Terminating...")
            self.scheduler.terminate()
            self.comm.kill()
            self.logger.info("Terminated...")

    def __parseResults(self, round, task_results):
        results = []
        for teamId in xrange(self.conf.numTeams()):
            results.append([])
            for serviceId in xrange(self.servicebot_conf.numServices()):
                task = task_results[teamId][serviceId]

                if (task.status() == ServiceTask.OK):
                    results[teamId].append('g')

                elif (task.status() == ServiceTask.INVALID_FLAG):
                    results[teamId].append('b')

                else:
                    results[teamId].append('e')

        return BotMessage("SERVICE_RESULTS", (round, results))