Beispiel #1
0
    def testMethods(self):
        messageBusPort = self.startMessageBus()
        node = Node(messageBusPort)
        while not node.client.isRegistered():
            node.client.poll()
        pid = os.fork()
        if not pid:
            try:
                try:
                    node.client.serve()
                except Exception, err:
                    print err
            finally:
                os._exit(0)
        try:
            client = busclient.MessageBusClient('localhost',
                                                messageBusPort,
                                                dispatcher=None,
                                                sessionClass='NODE_CLI')
            while not client.isRegistered():
                client.poll()
            client = NodeClient(client, node.client.getSessionId())

            f = deps.parseFlavor('is:x86')
            assert (client.getResults(f) == f)
            try:
                client.raiseError('a')
                assert 0, 'should have raised error'
            except errors.RmakeError, err:
                assert (str(err) == 'a')
        finally:
            self._kill(pid)
Beispiel #2
0
 def __init__(self, messageBusHost, messageBusPort, cfg, server, node=None,
              logMessages=True):
     subscriptions = set()
     for cls in type(self).mro():
         if 'subscriptions' in cls.__dict__:
             subscriptions.update(cls.subscriptions)
     self.subscriptions = list(subscriptions)
     self.cfg = cfg
     self.server = server
     self.node = node
     if logMessages:
         messageLogPath = cfg.logDir + '/messages/%s.log' % self.name
         logPath = cfg.logDir + '/%s.log' % self.name
     else:
         messageLogPath = logPath = None
     self.bus = busclient.MessageBusClient(messageBusHost,
                                           messageBusPort,
                                           dispatcher=self,
                                           sessionClass=self.sessionClass,
                                           logPath=logPath,
                                           messageLogPath=messageLogPath,
                                           subscriptions=self.subscriptions,
                                           name=self.name,
                                           )
     apirpc.ApiServer.__init__(self, self.bus.logger)
Beispiel #3
0
 def __init__(self, messageBusPort):
     apirpc.ApiServer.__init__(self)
     self.client = busclient.MessageBusClient(
         'localhost',
         messageBusPort,
         dispatcher=self,
         sessionClass=self.sessionClass,
         connectionTimeout=10)
     self.client.logger.setQuietMode()
Beispiel #4
0
    def testDisconnect(self):
        messageBusLog = self.workDir + '/messagebus.log'
        messageBusMessages = self.workDir + '/messagebus.messages'
        clientLog = self.workDir + '/client-log'
        mgr = messagebus.MessageBus('', 0, logPath=messageBusLog, messagePath=messageBusMessages)
        mgr._logger.disableConsole()
        port = mgr.getPort()
        client = busclient.MessageBusClient('localhost', port, None, logPath=clientLog)
        client.logger.disableConsole()
        client.connect()
        client2 = busclient.MessageBusClient('localhost', port, None, logPath=clientLog)
        client2.logger.disableConsole()
        client2.connect()
        p = Poller(mgr, client, client2)
        while (p.writable() or not client.isRegistered()
               or not client2.isRegistered()):
            p.poll()
        client2.popMessages()

        client2.subscribe('/internal/nodes')
        while p.poll():
            pass
        client.disconnect()
        while not client2.hasMessages():
            p.poll()
        m, = client2.popMessages()
        assert(isinstance(m, messages.NodeStatus))
        assert(m.getStatus() == 'DISCONNECTED')

        client.connect()
        while not client2.hasMessages():
            p.poll()
        m, = client2.popMessages()
        assert(isinstance(m, messages.NodeStatus))
        assert(m.getStatus() == 'RECONNECTED')
        assert(m.getStatusId() == client.getSessionId())
Beispiel #5
0
 def __init__(self,
              messageBusHost,
              messageBusPort,
              cfg,
              server,
              node=None,
              logMessages=True):
     self.subscriptions = list(self.subscriptions)  # copy from class
     self.cfg = cfg
     self.server = server
     self.node = node
     if logMessages:
         messageLogPath = cfg.logDir + '/messages/%s.log' % self.name
         logPath = cfg.logDir + '/%s.log' % self.name
     else:
         messageLogPath = logPath = None
     self.bus = busclient.MessageBusClient(messageBusHost,
                                           messageBusPort,
                                           dispatcher=self,
                                           sessionClass=self.sessionClass,
                                           logPath=logPath,
                                           messageLogPath=messageLogPath,
                                           subscriptions=self.subscriptions)
     apirpc.ApiServer.__init__(self, self.bus.logger)
