예제 #1
0
    def testRestore(self):
        def call(*args, **kw):
            expected = 'zcat %s/6861736868617368686173686861736868617368.tar.gz | tar -xmC /some/dir' %self.cacheDir
            self.failUnlessEqual(args, (expected,))
            self.failUnless(kw == dict(shell=True))

        mock.replaceFunctionOnce(subprocess, 'call', call)
        self.chrootCache.restore('hash' * 5, '/some/dir')
예제 #2
0
    def testRestore(self):
        def call(*args, **kw):
            expected = 'zcat %s/6861736868617368686173686861736868617368.tar.gz | tar -xmC /some/dir' % self.cacheDir
            self.failUnlessEqual(args, (expected, ))
            self.failUnless(kw == dict(shell=True))

        mock.replaceFunctionOnce(subprocess, 'call', call)
        self.chrootCache.restore('hash' * 5, '/some/dir')
예제 #3
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)
예제 #4
0
    def testStore(self):
        def call(*args, **kw):
            expected = 'tar -cC /some/dir . | gzip -1 - > %s/6861736868617368686173686861736868617368.ABC123.tar.gz' % self.cacheDir
            self.failUnlessEqual(args, (expected, ))
            self.failUnless(kw == dict(shell=True))

        def mkstemp(*args, **kw):
            return (
                os.open('/dev/null', os.O_WRONLY),
                '%s/6861736868617368686173686861736868617368.ABC123.tar.gz' %
                self.cacheDir)

        def rename(*args, **kw):
            pass

        mock.replaceFunctionOnce(subprocess, 'call', call)
        mock.replaceFunctionOnce(util, 'mkdirChain', self._mkdirChain)
        mock.replaceFunctionOnce(tempfile, 'mkstemp', mkstemp)
        mock.replaceFunctionOnce(os, 'rename', rename)
        mock.mock(ChrootManifest, 'store')
        mock.mock(locking, 'LockFile')
        self.chrootCache.store('hash' * 5, '/some/dir')
        ChrootManifest.store._mock.assertCalled(
            '/some/dir', '%s/6861736868617368686173686861736868617368.tar.gz' %
            self.cacheDir)
        locking.LockFile._mock.assertCalled(
            '%s/6861736868617368686173686861736868617368.tar.gz.lock' %
            self.cacheDir)
예제 #5
0
    def testGetChrootCache(self):
        c = servercfg.rMakeBuilderConfiguration()

        # test no setting
        self.failUnlessEqual(c.getChrootCache(), None)
        self.failUnlessEqual(c._getChrootCacheDir(), None)

        # test a valid setting
        c.configLine('chrootcache local /path/to/cache')
        chrootCache = c.getChrootCache()
        self.failUnless(isinstance(chrootCache, chrootcache.LocalChrootCache))
        self.failUnlessEqual(c._getChrootCacheDir(), '/path/to/cache')

        # test checkBuildSanity - need to mock out some bits for that
        def getpwuid(*args):
            class struct_passwd:
                pass

            p = struct_passwd()
            p.pw_name = constants.rmakeUser
            return p

        mock.replaceFunctionOnce(pwd, 'getpwuid', getpwuid)
        mock.mockMethod(c._checkDir, True)
        c.checkBuildSanity()
        self.failUnlessEqual(
            c._checkDir._mock.calls,
            [(('buildDir', '/var/rmake'), ()),
             (('chroot dir (subdirectory of buildDir)', '/var/rmake/chroots',
               'rmake', 448), ()),
             (('chroot archive dir (subdirectory of buildDir)',
               '/var/rmake/archive', 'rmake', 448), ()),
             (('chroot cache dir (subdirectory of buildDir)', '/path/to/cache',
               'rmake', 448), ())])

        # test an invalid setting
        c.configLine('chrootcache unknown /path/to/cache')
        try:
            c.getChrootCache()
            self.fail('exception expected was not raised')
        except Exception, e:
            self.failUnless(isinstance(e, errors.RmakeError))
            start = "Unknown chroot cache type of 'unknown' specified. Valid types are:"
            if not str(e).startswith(start):
                self.fail("%r should start with %r" % (str(e), start))
