Exemple #1
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)
Exemple #2
0
    def testNodeRPCClient(self):
        from rmake.multinode import workernode
        from rmake.worker import command
        server, sessionClient = self._setupMockNode()
        mock.mockMethod(server.client._logger.logRPCCall)
        rpcClient = workernode.WorkerNodeRPCClient(server.client.getBusClient(),
                                                   sessionClient.sessionId)
        assert(tuple(rpcClient.listCommands()) == ([], []))

        commandClass = mock.mockClass(command.BuildCommand,
                                      getCommandId=lambda: 'CMD-1',
                                      mock_enable=['pid', 'commandInfo'])
        server.queueCommand(commandClass, None, 'CMD-1')
        mock.mockFunctionOnce(os, 'fork', 342)
        server._serveLoopHook()
        self.assertEquals(rpcClient.listCommands(), ([], [('CMD-1', 342)]))
Exemple #3
0
    def testEnablePlatformProjectNoMirror(self):
        self._mockReposMgr()
        p = self._getPlatform()
        productId = self._getProductId()
        self.db.db.projects.update(productId, external=1)

        mock.mockFunctionOnce(self.db.db.projects, 'getProjectIdByFQDN',
            productId)

        p2 = self.db.updatePlatform(p.platformId, p)
        plat = self.db.db.platforms.get(p.platformId)

        # assert projectId was set for the platform
        self.assertTrue(plat['projectId'] is not None)
        # assert productId matches the product we created
        self.assertEquals(plat['projectId'], productId)

        mirrorId = self.db.db.inboundMirrors.getIdByColumn('targetProjectId',
                    productId)

        # should be the first mirror created
        self.assertEquals(mirrorId, 1)