Exemplo n.º 1
0
 def testDispatcherServerStopFull(self):
     self.startRmakeServer(multinode=True)
     self.startNode()
     trv = self.addComponent('sleep:source', '1.0',
                             [('sleep.recipe', sleepRecipe)])
     name, version, flavor = trv.getNameVersionFlavor()
     flavor = deps.parseFlavor('is:x86')
     buildTrove = self.newBuildTrove(1, name, version, flavor)
     m = mnmessages.BuildCommand('CMD-1', self.buildCfg, 1, buildTrove, [],
                                 [], self.cfg.buildLabel)
     admin = self.getAdminClient(self.rmakeCfg.messageBusPort)
     admin.sendMessage('/command', m)
     count = 0
     while not admin.listNodes() and count < 180:
         time.sleep(.1)
         count += .1
     nodeId = admin.listNodes()[0]
     count = 0
     #print 'Waiting for command to start'
     while not admin.listNodeCommands(nodeId)[1] and count < 180:
         time.sleep(.1)
         count += .1
     m = mnmessages.StopCommand('CMD-2', 1, targetCommandId='CMD-1')
     admin.sendMessage('/command', m)
     #print 'Waiting for command to die'
     while admin.listNodeCommands(nodeId)[1] and count < 180:
         time.sleep(.1)
         count += .1
         # ok, the stop command has finished, now that must be communicated
         # to the dispatcher.
     #print 'Waiting dispatcher to acknowledge'
     while admin.listAssignedCommands() and count < 180:
         time.sleep(.1)
         count += .1
Exemplo n.º 2
0
 def makeCommandMessage(self, num, jobId, troveTup, buildReqs=[]):
     buildTrove = self.newBuildTrove(jobId, *troveTup)
     commandId = 'CMD-%s' % num
     messageId = 'MSG-%s' % commandId
     m = mnmessages.BuildCommand(commandId, self.buildCfg, jobId,
                               buildTrove, buildReqs, [], 
                               self.cfg.buildLabel)
     m.stamp(messageId, 'SND-' + messageId, time.time())
     return m
Exemplo n.º 3
0
 def buildTrove(self, buildCfg, jobId, buildTrove, buildReqs, crossReqs,
                targetLabel, logData, builtTroves=None, bootstrapReqs=()):
     commandId = self.idgen.getBuildCommandId(buildTrove)
     m = messages.BuildCommand(commandId, buildCfg, jobId, buildTrove,
                               buildReqs, crossReqs, targetLabel, logData,
                               bootstrapReqs, builtTroves)
     self.bus.sendMessage('/command', m)
     self.bus.subscribe('/commandstatus?commandId=%s' % commandId)
     self._commands[commandId] = m
Exemplo n.º 4
0
    def testStopCommandFull(self):
        from rmake.messagebus import messages
        from rmake.multinode import messages as mnmessages
        # do one build from start -> finish to check out polling, etc.
        port = self.startMessageBus()
        node = self.startNode(messageBusPort=port)
        admin = self.getAdminClient(port)
        clients = admin.listMessageBusClients()
        nodeId = [ x[0] for x in clients.items() if x[1] == 'WORKER' ][0]

        # send a build command - we'll listen for a commandStatus
        # command.
        trv = self.addComponent('sleep:source', '1',
                                [('sleep.recipe', rmakehelp.sleepRecipe)])
        buildTrove = self.newBuildTrove(1, *trv.getNameVersionFlavor())

        m = mnmessages.BuildCommand('CMD-1', self.buildCfg, 1, buildTrove, [],
                                    [], self.cfg.buildLabel,
                                    targetNode=nodeId)
        subscriber = self.createEventSubscriber(port)
        admin.sendMessage('/command', m)
        count = 0
        while not admin.listNodeCommands(nodeId) and count < 30:
            subscriber.poll()
            time.sleep(.1)
            count += .1
        assert(count != 30)
        count = 0
        while not subscriber._troveBuilding and count < 30:
            subscriber.poll()
            time.sleep(.1)
            count += .1
        assert(count != 30)
        m = mnmessages.StopCommand('CMD-2', 1,
                                   targetCommandId='CMD-1',
                                   targetNode=nodeId)
        admin.sendMessage('/command', m)
        count = 0
        while count < 30 and admin.listNodeCommands(nodeId)[1]:
            subscriber.poll()
            time.sleep(.1)
            count += .1
        assert(count != 30)
        troveTup = buildTrove.getNameVersionFlavor()
        subscriber.assertTroveBuilding(1, *troveTup)
        subscriber.poll()
        count = 0
        while count < 30 and not subscriber._troveFailed:
            subscriber.poll()
            time.sleep(.1)
            count += .1
        subscriber.assertTroveFailed(1, *troveTup)
        reason = subscriber.getFailureReason(1, *troveTup)
        assert(str(reason) == 'Failed while building: Stop requested')
Exemplo n.º 5
0
    def testNodeServer(self):
        from rmake.messagebus import messages
        from rmake.multinode import messages as mnmessages
        from rmake.multinode import workernode
        # test how the node responds to various messages sent in from our
        # fake client.
        server, sessionClient = self._setupMockNode()
        trv = self.addComponent('simple:source', '1',
                                [('simple.recipe', recipes.simpleRecipe)])

        # send a build command
        buildTrove = self.newBuildTrove(1, *trv.getNameVersionFlavor())
        m = mnmessages.BuildCommand('CMD-1', self.buildCfg, 1, buildTrove, [],
                                    [], self.cfg.buildLabel,
                                    targetNode='WORKER-foo')

        # this should result in the command being queued...
        mock.mockMethod(server.queueCommand)
        mock.mockMethod(server.chrootManager.getRootFactory)
        sessionClient.handle_message(m)
        commandClass = server.queueCommand._mock.calls[0][0][0]
        self.assertEquals(commandClass, command.BuildCommand)
        commandClass = mock.mockClass(command.BuildCommand,
                                      mock_enable=['pid'],
                                      getCommandId=lambda: 'CMD-1',
                                      isErrored=lambda: False)
        server.queueCommand._mock.method(commandClass, self.cfg, 1, 'CMD-1')
        assert(server.listQueuedCommands())

        # pretend we forked this command...
        mock.mockFunctionOnce(os, 'fork', 342)
        server._serveLoopHook()
        assert(server.listCommands())
        # and now it's died...
        mock.mockFunctionOnce(os, 'waitpid', (342, 0))
        server._serveLoopHook()
        assert(not server.listCommands())
        self._check(sessionClient, mnmessages.CommandStatus,
                    destination='/commandstatus', commandId='CMD-1',
                    status=mnmessages.CommandStatus.COMPLETED)

        # let's create another command, one that fails on initialization
        commandClass = command.Command
        def _raise(*args, **kw):
            raise RuntimeError('foo')
        mock.replaceFunctionOnce(commandClass, '__init__', _raise)
        server.queueCommand._mock.method(commandClass, self.cfg, 'CMD-1')

        server._serveLoopHook()
        self._check(sessionClient, mnmessages.CommandStatus,
                    destination='/commandstatus', commandId='CMD-1',
                    status=mnmessages.CommandStatus.ERROR)
Exemplo n.º 6
0
    def testNodeServerFull(self):
        from rmake.messagebus import messages
        from rmake.multinode import messages as mnmessages
        # do one build from start -> finish to check out polling, etc.
        port = self.startMessageBus()
        node = self.startNode(messageBusPort=port)
        admin = self.getAdminClient(port)
        clients = admin.listMessageBusClients()
        nodeId = [ x[0] for x in clients.items() if x[1] == 'WORKER' ][0]


        # send a build command - we'll listen for a commandStatus
        # command.
        trv = self.addComponent('simple:source', '1',
                                [('simple.recipe', recipes.simpleRecipe)])
        buildTrove = self.newBuildTrove(1, *trv.getNameVersionFlavor())

        m = mnmessages.BuildCommand('CMD-1', self.buildCfg, 1, buildTrove, [],
                                    [], self.cfg.buildLabel,
                                    targetNode=nodeId)
        subscriber = self.createEventSubscriber(port)
        admin.sendMessage('/command', m)
        while not admin.listNodeCommands(nodeId)[1]:
            subscriber.poll()
            time.sleep(.1)
        while admin.listNodeCommands(nodeId)[1]:
            subscriber.poll()
            time.sleep(.1)
        print "Command Done"
        subscriber.poll()
        # we should have gotten a troveBuilding message at some point,
        # and then a troveBuilt!
        troveTup = buildTrove.getNameVersionFlavor()
        subscriber.assertTroveBuilding(1, *troveTup)
        subscriber.assertTroveBuilt(1, *troveTup)
        binaries = subscriber.getTrovesBuilt(1, *troveTup)
        repos = self.openRepository()
        repos.getTroves(binaries, withFiles=False)