예제 #6
0
    def testHasChroot(self):
        def isfile(*args, **kw):
            self.failUnless(kw == {})
            expected = '%s/6861736868617368686173686861736868617368.tar.gz' %self.cacheDir
            self.failUnlessEqual(args, (expected,))
            return True

        mock.replaceFunctionOnce(os.path, 'isfile', isfile)
        self.failUnless(self.chrootCache.hasChroot('hash' * 5))

        def isfile(*args, **kw):
            self.failUnless(len(args) == 1)
            self.failUnless(kw == {})
            self.failUnless(args[0].endswith('/work/chrootcache/6861736868617368686173686861736868617368.tar.gz'))
            return False

        mock.replaceFunctionOnce(os.path, 'isfile', isfile)
        self.failUnless(not self.chrootCache.hasChroot('hash' * 5))
예제 #7
0
    def testHasChroot(self):
        def isfile(*args, **kw):
            self.failUnless(kw == {})
            expected = '%s/6861736868617368686173686861736868617368.tar.gz' % self.cacheDir
            self.failUnlessEqual(args, (expected, ))
            return True

        mock.replaceFunctionOnce(os.path, 'isfile', isfile)
        self.failUnless(self.chrootCache.hasChroot('hash' * 5))

        def isfile(*args, **kw):
            self.failUnless(len(args) == 1)
            self.failUnless(kw == {})
            self.failUnless(args[0].endswith(
                '/work/chrootcache/6861736868617368686173686861736868617368.tar.gz'
            ))
            return False

        mock.replaceFunctionOnce(os.path, 'isfile', isfile)
        self.failUnless(not self.chrootCache.hasChroot('hash' * 5))
예제 #8
0
    def testGetChrootCache(self):
        c = servercfg.rMakeBuilderConfiguration()

        # test no setting
        self.failUnlessEqual(c.getChrootCache(), None)
        self.failUnlessEqual(c._getChrootCacheDir(), None)

        # test a valid setting
        c.configLine('chrootcache local /path/to/cache')
        chrootCache = c.getChrootCache()
        self.failUnless(isinstance(chrootCache, chrootcache.LocalChrootCache))
        self.failUnlessEqual(c._getChrootCacheDir(), '/path/to/cache')

        # test checkBuildSanity - need to mock out some bits for that
        def getpwuid(*args):
            class struct_passwd:
                pass
            p = struct_passwd()
            p.pw_name = constants.rmakeUser
            return p
        mock.replaceFunctionOnce(pwd, 'getpwuid', getpwuid)
        mock.mockMethod(c._checkDir, True)
        c.checkBuildSanity()
        self.failUnlessEqual(c._checkDir._mock.calls,
                             [
            (('buildDir', '/var/rmake'), ()),
            (('chroot dir (subdirectory of buildDir)', '/var/rmake/chroots', 'rmake', 448), ()),
            (('chroot archive dir (subdirectory of buildDir)', '/var/rmake/archive', 'rmake', 448), ()),
            (('chroot cache dir (subdirectory of buildDir)', '/path/to/cache', 'rmake', 448), ())
            ])

        # test an invalid setting
        c.configLine('chrootcache unknown /path/to/cache')
        try:
            c.getChrootCache()
            self.fail('exception expected was not raised')
        except Exception, e:
            self.failUnless(isinstance(e, errors.RmakeError))
            start = "Unknown chroot cache type of 'unknown' specified. Valid types are:"
            if not str(e).startswith(start):
                self.fail("%r should start with %r" % (str(e), start))
예제 #9
0
    def testStore(self):
        def call(*args, **kw):
            expected = 'tar cSpf - -C /some/dir . | gzip -1 - > %s/6861736868617368686173686861736868617368.ABC123.tar.gz' %self.cacheDir
            self.failUnlessEqual(args, (expected,))
            self.failUnless(kw == dict(shell=True))

        def mkstemp(*args, **kw):
            return (
                os.open('/dev/null', os.O_WRONLY),
                '%s/6861736868617368686173686861736868617368.ABC123.tar.gz' %
                    self.cacheDir)

        def rename(*args, **kw):
            pass

        mock.replaceFunctionOnce(subprocess, 'call', call)
        mock.replaceFunctionOnce(util, 'mkdirChain', self._mkdirChain)
        mock.replaceFunctionOnce(tempfile, 'mkstemp', mkstemp)
        mock.replaceFunctionOnce(os, 'rename', rename)
        self.chrootCache.store('hash' * 5, '/some/dir')