Beispiel #6
0
 def __init__(self, busHost='127.0.0.1', busPort=50900):
     self.bus = busclient.MessageBusClient(busHost, busPort, None)
     self.bus.logger.setQuietMode()
     self.dispatcher = rpclib.DispatcherRPCClient(self.bus)
Beispiel #7
0
def getAdminClient(host, port):
    bus = busclient.MessageBusClient(host, port, None)
    bus.logger.setQuietMode()
    return MessageBusAdminClient(bus)
Beispiel #8
0
    def testMessageBus(self):
        class MyMessage(messages.Message):
            messageType = 'MINE'

            def set(self, **params):
                self.updateHeaders(params)
        logPath = self.workDir + '/messagebus.log'
        messagePath = self.workDir + '/messagebus.messages'
        clientLog = self.workDir + '/client-log'
        mgr = messagebus.MessageBus('', 0, logPath, messagePath)
        mgr.getLogger().disableConsole()
        port = mgr.getPort()
        client = busclient.MessageBusClient('localhost', port, None, logPath=clientLog)
        client.logger.disableConsole()
        client.connect()
        client2 = busclient.MessageBusClient('localhost', port, None, logPath=clientLog)
        client2.logger.disableConsole()
        client2.connect()
        client3 = busclient.MessageBusClient('localhost', port, None, logPath=clientLog)
        client3.logger.disableConsole()
        client3.connect()
        p = Poller(mgr, client, client2, client3)
        while (p.writable() or not client.isRegistered() or not
                client2.isRegistered() or not client3.isRegistered()):
            p.poll()
        client.popMessages()
        client2.popMessages()
        client3.popMessages()

        client2.subscribe('/foo')
        client3.subscribe('/foo')
        client.subscribe('/foo?a=b')
        msg = MyMessage()
        msg.set(a='b')
        msg2 = MyMessage()
        msg2.set(c='d')
        msg3 = MyMessage()
        msg3.set(e='f')
        client2.sendMessage('/foo', msg)
        client2.sendMessage('/foo', msg2)
        client.sendMessage('/foo', msg2)
        client.sendMessage('/foo', msg3, client2.getSessionId())

        while p.poll() or not client.hasMessages() or not client2.hasMessages():
            pass
        msg, = client.popMessages()
        assert(msg.headers.a == 'b')
        assert(msg.getSessionId() == client2.getSessionId())
        assert(msg.getMessageId() == '%s:2' % client2.getSessionId())
        assert(msg.getDestination() == '/foo')
        assert(msg.getTimestamp())

        msg, two = client2.popMessages()
        assert(msg.headers.c == 'd')
        assert(msg.getSessionId() == client.getSessionId())
        assert(msg.getMessageId() == '%s:2' % client.getSessionId())
        assert(msg.getDestination() == '/foo')
        assert(msg.getTargetId() is None)
        assert(msg.getTimestamp())
        assert(two.headers.e == 'f')
        assert(two.getSessionId() == client.getSessionId())
        assert(two.getMessageId() == '%s:3' % client.getSessionId())
        assert(two.getDestination() == '/foo')
        assert(two.getTargetId() == client2.getSessionId())
        assert(two.getTimestamp())

        msgs = client3.popMessages()
        assert msg3.getMessageId() not in [x.getMessageId() for x in msgs]
Beispiel #9
0
    def __init__(self, (busHost, busPort), nodeInfo=None, logger=None):
        if not logger:
            logger = buslogger.MessageBusLogger.new(
                    'messagebus.' + self.sessionClass)
        apirpc.ApiServer.__init__(self, logger=logger)

        self.subscriptions = list(self.subscriptions)
        if nodeInfo:
            self.nodeInfo = nodeInfo
        elif self.nodeType:
            self.nodeInfo = self.nodeType()
        else:
            self.nodeInfo = None

        self.bus = busclient.MessageBusClient(busHost, busPort,
                dispatcher=self, sessionClass=self.sessionClass,
                subscriptions=self.subscriptions)
        self.bus.logger = self.bus.session.logger = logger

        self.lastTimer = time.time()
        self.onStart()

    def onStart(self):
        pass

    def onTimer(self):
        pass

    def handleRequestIfReady(self, sleepTime=1.0):
        self.bus.poll(sleepTime, maxIterations=1)
        if time.time() - self.lastTimer >= self.timerPeriod: