Esempio n. 1
0
    def schedule_test(self, ch, method, props, body):
        log.msg('Schedule test msg received')

        hostlist = HostList()

        host_id  = None
        claim_id = None
        body = json.loads(body)
        if len(body) == 3:
            host_id  = body[0]
            claim_id = body[1]
            script   = eval(body[2])

            test_script = TestScript()
            test_script.from_json(script)

            host = self.config.schedule(host_id, claim_id, script)
            if host:
                hostlist.append(host)

        msg = hostlist.to_json()

        ch.basic_publish(exchange='',
                         routing_key=props.reply_to,
                         properties=pika.BasicProperties(
                             correlation_id = props.correlation_id,
                             content_type = 'application/json',
                         ),
                         body=str(msg))

        log.msg('Execute schedule response sent')

        # Try to start tests
        if host_id:
            self.config.try_start_testing(host_id, claim_id)
Esempio n. 2
0
    def reclaim_host(self, ch, method, props, body):
        log.msg('Reclaim host msg received')

        hostlist = HostList()

        body = json.loads(body)
        if len(body) == 2:
            host_id  = body[0]
            claim_id = body[1]

            host = self.config.reclaim_host(host_id, claim_id)
            if host:
                hostlist.append(host)

        msg = hostlist.to_json()

        ch.basic_publish(exchange='',
                         routing_key=props.reply_to,
                         properties=pika.BasicProperties(
                             correlation_id = props.correlation_id,
                             content_type = 'application/json',
                         ),
                         body=str(msg))

        log.msg('Reclaimed hostlist sent')
Esempio n. 3
0
    def get_hosts(self):
        msg = MsgGetHostList()
        self.send(msg)

        log.msg('get_hosts send to server')

        msg = self.receive()
        if not msg:
            return HostList()

#        msg_id = msg[0]
#        if msg_id != '6':
#            log.error('Invalid reply from server')
#            return

        data = eval(msg)
        hostlist = HostList.from_json(data)

        return hostlist
Esempio n. 4
0
    def reclaim_host(self, host_id, claim_id):
        assert host_id > 0

        msg = MsgReclaimHost(host_id, claim_id)
        self.send(msg)

        log.msg("reclaim_host (id: %d) send to server" % host_id)

        msg = self.receive()
        if not msg:
            return HostList()

#        msg_id = msg[0]
#        if msg_id != '6':
#            log.error('Invalid reply from server')
#            return

        data = eval(msg)
        hostlist = HostList.from_json(data)

        return hostlist
Esempio n. 5
0
 def __init__(self):
     self._hostlist = HostList()
     self._lock = Lock()
Esempio n. 6
0
class ServerConfig(object):
    #    __metaclass__ = Singleton

    _hostlist = None
    _lock = None

    def __init__(self):
        self._hostlist = HostList()
        self._lock = Lock()

    def hostlist(self):
        with self._lock:
            return self._hostlist

    def create_host(self):
        with self._lock:
            host = self._hostlist.create_host()
            return host

    def create_dynamic_host(self):
        with self._lock:
            host = self._hostlist.create_dynamic_host()
            return host

    def update_host(self, host):
        with self._lock:
            orig_host = self._hostlist.get_by_id(host.get_id())
            if not orig_host:
                log.error('No host in the host list')
                return

            orig_host.copy(host)

    def claim_host(self, host_id, claim_id):
        with self._lock:
            host = self._hostlist.get_by_id(host_id)
            if host:
                claim_event = HostEvent(FSMEvents.AE_CLAIM, claim_id)
                accepted = host.send_event(claim_event)
                if accepted:
                    return host

            return None

    def reclaim_host(self, host_id, claim_id):
        with self._lock:
            host = self._hostlist.get_by_id(host_id)
            if host:
                reclaim_event = HostEvent(FSMEvents.AE_RECLAIM, claim_id)
                accepted = host.send_event(reclaim_event)
                if accepted:
                    return host

            return None

    def schedule(self, host_id, claim_id, test_script):
        with self._lock:
            host = self._hostlist.get_by_id(host_id)
            if host:
                schedule_event = HostEvent(FSMEvents.AE_SCHEDULE_TEST,
                                           test_script)
                accepted = host.send_event(schedule_event)
                if accepted:
                    return host

            return None

    def try_start_testing(self, host_id, claim_id):
        with self._lock:
            host = self._hostlist.get_by_id(host_id)
            if host:
                if host.get_state() == FSMStates.AF_TESTING:
                    log.msg('Host already in Start Testing state')
                    return

                event = HostEvent(FSMEvents.AE_START_TESTING, claim_id)
                host.send_event(event)

    def execution_done(self, hostname):
        with self._lock:
            host = self._hostlist.get_by_hostname(hostname)
            if host:
                event = HostEvent(FSMEvents.AE_STOP_TESTING)
                host.send_event(event)